FSF GCC merge 02/23/03
[official-gcc.git] / libstdc++-v3 / docs / html / makedoc.awk
blob9da77d9c1a1f33e1501f8511a584e63630e1b430
1 # Take apart bits of HTML and puts them back together again in new and
2 # fascinating ways. Copyright (C) 2002 Free Software Foundation, Inc.
3 # Contributed by Phil Edwards <pme@gcc.gnu.org>. Simple two-state automaton
4 # inspired by Richard Henderson's gcc/mkmap-symver.awk.
6 # 'file' is the name of the file on stdin
7 # 'title' is the text to print at the start of the list
9 BEGIN {
10 state = "looking";
11 entries = 0;
12 printf (" <li>%s\n", title);
13 printf (" <ul>\n");
16 # Searching for the little table of contents at the top.
17 state == "looking" && /^<h1>Contents/ {
18 state = "entries";
19 next;
22 # Ignore everything else up to that point.
23 state == "looking" {
24 next;
27 # An entry in the table of contents. Pull that line apart.
28 state == "entries" && /<li>/ {
29 extract_info($0);
30 next;
33 # End of the list. Don't bother reading the rest of the file. (It could
34 # also contain more <li>'s, so that would be incorrect as well as wasteful.)
35 state == "entries" && /^<\/ul>/ {
36 exit;
39 END {
40 for (i = 0; i < entries; i++)
41 printf (" %s\n", entry[i]);
42 printf (" </ul>\n </li>\n\n");
45 function extract_info(line) {
46 # thistarget will be things like "#5" or "elsewhere.html"
47 match(line,"href=\".*\"");
48 thistarget = substr(line,RSTART+6,RLENGTH-7);
50 # take apart the filename
51 split(file,X,"/");
52 if (thistarget ~ /^#/) {
53 # local name, use directory and filename
54 target = file thistarget
55 } else {
56 # different file, only use directory
57 target = X[1] "/" thistarget
60 # visible text
61 gsub("</a></li>","",line);
62 start = index(line,"\">") + 2;
63 thistext = substr(line,start);
65 # Assemble and store the HTML for later output.
66 entry[entries++] = "<li><a href=\"" target "\">" thistext "</a></li>"
69 # vim:sw=2