Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lnet / utils / parser.c
index b91295b..db5292d 100644 (file)
 #include <sys/param.h>
 #include <assert.h>
 
+#include <config.h>
 #ifdef HAVE_LIBREADLINE
 #define        READLINE_LIBRARY
 #include <readline/readline.h>
-
-/* completion_matches() is #if 0-ed out in modern glibc */
-#ifndef completion_matches
-#  define completion_matches rl_completion_matches
-#endif
 #endif
-
+//extern char **completion_matches __P((char *, rl_compentry_func_t *));
 extern void using_history(void);
 extern void stifle_history(int);
 extern void add_history(char *);
@@ -225,15 +221,14 @@ static char **command_completion(char * text, int start, int end)
     char       * pos;
 
     match_tbl = top_level;
-    
     for (table = find_cmd(rl_line_buffer, match_tbl, &pos);
-        table; table = find_cmd(pos, match_tbl, &pos)) 
-    {
+        table;
+        table = find_cmd(pos, match_tbl, &pos)) {
 
        if (*(pos - 1) == ' ') match_tbl = table->pc_sub_cmd;
     }
 
-    return completion_matches(text, command_generator);
+    return(completion_matches(text, command_generator));
 }
 #endif
 
@@ -642,6 +637,68 @@ int Parser_arg2int(const char *inp, long *result, int base)
                 return 1;
 }
 
+/* Convert human readable size string to and int; "1k" -> 1000 */
+int Parser_size (int *sizep, char *str) {
+        int size;
+        char mod[32];
+
+        switch (sscanf (str, "%d%1[gGmMkK]", &size, mod)) {
+        default:
+                return (-1);
+
+        case 1:
+                *sizep = size;
+                return (0);
+
+        case 2:
+                switch (*mod) {
+                case 'g':
+                case 'G':
+                        *sizep = size << 30;
+                        return (0);
+
+                case 'm':
+                case 'M':
+                        *sizep = size << 20;
+                        return (0);
+
+                case 'k':
+                case 'K':
+                        *sizep = size << 10;
+                        return (0);
+
+                default:
+                        *sizep = size;
+                        return (0);
+                }
+        }
+}
+
+/* Convert a string boolean to an int; "enable" -> 1 */
+int Parser_bool (int *b, char *str) {
+        if (!strcasecmp (str, "no") ||
+            !strcasecmp (str, "n") ||
+            !strcasecmp (str, "off") ||
+            !strcasecmp (str, "down") ||
+            !strcasecmp (str, "disable"))
+        {
+                *b = 0;
+                return (0);
+        }
+        
+        if (!strcasecmp (str, "yes") ||
+            !strcasecmp (str, "y") ||
+            !strcasecmp (str, "on") ||
+            !strcasecmp (str, "up") ||
+            !strcasecmp (str, "enable"))
+        {
+                *b = 1;
+                return (0);
+        }
+        
+        return (-1);
+}
+
 int Parser_quit(int argc, char **argv)
 {
         argc = argc;