]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/command.c
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
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.
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.
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
43 #include "logformat.h"
60 cmd_compare(const void *a
, const void *b
)
62 return strcmp(((const cmdinfo_t
*)a
)->name
,
63 ((const cmdinfo_t
*)b
)->name
);
70 cmdtab
= xrealloc((void *)cmdtab
, ++ncmds
* sizeof(*cmdtab
));
71 cmdtab
[ncmds
- 1] = *ci
;
72 qsort(cmdtab
, ncmds
, sizeof(*cmdtab
), cmd_compare
);
84 ct
= find_command(cmd
);
86 dbprintf(_("command %s not found\n"), cmd
);
89 if (argc
-1 < ct
->argmin
|| (ct
->argmax
!= -1 && argc
-1 > ct
->argmax
)) {
90 dbprintf(_("bad argument count %d to %s, expected "), argc
-1, cmd
);
92 dbprintf(_("at least %d"), ct
->argmin
);
93 else if (ct
->argmin
== ct
->argmax
)
94 dbprintf("%d", ct
->argmin
);
96 dbprintf(_("between %d and %d"), ct
->argmin
, ct
->argmax
);
97 dbprintf(_(" arguments\n"));
100 platform_getoptreset();
101 return ct
->cfunc(argc
, argv
);
110 for (ct
= cmdtab
; ct
< &cmdtab
[ncmds
]; ct
++) {
111 if (strcmp(ct
->name
, cmd
) == 0 ||
112 (ct
->altname
&& strcmp(ct
->altname
, cmd
) == 0))
113 return (const cmdinfo_t
*)ct
;