Fix a few 'gcc -fanalyzer' warnings.
[pwmd.git] / doc / extract-help-text.awk
blob40b9e8f379c2dbe49577bdba033eb221004eff18
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
9 name_length = 0
11 while (getline > 0)
12 if ($0 ~ /!END-HELP-TEXT!/) {
13 exit
15 else if ($0 ~ /new_command\(/) {
16 desc = ""
17 getline
18 sub(/^"/,"")
19 idx = index($0,"\\n")+7;
20 chapter = substr($0,idx,length())
21 sub(/ \*\//,"",chapter)
22 sub(/\\n".*$/,"")
23 gsub(/\\"/,"\"")
24 name = sub(/^[^ ]*/,"&")
26 if (length($name) > name_length)
27 name_length = length($name)
29 info = "@node " $name ", !NEXT!, !PREV!, Commands\n"
30 info = info "@section " chapter "\n"
31 info = info "@cindex " $name " command\n"
32 info = info "Syntax:\n"
33 info = info "@example\n"
34 info = info $0 "\n"
35 info = info "@end example\n"
36 list[list_total "," "name"] = $name
38 while (getline > 0)
39 if ($0 ~ /^\)\);/) {
40 break
42 else {
43 gsub(/\\n"$/,"")
44 gsub(/"/,"")
45 gsub(/\n/,"")
46 desc = desc $0 "\n"
49 desc = desc "\n"
50 list[list_total "," "chapter"] = chapter
51 list[list_total "," "info"] = info
52 list[list_total "," "desc"] = desc
53 list_total++
60 # Borrowed from http://awk.info/?TenLiners
62 function qsort(A, left, right, i, last) {
63 if (left >= right)
64 return
65 swap(A, left, left+int((right-left+1)*rand()))
66 last = left
67 for (i = left+1; i <= right; i++)
68 if (A[i "," "name"] < A[left "," "name"])
69 swap(A, ++last, i)
70 swap(A, left, last)
71 qsort(A, left, last-1)
72 qsort(A, last+1, right)
75 function swap(A, i, j, hrm) {
76 name = A[i "," "name"];
77 chapter = A[i "," "chapter"];
78 info = A[i "," "info"];
79 desc = A[i "," "desc"];
80 A[i "," "name"] = A[j "," "name"]
81 A[i "," "chapter"] = A[j "," "chapter"]
82 A[i "," "info"] = A[j "," "info"]
83 A[i "," "desc"] = A[j "," "desc"]
84 A[j "," "name"] = name;
85 A[j "," "chapter"] = chapter;
86 A[j "," "info"] = info;
87 A[j "," "desc"] = desc;
90 END {
91 qsort(list, 1, list_total-1)
93 print "@menu" > "menu.texi"
94 for (t = 1; t < list_total; t++) {
95 if (t == 1) {
96 sub(/!PREV!/, "", list[t "," "info"])
98 else {
99 sub(/!PREV!/, list[t-1 "," "name"], list[t "," "info"])
102 if (t == list_total-1) {
103 sub(/!NEXT!/, "", list[t "," "info"])
105 else {
106 sub(/!NEXT!/, list[t+1 "," "name"], list[t "," "info"])
109 print list[t "," "info"] "\n" list[t "," "desc"]
111 n = name_length - length(list[t "," "name"])
112 sp = " "
113 while (n--)
114 sp = sp " "
116 print "* " list[t "," "name"] "::" sp list[t "," "chapter"] >> "menu.texi"
119 print "@end menu" > "menu.texi"
120 close("menu.texi")