correct macro parameter parentizing
[nobug.git] / doc / asciidoc.pawk
blob130fba8143e19fab47c3e34dadfb4d4d98469829
2 # include asciidoc comments about filename and linenumber in generated document
3 match($0, com "([[:alpha:]][[:alnum:]_]*)(([.]([^[:space:]]*)))?", p) {
4     if(p[1] != old_index)
5     {
6         old_index = p[1]
7         append(p[1], p[4], "// "FILENAME ":" FNR " //")
8     }
11 # Create an asciidoc paragraph and index entry
12 #             Sec       Name  Index Explanation
13 match($0, com"(.*) PARA (.*); *(.*); *(.*)", p) {
14     if(p[3])
15     {
16         if (p[4]) append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
17         append(p[1],"","[["p[3]"]]")
18     }
19     append(p[1],"","."p[2])
20     next
23 BEGIN {
24     asciidoc_header[0]="="
25     asciidoc_header[1]="-"
26     asciidoc_header[2]="~"
27     asciidoc_header[3]="^"
28     asciidoc_header[4]="+"
29     asciidoc_level=1
33 # Create an asciidoc headline and index entry
34 #             Sec      Typ Name  Index Explanation
35 match($0, com"(.*) HEAD([^ ]+) (.*); *(.*); *(.*)", p) {
36     if (p[2] == "==")
37         p[2] = asciidoc_header[asciidoc_level]
38     else if (p[2] == "++")
39     {
40         if (asciidoc_level < 4) ++asciidoc_level
41         p[2] = asciidoc_header[asciidoc_level]
42     }
43     else if (p[2] == "--")
44     {
45         if (asciidoc_level > 1) --asciidoc_level
46         p[2] = asciidoc_header[asciidoc_level]
47     }
48     else
49     {
50         for (n_HEAD = 0; n_HEAD <=4; ++n_HEAD) {
51             if (p[2] == asciidoc_header[n_HEAD]) {
52                 asciidoc_level = n_HEAD
53                 break
54             }
55         }
56     }
58     if (p[3])
59     {
60         if (p[4])
61         {
62             if (p[5]) append("index", tolower(p[4]), "xref:"p[4]"["p[3]"]:: "p[5])
63             append(p[1],"","[["p[4]"]]")
64         }
65         append(p[1],"",p[3])
66         append(p[1],"",gensub(/./, p[2], "g", p[3]))
67     }
68     next
72 # Create an asciidoc index and anchor
73 #             Sec        Title Index Explanation
74 match($0, com"(.*) INDEX (.*); (.*); (.*)", p) {
75     if (p[4]) append("index", tolower(p[3]), "xref:"p[3]"["p[2]"]:: "p[4])
76     append(p[1],"","[["p[3]"]]")
77     next