nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* source: xiohelp.c */ |
2 | /* Copyright Gerhard Rieger 2001-2009 */ |
||
3 | /* Published under the GNU General Public License V.2, see file COPYING */ |
||
4 | |||
5 | /* this file contains the source for the help function */ |
||
6 | |||
7 | #include "xiosysincludes.h" |
||
8 | #include "xioopen.h" |
||
9 | |||
10 | #include "xiohelp.h" |
||
11 | |||
12 | #if WITH_HELP |
||
13 | |||
14 | /* keep consistent with xioopts.h:enum e_types ! */ |
||
15 | static const char *optiontypenames[] = { |
||
16 | "CONST", "BIN", "BOOL", "BYTE", |
||
17 | "INT", "LONG", "STRING", "PTRDIFF", |
||
18 | "SHORT", "SIZE_T", "SOCKADDR", "UNSIGNED-INT", |
||
19 | "UNSIGNED-LONG","UNSIGNED-SHORT","MODE_T", "GID_T", |
||
20 | "UID_T", "INT[3]", "STRUCT-TIMEVAL", "STRUCT-TIMESPEC", |
||
21 | "DOUBLE", "STRING-NULL", "LONG:LONG", "OFF_T", |
||
22 | "OFF64_T", "INT:INT", "INT:INTP", "INT:BIN", |
||
23 | "INT:STRING", "INT:INT:INT", "INT:INT:BIN", "INT:INT:STRING", |
||
24 | "IP4NAME", "STRING:STRING", |
||
25 | |||
26 | #if HAVE_STRUCT_LINGER |
||
27 | "STRUCT-LINGER", |
||
28 | #endif |
||
29 | #if HAVE_STRUCT_IP_MREQN |
||
30 | "STRUCT-IP_MREQN", |
||
31 | #elif HAVE_STRUCT_IP_MREQ |
||
32 | "STRUCT-IP_MREQ", |
||
33 | #endif |
||
34 | } ; |
||
35 | |||
36 | |||
37 | /* keep consistent with xioopts.h:#define GROUP_* ! */ |
||
38 | static const char *addressgroupnames[] = { |
||
39 | "FD", "FIFO", "SOCKS5", "BLK", |
||
40 | "REG", "SOCKET", "READLINE", "undef", |
||
41 | "NAMED", "OPEN", "EXEC", "FORK", |
||
42 | "LISTEN", "DEVICE", "CHILD", "RETRY", |
||
43 | "TERMIOS", "RANGE", "PTY", "PARENT", |
||
44 | "UNIX", "IP4", "IP6", "INTERFACE", |
||
45 | "UDP", "TCP", "SOCKS4", "OPENSSL", |
||
46 | "PROCESS", "APPL", "HTTP", "SCTP" |
||
47 | } ; |
||
48 | |||
49 | |||
50 | /* keep consistent with xioopts.h:enum ephase ! */ |
||
51 | static char *optionphasenames[] = { |
||
52 | "ALL", "INIT", "EARLY", |
||
53 | "PREOPEN", "OPEN", "PASTOPEN", |
||
54 | "PRESOCKET", "SOCKET", "PASTSOCKET", |
||
55 | "PREBIGEN", "BIGEN", "PASTBIGEN", |
||
56 | "FD", |
||
57 | "PREBIND", "BIND", "PASTBIND", |
||
58 | "PRELISTEN", "LISTEN", "PASTLISTEN", |
||
59 | "PRECONNECT", "CONNECT", "PASTCONNECT", |
||
60 | "PREACCEPT", "ACCEPT", "PASTACCEPT", |
||
61 | "CONNECTED", |
||
62 | "PREFORK", "FORK", "PASTFORK", |
||
63 | "LATE", "LATE2", |
||
64 | "PREEXEC", "EXEC", "SPECIFIC", |
||
65 | NULL |
||
66 | } ; |
||
67 | |||
68 | |||
69 | /* print a line about a single option */ |
||
70 | static int xiohelp_option(FILE *of, const struct optname *on, const char *name) { |
||
71 | int j; |
||
72 | unsigned int groups; |
||
73 | bool occurred; |
||
74 | |||
75 | fprintf(of, " %s\tgroups=", name); |
||
76 | groups = on->desc->group; occurred = false; |
||
77 | for (j = 0; j < 32; ++j) { |
||
78 | if (groups & 1) { |
||
79 | if (occurred) { fputc(',', of); } |
||
80 | fprintf(of, "%s", addressgroupnames[j]); |
||
81 | occurred = true; |
||
82 | } |
||
83 | groups >>= 1; |
||
84 | } |
||
85 | fprintf(of, "\tphase=%s", optionphasenames[on->desc->phase]); |
||
86 | fprintf(of, "\ttype=%s", optiontypenames[on->desc->type]); |
||
87 | fputc('\n', of); |
||
88 | return 0; |
||
89 | } |
||
90 | |||
91 | int xioopenhelp(FILE *of, |
||
92 | int level /* 0..only addresses, 1..and options */ |
||
93 | ) { |
||
94 | const struct xioaddrname *an; |
||
95 | const struct optname *on; |
||
96 | int i, j; |
||
97 | unsigned int groups; |
||
98 | bool occurred; |
||
99 | |||
100 | fputs(" bi-address:\n", of); |
||
101 | fputs(" pipe[,<opts>]\tgroups=FD,FIFO\n", of); |
||
102 | if (level == 2) { |
||
103 | fputs(" echo is an alias for pipe\n", of); |
||
104 | fputs(" fifo is an alias for pipe\n", of); |
||
105 | } |
||
106 | fputs(" <single-address>%<single-address>\n", of); |
||
107 | fputs(" <single-address>\n", of); |
||
108 | fputs(" single-address:\n", of); |
||
109 | fputs(" <address-head>[,<opts>]\n", of); |
||
110 | fputs(" address-head:\n", of); |
||
111 | an = &address_names[0]; |
||
112 | i = 0; |
||
113 | while (address_names[i].name) { |
||
114 | if (!strcmp(an->name, (an->desc)[0]->common_desc.defname)) { |
||
115 | /* it is a canonical address name */ |
||
116 | const union xioaddr_desc **ad; |
||
117 | ad = an->desc; |
||
118 | while (*ad != NULL) { |
||
119 | const char *syntax; |
||
120 | int pos = 0; |
||
121 | fprintf(of, " %s", an->name); pos += strlen(an->name); |
||
122 | if ((*ad)->tag == XIOADDR_ENDPOINT) { |
||
123 | syntax = (*ad)->endpoint_desc.syntax; |
||
124 | } else if ((*ad)->tag == XIOADDR_INTER) { |
||
125 | syntax = (*ad)->inter_desc.syntax; |
||
126 | } else { |
||
127 | syntax = NULL; |
||
128 | } |
||
129 | if (syntax) { |
||
130 | fputs(syntax, of); pos += strlen(syntax); } |
||
131 | while (pos < 36) { putc(' ', of); ++pos; } |
||
132 | if ((*ad)->common_desc.leftdirs & XIOBIT_RDONLY) { |
||
133 | putc('r', of); } else { putc(' ', of); } |
||
134 | if ((*ad)->common_desc.leftdirs & XIOBIT_WRONLY) { |
||
135 | putc('w', of); } else { putc(' ', of); } |
||
136 | if ((*ad)->common_desc.leftdirs & XIOBIT_RDWR) { |
||
137 | putc('b', of); } else { putc(' ', of); } |
||
138 | putc(' ', of); |
||
139 | if ((*ad)->tag == 1) { |
||
140 | while (pos < 36) { putc(' ', of); ++pos; } |
||
141 | if ((*ad)->inter_desc.rightdirs & XIOBIT_RDONLY) { |
||
142 | putc('r', of); } else { putc(' ', of); } |
||
143 | if ((*ad)->inter_desc.rightdirs & XIOBIT_WRONLY) { |
||
144 | putc('w', of); } else { putc(' ', of); } |
||
145 | if ((*ad)->inter_desc.rightdirs & XIOBIT_RDWR) { |
||
146 | putc('b', of); } else { putc(' ', of); } |
||
147 | } else { |
||
148 | fputs(" ", of); |
||
149 | } |
||
150 | |||
151 | pos += 7; |
||
152 | fputs(" groups=", of); |
||
153 | groups = (*ad)->common_desc.groups; occurred = false; |
||
154 | for (j = 0; j < 32; ++j) { |
||
155 | if (groups & 1) { |
||
156 | if (occurred) { fputc(',', of); } |
||
157 | fprintf(of, "%s", addressgroupnames[j]); |
||
158 | pos += strlen(addressgroupnames[j]); |
||
159 | occurred = true; |
||
160 | } |
||
161 | groups >>= 1; |
||
162 | } |
||
163 | fputc('\n', of); |
||
164 | ++ad; |
||
165 | } |
||
166 | } else if (level == 2) { |
||
167 | fprintf(of, " %s is an alias name for %s\n", an->name, (an->desc)[0]->common_desc.defname); |
||
168 | } |
||
169 | ++an; ++i; |
||
170 | } |
||
171 | if (level == 2) { |
||
172 | fputs(" <num> is a short form for fd:<num>\n", of); |
||
173 | fputs(" <filename> is a short form for gopen:<filename>\n", of); |
||
174 | } |
||
175 | |||
176 | if (level <= 0) return 0; |
||
177 | |||
178 | fputs(" opts:\n", of); |
||
179 | fputs(" <opt>{,<opts>}:\n", of); |
||
180 | fputs(" opt:\n", of); |
||
181 | on = optionnames; |
||
182 | while (on->name != NULL) { |
||
183 | if (on->desc->nickname!= NULL |
||
184 | && !strcmp(on->name, on->desc->nickname)) { |
||
185 | if (level == 2) { |
||
186 | fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname); |
||
187 | } else { |
||
188 | xiohelp_option(of, on, on->name); |
||
189 | } |
||
190 | } else if (on->desc->nickname == NULL && |
||
191 | !strcmp(on->name, on->desc->defname)) { |
||
192 | xiohelp_option(of, on, on->name); |
||
193 | } else if (level == 2) { |
||
194 | if (!strcmp(on->name, on->desc->defname)) { |
||
195 | xiohelp_option(of, on, on->name); |
||
196 | } else { |
||
197 | fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname); |
||
198 | } |
||
199 | } |
||
200 | ++on; |
||
201 | } |
||
202 | fflush(of); |
||
203 | return 0; |
||
204 | } |
||
205 | |||
206 | #endif /* WITH_HELP */ |