6 // JOS command-line parsing functions.
8 // Initializes the Argstate buffer from argc and argv.
9 // (Note: it is safe to use a 'const char **' for argv.)
10 void argstart(int *argc
, char **argv
, struct Argstate
*args
);
12 // Returns the next flag in the argument list,
13 // or -1 if there are no more flags.
15 // Flags stop at a non-flag (anything that doesn't start with '-'),
16 // at the end of the argument list, before "-", or after "--",
17 // whichever comes first. Any "--" argument is not returned.
19 // Consumes arguments from the argc/argv array passed in to argstart.
20 // If you argstart with an argc/argv array of ["sh", "-i", "foo"],
21 // the first call to argnext will return 'i' and change the array to
22 // ["sh", "foo"]. Thus, when argnext returns -1, the argc/argv array
23 // contains just the non-flag arguments.
24 int argnext(struct Argstate
*);
26 // Returns the next value for the current flag, or 0 if it has no value.
27 // For example, given an argument list ["-fval1", "val2", "val3"],
28 // a call to argnext() will return 'f', after which repeated calls to
29 // argnextvalue will return "val1", "val2", and "val3".
30 // Consumes arguments from the argc/argv array.
31 char *argnextvalue(struct Argstate
*);
33 // Returns the current flag's value, or 0 if it has no value.
34 // Behaves like argnextvalue, except that repeated calls to argvalue will
35 // return the same value.
36 char *argvalue(struct Argstate
*);
38 // Used by panic() to print the program name.
39 extern const char *argv0
;
43 // #include <inc/lib.h>
46 // umain(int argc, char **argv)
49 // struct Argstate args;
51 // argstart(&argc, argv, &args);
52 // while ((i = argnext(&args)) >= 0)
56 // cprintf("'-%c' flag\n", i);
59 // cprintf("'-f %s' flag\n", argvalue(&args));
62 // cprintf("unknown flag\n");
65 // for (i = 1; i < argc; i++)
66 // cprintf("argument '%s'\n", argv[i]);
69 // If this program is run with the arguments
70 // ["-rx", "-f", "foo", "--", "-r", "duh"]