doc: Fix appending C comments in texinfo docs.
[pwmd.git] / doc / extract-help-text.awk
blob1b0dd9826e5003293ea0b7f7de68e1f1312be3e1
1 # Read in commands.c and add texinfo commands. See Makefile.am.
3 BEGIN {
6 while (getline > 0)
7 if ($0 ~ /!BEGIN-HELP-TEXT!/) {
8 list_total = 1
10 while (getline > 0)
11 if ($0 ~ /!END-HELP-TEXT!/) {
12 exit
14 else if ($0 ~ /new_command\(/) {
15 desc = ""
16 getline
17 sub(/^\"/,"")
18 idx = index($0,"\\n")+7;
19 chapter = substr($0,idx,length());
20 sub(/ \*\//,"",chapter);
21 sub(/\\n\".*$/,"")
22 name = sub(/^[^ ]*/,"&");
23 info = "@node " $name ", !NEXT!, !PREV!, Commands\n"
24 info = info "@chapter " chapter "\n"
25 info = info "@cindex " $name " command\n"
26 info = info "Syntax:\n"
27 info = info "@example\n"
28 info = info $0 "\n"
29 info = info "@end example\n"
30 list[list_total "," "name"] = $name
32 while (getline > 0)
33 if ($0 ~ /^\)\);/) {
34 break
36 else {
37 gsub(/\\n\"$/,"")
38 gsub(/"/,"")
39 gsub(/\n/,"")
40 desc = desc $0 "\n"
43 desc = desc "\n"
44 list[list_total "," "chapter"] = chapter
45 list[list_total "," "info"] = info
46 list[list_total "," "desc"] = desc
47 list_total++
54 # Borrowed from http://awk.info/?TenLiners
56 function qsort(A, left, right, i, last) {
57 if (left >= right)
58 return
59 swap(A, left, left+int((right-left+1)*rand()))
60 last = left
61 for (i = left+1; i <= right; i++)
62 if (A[i "," "name"] < A[left "," "name"])
63 swap(A, ++last, i)
64 swap(A, left, last)
65 qsort(A, left, last-1)
66 qsort(A, last+1, right)
69 function swap(A, i, j, hrm) {
70 name = A[i "," "name"];
71 chapter = A[i "," "chapter"];
72 info = A[i "," "info"];
73 desc = A[i "," "desc"];
74 A[i "," "name"] = A[j "," "name"]
75 A[i "," "chapter"] = A[j "," "chapter"]
76 A[i "," "info"] = A[j "," "info"]
77 A[i "," "desc"] = A[j "," "desc"]
78 A[j "," "name"] = name;
79 A[j "," "chapter"] = chapter;
80 A[j "," "info"] = info;
81 A[j "," "desc"] = desc;
84 END {
85 qsort(list, 1, list_total-1)
87 for (t = 1; t < list_total; t++) {
88 if (t == 1) {
89 sub(/!PREV!/, "", list[t "," "info"])
91 else {
92 sub(/!PREV!/, list[t-1 "," "name"], list[t "," "info"])
95 if (t == list_total-1) {
96 sub(/!NEXT!/, "", list[t "," "info"])
98 else {
99 sub(/!NEXT!/, list[t+1 "," "name"], list[t "," "info"])
102 print list[t "," "info"] "\n" list[t "," "desc"]
103 print "* " list[t "," "name"] "::" list[t "," "chapter"] > "menu.texi.in"
106 close("menu.texi.in")