]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Improve xfs_io and xfs_quota -c handling
authorBarry Naujok <bnaujok@sgi.com>
Mon, 16 Jul 2007 03:57:04 +0000 (03:57 +0000)
committerBarry Naujok <bnaujok@sgi.com>
Mon, 16 Jul 2007 03:57:04 +0000 (03:57 +0000)
Merge of master-melb:xfs-cmds:29139a by kenmcd.

  Define command global command flag

include/command.h
io/file.c
libxcmd/command.c
libxcmd/help.c
libxcmd/quit.c
quota/path.c

index db050601080680f9d5e0f6ab276d9d31245041b3..4869edf64d068abf1ba68f9deda752822d4f22bc 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef __COMMAND_H__
 #define __COMMAND_H__
 
+#define CMD_FLAG_GLOBAL        ((int)0x80000000)       /* don't iterate "args" */
+
 typedef int (*cfunc_t)(int argc, char **argv);
 typedef void (*helpfunc_t)(void);
 
@@ -52,6 +54,6 @@ extern const cmdinfo_t        *find_command(const char *cmd);
 
 extern void            command_loop(void);
 extern int             command_usage(const cmdinfo_t *ci);
-extern int             command(int argc, char **argv);
+extern int             command(const cmdinfo_t *ci, int argc, char **argv);
 
 #endif /* __COMMAND_H__ */
index 55bf31ae4f6fa909a1e4955fe04328e92f97c1da..debab0f66b5f281002553a1fccb629336d9d79f8 100644 (file)
--- a/io/file.c
+++ b/io/file.c
@@ -103,7 +103,8 @@ file_init(void)
        print_cmd.cfunc = print_f;
        print_cmd.argmin = 0;
        print_cmd.argmax = 0;
-       print_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK;
+       print_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK |
+                               CMD_FLAG_GLOBAL;
        print_cmd.oneline = _("list current open files and memory mappings");
 
        add_command(&file_cmd);
index dfde33b9e45c8260ceb4cd4a41da3625d6143723..ebf14134591bf206f52f1dffc4864cb9c5d7f0f6 100644 (file)
@@ -70,20 +70,15 @@ command_usage(
 
 int
 command(
+       const cmdinfo_t *ct,
        int             argc,
        char            **argv)
 {
-       char            *cmd;
-       const cmdinfo_t *ct;
+       char            *cmd = argv[0];
 
-       cmd = argv[0];
-       ct = find_command(cmd);
-       if (!ct) {
-               fprintf(stderr, _("command \"%s\" not found\n"), cmd);
-               return 0;
-       }
        if (!check_command(ct))
                return 0;
+
        if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) {
                if (ct->argmax == -1)
                        fprintf(stderr,
@@ -148,26 +143,35 @@ add_args_command(
 void
 command_loop(void)
 {
-       int     c, i, j = 0, done = 0;
-       char    *input;
-       char    **v;
+       int             c, i, j = 0, done = 0;
+       char            *input;
+       char            **v;
+       const cmdinfo_t *ct;
 
        for (i = 0; !done && i < ncmdline; i++) {
-               while (!done && (j = args_command(j))) {
-                       input = strdup(cmdline[i]);
-                       if (!input) {
-                               fprintf(stderr,
-                                       _("cannot strdup command '%s': %s\n"),
-                                       cmdline[i], strerror(errno));
-                               exit(1);
-                       }
-                       v = breakline(input, &c);
-                       if (c)
-                               done = command(c, v);
-                       free(v);
-                       free(input);
+               input = strdup(cmdline[i]);
+               if (!input) {
+                       fprintf(stderr,
+                               _("cannot strdup command '%s': %s\n"),
+                               cmdline[i], strerror(errno));
+                       exit(1);
+               }
+               v = breakline(input, &c);
+               if (c) {
+                       ct = find_command(v[0]);
+                       if (ct) {
+                               if (ct->flags & CMD_FLAG_GLOBAL)
+                                       done = command(ct, c, v);
+                               else {
+                                       j = 0;
+                                       while (!done && (j = args_command(j)))
+                                               done = command(ct, c, v);
+                               }
+                       } else
+                               fprintf(stderr, _("command \"%s\" not found\n"),
+                                       v[0]);
                }
-               j = 0;  /* reset */
+               doneline(input, v);
        }
        if (cmdline) {
                free(cmdline);
@@ -177,8 +181,14 @@ command_loop(void)
                if ((input = fetchline()) == NULL)
                        break;
                v = breakline(input, &c);
-               if (c)
-                       done = command(c, v);
+               if (c) {
+                       ct = find_command(v[0]);
+                       if (ct)
+                               done = command(ct, c, v);
+                       else
+                               fprintf(stderr, _("command \"%s\" not found\n"),
+                                       v[0]);
+               }
                doneline(input, v);
        }
 }
index c7a71b7846029fe3f7b344921031202ac5c863e4..2e567b68116cf0f0805b2f7a0b4b8ac41192e99e 100644 (file)
@@ -88,7 +88,7 @@ help_init(void)
        help_cmd.cfunc = help_f;
        help_cmd.argmin = 0;
        help_cmd.argmax = 1;
-       help_cmd.flags = -1;
+       help_cmd.flags = CMD_FLAG_GLOBAL;
        help_cmd.args = _("[command]");
        help_cmd.oneline = _("help for one or all commands");
 
index 89498455a40bfb78a7bea8e7ed202b8e346a2feb..83e48b26543e2092b0493a8dcb9f6a24db4c9e67 100644 (file)
@@ -38,7 +38,7 @@ quit_init(void)
        quit_cmd.cfunc = quit_f;
        quit_cmd.argmin = -1;
        quit_cmd.argmax = -1;
-       quit_cmd.flags = -1;
+       quit_cmd.flags = CMD_FLAG_GLOBAL;
        quit_cmd.oneline = _("exit the program");
 
        add_command(&quit_cmd);
index 5e9b884517921d75857513e3a351079db7d7dc9d..608cab5ebd1d7e56bb582c265f96101e82a9521b 100644 (file)
@@ -122,6 +122,7 @@ path_init(void)
        path_cmd.cfunc = path_f;
        path_cmd.argmin = 0;
        path_cmd.argmax = 1;
+       path_cmd.flags = CMD_FLAG_GLOBAL;
        path_cmd.oneline = _("set current path, or show the list of paths");
 
        print_cmd.name = _("print");
@@ -129,6 +130,7 @@ path_init(void)
        print_cmd.cfunc = print_f;
        print_cmd.argmin = 0;
        print_cmd.argmax = 0;
+       print_cmd.flags = CMD_FLAG_GLOBAL;
        print_cmd.oneline = _("list known mount points and projects");
 
        if (expert)