]>
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 | ||
1d7e80ee | 19 | #include <xfs/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" | |
61983f67 | 43 | #include "metadump.h" |
2bd0ea18 NS |
44 | #include "output.h" |
45 | #include "print.h" | |
46 | #include "quit.h" | |
47 | #include "sb.h" | |
2bd0ea18 NS |
48 | #include "write.h" |
49 | #include "malloc.h" | |
50 | #include "dquot.h" | |
51 | ||
52 | cmdinfo_t *cmdtab; | |
53 | int ncmds; | |
54 | ||
2bd0ea18 NS |
55 | static int |
56 | cmd_compare(const void *a, const void *b) | |
57 | { | |
58 | return strcmp(((const cmdinfo_t *)a)->name, | |
59 | ((const cmdinfo_t *)b)->name); | |
60 | } | |
61 | ||
62 | void | |
63 | add_command( | |
64 | const cmdinfo_t *ci) | |
65 | { | |
66 | cmdtab = xrealloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab)); | |
67 | cmdtab[ncmds - 1] = *ci; | |
68 | qsort(cmdtab, ncmds, sizeof(*cmdtab), cmd_compare); | |
69 | } | |
70 | ||
71 | int | |
72 | command( | |
73 | int argc, | |
74 | char **argv) | |
75 | { | |
76 | char *cmd; | |
77 | const cmdinfo_t *ct; | |
78 | ||
79 | cmd = argv[0]; | |
80 | ct = find_command(cmd); | |
81 | if (ct == NULL) { | |
9ee7055c | 82 | dbprintf(_("command %s not found\n"), cmd); |
2bd0ea18 NS |
83 | return 0; |
84 | } | |
85 | if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) { | |
9ee7055c | 86 | dbprintf(_("bad argument count %d to %s, expected "), argc-1, cmd); |
2bd0ea18 | 87 | if (ct->argmax == -1) |
9ee7055c | 88 | dbprintf(_("at least %d"), ct->argmin); |
2bd0ea18 NS |
89 | else if (ct->argmin == ct->argmax) |
90 | dbprintf("%d", ct->argmin); | |
91 | else | |
9ee7055c AM |
92 | dbprintf(_("between %d and %d"), ct->argmin, ct->argmax); |
93 | dbprintf(_(" arguments\n")); | |
2bd0ea18 NS |
94 | return 0; |
95 | } | |
c0211f67 | 96 | platform_getoptreset(); |
2bd0ea18 NS |
97 | return ct->cfunc(argc, argv); |
98 | } | |
99 | ||
100 | const cmdinfo_t * | |
101 | find_command( | |
102 | const char *cmd) | |
103 | { | |
104 | cmdinfo_t *ct; | |
105 | ||
106 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { | |
107 | if (strcmp(ct->name, cmd) == 0 || | |
108 | (ct->altname && strcmp(ct->altname, cmd) == 0)) | |
109 | return (const cmdinfo_t *)ct; | |
110 | } | |
111 | return NULL; | |
112 | } | |
113 | ||
114 | void | |
115 | init_commands(void) | |
116 | { | |
117 | addr_init(); | |
118 | agf_init(); | |
119 | agfl_init(); | |
120 | agi_init(); | |
57c9fccb | 121 | attrset_init(); |
2bd0ea18 NS |
122 | block_init(); |
123 | bmap_init(); | |
124 | check_init(); | |
125 | convert_init(); | |
126 | debug_init(); | |
127 | echo_init(); | |
128 | frag_init(); | |
129 | freesp_init(); | |
130 | help_init(); | |
131 | hash_init(); | |
132 | inode_init(); | |
133 | input_init(); | |
134 | io_init(); | |
61983f67 | 135 | metadump_init(); |
2bd0ea18 NS |
136 | output_init(); |
137 | print_init(); | |
138 | quit_init(); | |
139 | sb_init(); | |
2bd0ea18 NS |
140 | type_init(); |
141 | write_init(); | |
142 | dquot_init(); | |
143 | } |