d1cff511 |
1 | /* |
2 | * adh-main.c |
3 | * - useful general-purpose resolver client program |
4 | * main program and useful subroutines |
5 | */ |
6 | /* |
7 | * This file is |
8 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
9 | * |
10 | * It is part of adns, which is |
11 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
12 | * Copyright (C) 1999 Tony Finch <dot@dotat.at> |
13 | * |
14 | * This program is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2, or (at your option) |
17 | * any later version. |
18 | * |
19 | * This program is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License |
25 | * along with this program; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | */ |
28 | |
29 | #include <stdio.h> |
30 | #include <string.h> |
31 | #include <errno.h> |
32 | |
33 | void sysfail(const char *what, int errnoval) { |
34 | fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval)); |
35 | exit(10); |
36 | } |
37 | |
38 | static void domain_do_arg(const char *domain) { |
39 | if (ov_pipe) usageerr("-f/--pipe not consistent with domains on command line"); |
40 | domain_do(arg); |
41 | } |
42 | |
43 | static void of_type(const struct optinfo *oi, const char *arg) { abort(); } |
44 | |
45 | int main(int argc, const char *const *argv) { |
46 | const char *arg; |
47 | const |
48 | |
49 | while (arg= *++argv) { |
50 | if (arg[0] != '-') { |
51 | if (arg[1] == '-') { |
52 | oip= opt_findl(arg+2); |
53 | if (oip->type == ot_funcarg) { |
54 | arg= *++argv; |
55 | if (!arg) usageerr("option --%s requires a value argument",oip->lopt); |
56 | } else { |
57 | arg= 0; |
58 | } |
59 | opt_do(oip,arg); |
60 | } else if (arg[1] == 0) { |
61 | arg= *++argv; |
62 | if (!arg) usageerr("option `-' must be followed by a domain"); |
63 | domain_do_arg(arg); |
64 | } else { /* arg[1] != '-', != '\0' */ |
65 | ++arg; |
66 | while (*arg) { |
67 | oip= opt_finds(&arg); |
68 | if (oip->type == ot_funcarg) { |
69 | if (!*arg) { |
70 | arg= *++argv; |
71 | if (!arg) usageerr("option -%s requires a value argument",oip->sopt); |
72 | } |
73 | arg= ""; |
74 | } else { |
75 | arg= 0; |
76 | } |
77 | opt_do(oip,arg); |
78 | } |
79 | } |
80 | } else { /* arg[0] != '-' */ |
81 | domain_do_arg(arg); |
82 | } |
83 | } |
84 | |
85 | if (ov_pipe) { |
86 | |
87 | if (ov_pipe) usageerr("-f/--pipe not |
88 | |
89 | if (oip && ads) usageerr("global option %s must precede all query domains",arg); |
90 | if (!oip) oip= opt_findl(arg+2,perquery_options); |
91 | if (!oip) usageerr("unknown option %s",arg); |
92 | } |
93 | |
94 | if (!oip && |
95 | if (!oip) { |
96 | } |
97 | while (argv[1] && argv[1][0] == '-') { |
98 | if (argv[1][1] == '-') { |
99 | oip= findlong( |
100 | } |
101 | of_help(0,0); |
102 | abort(); |
103 | } |