Browse files

Build: Add a better parsing method

This will replace splitchapters.sh and pickchapter.sh with a unified
approach.
  • Loading branch information...
1 parent e27018c commit a19ebd756ea47ee5ce5ac15e5873125a9facfc73 @KristianLyng KristianLyng committed Mar 27, 2012
Showing with 112 additions and 4 deletions.
  1. +4 −4 Makefile
  2. +53 −0 util/parse.igawk
  3. +23 −0 util/pickchapter2.igawk
  4. +32 −0 util/splitchapters.igawk
View
8 Makefile
@@ -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
@@ -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
@@ -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
View
53 util/parse.igawk
@@ -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);
+}
View
23 util/pickchapter2.igawk
@@ -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]);
+ }
+ }
+}
View
32 util/splitchapters.igawk
@@ -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.