Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 102 lines (91 sloc) 3.435 kb
beb47437 »
2007-10-13 Add tests for parse-options.c
1 #include "cache.h"
2 #include "parse-options.h"
c8ba1639 »
2011-06-09 parse-options: add OPT_STRING_LIST helper
3 #include "string-list.h"
beb47437 »
2007-10-13 Add tests for parse-options.c
4
5 static int boolean = 0;
c4aca9cc »
2008-07-30 Fix test-parse-options "integer" test
6 static int integer = 0;
7 static unsigned long timestamp;
010a2dac »
2008-06-22 Extend parse-options test suite
8 static int abbrev = 7;
9 static int verbose = 0, dry_run = 0, quiet = 0;
beb47437 »
2007-10-13 Add tests for parse-options.c
10 static char *string = NULL;
df217ed6 »
2009-05-23 parse-opts: add OPT_FILENAME and transition builtins
11 static char *file = NULL;
6bbfd1fa »
2009-09-25 parse-opt: ignore negation of OPT_NONEG for ambiguity checks
12 static int ambiguous;
c8ba1639 »
2011-06-09 parse-options: add OPT_STRING_LIST helper
13 static struct string_list list;
beb47437 »
2007-10-13 Add tests for parse-options.c
14
2af202be »
2009-06-18 Fix various sparse warnings in the git source code
15 static int length_callback(const struct option *opt, const char *arg, int unset)
010a2dac »
2008-06-22 Extend parse-options test suite
16 {
17 printf("Callback: \"%s\", %d\n",
18 (arg ? arg : "not set"), unset);
19 if (unset)
20 return 1; /* do not support unset */
21
8caa3acf »
2008-08-13 test-parse-options: use appropriate cast in length_callback
22 *(int *)opt->value = strlen(arg);
010a2dac »
2008-06-22 Extend parse-options test suite
23 return 0;
24 }
25
2af202be »
2009-06-18 Fix various sparse warnings in the git source code
26 static int number_callback(const struct option *opt, const char *arg, int unset)
e0319ff5 »
2009-05-07 parseopt: add OPT_NUMBER_CALLBACK
27 {
28 *(int *)opt->value = strtol(arg, NULL, 10);
29 return 0;
30 }
31
84d32bf7 »
2013-04-27 sparse: Fix mingw_main() argument number/type errors
32 int main(int argc, char **argv)
beb47437 »
2007-10-13 Add tests for parse-options.c
33 {
df217ed6 »
2009-05-23 parse-opts: add OPT_FILENAME and transition builtins
34 const char *prefix = "prefix/";
beb47437 »
2007-10-13 Add tests for parse-options.c
35 const char *usage[] = {
36 "test-parse-options <options>",
37 NULL
38 };
39 struct option options[] = {
b9e63ddd »
2012-02-25 test-parse-options: convert to OPT_BOOL()
40 OPT_BOOL(0, "yes", &boolean, "get a boolean"),
41 OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
42 { OPTION_SET_INT, 'B', "no-fear", &boolean, NULL,
43 "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
44 OPT_COUNTUP('b', "boolean", &boolean, "increment by one"),
010a2dac »
2008-06-22 Extend parse-options test suite
45 OPT_BIT('4', "or4", &boolean,
46 "bitwise-or boolean with ...0100", 4),
2f4b97f9 »
2009-05-07 parseopt: add OPT_NEGBIT
47 OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4),
010a2dac »
2008-06-22 Extend parse-options test suite
48 OPT_GROUP(""),
beb47437 »
2007-10-13 Add tests for parse-options.c
49 OPT_INTEGER('i', "integer", &integer, "get a integer"),
50 OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
010a2dac »
2008-06-22 Extend parse-options test suite
51 OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
c4aca9cc »
2008-07-30 Fix test-parse-options "integer" test
52 OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
010a2dac »
2008-06-22 Extend parse-options test suite
53 OPT_CALLBACK('L', "length", &integer, "str",
54 "get length of <str>", length_callback),
41dbcd45 »
2011-02-15 Make <identifier> lowercase as per CodingGuidelines
55 OPT_FILENAME('F', "file", &file, "set file to <file>"),
010a2dac »
2008-06-22 Extend parse-options test suite
56 OPT_GROUP("String options"),
beb47437 »
2007-10-13 Add tests for parse-options.c
57 OPT_STRING('s', "string", &string, "string", "get a string"),
58 OPT_STRING(0, "string2", &string, "str", "get another string"),
243e0614 »
2007-11-05 parse-options: abbreviation engine fix.
59 OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
3a9f0f41 »
2008-01-26 parse-options: catch likely typo in presense of aggregated options.
60 OPT_STRING('o', NULL, &string, "str", "get another string"),
6acec038 »
2011-09-28 parseopt: add OPT_NOOP_NOARG
61 OPT_NOOP_NOARG(0, "obsolete"),
c8ba1639 »
2011-06-09 parse-options: add OPT_STRING_LIST helper
62 OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
010a2dac »
2008-06-22 Extend parse-options test suite
63 OPT_GROUP("Magic arguments"),
580d5bff »
2008-03-02 parse-options: new option type to treat an option-like parameter as a…
64 OPT_ARGUMENT("quux", "means --quux"),
e0319ff5 »
2009-05-07 parseopt: add OPT_NUMBER_CALLBACK
65 OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
66 number_callback),
b9e63ddd »
2012-02-25 test-parse-options: convert to OPT_BOOL()
67 { OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
51a9949e »
2009-05-07 parseopt: add PARSE_OPT_NODASH
68 PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },
b9e63ddd »
2012-02-25 test-parse-options: convert to OPT_BOOL()
69 { OPTION_COUNTUP, 0, "ambiguous", &ambiguous, NULL,
6bbfd1fa »
2009-09-25 parse-opt: ignore negation of OPT_NONEG for ambiguity checks
70 "positive ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
b9e63ddd »
2012-02-25 test-parse-options: convert to OPT_BOOL()
71 { OPTION_COUNTUP, 0, "no-ambiguous", &ambiguous, NULL,
6bbfd1fa »
2009-09-25 parse-opt: ignore negation of OPT_NONEG for ambiguity checks
72 "negative ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
010a2dac »
2008-06-22 Extend parse-options test suite
73 OPT_GROUP("Standard options"),
74 OPT__ABBREV(&abbrev),
fd03881a »
2010-11-08 add description parameter to OPT__VERBOSE
75 OPT__VERBOSE(&verbose, "be verbose"),
e21adb8c »
2010-11-08 add description parameter to OPT__DRY_RUN
76 OPT__DRY_RUN(&dry_run, "dry run"),
d52ee6e6 »
2010-11-08 add description parameter to OPT__QUIET
77 OPT__QUIET(&quiet, "be quiet"),
beb47437 »
2007-10-13 Add tests for parse-options.c
78 OPT_END(),
79 };
80 int i;
81
84d32bf7 »
2013-04-27 sparse: Fix mingw_main() argument number/type errors
82 argc = parse_options(argc, (const char **)argv, prefix, options, usage, 0);
beb47437 »
2007-10-13 Add tests for parse-options.c
83
84 printf("boolean: %d\n", boolean);
c4aca9cc »
2008-07-30 Fix test-parse-options "integer" test
85 printf("integer: %u\n", integer);
86 printf("timestamp: %lu\n", timestamp);
beb47437 »
2007-10-13 Add tests for parse-options.c
87 printf("string: %s\n", string ? string : "(not set)");
010a2dac »
2008-06-22 Extend parse-options test suite
88 printf("abbrev: %d\n", abbrev);
89 printf("verbose: %d\n", verbose);
90 printf("quiet: %s\n", quiet ? "yes" : "no");
91 printf("dry run: %s\n", dry_run ? "yes" : "no");
df217ed6 »
2009-05-23 parse-opts: add OPT_FILENAME and transition builtins
92 printf("file: %s\n", file ? file : "(not set)");
beb47437 »
2007-10-13 Add tests for parse-options.c
93
c8ba1639 »
2011-06-09 parse-options: add OPT_STRING_LIST helper
94 for (i = 0; i < list.nr; i++)
95 printf("list: %s\n", list.items[i].string);
96
beb47437 »
2007-10-13 Add tests for parse-options.c
97 for (i = 0; i < argc; i++)
98 printf("arg %02d: %s\n", i, argv[i]);
99
100 return 0;
101 }
Something went wrong with that request. Please try again.