Whamcloud - gitweb
3fbb09e0fde33d46420d9a0963cc73ecb34fd9e4
[fs/lustre-release.git] / libcfs / libcfs / util / parser.c
1 /*
2  * Copyright (C) 2001 Cluster File Systems, Inc.
3  *
4  * Copyright (c) 2014, 2017, Intel Corporation.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #include <stddef.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <getopt.h>
30 #include <malloc.h>
31 #ifdef HAVE_LIBREADLINE
32 # include <readline/history.h>
33 # include <readline/readline.h>
34 #endif /* HAVE_LIBREADLINE */
35 #include <string.h>
36 #include <unistd.h>
37
38 #include <libcfs/util/parser.h>
39 #include <linux/lustre/lustre_ver.h>
40
41 static command_t * top_level;           /* Top level of commands, initialized by
42                                     * InitParser                              */
43 static char * parser_prompt = NULL;/* Parser prompt, set by InitParser      */
44 static int done;                   /* Set to 1 if user types exit or quit   */
45 static int ignore_errors;       /* Normally, the parser will quit when
46                                    an error occurs in non-interacive
47                                    mode. Setting this to non-zero will
48                                    force it to keep buggering on. */
49
50
51 /* static functions */
52 static char *skipwhitespace(char *s);
53 static char *skiptowhitespace(char *s);
54 static command_t *find_cmd(char *name, command_t cmds[], char **next);
55 static int process(char *s, char **next, command_t *lookup, command_t **result,
56                    char **prev);
57
58 static char * skipwhitespace(char * s)
59 {
60         char * t;
61         int    len;
62
63         len = (int)strlen(s);
64         for (t = s; t <= s + len && isspace(*t); t++);
65         return(t);
66 }
67
68
69 static char * skiptowhitespace(char * s)
70 {
71         char * t;
72
73         for (t = s; *t && !isspace(*t); t++);
74         return(t);
75 }
76
77 static int line2args(char *line, char **argv, int maxargs)
78 {
79         char *arg;
80         int i = 0;
81
82         arg = strtok(line, " \t");
83         if (arg == NULL || maxargs < 1)
84                 return 0;
85
86         argv[i++] = arg;
87         while ((arg = strtok(NULL, " \t")) != NULL && i < maxargs)
88                 argv[i++] = arg;
89         return i;
90 }
91
92 /* find a command -- return it if unique otherwise print alternatives */
93 static command_t *Parser_findargcmd(char *name, command_t cmds[])
94 {
95         command_t *cmd;
96
97         for (cmd = cmds; cmd->pc_name; cmd++) {
98                 if (strcmp(name, cmd->pc_name) == 0)
99                         return cmd;
100         }
101         return NULL;
102 }
103
104 void Parser_ignore_errors(int ignore)
105 {
106         ignore_errors = ignore;
107 }
108
109 int Parser_execarg(int argc, char **argv, command_t cmds[])
110 {
111         command_t *cmd;
112
113         cmd = Parser_findargcmd(argv[0], cmds);
114         if (cmd != NULL && cmd->pc_func != NULL) {
115                 int rc = (cmd->pc_func)(argc, argv);
116                 if (rc == CMD_HELP)
117                         fprintf(stderr, "%s\n", cmd->pc_help);
118                 return rc;
119         } else {
120                 printf("Try interactive use without arguments or use one of:\n");
121                 for (cmd = cmds; cmd->pc_name; cmd++)
122                         printf("\"%s\"\n", cmd->pc_name);
123                 printf("as argument.\n");
124         }
125         return -1;
126 }
127
128 /* returns the command_t * (NULL if not found) corresponding to a
129    _partial_ match with the first token in name.  It sets *next to
130    point to the following token. Does not modify *name. */
131 static command_t * find_cmd(char * name, command_t cmds[], char ** next)
132 {
133         int    i, len;
134
135         if (!cmds || !name )
136                 return NULL;
137
138         /* This sets name to point to the first non-white space character,
139            and next to the first whitespace after name, len to the length: do
140            this with strtok*/
141         name = skipwhitespace(name);
142         *next = skiptowhitespace(name);
143         len = (int)(*next - name);
144         if (len == 0)
145                 return NULL;
146
147         for (i = 0; cmds[i].pc_name; i++) {
148                 if (strncasecmp(name, cmds[i].pc_name, len) == 0) {
149                         *next = skipwhitespace(*next);
150                         return(&cmds[i]);
151                 }
152         }
153         return NULL;
154 }
155
156 /* Recursively process a command line string s and find the command
157    corresponding to it. This can be ambiguous, full, incomplete,
158    non-existent. */
159 static int process(char *s, char ** next, command_t *lookup,
160                    command_t **result, char **prev)
161 {
162         *result = find_cmd(s, lookup, next);
163         *prev = s;
164
165         /* non existent */
166         if (!*result)
167                 return CMD_NONE;
168
169         /* found entry: is it ambigous, i.e. not exact command name and
170            more than one command in the list matches.  Note that find_cmd
171            points to the first ambiguous entry */
172         if (strncasecmp(s, (*result)->pc_name, strlen((*result)->pc_name))) {
173                 char *another_next;
174                 command_t *another_result = find_cmd(s, (*result) + 1,
175                                                      &another_next);
176                 int found_another = 0;
177
178                 while (another_result) {
179                         if (strncasecmp(s, another_result->pc_name,
180                                         strlen(another_result->pc_name)) == 0){
181                                 *result = another_result;
182                                 *next = another_next;
183                                 goto got_it;
184                         }
185                         another_result = find_cmd(s, another_result + 1,
186                                                   &another_next);
187                         found_another = 1;
188                 }
189                 if (found_another)
190                         return CMD_AMBIG;
191         }
192
193 got_it:
194         /* found a unique command: component or full? */
195         if ((*result)->pc_func != NULL) {
196                 return CMD_COMPLETE;
197         } else {
198                 if (**next == '\0') {
199                         return CMD_INCOMPLETE;
200                 } else {
201                         return process(*next, next, (*result)->pc_sub_cmd,
202                                        result, prev);
203                 }
204         }
205 }
206
207 #ifdef HAVE_LIBREADLINE
208 static command_t * match_tbl;   /* Command completion against this table */
209 static char * command_generator(const char * text, int state)
210 {
211         static int index,
212                 len;
213         char       *name;
214
215         /* Do we have a match table? */
216         if (!match_tbl)
217                 return NULL;
218
219         /* If this is the first time called on this word, state is 0 */
220         if (!state) {
221                 index = 0;
222                 len = (int)strlen(text);
223         }
224
225         /* Return next name in the command list that paritally matches test */
226         while ( (name = (match_tbl + index)->pc_name) ) {
227                 index++;
228
229                 if (strncasecmp(name, text, len) == 0) {
230                         return(strdup(name));
231                 }
232         }
233
234         /* No more matches */
235         return NULL;
236 }
237
238 /* probably called by readline */
239 static char **command_completion(const char *text, int start, int end)
240 {
241         command_t   * table;
242         char        * pos;
243
244         match_tbl = top_level;
245         
246         for (table = find_cmd(rl_line_buffer, match_tbl, &pos);
247              table; table = find_cmd(pos, match_tbl, &pos)) 
248         {
249
250                 if (*(pos - 1) == ' ') match_tbl = table->pc_sub_cmd;
251         }
252
253         return rl_completion_matches(text, command_generator);
254 }
255 #endif
256
257 /* take a string and execute the function or print help */
258 int execute_line(char * line)
259 {
260         command_t       *cmd, *ambig;
261         char            *prev;
262         char            *next, *tmp;
263         char            *argv[MAXARGS];
264         int             i;
265         int             rc = 0;
266
267         switch (process(line, &next, top_level, &cmd, &prev)) {
268         case CMD_AMBIG:
269                 fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
270                 while ((ambig = find_cmd(prev, cmd, &tmp))) {
271                         fprintf(stderr, "%s ", ambig->pc_name);
272                         cmd = ambig + 1;
273                 }
274                 fprintf(stderr, "\n");
275                 break;
276         case CMD_NONE:
277                 fprintf(stderr, "No such command, type help\n");
278                 break;
279         case CMD_INCOMPLETE:
280                 fprintf(stderr, "'%s' incomplete command.  Use '%s x' where "
281                         "x is one of:\n", line, line);
282                 fprintf(stderr, "\t");
283                 for (i = 0; cmd->pc_sub_cmd[i].pc_name; i++)
284                         fprintf(stderr, "%s ", cmd->pc_sub_cmd[i].pc_name);
285                 fprintf(stderr, "\n");
286                 break;
287         case CMD_COMPLETE:
288                 optind = 0;
289                 i = line2args(line, argv, MAXARGS);
290                 rc = (cmd->pc_func)(i, argv);
291
292                 if (rc == CMD_HELP)
293                         fprintf(stderr, "%s\n", cmd->pc_help);
294
295                 break;
296         }
297
298         return rc;
299 }
300
301 #ifdef HAVE_LIBREADLINE
302 static void noop_int_fn(int unused) { }
303 static void noop_void_fn(void) { }
304 #endif
305
306 /* just in case you're ever in an airplane and discover you
307  * forgot to install readline-dev. :) */
308 static int init_input(void)
309 {
310         int interactive = isatty(fileno(stdin));
311
312 #ifdef HAVE_LIBREADLINE
313         using_history();
314         stifle_history(HISTORY);
315
316         if (!interactive) {
317                 rl_prep_term_function = noop_int_fn;
318                 rl_deprep_term_function = noop_void_fn;
319         }
320
321         rl_attempted_completion_function = command_completion;
322         rl_completion_entry_function = command_generator;
323 #endif
324         return interactive;
325 }
326
327 #ifndef HAVE_LIBREADLINE
328 #define add_history(s)
329 char * readline(char * prompt)
330 {
331         int size = 2048;
332         char *line = malloc(size);
333         char *ptr = line;
334         int c;
335         int eof = 0;
336
337         if (line == NULL)
338                 return NULL;
339         if (prompt)
340                 printf ("%s", prompt);
341
342         while (1) {
343                 if ((c = fgetc(stdin)) != EOF) {
344                         if (c == '\n')
345                                 goto out;
346                         *ptr++ = (char)c;
347
348                         if (ptr - line >= size - 1) {
349                                 char *tmp;
350
351                                 size *= 2;
352                                 tmp = malloc(size);
353                                 if (tmp == NULL)
354                                         goto outfree;
355                                 memcpy(tmp, line, ptr - line);
356                                 ptr = tmp + (ptr - line);
357                                 free(line);
358                                 line = tmp;
359                         }
360                 } else {
361                         eof = 1;
362                         if (ferror(stdin) || feof(stdin))
363                                 goto outfree;
364                         goto out;
365                 }
366         }
367 out:
368         *ptr = 0;
369         if (eof && (strlen(line) == 0)) {
370                 free(line);
371                 line = NULL;
372         }
373         return line;
374 outfree:
375         free(line);
376         return NULL;
377 }
378 #endif
379
380 /* this is the command execution machine */
381 int Parser_commands(void)
382 {
383         char *line, *s;
384         int rc = 0, save_error = 0;
385         int interactive;
386
387         interactive = init_input();
388
389         while(!done) {
390                 line = readline(interactive ? parser_prompt : NULL);
391
392                 if (!line) break;
393
394                 s = skipwhitespace(line);
395
396                 if (*s) {
397                         add_history(s);
398                         rc = execute_line(s);
399                 }
400                 /* stop on error if not-interactive */
401                 if (rc != 0 && !interactive) {
402                         if (save_error == 0)
403                                 save_error = rc;
404                         if (!ignore_errors)
405                                 done = 1;
406                 }
407
408                 free(line);
409         }
410         if (save_error)
411                 rc = save_error;
412         return rc;
413 }
414
415
416 /* sets the parser prompt */
417 void Parser_init(char * prompt, command_t * cmds)
418 {
419         done = 0;
420         top_level = cmds;
421         if (parser_prompt) free(parser_prompt);
422         parser_prompt = strdup(prompt);
423 }
424
425 /* frees the parser prompt */
426 void Parser_exit(int argc, char *argv[])
427 {
428         done = 1;
429         free(parser_prompt);
430         parser_prompt = NULL;
431 }
432
433 /* convert a string to an integer */
434 int Parser_int(char *s, int *val)
435 {
436         int ret;
437
438         if (*s != '0')
439                 ret = sscanf(s, "%d", val);
440         else if (*(s+1) != 'x')
441                 ret = sscanf(s, "%o", val);
442         else {
443                 s++;
444                 ret = sscanf(++s, "%x", val);
445         }
446
447         return(ret);
448 }
449
450
451 void Parser_qhelp(int argc, char *argv[]) {
452
453         printf("usage: %s [COMMAND] [OPTIONS]... [ARGS]\n",
454                 program_invocation_short_name);
455         printf("Without any parameters, interactive mode is invoked\n");
456
457         printf("Try '%s help <COMMAND>' or '%s --list-commands' for more information\n",
458                 program_invocation_short_name, program_invocation_short_name);
459 }
460
461 int Parser_help(int argc, char **argv)
462 {
463         char line[1024];
464         char *next, *prev, *tmp;
465         command_t *result, *ambig;
466         int i;
467
468         if ( argc == 1 ) {
469                 Parser_qhelp(argc, argv);
470                 return 0;
471         }
472
473         /* Joining command line arguments without space is not critical here
474          * because of this string is used for search a help topic and assume
475          * that only one argument will be (the name of topic). For example:
476          * lst > help ping run
477          * pingrun: Unknown command. */
478         line[0] = '\0';
479         for (i = 1;  i < argc; i++) {
480                 if (strlen(argv[i]) >= sizeof(line) - strlen(line))
481                         return -E2BIG;
482                 /* The function strlcat() cannot be used here because of
483                  * this function is used in LNet utils that is not linked
484                  * with libcfs.a. */
485                 strncat(line, argv[i], sizeof(line) - strlen(line));
486         }
487
488         switch ( process(line, &next, top_level, &result, &prev) ) {
489         case CMD_COMPLETE:
490                 fprintf(stderr, "%s: %s\n",line, result->pc_help);
491                 break;
492         case CMD_NONE:
493                 fprintf(stderr, "%s: Unknown command.\n", line);
494                 break;
495         case CMD_INCOMPLETE:
496                 fprintf(stderr,
497                         "'%s' incomplete command.  Use '%s x' where x is one of:\n",
498                         line, line);
499                 fprintf(stderr, "\t");
500                 for (i = 0; result->pc_sub_cmd[i].pc_name; i++) {
501                         fprintf(stderr, "%s ", result->pc_sub_cmd[i].pc_name);
502                 }
503                 fprintf(stderr, "\n");
504                 break;
505         case CMD_AMBIG:
506                 fprintf(stderr, "Ambiguous command \'%s\'\nOptions: ", line);
507                 while( (ambig = find_cmd(prev, result, &tmp)) ) {
508                         fprintf(stderr, "%s ", ambig->pc_name);
509                         result = ambig + 1;
510                 }
511                 fprintf(stderr, "\n");
512                 break;
513         }
514         return 0;
515 }
516
517
518 void Parser_printhelp(char *cmd)
519 {
520         char *argv[] = { "help", cmd };
521         Parser_help(2, argv);
522 }
523
524
525 /*************************************************************************
526  * COMMANDS                                                              *
527  *************************************************************************/
528
529 /**
530  * Parser_list_commands() - Output a list of the supported commands.
531  * @cmdlist:      Array of structures describing the commands.
532  * @buffer:       String buffer used to temporarily store the output text.
533  * @buf_size:     Length of the string buffer.
534  * @parent_cmd:   When called recursively, contains the name of the parent cmd.
535  * @col_start:    Column where printing should begin.
536  * @col_num:      The number of commands printed in a single row.
537  *
538  * The commands and subcommands supported by the utility are printed, arranged
539  * into several columns for readability.  If a command supports subcommands, the
540  * function is called recursively, and the name of the parent command is
541  * supplied so that it can be prepended to the names of the subcommands.
542  *
543  * Return: The number of items that were printed.
544  */
545 int Parser_list_commands(const command_t *cmdlist, char *buffer,
546                          size_t buf_size, const char *parent_cmd,
547                          int col_start, int col_num)
548 {
549         int col = col_start;
550         int char_max;
551         int len;
552         char fmt[6];
553         int count = 0;
554         int rc;
555
556         if (col_start >= col_num)
557                 return 0;
558
559         char_max = (buf_size - 1) / col_num; /* Reserve 1 char for NUL */
560
561         for (; cmdlist->pc_name != NULL; cmdlist++) {
562                 if (cmdlist->pc_func == NULL && cmdlist->pc_sub_cmd == NULL)
563                         break;
564                 count++;
565                 if (parent_cmd != NULL)
566                         len = snprintf(&buffer[col * char_max],
567                                        char_max + 1, "%s %s", parent_cmd,
568                                        cmdlist->pc_name);
569                 else
570                         len = snprintf(&buffer[col * char_max],
571                                        char_max + 1, "%s", cmdlist->pc_name);
572
573                 /* Add trailing spaces to pad the entry to the column size */
574                 if (len < char_max) {
575                         snprintf(fmt, 6, "%%-%2ds", char_max - len);
576                         snprintf(&buffer[col * char_max] + len,
577                                  char_max - len + 1, fmt, " ");
578                 } else {
579                         buffer[(col + 1) * char_max - 1] = ' ';
580                 }
581
582                 col++;
583                 if (col >= col_num) {
584                         fprintf(stdout, "%s\n", buffer);
585                         col = 0;
586                         buffer[0] = '\0';
587                 }
588
589                 if (cmdlist->pc_sub_cmd != NULL) {
590                         rc = Parser_list_commands(cmdlist->pc_sub_cmd, buffer,
591                                                  buf_size, cmdlist->pc_name,
592                                                  col, col_num);
593                         col = (col + rc) % col_num;
594                         count += rc;
595                 }
596         }
597         if (parent_cmd == NULL && col != 0)
598                 fprintf(stdout, "%s\n", buffer);
599         return count;
600 }
601
602 char *Parser_getstr(const char *prompt, const char *deft, char *res,
603                     size_t len)
604 {
605         char *line = NULL;
606         int size = strlen(prompt) + strlen(deft) + 8;
607         char *theprompt;
608         theprompt = malloc(size);
609         assert(theprompt);
610
611         sprintf(theprompt, "%s [%s]: ", prompt, deft);
612
613         line  = readline(theprompt);
614         free(theprompt);
615
616         /* The function strlcpy() cannot be used here because of
617          * this function is used in LNet utils that is not linked
618          * with libcfs.a. */
619         if (line == NULL || *line == '\0')
620                 strncpy(res, deft, len);
621         else
622                 strncpy(res, line, len);
623         res[len - 1] = '\0';
624
625         if (line != NULL) {
626                 free(line);
627                 return res;
628         }
629         return NULL;
630 }
631
632 /* get integer from prompt, loop forever to get it */
633 int Parser_getint(const char *prompt, long min, long max, long deft, int base)
634 {
635         int rc;
636         long result;
637         char *line;
638         int size = strlen(prompt) + 40;
639         char *theprompt = malloc(size);
640         assert(theprompt);
641         sprintf(theprompt,"%s [%ld, (0x%lx)]: ", prompt, deft, deft);
642
643         fflush(stdout);
644
645         do {
646                 line = NULL;
647                 line = readline(theprompt);
648                 if ( !line ) {
649                         fprintf(stdout, "Please enter an integer.\n");
650                         fflush(stdout);
651                         continue;
652                 }
653                 if ( *line == '\0' ) {
654                         free(line);
655                         result =  deft;
656                         break;
657                 }
658                 rc = Parser_arg2int(line, &result, base);
659                 free(line);
660                 if ( rc != 0 ) {
661                         fprintf(stdout, "Invalid string.\n");
662                         fflush(stdout);
663                 } else if ( result > max || result < min ) {
664                         fprintf(stdout, "Error: response must lie between %ld and %ld.\n",
665                                 min, max);
666                         fflush(stdout);
667                 } else {
668                         break;
669                 }
670         } while ( 1 ) ;
671
672         if (theprompt)
673                 free(theprompt);
674         return result;
675
676 }
677
678 /* get boolean (starting with YyNn; loop forever */
679 int Parser_getbool(const char *prompt, int deft)
680 {
681         int result = 0;
682         char *line;
683         int size = strlen(prompt) + 8;
684         char *theprompt = malloc(size);
685         assert(theprompt);
686
687         fflush(stdout);
688
689         if ( deft != 0 && deft != 1 ) {
690                 fprintf(stderr, "Error: Parser_getbool given bad default %d\n",
691                         deft);
692                 assert ( 0 );
693         }
694         sprintf(theprompt, "%s [%s]: ", prompt, (deft==0)? "N" : "Y");
695
696         do {
697                 line = NULL;
698                 line = readline(theprompt);
699                 if ( line == NULL ) {
700                         result = deft;
701                         break;
702                 }
703                 if ( *line == '\0' ) {
704                         result = deft;
705                         break;
706                 }
707                 if ( *line == 'y' || *line == 'Y' ) {
708                         result = 1;
709                         break;
710                 }
711                 if ( *line == 'n' || *line == 'N' ) {
712                         result = 0;
713                         break;
714                 }
715                 if ( line )
716                         free(line);
717                 fprintf(stdout, "Invalid string. Must start with yY or nN\n");
718                 fflush(stdout);
719         } while ( 1 );
720
721         if ( line )
722                 free(line);
723         if ( theprompt )
724                 free(theprompt);
725         return result;
726 }
727
728 /* parse int out of a string or prompt for it */
729 long Parser_intarg(const char *inp, const char *prompt, int deft,
730                    int min, int max, int base)
731 {
732         long result;
733         int rc;
734
735         rc = Parser_arg2int(inp, &result, base);
736
737         if ( rc == 0 ) {
738                 return result;
739         } else {
740                 return Parser_getint(prompt, deft, min, max, base);
741         }
742 }
743
744 /* parse int out of a string or prompt for it */
745 char *Parser_strarg(char *inp, const char *prompt, const char *deft,
746                     char *answer, int len)
747 {
748         if ( inp == NULL || *inp == '\0' ) {
749                 return Parser_getstr(prompt, deft, answer, len);
750         } else
751                 return inp;
752 }
753
754 /* change a string into a number: return 0 on success. No invalid characters
755    allowed. The processing of base and validity follows strtol(3)*/
756 int Parser_arg2int(const char *inp, long *result, int base)
757 {
758         char *endptr;
759
760         if ( (base !=0) && (base < 2 || base > 36) )
761                 return 1;
762
763         *result = strtol(inp, &endptr, base);
764
765         if ( *inp != '\0' && *endptr == '\0' )
766                 return 0;
767         else
768                 return 1;
769 }
770
771 /* Convert human readable size string to and int; "1k" -> 1000 */
772 int Parser_size (int *sizep, char *str) {
773         int size;
774         char mod[32];
775
776         switch (sscanf (str, "%d%1[gGmMkK]", &size, mod)) {
777         default:
778                 return (-1);
779
780         case 1:
781                 *sizep = size;
782                 return (0);
783
784         case 2:
785                 switch (*mod) {
786                 case 'g':
787                 case 'G':
788                         *sizep = size << 30;
789                         return (0);
790
791                 case 'm':
792                 case 'M':
793                         *sizep = size << 20;
794                         return (0);
795
796                 case 'k':
797                 case 'K':
798                         *sizep = size << 10;
799                         return (0);
800
801                 default:
802                         *sizep = size;
803                         return (0);
804                 }
805         }
806 }
807
808 /* Convert a string boolean to an int; "enable" -> 1 */
809 int Parser_bool (int *b, char *str) {
810         if (!strcasecmp (str, "no") ||
811             !strcasecmp (str, "n") ||
812             !strcasecmp (str, "off") ||
813             !strcasecmp (str, "down") ||
814             !strcasecmp (str, "disable"))
815         {
816                 *b = 0;
817                 return (0);
818         }
819
820         if (!strcasecmp (str, "yes") ||
821             !strcasecmp (str, "y") ||
822             !strcasecmp (str, "on") ||
823             !strcasecmp (str, "up") ||
824             !strcasecmp (str, "enable"))
825         {
826                 *b = 1;
827                 return (0);
828         }
829
830         return (-1);
831 }
832
833 int Parser_quit(int argc, char **argv)
834 {
835         argc = argc;
836         argv = argv;
837         done = 1;
838         return 0;
839 }
840
841 int Parser_version(int argc, char **argv)
842 {
843         fprintf(stdout, "%s %s\n", program_invocation_short_name,
844                 LUSTRE_VERSION_STRING);
845         return 0;
846 }