Skip to content

Commit

Permalink
Build: Add a better parsing method
Browse files Browse the repository at this point in the history
This will replace splitchapters.sh and pickchapter.sh with a unified
approach.
  • Loading branch information
KristianLyng committed Mar 27, 2012
1 parent e27018c commit a19ebd7
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RST2PDF=/usr/bin/rst2pdf
BDIR=build
CACHECENTERC=../varnish-cache/bin/varnishd/cache_center.c
PICK = "./util/pickchapter.sh"
PICK = "./util/pickchapter2.igawk"

# The following are chapter lists for the relevant versions of the PDFs.
# Please note that they need to be exact. No extra spaces, case sensitive
Expand Down Expand Up @@ -57,7 +57,7 @@ sphinx: ${common} src/conf.py
rm $$a; \
touch $$a; \
done
util/splitchapters.sh ${rstsrc} src/
util/splitchapters.igawk -v dst=src/ < ${rstsrc}
sed -i 's/\.\. class:: handout//' src/*.rst
sphinx-build -b html -d build/doctrees src/ build/html

Expand Down Expand Up @@ -95,11 +95,11 @@ ${BDIR}:

${BDIR}/varnish-%.pdf: ${common} ui/pdf.style
@echo Building PDFs for $*...
@${PICK} ${$*} | ${RST2PDF} -s ui/pdf.style -b2 -o $@
@${PICK} -v include=${$*} < ${rstsrc} | ${RST2PDF} -s ui/pdf.style -b2 -o $@

${BDIR}/varnish_slide-%.pdf: ${common} ui/pdf_slide.style
@echo Building PDF slides for $*...
@${PICK} ${$*} | ./util/strip-class.gawk | ${RST2PDF} -s ui/pdf_slide.style -b2 -o $@
@${PICK} -v include=${$*} < ${rstsrc} | ./util/strip-class.gawk | ${RST2PDF} -s ui/pdf_slide.style -b2 -o $@

util/param.rst:
( sleep 2; echo param.show ) | varnishd -n /tmp/meh -a localhost:2211 -d | gawk -v foo=0 '(foo == 2) && (/^[a-z]/) { printf ".. |default_"$$1"| replace:: "; gsub($$1,""); print; } /^200 / { foo++;}' > util/param.rst
Expand Down
53 changes: 53 additions & 0 deletions util/parse.igawk
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);
}
23 changes: 23 additions & 0 deletions util/pickchapter2.igawk
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]);
}
}
}
32 changes: 32 additions & 0 deletions util/splitchapters.igawk
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) {
}

0 comments on commit a19ebd7

Please sign in to comment.