[Mesa-dev] [PATCH 6/8] glcpp: Add --disable-line-continuations argument to standalone glcpp

Kenneth Graunke kenneth at whitecape.org
Wed Jan 2 19:11:10 PST 2013


On 12/05/2012 05:32 PM, Carl Worth wrote:
> 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).
> ---
>   src/glsl/glcpp/glcpp.c |   43 +++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 41 insertions(+), 2 deletions(-)
>
> diff --git a/src/glsl/glcpp/glcpp.c b/src/glsl/glcpp/glcpp.c
> index 79fbdac..5352703 100644
> --- a/src/glsl/glcpp/glcpp.c
> +++ b/src/glsl/glcpp/glcpp.c
> @@ -100,6 +100,18 @@ 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");
> +	fprintf (stderr, "\n");
> +	fprintf (stderr, "Pre-process the given filename (stdin if no filename given).\n");
> +	fprintf (stderr, "The following options are supported:\n");
> +	fprintf (stderr, "    --disable-line-continuations      Do not interpret lines ending with a\n");
> +	fprintf (stderr, "                                      backslash ('\\') as a line continuation.\n");
>   }
>
>   int
> @@ -111,11 +123,38 @@ main (int argc, char *argv[])
>   	const char *shader;
>   	int ret;
>   	struct gl_context gl_ctx;
> +	int i;
>
>   	init_fake_gl_context (&gl_ctx);
>
> -	if (argc) {
> -		filename = argv[1];
> +	for (i = 1; i < argc; i++) {
> +		/* An argument of -- means that no subsequent
> +		 * arguments are options.
> +		 */
> +		if (strcmp(argv[i], "--") == 0) {
> +			i++;
> +			break;
> +		}
> +
> +		/* An argument not starting with '-' is not an
> +		 * option.
> +		 */
> +		if (argv[i][0] != '-')
> +			break;
> +
> +		/* Interpret known options.
> +		 */
> +		if (strcmp(argv[i], "--disable-line-continuations") == 0) {
> +			gl_ctx.Const.DisableGLSLLineContinuations = true;
> +		} else {
> +			fprintf (stderr, "Unknown option: %s\n", argv[i]);
> +			usage ();
> +			exit (1);
> +		}
> +	}
> +
> +	if (i < argc) {
> +		filename = argv[i];
>   	}
>
>   	shader = load_text_file (ctx, filename);

Why not use getopt()?  The standalone GLSL compiler already does, so it 
doesn't add another dependency.

For the single option you've added here, your code is reasonable, but 
ad-hoc option parsing gets out of control quick.


More information about the mesa-dev mailing list