1 # $Id: splitinfo.gawk 34143 2014-05-20 17:30:45Z karl $
2 # Public domain. Originally written 2014 by Karl Berry.
3 # Split chapter 2 of plain text output from makeinfo,
4 # making each section into a separate README file.
7 lastline = ""; # have to read one line ahead
8 outfile = ""; # where we are currently outputting
12 if (/^[*]+$/) { # starting new chapter
13 # if we're at the index or an appendix, quit.
14 if (lastline == "Index" || lastline ~ /^Appendix /) exit (0);
16 # move on unless starting a chapter we want (not top, intro, etc.)
17 if (lastline !~ /^[2-9]/) next;
19 # ok, we want this chapter. if we had a file open already, close it.
20 if (outfile) close (outfile);
22 # turn chapter title into filename and start new.
23 outfile = tolower (lastline); # all lowercase
24 chapnum = substr (outfile, 0, 1); # chapter number
25 sub ("^. ", "", outfile); # remove chapnum and following space
26 sub (" .*", "", outfile); # remove next space and everything
27 # after, leaving just the first word.
29 # start numbering the README files at 0.
30 chapnum = chapnum - 2;
31 outfile = "README." chapnum outfile; # prefix "README.
33 print "(This file was generated by makeinfo and splitinfo.gawk.)">outfile;
34 print "(Released under the old-style GNU documentation license;" >outfile;
35 print " see sources or other output files for full text.)" >outfile;
37 print lastline >outfile;
38 # $0 will be printed as lastline, next time through.
42 print lastline >outfile;