Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add = to getopt_long #42

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/global/cgetopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ int getopt_long(int argc, char *argv[], const char *optstring,
nextchar++;
const struct option *curlong = longopts;
while (curlong->name != NULL) {
if (strcmp(curlong->name, nextchar) == 0) {
size_t name_len = strlen(curlong->name);
if (strncmp(curlong->name, nextchar, name_len) == 0) {
if (longindex != NULL)
*longindex = curlong - longopts;
optind++;
nextchar = NULL;
if (longopts->flag) {
*curlong->flag = curlong->val;
c = 0;
Expand All @@ -159,17 +159,23 @@ int getopt_long(int argc, char *argv[], const char *optstring,
((coropt + 1) >= argc || argv[(coropt + 1)][0] == '-'))
goto exit;
if (curlong->has_arg) {
EXCHANGE(coropt);
coropt++;
if (coropt >= argc || argv[coropt][0] == '-') {
getopt_printerr("option requires an argument\n");
optopt = curlong->val;
c = '?';
goto exit;
if (*(nextchar + name_len) != '=') {
nextchar = NULL;
EXCHANGE(coropt);
coropt++;
if (coropt >= argc || argv[coropt][0] == '-') {
getopt_printerr("option requires an argument\n");
optopt = curlong->val;
c = '?';
goto exit;
}
optarg = argv[coropt];
optind++;
} else {
optarg = nextchar + (name_len + 1);
}
optarg = argv[coropt];
optind++;
}
nextchar = NULL;
goto exit;
}
curlong++;
Expand Down