X-Git-Url: https://git.cworth.org/git?p=glaze;a=blobdiff_plain;f=glaze.c;h=02a39275d0b3ba50101988e2386b7e499ecf8c88;hp=72070256fb4365d6874ba58a3d28f94495c5f9e9;hb=HEAD;hpb=cec0694a7f219bd3590e6a04beba34ca45539540 diff --git a/glaze.c b/glaze.c index 7207025..02a3927 100644 --- a/glaze.c +++ b/glaze.c @@ -19,45 +19,76 @@ * THE SOFTWARE. */ -#define _GNU_SOURCE -#include - -#include "glaze.h" - #include #include +#include +#include + +#include -void * -glaze_lookup (char *function) +static void +usage (void) { - static void *libgl_handle = NULL; - void *ret; + printf ("Usage: glaze --wrapper= [program args...]\n" + "\n" + "Execute with providing alternate OpenGL functions.\n"); +} - if (libgl_handle == NULL) { - const char *path; +enum { + WRAPPER_OPT = CHAR_MAX + 1 +}; - path = getenv ("GLAZE_LIBGL"); - if (path == NULL) { - fprintf (stderr, "GLAZE_LIBGL unset. " - "Please set to path of libGL.so under glaze.\n" - ); - exit (1); - } +int +main (int argc, char *argv[]) +{ + const char *wrapper = NULL; + int opt; + + /* The initial '+' means that getopt will stop looking for + * options after the first non-option argument. This means + * that a command such as: + * + * glaze glenv --renderer=Foo glxgears + * + * Will do what is intended, (namely, have glaze invoke "glenv + * --renderer=Foo glxgears" rather than trying to interpret + * --renderer=Foo as an option to glaze itself. + */ + const char *short_options="+h"; + const struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {"wrapper", required_argument, 0, WRAPPER_OPT}, + {0, 0, 0, 0} + }; + + while (1) + { + opt = getopt_long (argc, argv, short_options, long_options, NULL); + if (opt == -1) + break; - libgl_handle = dlopen (path, RTLD_LAZY | RTLD_GLOBAL); - if (libgl_handle == NULL) { - fprintf (stderr, "Error: Failed to dlopen %s\n", path); + switch (opt) { + case 'h': + usage (); + return 0; + case WRAPPER_OPT: + wrapper = optarg; + break; + default: + fprintf (stderr, "Internal error: " + "unexpected getopt value: %d\n", opt); exit (1); } } - ret = dlsym (libgl_handle, function); - - if (ret == NULL) { - fprintf (stderr, "Error: glaze_lookup failed to dlsym %s\n", - function); + if (optind >= argc) { + fprintf (stderr, "Error: No program name provided, " + "see (glaze --help)\n"); exit (1); } - return ret; + glaze_execute (argc - optind, &argv[optind], wrapper); + + /* If glaze_execute returns then something went wrong. */ + return 1; }