Mercurial > hg > toybox
annotate lib/args.c @ 1071:e7454bb7af5a draft
Fluff out option parsing documentation, add another DEBUG test.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 21 Sep 2013 12:24:04 -0500 |
parents | de0ecfb36b7c |
children | 7a45b9b54d3d |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
1 /* args.c - Command line argument parsing. |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2006 Rob Landley <rob@landley.net> |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 */ |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 #include "toys.h" |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 // Design goals: |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
9 // Don't use getopt() out of libc. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
10 // Don't permute original arguments (screwing up ps/top output). |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
11 // Integrated --long options "(noshort)a(along)b(blong1)(blong2)" |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
13 /* This uses a getopt-like option string, but not getopt() itself. We call |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
14 * it the get_opt string. |
156
1e8f4b05cb65
Remove trailing whitespace (thanks to Charlie Shepherd), and a couple comment
Rob Landley <rob@landley.net>
parents:
144
diff
changeset
|
15 * |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
16 * Each option in the get_opt string corresponds to a bit position in the |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
17 * return value. The rightmost argument is (1<<0), the next to last is (1<<1) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
18 * and so on. If the option isn't seen in argv[], its bit remains 0. |
78
cd1f36a96185
Update args.c to implement numeric arguments.
Rob Landley <rob@landley.net>
parents:
49
diff
changeset
|
19 * |
cd1f36a96185
Update args.c to implement numeric arguments.
Rob Landley <rob@landley.net>
parents:
49
diff
changeset
|
20 * Options which have an argument fill in the corresponding slot in the global |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
21 * union "this" (see generated/globals.h), which it treats as an array of longs |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
22 * (note that sizeof(long)==sizeof(pointer) is guaranteed by LP64). |
78
cd1f36a96185
Update args.c to implement numeric arguments.
Rob Landley <rob@landley.net>
parents:
49
diff
changeset
|
23 * |
cd1f36a96185
Update args.c to implement numeric arguments.
Rob Landley <rob@landley.net>
parents:
49
diff
changeset
|
24 * You don't have to free the option strings, which point into the environment |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
25 * space. List objects should be freed by main() when command_main() returns. |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 * |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 * Example: |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
28 * Calling get_optflags() when toys.which->options="ab:c:d" and |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
29 * argv = ["command", "-b", "fruit", "-d", "walrus"] results in: |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
30 * |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
31 * Changes to struct toys: |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
32 * toys.optflags = 5 (I.E. 0101 so -b = 4 | -d = 1) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
33 * toys.optargs[0] = "walrus" (leftover argument) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
34 * toys.optargs[1] = NULL (end of list) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
35 * toys.optc = 1 (there was 1 leftover argument) |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
36 * |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
37 * Changes to union this: |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
38 * this[0]=NULL (because -c didn't get an argument this time) |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
39 * this[1]="fruit" (argument to -b) |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 */ |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
42 // Enabling TOYBOX_DEBUG in .config adds syntax checks to option string parsing |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
43 // which aren't needed in the final code (your option string is hardwired and |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
44 // should be correct when you ship), but are useful for development. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
45 |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
46 // What you can put in a get_opt string: |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
47 // Any otherwise unused character (all letters, unprefixed numbers) specify |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
48 // an option that sets a flag. The bit value is the same as the binary digit |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
49 // if you string the option characters together in order. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
50 // So in "abcdefgh" a = 128, h = 1 |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
51 // |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
52 // Suffixes specify that this option takes an argument (stored in GLOBALS): |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
53 // Note that pointer and long are always the same size, even on 64 bit. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
54 // : plus a string argument, keep most recent if more than one |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
55 // * plus a string argument, appended to a list |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
56 // # plus a signed long argument |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
57 // <LOW - die if less than LOW |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
58 // >HIGH - die if greater than HIGH |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
59 // =DEFAULT - value if not specified |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
60 // - plus a signed long argument defaulting to negative (say + for positive) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
61 // . plus a double precision floating point argument (with CFG_TOYBOX_FLOAT) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
62 // Chop this option out with USE_TOYBOX_FLOAT() in option string |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
63 // Same <LOW>HIGH=DEFAULT as # |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
64 // @ plus an occurrence counter (which is a long) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
65 // (longopt) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
66 // | this is required. If more than one marked, only one required. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
67 // ; long option's argument is optional (can only be supplied with --opt=) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
68 // ^ Stop parsing after encountering this argument |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
69 // " " (space char) the "plus an argument" must be separate |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
70 // I.E. "-j 3" not "-j3". So "kill -stop" != "kill -s top" |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
71 // |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
72 // At the beginning of the get_opt string (before any options): |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
73 // ^ stop at first nonoption argument |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
74 // <0 die if less than # leftover arguments (default 0) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
75 // >9 die if > # leftover arguments (default MAX_INT) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
76 // ? Allow unknown arguments (pass them through to command). |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
77 // & first argument has imaginary dash (ala tar/ps) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
78 // If given twice, all arguments have imaginary dash |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
79 // |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
80 // At the end: [groups] of previously seen options |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
81 // - Only one in group (switch off) [-abc] means -ab=-b, -ba=-a, -abc=-c |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
82 // | Synonyms (switch on all) [|abc] means -ab=-abc, -c=-abc |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
83 // ! More than one in group is error [!abc] means -ab calls error_exit() |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
84 // + First in group switches rest on [+abc] means -a=-abc, -b=-b, -c=-c |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
85 // primarily useful if you can switch things back off again. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
86 // |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
87 |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
88 // Notes from getopt man page |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
89 // - and -- cannot be arguments. |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
90 // -- force end of arguments |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
91 // - is a synonym for stdin in file arguments |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
92 // -abcd means -a -b -c -d (but if -b takes an argument, then it's -a -b cd) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
93 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
94 // Linked list of all known options (option string parsed into this). |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
95 // Hangs off getoptflagstate, freed at end of option parsing. |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 struct opts { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
97 struct opts *next; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
98 long *arg; // Pointer into union "this" to store arguments at. |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
99 int c; // Argument character to match |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
100 int flags; // |=1, ^=2 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
101 unsigned dex[3]; // which bits to disable/enable/exclude in toys.optflags |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
102 char type; // Type of arguments to store union "this" |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
103 union { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
104 long l; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
105 FLOAT f; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
106 } val[3]; // low, high, default - range of allowed values |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 }; |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
109 // linked list of long options. (Hangs off getoptflagstate, free at end of |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
110 // option parsing, details about flag to set and global slot to fill out |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
111 // stored in related short option struct, but if opt->c = -1 the long option |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
112 // is "bare" (has no corresponding short option). |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
113 struct longopts { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
114 struct longopts *next; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
115 struct opts *opt; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
116 char *str; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
117 int len; |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
118 }; |
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
119 |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
120 // State during argument parsing. |
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
121 struct getoptflagstate |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
123 int argc, minargs, maxargs, nodash; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
124 char *arg; |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
125 struct opts *opts; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
126 struct longopts *longopts; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
127 int noerror, nodash_now, stopearly; |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
128 unsigned excludes, requires; |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
129 }; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
131 // Use getoptflagstate to parse parse one command line option from argv |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
132 static int gotflag(struct getoptflagstate *gof, struct opts *opt) |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
134 int type; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
136 // Did we recognize this option? |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
137 if (!opt) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
138 if (gof->noerror) return 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
139 error_exit("Unknown option %s", gof->arg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
140 } |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
141 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
142 // Set flags |
1054
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
143 if (toys.optflags & opt->dex[0]) { |
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
144 struct opts *clr; |
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
145 unsigned i = 1; |
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
146 |
1058
de0ecfb36b7c
Fix [-group] argument dropping.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
147 for (clr=gof->opts, i=1; clr; clr = clr->next, i<<=1) |
de0ecfb36b7c
Fix [-group] argument dropping.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
148 if (clr->arg && (i & toys.optflags)) *clr->arg = 0; |
1054
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
149 toys.optflags &= ~opt->dex[0]; |
0d8a664f9941
Make [-abc] exclude logic clear argument slots when disabling options.
Rob Landley <rob@landley.net>
parents:
1036
diff
changeset
|
150 } |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
151 toys.optflags |= opt->dex[1]; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
152 gof->excludes |= opt->dex[2]; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
153 if (opt->flags&2) gof->stopearly=2; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 |
709 | 155 if (toys.optflags & gof->excludes) { |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
156 struct opts *bad; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
157 unsigned i = 1; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
158 |
773
edde4d30e98c
Ashwini Sharma pointed out that my previous tweak to [!abc] groups still didn't get the error reporting right (test case "touch -d 12 -r f2 f1"). This says "no 'r' with 'd'" for that, and still shouldn't be able to fall off the end of the list (segfault) because an option can't conflict with itself (that's what the ~(1<<i) on lib/args.c line 317 is for).
Rob Landley <rob@landley.net>
parents:
770
diff
changeset
|
159 for (bad=gof->opts, i=1; ;bad = bad->next, i<<=1) { |
edde4d30e98c
Ashwini Sharma pointed out that my previous tweak to [!abc] groups still didn't get the error reporting right (test case "touch -d 12 -r f2 f1"). This says "no 'r' with 'd'" for that, and still shouldn't be able to fall off the end of the list (segfault) because an option can't conflict with itself (that's what the ~(1<<i) on lib/args.c line 317 is for).
Rob Landley <rob@landley.net>
parents:
770
diff
changeset
|
160 if (opt == bad || !(i & toys.optflags)) continue; |
edde4d30e98c
Ashwini Sharma pointed out that my previous tweak to [!abc] groups still didn't get the error reporting right (test case "touch -d 12 -r f2 f1"). This says "no 'r' with 'd'" for that, and still shouldn't be able to fall off the end of the list (segfault) because an option can't conflict with itself (that's what the ~(1<<i) on lib/args.c line 317 is for).
Rob Landley <rob@landley.net>
parents:
770
diff
changeset
|
161 if (toys.optflags & bad->dex[2]) break; |
edde4d30e98c
Ashwini Sharma pointed out that my previous tweak to [!abc] groups still didn't get the error reporting right (test case "touch -d 12 -r f2 f1"). This says "no 'r' with 'd'" for that, and still shouldn't be able to fall off the end of the list (segfault) because an option can't conflict with itself (that's what the ~(1<<i) on lib/args.c line 317 is for).
Rob Landley <rob@landley.net>
parents:
770
diff
changeset
|
162 } |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
163 error_exit("No '%c' with '%c'", opt->c, bad->c); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
164 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
165 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
166 // Does this option take an argument? |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
167 if (!gof->arg) { |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
168 if (opt->flags & 8) return 0; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
169 gof->arg = ""; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
170 } else gof->arg++; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
171 type = opt->type; |
931
011df43e35d5
Option type @ counts number of occurrences, it doesn't take an argument.
Rob Landley <rob@landley.net>
parents:
891
diff
changeset
|
172 |
011df43e35d5
Option type @ counts number of occurrences, it doesn't take an argument.
Rob Landley <rob@landley.net>
parents:
891
diff
changeset
|
173 if (type == '@') ++*(opt->arg); |
011df43e35d5
Option type @ counts number of occurrences, it doesn't take an argument.
Rob Landley <rob@landley.net>
parents:
891
diff
changeset
|
174 else if (type) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
175 char *arg = gof->arg; |
32
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
29
diff
changeset
|
176 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
177 // Handle "-xblah" and "-x blah", but also a third case: "abxc blah" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
178 // to make "tar xCjfv blah1 blah2 thingy" work like |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
179 // "tar -x -C blah1 -j -f blah2 -v thingy" |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
180 |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
181 if (gof->nodash_now || (!arg[0] && !(opt->flags & 8))) |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
182 arg = toys.argv[++gof->argc]; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
183 if (!arg) { |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
184 char *s = "Missing argument to "; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
185 struct longopts *lo; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
186 |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
187 if (opt->c != -1) error_exit("%s-%c", s, opt->c); |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
188 |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
189 for (lo = gof->longopts; lo->opt != opt; lo = lo->next); |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
190 error_exit("%s--%.*s", s, lo->len, lo->str); |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
191 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
193 if (type == ':') *(opt->arg) = (long)arg; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
194 else if (type == '*') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
195 struct arg_list **list; |
298
1bb9f53a7101
Assemble '*' repeated argument list in order. Also implement '@' counter.
Rob Landley <rob@landley.net>
parents:
294
diff
changeset
|
196 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
197 list = (struct arg_list **)opt->arg; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
198 while (*list) list=&((*list)->next); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
199 *list = xzalloc(sizeof(struct arg_list)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
200 (*list)->arg = arg; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
201 } else if (type == '#' || type == '-') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
202 long l = atolx(arg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
203 if (type == '-' && !ispunct(*arg)) l*=-1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
204 if (l < opt->val[0].l) error_exit("-%c < %ld", opt->c, opt->val[0].l); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
205 if (l > opt->val[1].l) error_exit("-%c > %ld", opt->c, opt->val[1].l); |
415
2cbbd4c5eaaa
Add <>= to lib/args.c, with documentation.
Rob Landley <rob@landley.net>
parents:
393
diff
changeset
|
206 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
207 *(opt->arg) = l; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
208 } else if (CFG_TOYBOX_FLOAT && type == '.') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
209 FLOAT *f = (FLOAT *)(opt->arg); |
415
2cbbd4c5eaaa
Add <>= to lib/args.c, with documentation.
Rob Landley <rob@landley.net>
parents:
393
diff
changeset
|
210 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
211 *f = strtod(arg, &arg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
212 if (opt->val[0].l != LONG_MIN && *f < opt->val[0].f) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
213 error_exit("-%c < %lf", opt->c, (double)opt->val[0].f); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
214 if (opt->val[1].l != LONG_MAX && *f > opt->val[1].f) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
215 error_exit("-%c > %lf", opt->c, (double)opt->val[1].f); |
931
011df43e35d5
Option type @ counts number of occurrences, it doesn't take an argument.
Rob Landley <rob@landley.net>
parents:
891
diff
changeset
|
216 } |
29
5566beb17d5a
Fix a half-dozen bugs in argument parsing. More seems to work than not now.
Rob Landley <rob@landley.net>
parents:
28
diff
changeset
|
217 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
218 if (!gof->nodash_now) gof->arg = ""; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
219 } |
32
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
29
diff
changeset
|
220 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
221 return 0; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 } |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
224 // Parse this command's options string into struct getoptflagstate, which |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
225 // includes a struct opts linked list in reverse order (I.E. right-to-left) |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
226 void parse_optflaglist(struct getoptflagstate *gof) |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
228 char *options = toys.which->options; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
229 long *nextarg = (long *)&this; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
230 struct opts *new = 0; |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
231 int idx; |
28
be59ed005902
Allocate a more sane amount of memory.
Rob Landley <rob@landley.net>
parents:
26
diff
changeset
|
232 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
233 // Parse option format string |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
234 memset(gof, 0, sizeof(struct getoptflagstate)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
235 gof->maxargs = INT_MAX; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
236 if (!options) return; |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
237 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
238 // Parse leading special behavior indicators |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
239 for (;;) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
240 if (*options == '^') gof->stopearly++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
241 else if (*options == '<') gof->minargs=*(++options)-'0'; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
242 else if (*options == '>') gof->maxargs=*(++options)-'0'; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
243 else if (*options == '?') gof->noerror++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
244 else if (*options == '&') gof->nodash++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
245 else break; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
246 options++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
247 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
248 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
249 // Parse option string into a linked list of options with attributes. |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
250 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
251 if (!*options) gof->stopearly++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
252 while (*options) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
253 char *temp; |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
254 |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
255 // Option groups come after all options are defined |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
256 if (*options == '[') break; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
257 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
258 // Allocate a new list entry when necessary |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
259 if (!new) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
260 new = xzalloc(sizeof(struct opts)); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
261 new->next = gof->opts; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
262 gof->opts = new; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
263 new->val[0].l = LONG_MIN; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
264 new->val[1].l = LONG_MAX; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
265 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
266 // Each option must start with "(" or an option character. (Bare |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
267 // longopts only come at the start of the string.) |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
268 if (*options == '(' && new->c != -1) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
269 char *end; |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
270 struct longopts *lo; |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
271 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
272 // Find the end of the longopt |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
273 for (end = ++options; *end && *end != ')'; end++); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
274 if (CFG_TOYBOX_DEBUG && !*end) error_exit("(longopt) didn't end"); |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
275 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
276 // init a new struct longopts |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
277 lo = xmalloc(sizeof(struct longopts)); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
278 lo->next = gof->longopts; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
279 lo->opt = new; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
280 lo->str = options; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
281 lo->len = end-options; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
282 gof->longopts = lo; |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
283 options = ++end; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
284 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
285 // Mark this struct opt as used, even when no short opt. |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
286 if (!new->c) new->c = -1; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
287 |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
288 continue; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
289 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
290 // If this is the start of a new option that wasn't a longopt, |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
291 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
292 } else if (strchr(":*#@.-", *options)) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
293 if (CFG_TOYBOX_DEBUG && new->type) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
294 error_exit("multiple types %c:%c%c", new->c, new->type, *options); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
295 new->type = *options; |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
296 } else if (-1 != (idx = stridx("|^ ;", *options))) new->flags |= 1<<idx; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
297 // bounds checking |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
298 else if (-1 != (idx = stridx("<>=", *options))) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
299 if (new->type == '#') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
300 long l = strtol(++options, &temp, 10); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
301 if (temp != options) new->val[idx].l = l; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
302 } else if (CFG_TOYBOX_FLOAT && new->type == '.') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
303 FLOAT f = strtod(++options, &temp); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
304 if (temp != options) new->val[idx].f = f; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
305 } else if (CFG_TOYBOX_DEBUG) error_exit("<>= only after .#"); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
306 options = --temp; |
261
ae693c7bf2f7
Add enable/disable/exclude logic, update docs.
Rob Landley <rob@landley.net>
parents:
255
diff
changeset
|
307 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
308 // At this point, we've hit the end of the previous option. The |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
309 // current character is the start of a new option. If we've already |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
310 // assigned an option to this struct, loop to allocate a new one. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
311 // (It'll get back here afterwards and fall through to next else.) |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
312 } else if (new->c) { |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
313 new = 0; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
314 continue; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
315 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
316 // Claim this option, loop to see what's after it. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
317 } else new->c = *options; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
318 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
319 options++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
320 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
321 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
322 // Initialize enable/disable/exclude masks and pointers to store arguments. |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
323 // (This goes right to left so we need the whole list before we can start.) |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
324 idx = 0; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
325 for (new = gof->opts; new; new = new->next) { |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
326 unsigned u = 1<<idx++; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
327 |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
328 new->dex[1] = u; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
329 if (new->flags & 1) gof->requires |= u; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
330 if (new->type) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
331 new->arg = (void *)nextarg; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
332 *(nextarg++) = new->val[2].l; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
333 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
334 } |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
335 |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
336 // Parse trailing group indicators |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
337 while (*options) { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
338 unsigned bits = 0; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
339 |
770 | 340 if (CFG_TOYBOX_DEBUG && *options != '[') error_exit("trailing %s", options); |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
341 |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
342 idx = stridx("-|!+", *++options); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
343 if (CFG_TOYBOX_DEBUG && idx == -1) error_exit("[ needs +-!"); |
1071
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
344 if (CFG_TOYBOX_DEBUG && (*options == ']' || !options)) |
e7454bb7af5a
Fluff out option parsing documentation, add another DEBUG test.
Rob Landley <rob@landley.net>
parents:
1058
diff
changeset
|
345 error_exit("empty []"); |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
346 |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
347 // Don't advance past ] but do process it once in loop. |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
348 while (*(options++) != ']') { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
349 struct opts *opt, *opt2 = 0; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
350 int i; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
351 |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
352 if (CFG_TOYBOX_DEBUG && !*options) error_exit("[ without ]"); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
353 // Find this option flag (in previously parsed struct opt) |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
354 for (i=0, opt = gof->opts; ; i++, opt = opt->next) { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
355 if (*options == ']') { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
356 if (!opt) break; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
357 if (idx == 3) { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
358 opt2->dex[1] |= bits; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
359 break; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
360 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
361 if (bits&(1<<i)) opt->dex[idx] |= bits&~(1<<i); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
362 } else { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
363 if (CFG_TOYBOX_DEBUG && !opt) |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
364 error_exit("[] unknown target %c", *options); |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
365 if (opt->c == *options) { |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
366 bits |= 1<<i; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
367 if (!opt2) opt2=opt; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
368 break; |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
369 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
370 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
371 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
372 } |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
373 } |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
374 } |
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
375 |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
376 // Fill out toys.optflags, toys.optargs, and this[] from toys.argv |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
377 |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
378 void get_optflags(void) |
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
379 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
380 struct getoptflagstate gof; |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
381 struct opts *catch; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
382 long saveflags; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
383 char *letters[]={"s",""}; |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
384 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
385 // Option parsing is a two stage process: parse the option string into |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
386 // a struct opts list, then use that list to process argv[]; |
393
bfc208c5ac79
Split out parse_optflaglist(), and move local variables to optflagstate.
Rob Landley <rob@landley.net>
parents:
392
diff
changeset
|
387 |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
845
diff
changeset
|
388 toys.exithelp++; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
389 // Allocate memory for optargs |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
390 saveflags = 0; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
391 while (toys.argv[saveflags++]); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
392 toys.optargs = xzalloc(sizeof(char *)*saveflags); |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
393 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
394 parse_optflaglist(&gof); |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
395 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
396 // Iterate through command line arguments, skipping argv[0] |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
397 for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
398 gof.arg = toys.argv[gof.argc]; |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
399 catch = NULL; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
400 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
401 // Parse this argument |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
402 if (gof.stopearly>1) goto notflag; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
403 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
404 gof.nodash_now = 0; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
405 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
406 // Various things with dashes |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
407 if (*gof.arg == '-') { |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
408 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
409 // Handle - |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
410 if (!gof.arg[1]) goto notflag; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
411 gof.arg++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
412 if (*gof.arg=='-') { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
413 struct longopts *lo; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
414 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
415 gof.arg++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
416 // Handle -- |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
417 if (!*gof.arg) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
418 gof.stopearly += 2; |
845
44ed476d5c87
Fix argument parsing so -- doesn't include itself in output.
Rob Landley <rob@landley.net>
parents:
773
diff
changeset
|
419 continue; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
420 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
421 |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
422 // do we match a known --longopt? |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
423 for (lo = gof.longopts; lo; lo = lo->next) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
424 if (!strncmp(gof.arg, lo->str, lo->len)) { |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
425 if (!gof.arg[lo->len]) gof.arg = 0; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
426 else if (gof.arg[lo->len] == '=' && lo->opt->type) |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
427 gof.arg += lo->len; |
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
428 else continue; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
429 // It's a match. |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
430 catch = lo->opt; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
431 break; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
432 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
433 } |
29
5566beb17d5a
Fix a half-dozen bugs in argument parsing. More seems to work than not now.
Rob Landley <rob@landley.net>
parents:
28
diff
changeset
|
434 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
435 // Should we handle this --longopt as a non-option argument? |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
436 if (!lo && gof.noerror) { |
1036
a25239480e7a
Improve --longopt parsing: general bugfixes, better error reporting, new ; option for optional arguments only suppliable with =.
Rob Landley <rob@landley.net>
parents:
978
diff
changeset
|
437 gof.arg -= 2; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
438 goto notflag; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
439 } |
294
3de1ea4d6b56
Fix command line option parsing so "echo -xen" actually prints "-xen". Add
Rob Landley <rob@landley.net>
parents:
289
diff
changeset
|
440 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
441 // Long option parsed, handle option. |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
442 gotflag(&gof, catch); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
443 continue; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
444 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
445 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
446 // Handle things that don't start with a dash. |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
447 } else { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
448 if (gof.nodash && (gof.nodash>1 || gof.argc == 1)) gof.nodash_now = 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
449 else goto notflag; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
450 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
451 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
452 // At this point, we have the args part of -args. Loop through |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
453 // each entry (could be -abc meaning -a -b -c) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
454 saveflags = toys.optflags; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
455 while (*gof.arg) { |
29
5566beb17d5a
Fix a half-dozen bugs in argument parsing. More seems to work than not now.
Rob Landley <rob@landley.net>
parents:
28
diff
changeset
|
456 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
457 // Identify next option char. |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
458 for (catch = gof.opts; catch; catch = catch->next) |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
459 if (*gof.arg == catch->c) |
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
460 if (!((catch->flags&4) && gof.arg[1])) break; |
29
5566beb17d5a
Fix a half-dozen bugs in argument parsing. More seems to work than not now.
Rob Landley <rob@landley.net>
parents:
28
diff
changeset
|
461 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
462 // Handle option char (advancing past what was used) |
705
3e81cd0bad4b
Teach option parsing about [groups] of related options.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
463 if (gotflag(&gof, catch) ) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
464 toys.optflags = saveflags; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
465 gof.arg = toys.argv[gof.argc]; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
466 goto notflag; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
467 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
468 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
469 continue; |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
470 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
471 // Not a flag, save value in toys.optargs[] |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
472 notflag: |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
473 if (gof.stopearly) gof.stopearly++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
474 toys.optargs[toys.optc++] = toys.argv[gof.argc]; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
475 } |
624
1e8b9acdafeb
Genericize llist code a bit: rename llist_free() to llist_traverse(), and no longer accept NULL as a synonym for free.
Rob Landley <rob@landley.net>
parents:
540
diff
changeset
|
476 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
477 // Sanity check |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
478 if (toys.optc<gof.minargs) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
479 error_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)], |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
480 gof.minargs, letters[!(gof.minargs-1)]); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
481 if (toys.optc>gof.maxargs) |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
482 error_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]); |
978
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
483 if (gof.requires && !(gof.requires & toys.optflags)) { |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
484 struct opts *req; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
485 char needs[32], *s = needs; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
486 |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
487 for (req = gof.opts; req; req = req->next) |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
488 if (req->flags & 1) *(s++) = req->c; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
489 *s = 0; |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
490 |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
491 error_exit("Needs %s-%s", s[1] ? "one of " : "", needs); |
6d3c39cb8a9d
Cleanup renice and implement '|' (required option) in argument parsing.
Rob Landley <rob@landley.net>
parents:
931
diff
changeset
|
492 } |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
845
diff
changeset
|
493 toys.exithelp = 0; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
494 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
495 if (CFG_TOYBOX_FREE) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
496 llist_traverse(gof.opts, free); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
497 llist_traverse(gof.longopts, free); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
684
diff
changeset
|
498 } |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
499 } |