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"
14 /* keep consistent with xioopts.h:enum e_types ! */
15 static const char *optiontypenames
[] = {
16 "CONST", "BIN", "BOOL", "BYTE",
17 "INT", "INT/NULL", "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",
26 #if HAVE_STRUCT_LINGER
29 #if HAVE_STRUCT_IP_MREQN
31 #elif HAVE_STRUCT_IP_MREQ
34 #if HAVE_STRUCT_IP_MREQ_SOURCE
41 /* keep consistent with xioopts.h:#define GROUP_* ! */
42 static const char *addressgroupnames
[] = {
43 "FD", "FIFO", "CHR", "BLK",
44 "REG", "SOCKET", "READLINE", "undef",
45 "NAMED", "OPEN", "EXEC", "FORK",
46 "LISTEN", "SHELL", "CHILD", "RETRY",
47 "TERMIOS", "RANGE", "PTY", "PARENT",
48 "UNIX", "IP4", "IP6", "INTERFACE",
49 "UDP", "TCP", "SOCKS", "OPENSSL",
50 "PROCESS", "APPL", "HTTP", "undef",
51 "POSIXMQ", "SCTP", "DCCP", "UDPLITE"
54 /* keep consistent with xioopts.h:enum ephase ! */
55 static char *optionphasenames
[] = {
56 "ALL", "INIT", "EARLY",
57 "PREOPEN", "OPEN", "PASTOPEN",
58 "PRESOCKET", "SOCKET", "PASTSOCKET",
59 "PREBIGEN", "BIGEN", "PASTBIGEN",
61 "PREBIND", "BIND", "PASTBIND",
62 "PRELISTEN", "LISTEN", "PASTLISTEN",
63 "PRECONNECT", "CONNECT", "PASTCONNECT",
64 "PREACCEPT", "ACCEPT", "PASTACCEPT",
66 "PREFORK", "FORK", "PASTFORK",
68 "PREEXEC", "EXEC", "PASTEXEC",
74 /* print a line about a single option */
75 static int xiohelp_option(FILE *of
, const struct optname
*on
, const char *name
) {
81 chars
= fprintf(of
, " %s", name
);
82 i
= (16 - chars
+ 7) / 8;
83 for (; i
> 0; --i
) { fputc('\t', of
); }
87 groups
= on
->desc
->group
;
90 for (j
= 0; j
< 8*sizeof(groups_t
); ++j
) {
96 fputs(addressgroupnames
[j
], of
);
97 chars
+= strlen(addressgroupnames
[j
]);
102 i
= (24 - chars
+ 7) / 8;
103 for (; i
> 0; --i
) { fputc('\t', of
); }
105 chars
= fprintf(of
, "phase=%s", optionphasenames
[on
->desc
->phase
]);
106 i
= (24 - chars
+ 7) / 8;
107 for (; i
> 0; --i
) { fputc('\t', of
); }
109 fprintf(of
, "type=%s", optiontypenames
[on
->desc
->type
]);
114 const char *xiohelp_opttypename(enum e_types typnum
)
116 if (typnum
< 0 || typnum
>= TYPE_OVERFLOW
) {
117 Warn2("%s(): invalid type number %d", __func__
, typnum
);
120 return optiontypenames
[typnum
];
123 int xioopenhelp(FILE *of
,
124 int level
/* 0..only addresses, 1..and options */
126 const struct addrname
*an
;
127 const struct optname
*on
;
132 fputs(" bi-address: /* is an address that may act both as data sync and source */\n", of
);
133 fputs(" <single-address>\n", of
);
134 fputs(" <single-address>!!<single-address>\n", of
);
135 fputs(" single-address:\n", of
);
136 fputs(" <address-head>[,<opts>]\n", of
);
137 fputs(" address-head:\n", of
);
138 an
= &addressnames
[0];
140 while (addressnames
[i
].name
) {
141 if (!strcmp(an
->name
, an
->desc
->defname
)) {
144 /* it is a canonical address name */
145 chars
= fprintf(of
, " %s", an
->name
);
146 if (an
->desc
->syntax
) {
147 fputs(an
->desc
->syntax
, of
);
148 chars
+= strlen(an
->desc
->syntax
);
150 i
= (40 - chars
+ 7) / 8;
151 for (; i
> 0; --i
) { fputc('\t', of
); }
152 fputs("\tgroups=", of
);
153 groups
= an
->desc
->groups
; occurred
= false;
154 for (j
= 0; j
< 32; ++j
) {
156 if (occurred
) { fputc(',', of
); }
157 fprintf(of
, "%s", addressgroupnames
[j
]);
163 } else if (level
== 2) {
166 chars
= fprintf(of
, " %s", an
->name
);
167 i
= (40 - chars
+ 7) / 8;
168 for (; i
> 0; --i
) { fputc('\t', of
); }
170 fprintf(of
, "\tis an alias name for %s\n", an
->desc
->defname
);
175 fputs(" <num> is a short form for fd:<num>\n", of
);
176 fputs(" <filename> is a short form for gopen:<filename>\n", of
);
179 if (level
<= 0) return 0;
181 fputs(" opts:\n", of
);
182 fputs(" <opt>{,<opts>}:\n", of
);
183 fputs(" opt:\n", of
);
185 while (on
->name
!= NULL
) {
186 if (on
->desc
->nickname
!= NULL
187 && !strcmp(on
->name
, on
->desc
->nickname
)) {
191 chars
= fprintf(of
, " %s", on
->name
);
192 i
= (16 - chars
+ 7) / 8;
193 for (; i
> 0; --i
) { fputc('\t', of
); }
195 fprintf(of
, "\tis an alias for %s\n", on
->desc
->defname
);
197 xiohelp_option(of
, on
, on
->name
);
199 } else if (on
->desc
->nickname
== NULL
&&
200 !strcmp(on
->name
, on
->desc
->defname
)) {
201 xiohelp_option(of
, on
, on
->name
);
202 } else if (level
== 2) {
203 if (!strcmp(on
->name
, on
->desc
->defname
)) {
204 xiohelp_option(of
, on
, on
->name
);
208 chars
= fprintf(of
, " %s", on
->name
);
209 i
= (16 - chars
+ 7) / 8;
210 for (; i
> 0; --i
) { fputc('\t', of
); }
212 fprintf(of
, "\tis an alias for %s\n", on
->desc
->defname
);
221 /* This function may be used by address handling code to log syntax error */
228 Error5("%s: wrong number of parameters (%d instead of %d): usage: %s%s",
229 addr
, isnum
, expectnum
, addr
, syntax
);
233 #endif /* WITH_HELP */