Fix previous commit.
[pwmd.git] / doc / extract-help-text.awk
blobb99f405e7d4eb691a99a34cb466dfc4f9d3cf55f
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 "@chapter " 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 for (t = 1; t < list_total; t++) {
94 if (t == 1) {
95 sub(/!PREV!/, "", list[t "," "info"])
97 else {
98 sub(/!PREV!/, list[t-1 "," "name"], list[t "," "info"])
101 if (t == list_total-1) {
102 sub(/!NEXT!/, "", list[t "," "info"])
104 else {
105 sub(/!NEXT!/, list[t+1 "," "name"], list[t "," "info"])
108 print list[t "," "info"] "\n" list[t "," "desc"]
110 n = name_length - length(list[t "," "name"])
111 sp = " "
112 while (n--)
113 sp = sp " "
115 print "* " list[t "," "name"] "::" sp list[t "," "chapter"] > "menu.texi.in"
118 close("menu.texi.in")