ext2-* options are renamed to fs-*
[socat.git] / xiohelp.c
blob1977f4c0948dfea2a396ae26dac2b0f041045c18
1 /* source: xiohelp.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for the help function */
7 #include "xiosysincludes.h"
8 #include "xioopen.h"
10 #include "xiohelp.h"
12 #if WITH_HELP
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",
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 } ;
37 /* keep consistent with xioopts.h:#define GROUP_* ! */
38 static const char *addressgroupnames[] = {
39 "FD", "FIFO", "CHR", "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 } ;
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 } ;
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;
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;
83 groups >>= 1;
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;
91 int xioopenhelp(FILE *of,
92 int level /* 0..only addresses, 1..and options */
93 ) {
94 const struct addrname *an;
95 const struct optname *on;
96 int i, j;
97 unsigned int groups;
98 bool occurred;
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);
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 = &addressnames[0];
112 i = 0;
113 while (addressnames[i].name) {
114 if (!strcmp(an->name, an->desc->defname)) {
115 /* it is a canonical address name */
116 fprintf(of, " %s", an->name);
117 if (an->desc->syntax) {
118 fputs(an->desc->syntax, of); }
119 fputs("\tgroups=", of);
120 groups = an->desc->groups; occurred = false;
121 for (j = 0; j < 32; ++j) {
122 if (groups & 1) {
123 if (occurred) { fputc(',', of); }
124 fprintf(of, "%s", addressgroupnames[j]);
125 occurred = true;
127 groups >>= 1;
129 fputc('\n', of);
130 } else if (level == 2) {
131 fprintf(of, " %s is an alias name for %s\n", an->name, an->desc->defname);
133 ++an; ++i;
135 if (level == 2) {
136 fputs(" <num> is a short form for fd:<num>\n", of);
137 fputs(" <filename> is a short form for gopen:<filename>\n", of);
140 if (level <= 0) return 0;
142 fputs(" opts:\n", of);
143 fputs(" <opt>{,<opts>}:\n", of);
144 fputs(" opt:\n", of);
145 on = optionnames;
146 while (on->name != NULL) {
147 if (on->desc->nickname!= NULL
148 && !strcmp(on->name, on->desc->nickname)) {
149 if (level == 2) {
150 fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
151 } else {
152 xiohelp_option(of, on, on->name);
154 } else if (on->desc->nickname == NULL &&
155 !strcmp(on->name, on->desc->defname)) {
156 xiohelp_option(of, on, on->name);
157 } else if (level == 2) {
158 if (!strcmp(on->name, on->desc->defname)) {
159 xiohelp_option(of, on, on->name);
160 } else {
161 fprintf(of, " %s is an alias for %s\n", on->name, on->desc->defname);
164 ++on;
166 fflush(of);
167 return 0;
170 #endif /* WITH_HELP */