[PATCH rendercheck 2/2] Remove getopt-based argument parsing. (bug 6611)
Jesse Adkins
jesserayadkins at gmail.com
Tue Oct 26 16:10:48 PDT 2010
Solaris 9 doesn't have getopt.
Part 2 of a fix for #6611.
Signed-off-by: Jesse Adkins <jesserayadkins at gmail.com>
---
main.c | 94 ++++++++++++++++++++++++++++++----------------------------------
1 files changed, 44 insertions(+), 50 deletions(-)
diff --git a/main.c b/main.c
index 17252fb..d0bff06 100644
--- a/main.c
+++ b/main.c
@@ -24,7 +24,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <getopt.h>
extern int num_ops;
extern int num_colors;
@@ -132,7 +131,7 @@ int main(int argc, char **argv)
{
Display *dpy;
XEvent ev;
- int i, o, maj, min;
+ int i, j, maj, min;
static Bool is_sync = FALSE, print_version = FALSE;
XWindowAttributes a;
XSetWindowAttributes as;
@@ -140,47 +139,45 @@ int main(int argc, char **argv)
char *display = NULL;
char *test, *format, *opname, *nextname;
- static struct option longopts[] = {
- { "display", required_argument, NULL, 'd' },
- { "iterations", required_argument, NULL, 'i' },
- { "formats", required_argument, NULL, 'f' },
- { "tests", required_argument, NULL, 't' },
- { "ops", required_argument, NULL, 'o' },
- { "verbose", no_argument, NULL, 'v' },
- { "sync", no_argument, &is_sync, TRUE},
- { "minimalrendering", no_argument, &minimalrendering,
- TRUE},
- { "version", no_argument, &print_version, TRUE },
- { NULL, 0, NULL, 0 }
- };
-
- while ((o = getopt_long(argc, argv, "d:i:f:t:o:v", longopts, NULL)) != -1) {
- switch (o) {
- case 'd':
- display = optarg;
- break;
- case 'i':
- pixmap_move_iter = atoi(optarg);
- break;
- case 'o':
- for (i = 0; i < num_ops; i++)
- ops[i].disabled = TRUE;
-
- nextname = optarg;
+ for (i = 1; i < argc; i++) {
+ char *arg = argv[i];
+ if (strcmp(arg, "-d") == 0 || strcmp(arg, "-display") == 0) {
+ if (i++ >= argc)
+ usage(argv[0]);
+
+ display = argv[i];
+ }
+ else if (strcmp(arg, "-i") == 0 || strcmp(arg, "-iterations") == 0) {
+ if (i++ >= argc)
+ usage(argv[0]);
+
+ pixmap_move_iter = atoi(argv[i]);
+ }
+ else if (strcmp(arg, "-o") == 0 || strcmp(arg, "--ops") == 0) {
+ if (i++ >= argc)
+ usage(argv[0]);
+
+ for (j = 0; j < num_ops; j++)
+ ops[j].disabled = TRUE;
+
+ nextname = argv[i];
while ((opname = strsep(&nextname, ",")) != NULL) {
- for (i = 0; i < num_ops; i++) {
- if (strcasecmp(ops[i].name, opname) !=
+ for (j = 0; j < num_ops; j++) {
+ if (strcasecmp(ops[j].name, opname) !=
0)
continue;
- ops[i].disabled = FALSE;
+ ops[j].disabled = FALSE;
break;
}
- if (i == num_ops)
+ if (j == num_ops)
usage(argv[0]);
}
- break;
- case 'f':
- nextname = optarg;
+ }
+ else if (strcmp(arg, "-f") == 0 || strcmp(arg, "--formats") == 0) {
+ if (i++ >= argc)
+ usage(argv[0]);
+
+ nextname = argv[i];
for (format_whitelist_len = 0;;format_whitelist_len++)
{
if ((format = strsep(&nextname, ",")) == NULL)
@@ -195,15 +192,17 @@ int main(int argc, char **argv)
/* Now the list is separated by \0s, so use strlen to
* step between entries.
*/
- format = optarg;
- for (i = 0; i < format_whitelist_len; i++) {
- format_whitelist[i] = strdup(format);
+ format = argv[i];
+ for (j = 0; j < format_whitelist_len; j++) {
+ format_whitelist[j] = strdup(format);
format += strlen(format) + 1;
}
+ }
+ else if (strcmp(arg, "-t") == 0 || strcmp(arg, "--test") == 0) {
+ if (i++ >= argc)
+ usage(argv[0]);
- break;
- case 't':
- nextname = optarg;
+ nextname = argv[i];
/* disable all tests */
enabled_tests = 0;
@@ -239,16 +238,11 @@ int main(int argc, char **argv)
usage(argv[0]);
}
}
-
- break;
- case 'v':
+ }
+ else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
is_verbose = TRUE;
- break;
- case 0:
- break;
- default:
+ else {
usage(argv[0]);
- break;
}
}
--
1.7.1
More information about the xorg-devel
mailing list