Skip to content

Commit

Permalink
Merge pull request #219 from infinnovation-dev/master
Browse files Browse the repository at this point in the history
libmisc: Accept --root=path and --prefix=path option syntax
  • Loading branch information
hallyn committed Feb 27, 2020
2 parents b6aaaba + 12ce42b commit 724442c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions libmisc/prefix_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
* Parse the command line options.
*/
int i;
const char *prefix = NULL;
const char *prefix = NULL, *val;

for (i = 0; i < argc; i++) {
val = NULL;
if ( (strcmp (argv[i], "--prefix") == 0)
|| ((strncmp (argv[i], "--prefix=", 9) == 0)
&& (val = argv[i] + 9))
|| (strcmp (argv[i], short_opt) == 0)) {
if (NULL != prefix) {
fprintf (stderr,
Expand All @@ -86,13 +89,16 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
exit (E_BAD_ARG);
}

if (i + 1 == argc) {
if (val) {
prefix = val;
} else if (i + 1 == argc) {
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
Prog, argv[i]);
exit (E_BAD_ARG);
} else {
prefix = argv[++ i];
}
prefix = argv[i + 1];
}
}

Expand Down
12 changes: 9 additions & 3 deletions libmisc/root_flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv)
* Parse the command line options.
*/
int i;
const char *newroot = NULL;
const char *newroot = NULL, *val;

for (i = 0; i < argc; i++) {
val = NULL;
if ( (strcmp (argv[i], "--root") == 0)
|| ((strncmp (argv[i], "--root=", 7) == 0)
&& (val = argv[i] + 7))
|| (strcmp (argv[i], short_opt) == 0)) {
if (NULL != newroot) {
fprintf (stderr,
Expand All @@ -68,13 +71,16 @@ extern void process_root_flag (const char* short_opt, int argc, char **argv)
exit (E_BAD_ARG);
}

if (i + 1 == argc) {
if (val) {
newroot = val;
} else if (i + 1 == argc) {
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
Prog, argv[i]);
exit (E_BAD_ARG);
} else {
newroot = argv[++ i];
}
newroot = argv[i + 1];
}
}

Expand Down

0 comments on commit 724442c

Please sign in to comment.