-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will replace splitchapters.sh and pickchapter.sh with a unified approach.
- Loading branch information
1 parent
e27018c
commit a19ebd7
Showing
4 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/igawk | ||
|
||
BEGIN { | ||
chapter="" | ||
pos=0 | ||
last="" | ||
} | ||
|
||
/^==+$/ { | ||
if (length(last) == length($0)) { | ||
chapter_done(chapter); | ||
chapterindex[nchapterindex++] = chapter | ||
subchapterindex[nsubchapterindex++] = chapter | ||
chapter=last; | ||
subchapter=chapter | ||
} | ||
} | ||
|
||
/^--+$/ || /^\.\.+$/ { | ||
if (length(last) == length($0)) { | ||
sub_chapter_done(subchapter); | ||
subchapterindex[nsubchapterindex++] = chapter | ||
subchapter=last; | ||
} | ||
} | ||
|
||
{ | ||
content[pos++] = last | ||
content["s:"subchapter,relpos["s:"subchapter]++] = last | ||
content[chapter,relpos[chapter]++] = last | ||
last = $0 | ||
} | ||
|
||
END { | ||
sub_chapter_done(subchapter); | ||
chapter_done(chapter); | ||
chapterindex[nchapterindex++] = chapter | ||
subchapterindex[nsubchapterindex++] = chapter | ||
} | ||
|
||
function print_chapter(chap,output, i) { | ||
for (i=0;i<relpos[chap];i++) { | ||
if (output != "") { | ||
printf("%s\n",content[chap,i]) >> output | ||
} else { | ||
printf("%s\n",content[chap,i]) | ||
} | ||
} | ||
} | ||
|
||
function print_sub_chapter(chap,output) { | ||
print_chapter("s:"chap,output); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/igawk -f | ||
|
||
@include util/parse.igawk | ||
|
||
function chapter_done(chap) { | ||
} | ||
|
||
function sub_chapter_done(chap) { | ||
} | ||
|
||
END { | ||
if (include != "*") { | ||
print_chapter(""); | ||
split(include,includea,","); | ||
for (a in includea) { | ||
print_chapter(includea[a]); | ||
} | ||
} else { | ||
for (i=0; i<nchapterindex; i++) { | ||
print_chapter(chapterindex[i]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/igawk -f | ||
|
||
# Splits chapters into individual files for each chapter and create an | ||
# index page for sphinx. | ||
# | ||
# Usage: util/splitchapters.igawk -v dst=src/ < varnish_book.rst | ||
|
||
@include util/parse.igawk | ||
|
||
BEGIN { | ||
aidx = dst "/build/autoindex.rst" | ||
print ".. toctree::" > aidx | ||
print "\t:maxdepth: 1" >> aidx | ||
print "" >> aidx | ||
} | ||
|
||
function chapter_done(chap) { | ||
if (chap == "") { | ||
return | ||
} | ||
chapterclean=chap | ||
gsub("[^a-zA-Z0-9]","_",chapterclean) | ||
path = dst chapterclean ".rst" | ||
print ".. include:: util/param.rst" > path | ||
print "" >> path | ||
print_chapter(chap,path) | ||
print "\t" chapterclean >> aidx | ||
} | ||
|
||
function sub_chapter_done(chap) { | ||
} | ||
|