Skip to content

Commit

Permalink
utils: uniformize the management of argc/argv changes
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Hoyet <valentin.hoyet@inria.fr>
Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
Valentin Hoyet authored and bgoglin committed May 25, 2020
1 parent 136a5f1 commit 4836002
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
6 changes: 2 additions & 4 deletions utils/hwloc/hwloc-bind.c
Expand Up @@ -125,8 +125,7 @@ int main(int argc, char *argv[])
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
argv++;
argc--;
opt = 1;
goto next_config;
}
if (!strcmp (argv[0], "--restrict-flags")) {
Expand All @@ -135,8 +134,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
restrict_flags = hwloc_utils_parse_restrict_flags(argv[1]);
argc--;
argv++;
opt = 1;
goto next_config;
}
if (!strcmp(argv[0], "--no-smt")) {
Expand Down
33 changes: 15 additions & 18 deletions utils/hwloc/hwloc-calc.c
Expand Up @@ -267,6 +267,8 @@ int main(int argc, char *argv[])
set = hwloc_bitmap_alloc();

while (argc >= 1) {
opt = 0;

if (!strcmp (argv[0], "--disallowed") || !strcmp (argv[0], "--whole-system")) {
flags |= HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED;
goto next_config;
Expand All @@ -282,8 +284,7 @@ int main(int argc, char *argv[])
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
argv++;
argc--;
opt = 1;
goto next_config;
}
if (!strcmp (argv[0], "--restrict-flags")) {
Expand All @@ -292,23 +293,21 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
restrict_flags = hwloc_utils_parse_restrict_flags(argv[1]);
argc--;
argv++;
opt = 1;
goto next_config;
}
if (hwloc_utils_lookup_input_option(argv, argc, &opt,
&input, &input_format,
callname)) {
argc--;
argv++;
opt = 1;
goto next_config;
}

break;

next_config:
argc--;
argv++;
argc -= opt+1;
argv += opt+1;
}

hwloc_topology_init(&topology);
Expand All @@ -331,6 +330,8 @@ int main(int argc, char *argv[])
}

while (argc >= 1) {
opt = 0;

if (*argv[0] == '-') {
if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose")) {
verbose++;
Expand Down Expand Up @@ -358,8 +359,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
numberoftype = argv[1];
argv++;
argc--;
opt = 1;
goto next;
}
if (!strcmp(argv[0], "--intersect") || !strcmp(argv[0], "-I")) {
Expand All @@ -368,8 +368,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
intersecttype = argv[1];
argv++;
argc--;
opt = 1;
goto next;
}
if (!strcmp(argv[0], "--hierarchical") || !strcmp(argv[0], "-H")) {
Expand All @@ -378,8 +377,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
hiertype = argv[1];
argv++;
argc--;
opt = 1;
goto next;
}
if (!strcasecmp(argv[0], "--pulist") || !strcmp(argv[0], "--proclist")) {
Expand Down Expand Up @@ -445,8 +443,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
outsep = argv[1];
argv++;
argc--;
opt = 1;
goto next;
}
if (!strcmp(argv[0], "--single")) {
Expand Down Expand Up @@ -482,8 +479,8 @@ int main(int argc, char *argv[])
}

next:
argc--;
argv++;
argc -= opt+1;
argv += opt+1;
}

if (numberoftype && hwloc_calc_type_depth(topology, numberoftype, &numberofdepth, "--number-of") < 0)
Expand Down
27 changes: 11 additions & 16 deletions utils/hwloc/hwloc-distrib.c
Expand Up @@ -77,6 +77,8 @@ int main(int argc, char *argv[])
break;
}

opt = 0;

if (*argv[0] == '-') {
if (!strcmp(argv[0], "--single")) {
singlify = 1;
Expand All @@ -101,8 +103,7 @@ int main(int argc, char *argv[])
if (hwloc_utils_lookup_input_option(argv, argc, &opt,
&input, &input_format,
callname)) {
argv += opt;
argc -= opt;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--ignore")) {
Expand All @@ -115,8 +116,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Unsupported type `%s' passed to --ignore, ignoring.\n", argv[1]);
else
hwloc_topology_set_type_filter(topology, type, HWLOC_TYPE_FILTER_KEEP_NONE);
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--from")) {
Expand All @@ -125,8 +125,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
from_type = argv[1];
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--to")) {
Expand All @@ -135,8 +134,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
to_type = argv[1];
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--at")) {
Expand All @@ -145,8 +143,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
from_type = to_type = argv[1];
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--reverse")) {
Expand All @@ -164,8 +161,7 @@ int main(int argc, char *argv[])
restrictstring = strdup(argv[1]+8);
restrict_flags |= HWLOC_RESTRICT_FLAG_BYNODESET;
}
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--restrict-flags")) {
Expand All @@ -174,8 +170,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
restrict_flags = hwloc_utils_parse_restrict_flags(argv[1]);
argc--;
argv++;
opt = 1;
goto next;
}
else if (!strcmp (argv[0], "--version")) {
Expand All @@ -196,8 +191,8 @@ int main(int argc, char *argv[])
n = atol(argv[0]);

next:
argc--;
argv++;
argc -= opt+1;
argv += opt+1;
}

if (n == -1) {
Expand Down

0 comments on commit 4836002

Please sign in to comment.