ReactOS 0.4.15-dev-7712-gbbbcd8e
adh-opts.c File Reference
#include "adnshost.h"
Include dependency graph for adh-opts.c:

Go to the source code of this file.

Typedefs

typedef int comparer_type(const char **optp, const struct optioninfo *entry)
 

Functions

static void printusage (void)
 
void of_version (const struct optioninfo *oi, const char *arg, const char *arg2)
 
void of_help (const struct optioninfo *oi, const char *arg, const char *arg2)
 
static int oc_long (const char **optp, const struct optioninfo *entry)
 
static int oc_short (const char **optp, const struct optioninfo *entry)
 
static const struct optioninfofind1 (const char **optp, const struct optioninfo *table, comparer_type *comparer)
 
static const struct optioninfofind (const char **optp, const char *prefix, comparer_type *comparer)
 
const struct optioninfoopt_findl (const char *opt)
 
const struct optioninfoopt_finds (const char **optp)
 
static void noninvert (const struct optioninfo *oip) NONRETURNING
 
void opt_do (const struct optioninfo *oip, int invert, const char *arg, const char *arg2)
 

Variables

int ov_env =1
 
int ov_pipe =0
 
int ov_asynch =0
 
int ov_verbose = 0
 
adns_rrtype ov_type = adns_r_none
 
int ov_search =0
 
int ov_qc_query =0
 
int ov_qc_anshost =0
 
int ov_qc_cname =1
 
int ov_tcp =0
 
int ov_cname =0
 
int ov_format =fmt_default
 
charov_id = 0
 
struct perqueryflags_remember ov_pqfr = { 1,1,1, tm_none }
 
static const struct optioninfo global_options []
 
static const struct optioninfo perquery_options []
 

Typedef Documentation

◆ comparer_type

typedef int comparer_type(const char **optp, const struct optioninfo *entry)

Definition at line 288 of file adh-opts.c.

Function Documentation

◆ find()

static const struct optioninfo * find ( const char **  optp,
const char prefix,
comparer_type comparer 
)
static

Definition at line 316 of file adh-opts.c.

318 {
319 const struct optioninfo *oip;
320 const char *opt;
321
322 opt= *optp;
324 if (oip) return oip;
325 oip= find1(optp,global_options,comparer);
326 if (!oip) usageerr("unknown option %s%s",prefix,opt);
327 if (ads) usageerr("global option %s%s specified after query domain(s)",prefix,opt);
328 return oip;
329}
void usageerr(const char *fmt,...)
Definition: adh-main.c:54
static const struct optioninfo * find1(const char **optp, const struct optioninfo *table, comparer_type *comparer)
Definition: adh-opts.c:306
static const struct optioninfo perquery_options[]
Definition: adh-opts.c:79
static const struct optioninfo global_options[]
Definition: adh-opts.c:43
adns_state ads
Definition: adh-query.c:35
static int comparer(const void *a, const void *b)

◆ find1()

static const struct optioninfo * find1 ( const char **  optp,
const struct optioninfo table,
comparer_type comparer 
)
static

Definition at line 306 of file adh-opts.c.

308 {
309 for (;;) {
310 if (table->type == ot_end) return 0;
311 if (comparer(optp,table)) return table;
312 table++;
313 }
314}

Referenced by FileCompareBothWild(), and find().

◆ noninvert()

static void noninvert ( const struct optioninfo oip)
static

Definition at line 335 of file adh-opts.c.

335 {
336 usageerr("option %s%s%s%s%s may not be inverted",
337 oip->sopt ? "-" : "", oip->sopt ? oip->sopt : "",
338 oip->lopt && oip->sopt ? " / " : "",
339 oip->lopt ? "--" : "", oip->lopt ? oip->lopt : "");
340}
const char * lopt
Definition: adnshost.h:68
const char * sopt
Definition: adnshost.h:68

Referenced by opt_do().

◆ oc_long()

static int oc_long ( const char **  optp,
const struct optioninfo entry 
)
static

Definition at line 290 of file adh-opts.c.

290 {
291 return entry->lopt && !strcmp(*optp,entry->lopt);
292}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
uint32_t entry
Definition: isohybrid.c:63

