|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include <stdio.h> |
|
6 #include <string.h> |
|
7 #include <stdlib.h> |
|
8 |
|
9 #include "nspr.h" |
|
10 #include "plgetopt.h" |
|
11 |
|
12 |
|
13 |
|
14 static const PLLongOpt optArray[] = { |
|
15 { "longa", 'a' , PR_TRUE }, |
|
16 { "longb", 'b' , PR_TRUE }, |
|
17 { "longc", 'c' , PR_FALSE }, |
|
18 { "longd", 'd' | 0x100, PR_TRUE }, |
|
19 { "longe", 'e' | 0x100, PR_FALSE }, |
|
20 { NULL, } |
|
21 }; |
|
22 |
|
23 int |
|
24 main(int argc, char **argv) |
|
25 { |
|
26 PLOptState *opt; |
|
27 PLOptStatus ostat; |
|
28 |
|
29 opt = PL_CreateLongOptState(argc, argv, "a:b:c", optArray); |
|
30 |
|
31 while (PL_OPT_OK == (ostat = PL_GetNextOpt(opt))) { |
|
32 if (opt->option == 0 && opt->longOptIndex < 0) |
|
33 printf("Positional parameter: \"%s\"\n", opt->value); |
|
34 else |
|
35 printf("%s option: %x (\'%c\', index %d), argument: \"%s\"\n", |
|
36 (ostat == PL_OPT_BAD) ? "BAD" : "GOOD", |
|
37 opt->longOption, opt->option ? opt->option : ' ', |
|
38 opt->longOptIndex, opt->value); |
|
39 |
|
40 } |
|
41 printf("last result was %s\n", (ostat == PL_OPT_BAD) ? "BAD" : "EOL"); |
|
42 PL_DestroyOptState(opt); |
|
43 return 0; |
|
44 } |