MCPcopy Create free account
hub / github.com/apache/cloudberry / getopt_long

Function getopt_long

src/port/getopt_long.c:56–218  ·  view source on GitHub ↗

* getopt_long * Parse argc/argv argument vector, with long options. * * This implementation does not use optreset. Instead, we guarantee that * it can be restarted on a new argv array after a previous call returned -1, * if the caller resets optind to 1 before the first call of the new series. * (Internally, this means we must be sure to reset "place" to EMSG before * returning -1.) */

Source from the content-addressed store, hash-verified

54 * returning -1.)
55 */
56int
57getopt_long(int argc, char *const argv[],
58 const char *optstring,
59 const struct option *longopts, int *longindex)
60{
61 static char *place = EMSG; /* option letter processing */
62 char *oli; /* option letter list index */
63
64 if (!*place)
65 { /* update scanning pointer */
66 if (optind >= argc)
67 {
68 place = EMSG;
69 return -1;
70 }
71
72 place = argv[optind];
73
74 if (place[0] != '-')
75 {
76 place = EMSG;
77 return -1;
78 }
79
80 place++;
81
82 if (!*place)
83 {
84 /* treat "-" as not being an option */
85 place = EMSG;
86 return -1;
87 }
88
89 if (place[0] == '-' && place[1] == '\0')
90 {
91 /* found "--", treat it as end of options */
92 ++optind;
93 place = EMSG;
94 return -1;
95 }
96
97 if (place[0] == '-' && place[1])
98 {
99 /* long option */
100 size_t namelen;
101 int i;
102
103 place++;
104
105 namelen = strcspn(place, "=");
106 for (i = 0; longopts[i].name != NULL; i++)
107 {
108 if (strlen(longopts[i].name) == namelen
109 && strncmp(place, longopts[i].name, namelen) == 0)
110 {
111 int has_arg = longopts[i].has_arg;
112
113 if (has_arg != no_argument)

Callers 15

InitConfigFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
get_optsFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
regression_mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
parse_psql_optionsFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 6

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
regression_mainFunction · 0.68
handle_argsFunction · 0.68
handle_argsFunction · 0.68