]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/command.c
apply gettext translation to more strings
[thirdparty/xfsprogs-dev.git] / db / command.c
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include <xfs/libxfs.h>
20 #include "addr.h"
21 #include "attrset.h"
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"
33 #include "agf.h"
34 #include "agfl.h"
35 #include "agi.h"
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"
43 #include "metadump.h"
44 #include "output.h"
45 #include "print.h"
46 #include "quit.h"
47 #include "sb.h"
48 #include "write.h"
49 #include "malloc.h"
50 #include "dquot.h"
51
52 cmdinfo_t *cmdtab;
53 int ncmds;
54
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) {
82 dbprintf(_("command %s not found\n"), cmd);
83 return 0;
84 }
85 if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) {
86 dbprintf(_("bad argument count %d to %s, expected "), argc-1, cmd);
87 if (ct->argmax == -1)
88 dbprintf(_("at least %d"), ct->argmin);
89 else if (ct->argmin == ct->argmax)
90 dbprintf("%d", ct->argmin);
91 else
92 dbprintf(_("between %d and %d"), ct->argmin, ct->argmax);
93 dbprintf(_(" arguments\n"));
94 return 0;
95 }
96 platform_getoptreset();
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();
121 attrset_init();
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();
135 metadump_init();
136 output_init();
137 print_init();
138 quit_init();
139 sb_init();
140 type_init();
141 write_init();
142 dquot_init();
143 }