]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/command.c
2 * Copyright (c) 2003-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <xfs/libxfs.h>
42 cmd_compare(const void *a
, const void *b
)
44 return strcmp(((const cmdinfo_t
*)a
)->name
,
45 ((const cmdinfo_t
*)b
)->name
);
52 cmdtab
= realloc((void *)cmdtab
, ++ncmds
* sizeof(*cmdtab
));
53 cmdtab
[ncmds
- 1] = *ci
;
54 qsort(cmdtab
, ncmds
, sizeof(*cmdtab
), cmd_compare
);
61 printf("%s %s\n", ci
->name
, ci
->oneline
);
74 ct
= find_command(cmd
);
76 fprintf(stderr
, _("command \"%s\" not found\n"), cmd
);
79 if (!file
&& !(ct
->flags
& CMD_NOFILE_OK
)) {
80 fprintf(stderr
, _("no files are open, try 'help open'\n"));
83 if (!mapping
&& !(ct
->flags
& CMD_NOMAP_OK
)) {
84 fprintf(stderr
, _("no mapped regions, try 'help mmap'\n"));
87 if (file
&& !(ct
->flags
& CMD_FOREIGN_OK
) &&
88 (file
->flags
& IO_FOREIGN
)) {
90 _("foreign file active, %s command is for XFS filesystems only\n"),
94 if (argc
-1 < ct
->argmin
|| (ct
->argmax
!= -1 && argc
-1 > ct
->argmax
)) {
97 _("bad argument count %d to %s, expected at least %d arguments\n"),
98 argc
-1, cmd
, ct
->argmin
);
99 else if (ct
->argmin
== ct
->argmax
)
101 _("bad argument count %d to %s, expected %d arguments\n"),
102 argc
-1, cmd
, ct
->argmin
);
105 _("bad argument count %d to %s, expected between %d and %d arguments\n"),
106 argc
-1, cmd
, ct
->argmin
, ct
->argmax
);
109 platform_getoptreset();
110 return ct
->cfunc(argc
, argv
);
119 for (ct
= cmdtab
; ct
< &cmdtab
[ncmds
]; ct
++) {
120 if (strcmp(ct
->name
, cmd
) == 0 ||
121 (ct
->altname
&& strcmp(ct
->altname
, cmd
) == 0))
122 return (const cmdinfo_t
*)ct
;