glcpp: Add --disable-line-continuations argument to standalone glcpp
authorCarl Worth <cworth@cworth.org>
Wed, 5 Dec 2012 21:15:48 +0000 (13:15 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 11 Jan 2013 21:55:41 +0000 (13:55 -0800)
This will allow testing of disabled line-continuation on a case-by-case basis,
(with the option communicated to the preprocessor via the GL context).

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/glcpp/glcpp.c

index 79fbdac5cc0f84484d3b650da22efce31413fe16..6994d7bb95528d611b516198627547b73f29817e 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <getopt.h>
+
 #include "glcpp.h"
 #include "main/mtypes.h"
 #include "main/shaderobj.h"
@@ -100,8 +102,31 @@ static void
 init_fake_gl_context (struct gl_context *gl_ctx)
 {
        gl_ctx->API = API_OPENGL_COMPAT;
+       gl_ctx->Const.DisableGLSLLineContinuations = false;
+}
+
+static void
+usage (void)
+{
+       fprintf (stderr,
+                "Usage: glcpp [OPTIONS] [--] [<filename>]\n"
+                "\n"
+                "Pre-process the given filename (stdin if no filename given).\n"
+                "The following options are supported:\n"
+                "    --disable-line-continuations      Do not interpret lines ending with a\n"
+                "                                      backslash ('\\') as a line continuation.\n");
 }
 
+enum {
+       DISABLE_LINE_CONTINUATIONS_OPT = CHAR_MAX + 1
+};
+
+const static struct option
+long_options[] = {
+       {"disable-line-continuations", no_argument, 0, DISABLE_LINE_CONTINUATIONS_OPT },
+       {0,                            0,           0, 0 }
+};
+
 int
 main (int argc, char *argv[])
 {
@@ -111,11 +136,28 @@ main (int argc, char *argv[])
        const char *shader;
        int ret;
        struct gl_context gl_ctx;
+       int c;
 
        init_fake_gl_context (&gl_ctx);
 
-       if (argc) {
-               filename = argv[1];
+       while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
+               switch (c) {
+               case DISABLE_LINE_CONTINUATIONS_OPT:
+                       gl_ctx.Const.DisableGLSLLineContinuations = true;
+                       break;
+               default:
+                       usage ();
+                       exit (1);
+               }
+       }
+
+       if (optind + 1 < argc) {
+               printf ("Unexpected argument: %s\n", argv[optind+1]);
+               usage ();
+               exit (1);
+       }
+       if (optind < argc) {
+               filename = argv[optind];
        }
 
        shader = load_text_file (ctx, filename);