| 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. |
| 5 |
|
| 6 |
BEGIN { |
| 7 |
lastline = ""; # have to read one line ahead |
| 8 |
outfile = ""; # where we are currently outputting |
| 9 |
} |
| 10 |
|
| 11 |
{ |
| 12 |
if (/^[*]+$/) { # starting new chapter |
| 13 |
# if we're at the index or an appendix, quit. |
| 14 |
if (lastline == "Index" || lastline ~ /^Appendix /) exit (0); |
| 15 |
|
| 16 |
# move on unless starting a chapter we want (not top, intro, etc.) |
| 17 |
if (lastline !~ /^[2-9]/) next; |
| 18 |
|
| 19 |
# ok, we want this chapter. if we had a file open already, close it. |
| 20 |
if (outfile) close (outfile); |
| 21 |
|
| 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. |
| 28 |
|
| 29 |
# start numbering the README files at 0. |
| 30 |
chapnum = chapnum - 2; |
| 31 |
outfile = "README." chapnum outfile; # prefix "README. |
| 32 |
# |
| 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; |
| 36 |
print "" >outfile; |
| 37 |
print lastline >outfile; |
| 38 |
# $0 will be printed as lastline, next time through. |
| 39 |
|
| 40 |
# splitting output. |
| 41 |
} else if (outfile) { |
| 42 |
print lastline >outfile; |
| 43 |
} |
| 44 |
|
| 45 |
lastline = $0; |
| 46 |
} |