Referenced by opt_findl().

◆ oc_short()

static int oc_short ( const char **  optp,
const struct optioninfo entry 
)
static

Definition at line 294 of file adh-opts.c.

294 {
295 const char *sopt;
296 int l;
297
298 sopt= entry->sopt;
299 if (!sopt) return 0;
300 l= strlen(sopt);
301 if (memcmp(*optp,sopt,l)) return 0;
302 (*optp) += l;
303 return 1;
304}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
r l[0]
Definition: byte_order.h:168

Referenced by opt_finds().

◆ of_help()

void of_help ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 282 of file adh-opts.c.

282 {
283 printusage();
284 if (fclose(stdout)) sysfail("finish writing output",errno);
285 quitnow(0);
286}
void sysfail(const char *what, int errnoval)
Definition: adh-main.c:49
void quitnow(int rc)
Definition: adh-main.c:42
static void printusage(void)
Definition: adh-opts.c:131
#define stdout
Definition: stdio.h:99
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define errno
Definition: errno.h:18

◆ of_version()

void of_version ( const struct optioninfo oi,
const char arg,
const char arg2 
)

Definition at line 278 of file adh-opts.c.

278 {
279 VERSION_PRINT_QUIT("adnshost");
280}
#define VERSION_PRINT_QUIT(program)
Definition: client.h:42

◆ opt_do()

void opt_do ( const struct optioninfo oip,
int  invert,
const char arg,
const char arg2 
)

Definition at line 342 of file adh-opts.c.

343 {
344 switch (oip->type) {
345 case ot_flag:
346 assert(!arg);
347 *oip->storep= !invert;
348 return;
349 case ot_value:
350 assert(!arg);
351 if (invert) noninvert(oip);
352 *oip->storep= oip->value;
353 return;
354 case ot_func: case ot_funcarg: case ot_funcarg2:
355 if (invert) noninvert(oip);
356 oip->func(oip,arg,arg2);
357 return;
358 default:
359 abort();
360 }
361}
static void noninvert(const struct optioninfo *oip) NONRETURNING
Definition: adh-opts.c:335
#define assert(x)
Definition: debug.h:53
GLboolean invert
Definition: gl.h:1949
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
#define abort()
Definition: i386-dis.c:34
optfunc * func
Definition: adnshost.h:70
int * storep
Definition: adnshost.h:69
int value
Definition: adnshost.h:69
enum optioninfo::oi_type type

Referenced by process_optarg().

◆ opt_findl()

const struct optioninfo * opt_findl ( const char opt)

Definition at line 331 of file adh-opts.c.

331{ return find(&opt,"--",oc_long); }
static int oc_long(const char **optp, const struct optioninfo *entry)
Definition: adh-opts.c:290
static TAGID TAGID find
Definition: db.cpp:155

Referenced by process_optarg().

◆ opt_finds()

const struct optioninfo * opt_finds ( const char **  optp)

Definition at line 332 of file adh-opts.c.

332{ return find(optp,"-",oc_short); }
static int oc_short(const char **optp, const struct optioninfo *entry)
Definition: adh-opts.c:294

Referenced by process_optarg().

◆ printusage()

static void printusage ( void  )
static

Definition at line 131 of file adh-opts.c.

