diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-05 12:23:13 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-05 12:23:13 +0000 |
| commit | 43fb3fcb2f204a0742219a5910bc5b2fd39346e5 (patch) | |
| tree | 6f0b5480069955a7b806296493f5cf6e1d18e508 /libbb | |
| parent | 35939d93783230998439848b2798865c598723e2 (diff) | |
| download | busybox-w32-43fb3fcb2f204a0742219a5910bc5b2fd39346e5.tar.gz busybox-w32-43fb3fcb2f204a0742219a5910bc5b2fd39346e5.tar.bz2 busybox-w32-43fb3fcb2f204a0742219a5910bc5b2fd39346e5.zip | |
- add a bit more documentation to vodz' recent additions.
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/getopt_ulflags.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c index 410f4d57d..37c4ec0f0 100644 --- a/libbb/getopt_ulflags.c +++ b/libbb/getopt_ulflags.c | |||
| @@ -110,21 +110,32 @@ const char *bb_opt_complementally | |||
| 110 | bb_getopt_ulflags's return value will be as if "-a -b -c" were | 110 | bb_getopt_ulflags's return value will be as if "-a -b -c" were |
| 111 | found. | 111 | found. |
| 112 | 112 | ||
| 113 | "ww" Double option have int counter usaging. For example ps applet: | 113 | "ww" Adjacent double options have a counter associated which indicates |
| 114 | the number of occurances of the option. For example the ps applet needs: | ||
| 114 | if w is given once, GNU ps sets the width to 132, | 115 | if w is given once, GNU ps sets the width to 132, |
| 115 | if w is given more than once, it is "unlimited" | 116 | if w is given more than once, it is "unlimited" |
| 116 | 117 | ||
| 117 | int w_counter = 0; | 118 | int w_counter = 0; |
| 118 | bb_opt_complementally = "ww"; | 119 | bb_opt_complementally = "ww"; |
| 119 | flags = bb_getopt_ulflags(argc, argv, "w", &w_counter); | 120 | bb_getopt_ulflags(argc, argv, "w", &w_counter); |
| 120 | 121 | ||
| 121 | if((flags & 1)) | 122 | if(w_counter) |
| 122 | width = (w_counter == 1) ? 132 : INT_MAX; | 123 | width = (w_counter == 1) ? 132 : INT_MAX; |
| 123 | else | 124 | else |
| 124 | get_terminal_width(...&width...); | 125 | get_terminal_width(...&width...); |
| 125 | 126 | ||
| 126 | w_counter - have counter -w usaging, must set int pointer | 127 | w_counter is a pointer to an integer. It has to be passed to |
| 127 | to bb_getopt_ulflags() after all other requires | 128 | bb_getopt_ulflags() after all other option argument sinks. |
| 129 | For example: accept multiple -v to indicate the level of verbosity and | ||
| 130 | for each -b optarg, add optarg to my_b. Finally, if b is given, turn off | ||
| 131 | c and vice versa: | ||
| 132 | |||
| 133 | llist_t *my_b = NULL; | ||
| 134 | int verbose_level = 0; | ||
| 135 | bb_opt_complementally = "vvb*b-c:c-b"; | ||
| 136 | bb_getopt_ulflags(argc, argv, "vb:c", &my_b, &verbose_level); | ||
| 137 | while (my_b) { dosomething_with(my_b->data) ; my_b = my_b->link; } | ||
| 138 | if (verbose_level) bb_printf("verbose\n"); | ||
| 128 | 139 | ||
| 129 | Special characters: | 140 | Special characters: |
| 130 | 141 | ||
| @@ -155,6 +166,16 @@ Special characters: | |||
| 155 | if(opt & 4) | 166 | if(opt & 4) |
| 156 | printf("Detected odd -x usaging\n"); | 167 | printf("Detected odd -x usaging\n"); |
| 157 | 168 | ||
| 169 | "-" A minus as the first char in a bb_opt_complementally group means to | ||
| 170 | convert the arguments as option. | ||
| 171 | For example: | ||
| 172 | |||
| 173 | bb_opt_complementally = "-:w"; | ||
| 174 | bb_getopt_ulflags(argc, argv, "w"); | ||
| 175 | |||
| 176 | Allows option 'w' to be given without a dash (./program w) | ||
| 177 | as well as with a dash (./program -w). | ||
| 178 | |||
| 158 | "~" A tilde between two options, or between an option and a group | 179 | "~" A tilde between two options, or between an option and a group |
| 159 | of options, means that they are mutually exclusive. Unlike | 180 | of options, means that they are mutually exclusive. Unlike |
| 160 | the "-" case above, an error will be forced if the options | 181 | the "-" case above, an error will be forced if the options |
| @@ -175,9 +196,6 @@ Special characters: | |||
| 175 | "!" If previous point set BB_GETOPT_ERROR, don`t return and call | 196 | "!" If previous point set BB_GETOPT_ERROR, don`t return and call |
| 176 | previous example internally | 197 | previous example internally |
| 177 | 198 | ||
| 178 | "-" A minus as one char in bb_opt_complementally group means that | ||
| 179 | convert the arguments as option, specail for "ps" applet. | ||
| 180 | |||
| 181 | "*" A star after a char in bb_opt_complementally means that the | 199 | "*" A star after a char in bb_opt_complementally means that the |
| 182 | option can occur multiple times: | 200 | option can occur multiple times: |
| 183 | 201 | ||
