]>
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
19 #include <xfs/libxfs.h>
56 cmd_compare(const void *a
, const void *b
)
58 return strcmp(((const cmdinfo_t
*)a
)->name
,
59 ((const cmdinfo_t
*)b
)->name
);
66 cmdtab
= xrealloc((void *)cmdtab
, ++ncmds
* sizeof(*cmdtab
));
67 cmdtab
[ncmds
- 1] = *ci
;
68 qsort(cmdtab
, ncmds
, sizeof(*cmdtab
), cmd_compare
);
80 ct
= find_command(cmd
);
82 dbprintf(_("command %s not found\n"), cmd
);
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
);
88 dbprintf(_("at least %d"), ct
->argmin
);
89 else if (ct
->argmin
== ct
->argmax
)
90 dbprintf("%d", ct
->argmin
);
92 dbprintf(_("between %d and %d"), ct
->argmin
, ct
->argmax
);
93 dbprintf(_(" arguments\n"));
96 platform_getoptreset();
97 return ct
->cfunc(argc
, argv
);
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
;