131 {
132 static const struct optioninfo *const all_optiontables[]= {
134 };
135
136 const struct optioninfo *const *oiap, *oip=0;
137 int maxsopt, maxlopt, l;
138
139 maxsopt= maxlopt= 0;
140
141 for (oiap=all_optiontables; *oiap; oiap++) {
142 for (oip=*oiap; oip->type != ot_end; oip++) {
143 if (oip->type == ot_funcarg) continue;
144 if (oip->sopt) { l= strlen(oip->sopt); if (l>maxsopt) maxsopt= l; }
145 if (oip->lopt) {
146 l= strlen(oip->lopt);
147 if (oip->type == ot_flag && !oip->value) l+= 3;
148 if (l>maxlopt) maxlopt= l;
149 }
150 }
151 }
152
153 fputs("usage: adnshost [global-opts] [query-opts] query-domain\n"
154 " [[query-opts] query-domain ...]\n"
155 " adnshost [global-opts] [query-opts] -f|--pipe\n",
156 stdout);
157
158 for (oiap=all_optiontables; *oiap; oiap++) {
159 putchar('\n');
160 for (oip=*oiap; oip->type != ot_end; oip++) {
161 switch (oip->type) {
162 case ot_flag:
163 if (!oip->value) {
164 if (oip->sopt) {
165 printf(" +%-*s --no-%-*s %s\n",
166 maxsopt, oip->sopt,
167 maxlopt-2, oip->lopt,
168 oip->desc);
169 } else {
170 printf(" --no-%-*s %s\n",
171 maxlopt+maxsopt+1, oip->lopt,
172 oip->desc);
173 }
174 break;
175 }
176 case ot_value: case ot_func: /* fall through */
177 if (oip->sopt) {
178 printf(" -%-*s --%-*s %s\n",
179 maxsopt, oip->sopt,
180 maxlopt+1, oip->lopt,
181 oip->desc);
182 } else {
183 printf(" --%-*s %s\n",
184 maxlopt+maxsopt+3, oip->lopt,
185 oip->desc);
186 }
187 break;
188 case ot_funcarg:
189 if (oip->sopt) {
190 l= (maxlopt + maxsopt - 9 -
191 (strlen(oip->sopt) + strlen(oip->lopt) + 2*strlen(oip->argdesc)));
192 printf(" -%s<%s> / --%s <%s>%*s%s\n",
193 oip->sopt, oip->argdesc, oip->lopt, oip->argdesc,
194 l>2 ? l : 2, "",
195 oip->desc);
196 } else {
197 l= (maxlopt + maxsopt + 1 -
198 (strlen(oip->lopt) + strlen(oip->argdesc)));
199 printf(" --%s <%s>%*s%s\n",
200 oip->lopt, oip->argdesc,
201 l>2 ? l : 2, "",
202 oip->desc);
203 }
204 break;
205 case ot_funcarg2:
206 assert(!oip->sopt);
207 l= (maxlopt + maxsopt - 2 -
208 (strlen(oip->lopt) + strlen(oip->argdesc) + strlen(oip->argdesc2)));
209 printf(" --%s <%s> <%s>%*s%s\n",
210 oip->lopt, oip->argdesc, oip->argdesc2,
211 l>2 ? l : 2, "",
212 oip->desc);
213 break;
214 case ot_desconly:
215 printf("%s\n", oip->desc);
216 break;
217 default:
218 abort();
219 }
220 }
221 }
222
223 printf("\nEscaping domains which might start with `-':\n"
224 " - %-*s Next argument is a domain, but more options may follow\n",
225 maxlopt+maxsopt+3, "<domain>");
226
227 fputs("\n"
228 "Query domains should always be quoted according to master file format.\n"
229 "\n"
230 "For binary options, --FOO and --no-FOO are opposites, as are\n"
231 "-X and +X. In each case the default is the one not listed.\n"
232 "Per query options stay set a particular way until they are reset,\n"
233 "whether they appear on the command line or on stdin.\n"
234 "All global options must preceed the first query domain.\n"
235 "\n"
236 "With -f, the input should be lines with either an option, possibly\n"
237 "with a value argument (separated from the option by a space if it's a long\n"
238 "option), or a domain (possibly preceded by a hyphen and a space to\n"
239 "distinguish it from an option).\n"
240 "\n"
241 "Output format is master file format without class or TTL by default:\n"
242 " [<owner>] [<ttl>] [<type>] <data>\n"
243 "or if the <owner> domain refers to a CNAME and --show-cname is on\n"
244 " [<owner>] [<ttl>] CNAME <cname>\n"
245 " [<cname>] [<ttl>] <type> <data>\n"
246 "When a query fails you get an error message to stderr (with --fmt-simple).\n"
247 "Specify --fmt-inline for lines like this (broken here for readability):\n"
248 " ; failed <statustype> <statusnum> <statusabbrev> \\\n"
249 " [<owner>] [<ttl>] [<cname>] \"<status string>\"\n"
250 "If you use --fmt-asynch, which is the default for --asynch,\n"
251 "each answer (success or failure) is preceded by a line\n"
252 " <id> <nrrs> <statustype> <statusnum> <statusabbrev> \\\n"
253 " [<owner>] [<ttl>] [<cname>] \"<status string>\"\n"
254 "where <nrrs> is the number of RRs that follow and <cname> will be `$' or\n"
255 "the CNAME target; the CNAME indirection and error formats above are not used.\n"
256 "\n"
257 "Exit status:\n"
258 " 0 all went well\n"
259 " 1-6 at least one query failed with statustype:\n"
260 " 1 localfail )\n"
261 " 2 remotefail ) temporary errors\n"
262 " 3 tempfail __)_________________\n"
263 " 4 misconfig )\n"
264 " 5 misquery ) permanent errors\n"
265 " 6 permfail )\n"
266 " 10 system trouble\n"
267 " 11 usage problems\n"
268 "\n"
269 "Query types (see adns.h; default is addr):\n"
270 " ns soa ptr mx rp addr - enhanced versions\n"
271 " cname hinfo txt - types with only one version\n"
272 " a ns- soa- ptr- mx- rp- - _raw versions\n"
273 "Default is addr, or ptr for -i/--ptr queries\n",
274 stdout);
275 if (ferror(stdout)) sysfail("write usage message",errno);
276}
int putchar(int c)
Definition: crtsupp.c:12
#define printf
Definition: freeldr.h:94
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
@ ot_funcarg2
Definition: adnshost.h:65
@ ot_funcarg
Definition: adnshost.h:65
@ ot_value
Definition: adnshost.h:65
@ ot_desconly
Definition: adnshost.h:64
const char * argdesc
Definition: adnshost.h:71
const char * argdesc2
Definition: adnshost.h:71
const char * desc
Definition: adnshost.h:67

