Debian Codegraph @

doc/man/tools/getnames

raw
1 #! /usr/bin/nawk -f
2 #
3 # AWK script: getnames
4 #
5 # Usage: getnames opt=<language option letter> file ...
6 #
7 # Generates a list of file names followed by the commands that are linked
8 # to the file name. Output is piped to the awk script addinst
9 # Called from manrules.
10 #
11
12 BEGIN {
13 err = 0
14 }
15
16 NF == 2 && $1 == ".SH" && $2 == "NAME" {
17 getline
18
19 # Process the man pages from MIPS
20 if ($1 == ".nf") {
21 NAMELIST = ""
22 getline
23 while ($1 != ".fi") {
24 gsub(/\t/, "", $0)
25 gsub(/ /, "", $0)
26 gsub(/,/, " ", $0)
27 gsub(/:/, "", $0)
28 gsub(/\\f./, "", $0)
29 gsub(/\\s[-+]?[0-9]/, "", $0)
30 if (split($0, NAMES, "\\") == 1)
31 error("missing \\- in NAMES line")
32 else
33 NAMELIST = NAMELIST NAMES[1] " "
34 getline
35 }
36 outline(FILENAME, NAMELIST)
37
38 }
39 else if ($1 == ".Op") {
40 # Process the GL man pages with .Op's
41 if (opt == "") {
42 error("getnames requires opt=<language option letter> for GL "\
43 "man pages -- aborting")
44 exit(1)
45 }
46 # state values:
47 # 0 = outside .Op pair
48 # 1 = inside .Op for our option
49 # 2 = inside .Op for another option
50 # 3 = abort
51 # 4 = done
52 state = parseln() - 1;
53 NAMELIST = ""
54 while (state < 3) {
55 if (state == 1) {
56 if ($1 == ".B") {
57 gsub(/,/, "", $0)
58 gsub(/"/, "", $0)
59 gsub(/\.B/, "", $0)
60 gsub(/\\f./, "", $0)
61 gsub(/\\s[-+]?[0-9]/, "", $0)
62 NAMELIST = NAMELIST $0 " "
63 }
64 }
65 getline
66 ltype = parseln()
67 if (state == 0) {
68 if (ltype == 1) {
69 error("unexpected .Op with no arguments")
70 next
71 }
72 else
73 state = ltype - 1
74 }
75 else {
76 # state == 1 or 2
77 if (ltype == 4)
78 state = 3
79 else if (ltype > 1) {
80 error("unexpected .Op with arguments")
81 next
82 }
83 else if (ltype == 1) {
84 if (state == 1)
85 state = 4
86 else
87 state = 0
88 }
89 }
90 }
91 if (NAMELIST != "")
92 outline(FILENAME, NAMELIST)
93
94 }
95 else {
96 # Process all other man pages
97 # state values
98 # 0 = haven't found \-
99 # 1 = found \- (actually just `\')
100 # 2 = found .SH
101 state = 0;
102 NAMELIST = "";
103 while (state == 0) {
104 if ($1 == ".SH")
105 state = 2;
106 else {
107 gsub(/,/, " ", $0)
108 gsub(/"/, "", $0)
109 gsub(/:/, "", $0)
110 gsub(/\.B/, "", $0)
111 gsub(/\\f./, "", $0)
112 gsub(/\\s[-+]?[0-9]/, "", $0)
113 temp = split($0, NAMES, "\\")
114 NAMELIST = NAMELIST NAMES[1] " "
115 if (temp > 1)
116 state = 1
117 }
118 getline;
119 }
120 if (state == 2)
121 error("missing \\- in NAMES section")
122 else if (NAMELIST == "")
123 error("nothing before \\- in NAMES section")
124 else
125 outline(FILENAME, NAMELIST)
126 }
127 }
128 # parse .Op GL man page line, return values are:
129 # 0 = not .Op or .SH line
130 # 1 = .Op with no arguments
131 # 2 = .Op containing our option
132 # 3 = .Op not containing our option
133 # 4 = .SH line
134 func parseln() {
135 if ($1 == ".SH")
136 return 4
137 else if ($1 != ".Op")
138 return 0
139 else if (NF == 1)
140 return 1
141 else {
142 for (i = 2; i <= NF; i++) {
143 if ($i == opt)
144 return 2
145 }
146 return 3
147 }
148 }
149
150 END {
151 exit(err)
152 }
153
154 # all man page filenames are lowercase
155 func outline(fname, names) {
156 printf "%20s: %s\n", fname, names | "tr '[A-Z]' '[a-z]'"
157 }
158 func error(msg) {
159 print "getnames:", msg ": file", FILENAME ", line", FNR | "cat 1>&2"
160 err = 1
161 }