]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2bd0ea18 NS |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
2bd0ea18 | 20 | #include "addr.h" |
57c9fccb | 21 | #include "attrset.h" |
2bd0ea18 NS |
22 | #include "block.h" |
23 | #include "bmap.h" | |
24 | #include "check.h" | |
25 | #include "command.h" | |
26 | #include "convert.h" | |
27 | #include "debug.h" | |
28 | #include "type.h" | |
29 | #include "echo.h" | |
30 | #include "faddr.h" | |
31 | #include "fprint.h" | |
32 | #include "field.h" | |
128efca1 NS |
33 | #include "agf.h" |
34 | #include "agfl.h" | |
35 | #include "agi.h" | |
2bd0ea18 NS |
36 | #include "frag.h" |
37 | #include "freesp.h" | |
38 | #include "help.h" | |
39 | #include "hash.h" | |
40 | #include "inode.h" | |
41 | #include "input.h" | |
42 | #include "io.h" | |
c7a8ea47 | 43 | #include "logformat.h" |
61983f67 | 44 | #include "metadump.h" |
2bd0ea18 NS |
45 | #include "output.h" |
46 | #include "print.h" | |
47 | #include "quit.h" | |
48 | #include "sb.h" | |
2bd0ea18 NS |
49 | #include "write.h" |
50 | #include "malloc.h" | |
51 | #include "dquot.h" | |
86bb49e4 | 52 | #include "fsmap.h" |
b64af2c4 | 53 | #include "crc.h" |
2bd0ea18 NS |
54 | |
55 | cmdinfo_t *cmdtab; | |
56 | int ncmds; | |
57 | ||
2bd0ea18 NS |
58 | static int |
59 | cmd_compare(const void *a, const void *b) | |
60 | { | |
61 | return strcmp(((const cmdinfo_t *)a)->name, | |
62 | ((const cmdinfo_t *)b)->name); | |
63 | } | |
64 | ||
65 | void | |
66 | add_command( | |
67 | const cmdinfo_t *ci) | |
68 | { | |
69 | cmdtab = xrealloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); | |
70 | cmdtab[ncmds - 1] = *ci; | |
71 | qsort(cmdtab, ncmds, sizeof(*cmdtab), cmd_compare); | |
72 | } | |
73 | ||
74 | int | |
75 | command( | |
76 | int argc, | |
77 | char **argv) | |
78 | { | |
79 | char *cmd; | |
80 | const cmdinfo_t *ct; | |
81 | ||
82 | cmd = argv[0]; | |
83 | ct = find_command(cmd); | |
84 | if (ct == NULL) { | |
9ee7055c | 85 | dbprintf(_("command %s not found\n"), cmd); |
2bd0ea18 NS |
86 | return 0; |
87 | } | |
88 | if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) { | |
9ee7055c | 89 | dbprintf(_("bad argument count %d to %s, expected "), argc-1, cmd); |
2bd0ea18 | 90 | if (ct->argmax == -1) |
9ee7055c | 91 | dbprintf(_("at least %d"), ct->argmin); |
2bd0ea18 NS |
92 | else if (ct->argmin == ct->argmax) |
93 | dbprintf("%d", ct->argmin); | |
94 | else | |
9ee7055c AM |
95 | dbprintf(_("between %d and %d"), ct->argmin, ct->argmax); |
96 | dbprintf(_(" arguments\n")); | |
2bd0ea18 NS |
97 | return 0; |
98 | } | |
c0211f67 | 99 | platform_getoptreset(); |
2bd0ea18 NS |
100 | return ct->cfunc(argc, argv); |
101 | } | |
102 | ||
103 | const cmdinfo_t * | |
104 | find_command( | |
105 | const char *cmd) | |
106 | { | |
107 | cmdinfo_t *ct; | |
108 | ||
109 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { | |
110 | if (strcmp(ct->name, cmd) == 0 || | |
111 | (ct->altname && strcmp(ct->altname, cmd) == 0)) | |
112 | return (const cmdinfo_t *)ct; | |
113 | } | |
114 | return NULL; | |
115 | } | |
116 | ||
117 | void | |
118 | init_commands(void) | |
119 | { | |
120 | addr_init(); | |
121 | agf_init(); | |
122 | agfl_init(); | |
123 | agi_init(); | |
57c9fccb | 124 | attrset_init(); |
2bd0ea18 NS |
125 | block_init(); |
126 | bmap_init(); | |
127 | check_init(); | |
128 | convert_init(); | |
b64af2c4 | 129 | crc_init(); |
2bd0ea18 NS |
130 | debug_init(); |
131 | echo_init(); | |
132 | frag_init(); | |
133 | freesp_init(); | |
86bb49e4 | 134 | fsmap_init(); |
2bd0ea18 NS |
135 | help_init(); |
136 | hash_init(); | |
137 | inode_init(); | |
138 | input_init(); | |
c7a8ea47 | 139 | logformat_init(); |
2bd0ea18 | 140 | io_init(); |
61983f67 | 141 | metadump_init(); |
2bd0ea18 NS |
142 | output_init(); |
143 | print_init(); | |
144 | quit_init(); | |
145 | sb_init(); | |
2bd0ea18 NS |
146 | type_init(); |
147 | write_init(); | |
148 | dquot_init(); | |
149 | } |