Referenced by of_help().

Variable Documentation

◆ global_options

const struct optioninfo global_options[]
static

Definition at line 43 of file adh-opts.c.

Referenced by find(), GlobalOptions_CreateInstance(), printusage(), and test_GlobalOptions().

◆ ov_asynch

int ov_asynch =0

Definition at line 35 of file adh-opts.c.

Referenced by ensure_adns_init(), and main().

◆ ov_cname

int ov_cname =0

Definition at line 39 of file adh-opts.c.

Referenced by prep_query().

◆ ov_env

int ov_env =1

Definition at line 35 of file adh-opts.c.

Referenced by ensure_adns_init().

◆ ov_format

int ov_format =fmt_default

Definition at line 39 of file adh-opts.c.

Referenced by ensure_adns_init(), prep_query(), print_dnsfail(), and query_done().

◆ ov_id

char* ov_id = 0

Definition at line 40 of file adh-opts.c.

Referenced by of_asynch_id(), prep_query(), and quitnow().

◆ ov_pipe

int ov_pipe =0

Definition at line 35 of file adh-opts.c.

Referenced by main(), prep_query(), and read_stdin().

◆ ov_pqfr

struct perqueryflags_remember ov_pqfr = { 1,1,1, tm_none }

Definition at line 41 of file adh-opts.c.

Referenced by prep_query().

◆ ov_qc_anshost

int ov_qc_anshost =0

Definition at line 38 of file adh-opts.c.

Referenced by prep_query().

◆ ov_qc_cname

int ov_qc_cname =1

Definition at line 38 of file adh-opts.c.

Referenced by prep_query().

◆ ov_qc_query

int ov_qc_query =0

Definition at line 38 of file adh-opts.c.

Referenced by prep_query().

◆ ov_search

int ov_search =0

Definition at line 38 of file adh-opts.c.

Referenced by prep_query().

◆ ov_tcp

int ov_tcp =0

Definition at line 39 of file adh-opts.c.

Referenced by prep_query().

◆ ov_type

Definition at line 37 of file adh-opts.c.

Referenced by of_ptr(), of_reverse(), of_type(), and query_do().

◆ ov_verbose

int ov_verbose = 0

Definition at line 36 of file adh-opts.c.

Referenced by ensure_adns_init().

◆ perquery_options

const struct optioninfo perquery_options[]
static

Definition at line 79 of file adh-opts.c.

Referenced by find(), and printusage().