summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2014-07-15 08:39:20 -0600
committerBrian Paul <brianp@vmware.com>2014-07-16 07:30:30 -0600
commite769bc682b4a0d0f597286b067f54f923d159866 (patch)
tree16b86f174992be5de228786dc4f1a89523448740
parent38131f85400026b6fa4df84fa1be32dfe17e7191 (diff)
glxinfo/wglinfo: move argument parsing into common code
Reviewed-by: José Fonseca <jfonseca@vmware.com>
-rw-r--r--src/wgl/wglinfo.c59
-rw-r--r--src/xdemos/glinfo_common.c68
-rw-r--r--src/xdemos/glinfo_common.h25
-rw-r--r--src/xdemos/glxinfo.c85
4 files changed, 113 insertions, 124 deletions
diff --git a/src/wgl/wglinfo.c b/src/wgl/wglinfo.c
index e14ebd6b..fe94dccb 100644
--- a/src/wgl/wglinfo.c
+++ b/src/wgl/wglinfo.c
@@ -42,14 +42,6 @@
#include "glinfo_common.h"
-typedef enum
-{
- Normal,
- Wide,
- Verbose
-} InfoMode;
-
-
static GLboolean have_WGL_ARB_pixel_format;
static GLboolean have_WGL_ARB_multisample;
@@ -534,67 +526,26 @@ find_best_visual(HDC hdc)
}
-static void
-usage(void)
-{
- printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
- printf("\t-v: Print visuals info in verbose form.\n");
- printf("\t-t: Print verbose table.\n");
- printf("\t-h: This information.\n");
- printf("\t-b: Find the 'best' visual and print its number.\n");
- printf("\t-l: Print interesting OpenGL limits.\n");
- printf("\t-s: Print a single extension per line.\n");
-}
-
int
main(int argc, char *argv[])
{
HDC hdc;
- InfoMode mode = Normal;
- GLboolean findBest = GL_FALSE;
- GLboolean limits = GL_FALSE;
- GLboolean singleLine = GL_FALSE;
- int i;
+ struct options opts;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-t") == 0) {
- mode = Wide;
- }
- else if (strcmp(argv[i], "-v") == 0) {
- mode = Verbose;
- }
- else if (strcmp(argv[i], "-b") == 0) {
- findBest = GL_TRUE;
- }
- else if (strcmp(argv[i], "-l") == 0) {
- limits = GL_TRUE;
- }
- else if (strcmp(argv[i], "-h") == 0) {
- usage();
- return 0;
- }
- else if(strcmp(argv[i], "-s") == 0) {
- singleLine = GL_TRUE;
- }
- else {
- printf("Unknown option `%s'\n", argv[i]);
- usage();
- return 0;
- }
- }
+ parse_args(argc, argv, &opts);
hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
- if (findBest) {
+ if (opts.findBest) {
int b;
b = find_best_visual(hdc);
printf("%d\n", b);
}
else {
- print_screen_info(hdc, limits, singleLine);
+ print_screen_info(hdc, opts.limits, opts.singleLine);
printf("\n");
- print_visual_info(hdc, mode);
+ print_visual_info(hdc, opts.mode);
}
return 0;
diff --git a/src/xdemos/glinfo_common.c b/src/xdemos/glinfo_common.c
index 248b9376..95ef5456 100644
--- a/src/xdemos/glinfo_common.c
+++ b/src/xdemos/glinfo_common.c
@@ -718,3 +718,71 @@ context_flags_string(int mask)
}
+static void
+usage(void)
+{
+#ifdef _WIN32
+ printf("Usage: wglinfo [-v] [-t] [-h] [-b] [-l] [-s]\n");
+#else
+ printf("Usage: glxinfo [-v] [-t] [-h] [-b] [-l] [-s] [-i] [-display <dname>]\n");
+ printf("\t-display <dname>: Print GLX visuals on specified server.\n");
+ printf("\t-i: Force an indirect rendering context.\n");
+#endif
+ printf("\t-v: Print visuals info in verbose form.\n");
+ printf("\t-t: Print verbose table.\n");
+ printf("\t-h: This information.\n");
+ printf("\t-b: Find the 'best' visual and print its number.\n");
+ printf("\t-l: Print interesting OpenGL limits.\n");
+ printf("\t-s: Print a single extension per line.\n");
+}
+
+
+void
+parse_args(int argc, char *argv[], struct options *options)
+{
+ int i;
+
+ options->mode = Normal;
+ options->findBest = GL_FALSE;
+ options->limits = GL_FALSE;
+ options->singleLine = GL_FALSE;
+ options->displayName = NULL;
+ options->allowDirect = GL_FALSE;
+
+ for (i = 1; i < argc; i++) {
+#ifndef _WIN32
+ if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
+ options->displayName = argv[i + 1];
+ i++;
+ }
+ else if (strcmp(argv[i], "-i") == 0) {
+ options->allowDirect = GL_FALSE;
+ }
+ else
+#endif
+ if (strcmp(argv[i], "-t") == 0) {
+ options->mode = Wide;
+ }
+ else if (strcmp(argv[i], "-v") == 0) {
+ options->mode = Verbose;
+ }
+ else if (strcmp(argv[i], "-b") == 0) {
+ options->findBest = GL_TRUE;
+ }
+ else if (strcmp(argv[i], "-l") == 0) {
+ options->limits = GL_TRUE;
+ }
+ else if (strcmp(argv[i], "-h") == 0) {
+ usage();
+ exit(0);
+ }
+ else if(strcmp(argv[i], "-s") == 0) {
+ options->singleLine = GL_TRUE;
+ }
+ else {
+ printf("Unknown option `%s'\n", argv[i]);
+ usage();
+ exit(0);
+ }
+ }
+}
diff --git a/src/xdemos/glinfo_common.h b/src/xdemos/glinfo_common.h
index d0daf4dd..a2687276 100644
--- a/src/xdemos/glinfo_common.h
+++ b/src/xdemos/glinfo_common.h
@@ -63,6 +63,27 @@ struct bit_info
};
+typedef enum
+{
+ Normal,
+ Wide,
+ Verbose
+} InfoMode;
+
+
+struct options
+{
+ InfoMode mode;
+ GLboolean findBest;
+ GLboolean limits;
+ GLboolean singleLine;
+ /* GLX only */
+ char *displayName;
+ GLboolean allowDirect;
+};
+
+
+
void
print_extension_list(const char *ext, GLboolean singleLine);
@@ -86,4 +107,8 @@ const char *
context_flags_string(int mask);
+void
+parse_args(int argc, char *argv[], struct options *options);
+
+
#endif /* GLINFO_COMMON_H */
diff --git a/src/xdemos/glxinfo.c b/src/xdemos/glxinfo.c
index 5208423e..6e7fa3a6 100644
--- a/src/xdemos/glxinfo.c
+++ b/src/xdemos/glxinfo.c
@@ -63,13 +63,6 @@
#define GLX_COLOR_INDEX_BIT 0x00000002
#endif
-typedef enum
-{
- Normal,
- Wide,
- Verbose
-} InfoMode;
-
struct visual_attribs
{
@@ -1204,76 +1197,24 @@ find_best_visual(Display *dpy, int scrnum)
}
-static void
-usage(void)
-{
- printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-s] [-display <dname>]\n");
- printf("\t-v: Print visuals info in verbose form.\n");
- printf("\t-t: Print verbose table.\n");
- printf("\t-display <dname>: Print GLX visuals on specified server.\n");
- printf("\t-h: This information.\n");
- printf("\t-i: Force an indirect rendering context.\n");
- printf("\t-b: Find the 'best' visual and print its number.\n");
- printf("\t-l: Print interesting OpenGL limits.\n");
- printf("\t-s: Print a single extension per line.\n");
-}
-
-
int
main(int argc, char *argv[])
{
- char *displayName = NULL;
Display *dpy;
int numScreens, scrnum;
- InfoMode mode = Normal;
- Bool findBest = False;
- Bool limits = False;
- Bool allowDirect = True;
- Bool singleLine = False;
+ struct options opts;
Bool coreWorked;
- int i;
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
- displayName = argv[i + 1];
- i++;
- }
- else if (strcmp(argv[i], "-t") == 0) {
- mode = Wide;
- }
- else if (strcmp(argv[i], "-v") == 0) {
- mode = Verbose;
- }
- else if (strcmp(argv[i], "-b") == 0) {
- findBest = True;
- }
- else if (strcmp(argv[i], "-i") == 0) {
- allowDirect = False;
- }
- else if (strcmp(argv[i], "-l") == 0) {
- limits = True;
- }
- else if (strcmp(argv[i], "-h") == 0) {
- usage();
- return 0;
- }
- else if (strcmp(argv[i], "-s") == 0) {
- singleLine = True;
- }
- else {
- printf("Unknown option `%s'\n", argv[i]);
- usage();
- return 0;
- }
- }
+ parse_args(argc, argv, &opts);
- dpy = XOpenDisplay(displayName);
+ dpy = XOpenDisplay(opts.displayName);
if (!dpy) {
- fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
+ fprintf(stderr, "Error: unable to open display %s\n",
+ XDisplayName(opts.displayName));
return -1;
}
- if (findBest) {
+ if (opts.findBest) {
int b;
mesa_hack(dpy, 0);
b = find_best_visual(dpy, 0);
@@ -1284,14 +1225,18 @@ main(int argc, char *argv[])
print_display_info(dpy);
for (scrnum = 0; scrnum < numScreens; scrnum++) {
mesa_hack(dpy, scrnum);
- coreWorked = print_screen_info(dpy, scrnum, allowDirect, True, False, limits, singleLine, False);
- print_screen_info(dpy, scrnum, allowDirect, False, False, limits, singleLine, coreWorked);
- print_screen_info(dpy, scrnum, allowDirect, False, True, False, singleLine, True);
+ coreWorked = print_screen_info(dpy, scrnum, opts.allowDirect,
+ True, False, opts.limits,
+ opts.singleLine, False);
+ print_screen_info(dpy, scrnum, opts.allowDirect, False, False,
+ opts.limits, opts.singleLine, coreWorked);
+ print_screen_info(dpy, scrnum, opts.allowDirect, False, True, False,
+ opts.singleLine, True);
printf("\n");
- print_visual_info(dpy, scrnum, mode);
+ print_visual_info(dpy, scrnum, opts.mode);
#ifdef GLX_VERSION_1_3
- print_fbconfig_info(dpy, scrnum, mode);
+ print_fbconfig_info(dpy, scrnum, opts.mode);
#endif
if (scrnum + 1 < numScreens)
printf("\n\n");