From 0d5ef796f847bc51888a8883110cc607494a61f0 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 12 Jun 2009 12:57:59 +0200 Subject: glsl: Add a tokenise app. --- src/glsl/apps/tokenise.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 src/glsl/apps/tokenise.c (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c new file mode 100644 index 0000000000..2631b82998 --- /dev/null +++ b/src/glsl/apps/tokenise.c @@ -0,0 +1,318 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include +#include +#include +#include "../pp/sl_pp_purify.h" +#include "../pp/sl_pp_token.h" + + +int +main(int argc, + char *argv[]) +{ + FILE *in; + long size; + char *inbuf; + struct sl_pp_purify_options options; + char *outbuf; + struct sl_pp_token_info *tokens; + FILE *out; + unsigned int i; + + if (argc != 3) { + return 1; + } + + in = fopen(argv[1], "rb"); + if (!in) { + return 1; + } + + fseek(in, 0, SEEK_END); + size = ftell(in); + fseek(in, 0, SEEK_SET); + + inbuf = malloc(size + 1); + if (!inbuf) { + fclose(in); + return 1; + } + + if (fread(inbuf, 1, size, in) != size) { + free(inbuf); + fclose(in); + return 1; + } + inbuf[size] = '\0'; + + fclose(in); + + memset(&options, 0, sizeof(options)); + + if (sl_pp_purify(inbuf, &options, &outbuf)) { + free(inbuf); + return 1; + } + + free(inbuf); + + if (sl_pp_tokenise(outbuf, &tokens)) { + free(outbuf); + return 1; + } + + free(outbuf); + + out = fopen(argv[2], "wb"); + if (!out) { + free(tokens); + return 1; + } + + for (i = 0; tokens[i].token != SL_PP_EOF; i++) { + switch (tokens[i].token) { + case SL_PP_WHITESPACE: + break; + + case SL_PP_NEWLINE: + fprintf(out, "\n"); + break; + + case SL_PP_HASH: + fprintf(out, "# "); + break; + + case SL_PP_COMMA: + fprintf(out, ", "); + break; + + case SL_PP_SEMICOLON: + fprintf(out, "; "); + break; + + case SL_PP_LBRACE: + fprintf(out, "{ "); + break; + + case SL_PP_RBRACE: + fprintf(out, "} "); + break; + + case SL_PP_LPAREN: + fprintf(out, "( "); + break; + + case SL_PP_RPAREN: + fprintf(out, ") "); + break; + + case SL_PP_LBRACKET: + fprintf(out, "[ "); + break; + + case SL_PP_RBRACKET: + fprintf(out, "] "); + break; + + case SL_PP_DOT: + fprintf(out, ". "); + break; + + case SL_PP_INCREMENT: + fprintf(out, "++ "); + break; + + case SL_PP_ADDASSIGN: + fprintf(out, "+= "); + break; + + case SL_PP_PLUS: + fprintf(out, "+ "); + break; + + case SL_PP_DECREMENT: + fprintf(out, "-- "); + break; + + case SL_PP_SUBASSIGN: + fprintf(out, "-= "); + break; + + case SL_PP_MINUS: + fprintf(out, "- "); + break; + + case SL_PP_BITNOT: + fprintf(out, "~ "); + break; + + case SL_PP_NOTEQUAL: + fprintf(out, "!= "); + break; + + case SL_PP_NOT: + fprintf(out, "! "); + break; + + case SL_PP_MULASSIGN: + fprintf(out, "*= "); + break; + + case SL_PP_STAR: + fprintf(out, "* "); + break; + + case SL_PP_DIVASSIGN: + fprintf(out, "/= "); + break; + + case SL_PP_SLASH: + fprintf(out, "/ "); + break; + + case SL_PP_MODASSIGN: + fprintf(out, "%= "); + break; + + case SL_PP_MODULO: + fprintf(out, "% "); + break; + + case SL_PP_LSHIFTASSIGN: + fprintf(out, "<<= "); + break; + + case SL_PP_LSHIFT: + fprintf(out, "<< "); + break; + + case SL_PP_LESSEQUAL: + fprintf(out, "<= "); + break; + + case SL_PP_LESS: + fprintf(out, "< "); + break; + + case SL_PP_RSHIFTASSIGN: + fprintf(out, ">>= "); + break; + + case SL_PP_RSHIFT: + fprintf(out, ">> "); + break; + + case SL_PP_GREATEREQUAL: + fprintf(out, ">= "); + break; + + case SL_PP_GREATER: + fprintf(out, "> "); + break; + + case SL_PP_EQUAL: + fprintf(out, "== "); + break; + + case SL_PP_ASSIGN: + fprintf(out, "= "); + break; + + case SL_PP_AND: + fprintf(out, "&& "); + break; + + case SL_PP_BITANDASSIGN: + fprintf(out, "&= "); + break; + + case SL_PP_BITAND: + fprintf(out, "& "); + break; + + case SL_PP_XOR: + fprintf(out, "^^ "); + break; + + case SL_PP_BITXORASSIGN: + fprintf(out, "^= "); + break; + + case SL_PP_BITXOR: + fprintf(out, "^ "); + break; + + case SL_PP_OR: + fprintf(out, "|| "); + break; + + case SL_PP_BITORASSIGN: + fprintf(out, "|= "); + break; + + case SL_PP_BITOR: + fprintf(out, "| "); + break; + + case SL_PP_QUESTION: + fprintf(out, "? "); + break; + + case SL_PP_COLON: + fprintf(out, ": "); + break; + + case SL_PP_IDENTIFIER: + fprintf(out, "%s ", tokens[i].data.identifier); + free(tokens[i].data.identifier); + break; + + case SL_PP_NUMBER: + fprintf(out, "(%s) ", tokens[i].data.number); + free(tokens[i].data.number); + break; + + case SL_PP_OTHER: + if (tokens[i].data.other == '\'') { + fprintf(out, "'\\'' "); + } else { + fprintf(out, "'%c' ", tokens[i].data.other); + } + break; + + default: + assert(0); + } + } + + free(tokens); + fclose(out); + + return 0; +} -- cgit v1.2.3 From f24322fbf6599b31f07ebc548e390c77b803d67c Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 17 Jun 2009 13:49:06 +0200 Subject: glsl: Introduce sl_pp_context and maintain a reuseable pool of strings. --- src/glsl/apps/process.c | 21 ++++++++----- src/glsl/apps/tokenise.c | 15 ++++++--- src/glsl/apps/version.c | 10 ++++-- src/glsl/pp/SConscript | 1 + src/glsl/pp/sl_pp_context.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/glsl/pp/sl_pp_context.h | 52 ++++++++++++++++++++++++++++++ src/glsl/pp/sl_pp_process.c | 16 ++-------- src/glsl/pp/sl_pp_process.h | 3 +- src/glsl/pp/sl_pp_token.c | 29 ++++++++--------- src/glsl/pp/sl_pp_token.h | 7 +++-- src/glsl/pp/sl_pp_version.c | 35 +++++++++++++++------ src/glsl/pp/sl_pp_version.h | 4 ++- 12 files changed, 213 insertions(+), 57 deletions(-) create mode 100644 src/glsl/pp/sl_pp_context.c create mode 100644 src/glsl/pp/sl_pp_context.h (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 6e2828aa41..abcf1a92b8 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -28,6 +28,7 @@ #include #include #include +#include "../pp/sl_pp_context.h" #include "../pp/sl_pp_purify.h" #include "../pp/sl_pp_version.h" #include "../pp/sl_pp_process.h" @@ -42,6 +43,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + struct sl_pp_context context; struct sl_pp_token_info *tokens; unsigned int version; unsigned int tokens_eaten; @@ -86,19 +88,24 @@ main(int argc, free(inbuf); - if (sl_pp_tokenise(outbuf, &tokens)) { + sl_pp_context_init(&context); + + if (sl_pp_tokenise(&context, outbuf, &tokens)) { + sl_pp_context_destroy(&context); free(outbuf); return 1; } free(outbuf); - if (sl_pp_version(tokens, &version, &tokens_eaten)) { + if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) { + sl_pp_context_destroy(&context); free(tokens); return -1; } - if (sl_pp_process(&tokens[tokens_eaten], &outtokens)) { + if (sl_pp_process(&context, &tokens[tokens_eaten], &outtokens)) { + sl_pp_context_destroy(&context); free(tokens); return -1; } @@ -107,6 +114,7 @@ main(int argc, out = fopen(argv[2], "wb"); if (!out) { + sl_pp_context_destroy(&context); free(outtokens); return 1; } @@ -298,13 +306,11 @@ main(int argc, break; case SL_PP_IDENTIFIER: - fprintf(out, "%s ", outtokens[i].data.identifier); - free(outtokens[i].data.identifier); + fprintf(out, "%s ", sl_pp_context_cstr(&context, outtokens[i].data.identifier)); break; case SL_PP_NUMBER: - fprintf(out, "(%s) ", outtokens[i].data.number); - free(outtokens[i].data.number); + fprintf(out, "%s ", sl_pp_context_cstr(&context, outtokens[i].data.number)); break; case SL_PP_OTHER: @@ -316,6 +322,7 @@ main(int argc, } } + sl_pp_context_destroy(&context); free(outtokens); fclose(out); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 2631b82998..b5092ba35f 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -28,6 +28,7 @@ #include #include #include +#include "../pp/sl_pp_context.h" #include "../pp/sl_pp_purify.h" #include "../pp/sl_pp_token.h" @@ -41,6 +42,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + struct sl_pp_context context; struct sl_pp_token_info *tokens; FILE *out; unsigned int i; @@ -82,7 +84,10 @@ main(int argc, free(inbuf); - if (sl_pp_tokenise(outbuf, &tokens)) { + sl_pp_context_init(&context); + + if (sl_pp_tokenise(&context, outbuf, &tokens)) { + sl_pp_context_destroy(&context); free(outbuf); return 1; } @@ -91,6 +96,7 @@ main(int argc, out = fopen(argv[2], "wb"); if (!out) { + sl_pp_context_destroy(&context); free(tokens); return 1; } @@ -289,13 +295,11 @@ main(int argc, break; case SL_PP_IDENTIFIER: - fprintf(out, "%s ", tokens[i].data.identifier); - free(tokens[i].data.identifier); + fprintf(out, "%s ", sl_pp_context_cstr(&context, tokens[i].data.identifier)); break; case SL_PP_NUMBER: - fprintf(out, "(%s) ", tokens[i].data.number); - free(tokens[i].data.number); + fprintf(out, "(%s) ", sl_pp_context_cstr(&context, tokens[i].data.number)); break; case SL_PP_OTHER: @@ -311,6 +315,7 @@ main(int argc, } } + sl_pp_context_destroy(&context); free(tokens); fclose(out); diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index b49395ba97..c56ae9dde9 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -41,6 +41,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + struct sl_pp_context context; struct sl_pp_token_info *tokens; unsigned int version; unsigned int tokens_eaten; @@ -83,18 +84,23 @@ main(int argc, free(inbuf); - if (sl_pp_tokenise(outbuf, &tokens)) { + sl_pp_context_init(&context); + + if (sl_pp_tokenise(&context, outbuf, &tokens)) { + sl_pp_context_destroy(&context); free(outbuf); return 1; } free(outbuf); - if (sl_pp_version(tokens, &version, &tokens_eaten)) { + if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) { + sl_pp_context_destroy(&context); free(tokens); return -1; } + sl_pp_context_destroy(&context); free(tokens); out = fopen(argv[2], "wb"); diff --git a/src/glsl/pp/SConscript b/src/glsl/pp/SConscript index 0be2114794..3d4a1cb967 100644 --- a/src/glsl/pp/SConscript +++ b/src/glsl/pp/SConscript @@ -8,6 +8,7 @@ env = env.Clone() glsl = env.StaticLibrary( target = 'glsl', source = [ + 'sl_pp_context.c', 'sl_pp_process.c', 'sl_pp_purify.c', 'sl_pp_token.c', diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c new file mode 100644 index 0000000000..71712de1fe --- /dev/null +++ b/src/glsl/pp/sl_pp_context.c @@ -0,0 +1,77 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include +#include "sl_pp_context.h" + + +void +sl_pp_context_init(struct sl_pp_context *context) +{ + memset(context, 0, sizeof(struct sl_pp_context)); +} + +void +sl_pp_context_destroy(struct sl_pp_context *context) +{ + free(context->cstr_pool); +} + +int +sl_pp_context_add_str(struct sl_pp_context *context, + const char *str) +{ + unsigned int size; + unsigned int offset; + + size = strlen(str) + 1; + + if (context->cstr_pool_len + size > context->cstr_pool_max) { + context->cstr_pool_max = (context->cstr_pool_len + size + 0xffff) & ~0xffff; + context->cstr_pool = realloc(context->cstr_pool, context->cstr_pool_max); + } + + if (!context->cstr_pool) { + return -1; + } + + offset = context->cstr_pool_len; + memcpy(&context->cstr_pool[offset], str, size); + context->cstr_pool_len += size; + + return offset; +} + +const char * +sl_pp_context_cstr(const struct sl_pp_context *context, + int offset) +{ + if (offset == -1) { + return NULL; + } + return &context->cstr_pool[offset]; +} diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h new file mode 100644 index 0000000000..3a1e215625 --- /dev/null +++ b/src/glsl/pp/sl_pp_context.h @@ -0,0 +1,52 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SL_PP_CONTEXT_H +#define SL_PP_CONTEXT_H + + +struct sl_pp_context { + char *cstr_pool; + unsigned int cstr_pool_max; + unsigned int cstr_pool_len; +}; + +void +sl_pp_context_init(struct sl_pp_context *context); + +void +sl_pp_context_destroy(struct sl_pp_context *context); + +int +sl_pp_context_add_str(struct sl_pp_context *context, + const char *str); + +const char * +sl_pp_context_cstr(const struct sl_pp_context *context, + int offset); + +#endif /* SL_PP_VERSION_H */ diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c index 56b8fab52a..a97c750de4 100644 --- a/src/glsl/pp/sl_pp_process.c +++ b/src/glsl/pp/sl_pp_process.c @@ -26,7 +26,6 @@ **************************************************************************/ #include -#include #include "sl_pp_process.h" @@ -38,7 +37,8 @@ enum process_state { }; int -sl_pp_process(const struct sl_pp_token_info *input, +sl_pp_process(struct sl_pp_context *context, + const struct sl_pp_token_info *input, struct sl_pp_token_info **output) { unsigned int i = 0; @@ -132,18 +132,6 @@ sl_pp_process(const struct sl_pp_token_info *input, out_max = new_max; } - if (info.token == SL_PP_IDENTIFIER) { - info.data.identifier = strdup(info.data.identifier); - if (!info.data.identifier) { - return -1; - } - } else if (info.token == SL_PP_NUMBER) { - info.data.number = strdup(info.data.number); - if (!info.data.number) { - return -1; - } - } - out[out_len++] = info; if (info.token == SL_PP_EOF) { diff --git a/src/glsl/pp/sl_pp_process.h b/src/glsl/pp/sl_pp_process.h index 6e930ca567..b71ee4466a 100644 --- a/src/glsl/pp/sl_pp_process.h +++ b/src/glsl/pp/sl_pp_process.h @@ -32,7 +32,8 @@ int -sl_pp_process(const struct sl_pp_token_info *input, +sl_pp_process(struct sl_pp_context *context, + const struct sl_pp_token_info *input, struct sl_pp_token_info **output); #endif /* SL_PP_PROCESS_H */ diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c index 4001fe54c8..e200b961aa 100644 --- a/src/glsl/pp/sl_pp_token.c +++ b/src/glsl/pp/sl_pp_token.c @@ -30,7 +30,8 @@ static int -_tokenise_identifier(const char **pinput, +_tokenise_identifier(struct sl_pp_context *context, + const char **pinput, struct sl_pp_token_info *info) { const char *input = *pinput; @@ -38,7 +39,7 @@ _tokenise_identifier(const char **pinput, unsigned int i = 0; info->token = SL_PP_IDENTIFIER; - info->data.identifier = NULL; + info->data.identifier = -1; identifier[i++] = *input++; while ((*input >= 'a' && *input <= 'z') || @@ -52,11 +53,10 @@ _tokenise_identifier(const char **pinput, } identifier[i++] = '\0'; - info->data.identifier = malloc(i); - if (!info->data.identifier) { + info->data.identifier = sl_pp_context_add_str(context, identifier); + if (info->data.identifier == -1) { return -1; } - memcpy(info->data.identifier, identifier, i); *pinput = input; return 0; @@ -64,7 +64,8 @@ _tokenise_identifier(const char **pinput, static int -_tokenise_number(const char **pinput, +_tokenise_number(struct sl_pp_context *context, + const char **pinput, struct sl_pp_token_info *info) { const char *input = *pinput; @@ -72,7 +73,7 @@ _tokenise_number(const char **pinput, unsigned int i = 0; info->token = SL_PP_NUMBER; - info->data.number = NULL; + info->data.number = -1; number[i++] = *input++; while ((*input >= '0' && *input <= '9') || @@ -90,11 +91,10 @@ _tokenise_number(const char **pinput, } number[i++] = '\0'; - info->data.number = malloc(i); - if (!info->data.number) { + info->data.number = sl_pp_context_add_str(context, number); + if (info->data.number == -1) { return -1; } - memcpy(info->data.number, number, i); *pinput = input; return 0; @@ -102,7 +102,8 @@ _tokenise_number(const char **pinput, int -sl_pp_tokenise(const char *input, +sl_pp_tokenise(struct sl_pp_context *context, + const char *input, struct sl_pp_token_info **output) { struct sl_pp_token_info *out = NULL; @@ -171,7 +172,7 @@ sl_pp_tokenise(const char *input, case '.': if (input[1] >= '0' && input[1] <= '9') { - if (_tokenise_number(&input, &info)) { + if (_tokenise_number(context, &input, &info)) { free(out); return -1; } @@ -355,12 +356,12 @@ sl_pp_tokenise(const char *input, if ((*input >= 'a' && *input <= 'z') || (*input >= 'A' && *input <= 'Z') || (*input == '_')) { - if (_tokenise_identifier(&input, &info)) { + if (_tokenise_identifier(context, &input, &info)) { free(out); return -1; } } else if (*input >= '0' && *input <= '9') { - if (_tokenise_number(&input, &info)) { + if (_tokenise_number(context, &input, &info)) { free(out); return -1; } diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h index 5e7fae7d29..c801804ae6 100644 --- a/src/glsl/pp/sl_pp_token.h +++ b/src/glsl/pp/sl_pp_token.h @@ -90,8 +90,8 @@ enum sl_pp_token { }; union sl_pp_token_data { - char *identifier; - char *number; + int identifier; + int number; char other; }; @@ -101,7 +101,8 @@ struct sl_pp_token_info { }; int -sl_pp_tokenise(const char *input, +sl_pp_tokenise(struct sl_pp_context *context, + const char *input, struct sl_pp_token_info **output); #endif /* SL_PP_TOKEN_H */ diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c index e743a09841..89c3cfa1a5 100644 --- a/src/glsl/pp/sl_pp_version.c +++ b/src/glsl/pp/sl_pp_version.c @@ -54,7 +54,8 @@ _parse_integer(const char *input, int -sl_pp_version(const struct sl_pp_token_info *input, +sl_pp_version(struct sl_pp_context *context, + const struct sl_pp_token_info *input, unsigned int *version, unsigned int *tokens_eaten) { @@ -99,11 +100,18 @@ sl_pp_version(const struct sl_pp_token_info *input, break; case SL_PP_IDENTIFIER: - if (strcmp(input[i].data.identifier, "version")) { - return 0; + { + const char *id = sl_pp_context_cstr(context, input[i].data.identifier); + + if (!id) { + return -1; + } + if (strcmp(id, "version")) { + return 0; + } + i++; + found_version = 1; } - i++; - found_version = 1; break; default: @@ -119,12 +127,19 @@ sl_pp_version(const struct sl_pp_token_info *input, break; case SL_PP_NUMBER: - if (_parse_integer(input[i].data.number, version)) { - /* Expected version number. */ - return -1; + { + const char *num = sl_pp_context_cstr(context, input[i].data.number); + + if (!num) { + return -1; + } + if (_parse_integer(num, version)) { + /* Expected version number. */ + return -1; + } + i++; + found_number = 1; } - i++; - found_number = 1; break; default: diff --git a/src/glsl/pp/sl_pp_version.h b/src/glsl/pp/sl_pp_version.h index 7deee1a134..cee9f55bc6 100644 --- a/src/glsl/pp/sl_pp_version.h +++ b/src/glsl/pp/sl_pp_version.h @@ -28,11 +28,13 @@ #ifndef SL_PP_VERSION_H #define SL_PP_VERSION_H +#include "sl_pp_context.h" #include "sl_pp_token.h" int -sl_pp_version(const struct sl_pp_token_info *input, +sl_pp_version(struct sl_pp_context *context, + const struct sl_pp_token_info *input, unsigned int *version, unsigned int *tokens_eaten); -- cgit v1.2.3 From 169aead1b55446c7bfe669b6a822d56e8af15f7f Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 14 Sep 2009 13:08:07 +0200 Subject: glsl/apps: Adapt to pp interface change. --- src/glsl/apps/process.c | 5 ++++- src/glsl/apps/tokenise.c | 5 ++++- src/glsl/apps/version.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 71211ccb72..a11f9741f5 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -88,7 +88,10 @@ main(int argc, free(inbuf); - sl_pp_context_init(&context); + if (sl_pp_context_init(&context)) { + free(outbuf); + return 1; + } if (sl_pp_tokenise(&context, outbuf, &tokens)) { sl_pp_context_destroy(&context); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index b5092ba35f..64b0a2f05e 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -84,7 +84,10 @@ main(int argc, free(inbuf); - sl_pp_context_init(&context); + if (sl_pp_context_init(&context)) { + free(outbuf); + return 1; + } if (sl_pp_tokenise(&context, outbuf, &tokens)) { sl_pp_context_destroy(&context); diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index c56ae9dde9..9e579043b2 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -84,7 +84,10 @@ main(int argc, free(inbuf); - sl_pp_context_init(&context); + if (sl_pp_context_init(&context)) { + free(outbuf); + return 1; + } if (sl_pp_tokenise(&context, outbuf, &tokens)) { sl_pp_context_destroy(&context); -- cgit v1.2.3 From 69bdd47dba1f7331a632316e4f9cc9942fb93ca4 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 17 Sep 2009 10:45:16 +0200 Subject: glsl/apps: Always write out error condition. --- src/glsl/apps/purify.c | 21 +++++++++++++++------ src/glsl/apps/tokenise.c | 28 +++++++++++++++++++++------- src/glsl/apps/version.c | 29 ++++++++++++++++++++++++----- 3 files changed, 60 insertions(+), 18 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c index 7dff8aea45..d4c53704e5 100644 --- a/src/glsl/apps/purify.c +++ b/src/glsl/apps/purify.c @@ -54,14 +54,26 @@ main(int argc, size = ftell(in); fseek(in, 0, SEEK_SET); + out = fopen(argv[2], "wb"); + if (!out) { + fclose(in); + return 1; + } + inbuf = malloc(size + 1); if (!inbuf) { + fprintf(out, "$OOMERROR\n"); + + fclose(out); fclose(in); return 1; } if (fread(inbuf, 1, size, in) != size) { + fprintf(out, "$READERROR\n"); + free(inbuf); + fclose(out); fclose(in); return 1; } @@ -72,18 +84,15 @@ main(int argc, memset(&options, 0, sizeof(options)); if (sl_pp_purify(inbuf, &options, &outbuf)) { + fprintf(out, "$PURIFYERROR\n"); + free(inbuf); + fclose(out); return 1; } free(inbuf); - out = fopen(argv[2], "wb"); - if (!out) { - free(outbuf); - return 1; - } - fwrite(outbuf, 1, strlen(outbuf), out); free(outbuf); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 64b0a2f05e..1746e20c13 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -60,14 +60,26 @@ main(int argc, size = ftell(in); fseek(in, 0, SEEK_SET); + out = fopen(argv[2], "wb"); + if (!out) { + fclose(in); + return 1; + } + inbuf = malloc(size + 1); if (!inbuf) { + fprintf(out, "$OOMERROR\n"); + + fclose(out); fclose(in); return 1; } if (fread(inbuf, 1, size, in) != size) { + fprintf(out, "$READERROR\n"); + free(inbuf); + fclose(out); fclose(in); return 1; } @@ -78,32 +90,34 @@ main(int argc, memset(&options, 0, sizeof(options)); if (sl_pp_purify(inbuf, &options, &outbuf)) { + fprintf(out, "$PURIFYERROR\n"); + free(inbuf); + fclose(out); return 1; } free(inbuf); if (sl_pp_context_init(&context)) { + fprintf(out, "$CONTEXERROR\n"); + free(outbuf); + fclose(out); return 1; } if (sl_pp_tokenise(&context, outbuf, &tokens)) { + fprintf(out, "$ERROR: `%s'\n", context.error_msg); + sl_pp_context_destroy(&context); free(outbuf); + fclose(out); return 1; } free(outbuf); - out = fopen(argv[2], "wb"); - if (!out) { - sl_pp_context_destroy(&context); - free(tokens); - return 1; - } - for (i = 0; tokens[i].token != SL_PP_EOF; i++) { switch (tokens[i].token) { case SL_PP_WHITESPACE: diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index 9e579043b2..50c564b470 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -60,14 +60,26 @@ main(int argc, size = ftell(in); fseek(in, 0, SEEK_SET); + out = fopen(argv[2], "wb"); + if (!out) { + fclose(in); + return 1; + } + inbuf = malloc(size + 1); if (!inbuf) { + fprintf(out, "$OOMERROR\n"); + + fclose(out); fclose(in); return 1; } if (fread(inbuf, 1, size, in) != size) { + fprintf(out, "$READERROR\n"); + free(inbuf); + fclose(out); fclose(in); return 1; } @@ -78,39 +90,46 @@ main(int argc, memset(&options, 0, sizeof(options)); if (sl_pp_purify(inbuf, &options, &outbuf)) { + fprintf(out, "$PURIFYERROR\n"); + free(inbuf); + fclose(out); return 1; } free(inbuf); if (sl_pp_context_init(&context)) { + fprintf(out, "$CONTEXERROR\n"); + free(outbuf); + fclose(out); return 1; } if (sl_pp_tokenise(&context, outbuf, &tokens)) { + fprintf(out, "$ERROR: `%s'\n", context.error_msg); + sl_pp_context_destroy(&context); free(outbuf); + fclose(out); return 1; } free(outbuf); if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) { + fprintf(out, "$ERROR: `%s'\n", context.error_msg); + sl_pp_context_destroy(&context); free(tokens); + fclose(out); return -1; } sl_pp_context_destroy(&context); free(tokens); - out = fopen(argv[2], "wb"); - if (!out) { - return 1; - } - fprintf(out, "%u\n%u\n", version, -- cgit v1.2.3 From 5f9f30a75268bf6803627930ce982aede2c870f5 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 18 Sep 2009 11:20:42 +0200 Subject: glsl/apps: Use glsl pp public interface. --- src/glsl/apps/process.c | 42 ++++++++++++++++++++---------------------- src/glsl/apps/purify.c | 2 +- src/glsl/apps/tokenise.c | 21 ++++++++++----------- src/glsl/apps/version.c | 22 +++++++++++----------- 4 files changed, 42 insertions(+), 45 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 678b1005f8..1fdb09670c 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -28,10 +28,7 @@ #include #include #include -#include "../pp/sl_pp_context.h" -#include "../pp/sl_pp_purify.h" -#include "../pp/sl_pp_version.h" -#include "../pp/sl_pp_process.h" +#include "../pp/sl_pp_public.h" int @@ -43,7 +40,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; - struct sl_pp_context context; + struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; unsigned int tokens_eaten; @@ -103,7 +100,8 @@ main(int argc, free(inbuf); - if (sl_pp_context_init(&context)) { + context = sl_pp_context_create(); + if (!context) { fprintf(out, "$CONTEXERROR\n"); free(outbuf); @@ -111,10 +109,10 @@ main(int argc, return 1; } - if (sl_pp_tokenise(&context, outbuf, &tokens)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_tokenise(context, outbuf, &tokens)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(outbuf); fclose(out); return 1; @@ -122,19 +120,19 @@ main(int argc, free(outbuf); - if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(tokens); fclose(out); return -1; } - if (sl_pp_process(&context, &tokens[tokens_eaten], &outtokens)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_process(context, &tokens[tokens_eaten], &outtokens)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(tokens); fclose(out); return -1; @@ -329,11 +327,11 @@ main(int argc, break; case SL_PP_IDENTIFIER: - fprintf(out, "%s ", sl_pp_context_cstr(&context, outtokens[i].data.identifier)); + fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data.identifier)); break; case SL_PP_NUMBER: - fprintf(out, "%s ", sl_pp_context_cstr(&context, outtokens[i].data.number)); + fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data.number)); break; case SL_PP_OTHER: @@ -349,19 +347,19 @@ main(int argc, break; case SL_PP_EXTENSION_REQUIRE: - fprintf(out, "#extension %s : require", sl_pp_context_cstr(&context, outtokens[i].data.extension)); + fprintf(out, "#extension %s : require", sl_pp_context_cstr(context, outtokens[i].data.extension)); break; case SL_PP_EXTENSION_ENABLE: - fprintf(out, "#extension %s : enable", sl_pp_context_cstr(&context, outtokens[i].data.extension)); + fprintf(out, "#extension %s : enable", sl_pp_context_cstr(context, outtokens[i].data.extension)); break; case SL_PP_EXTENSION_WARN: - fprintf(out, "#extension %s : warn", sl_pp_context_cstr(&context, outtokens[i].data.extension)); + fprintf(out, "#extension %s : warn", sl_pp_context_cstr(context, outtokens[i].data.extension)); break; case SL_PP_EXTENSION_DISABLE: - fprintf(out, "#extension %s : disable", sl_pp_context_cstr(&context, outtokens[i].data.extension)); + fprintf(out, "#extension %s : disable", sl_pp_context_cstr(context, outtokens[i].data.extension)); break; case SL_PP_LINE: @@ -377,7 +375,7 @@ main(int argc, } } - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(outtokens); fclose(out); diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c index d4c53704e5..435bdbe514 100644 --- a/src/glsl/apps/purify.c +++ b/src/glsl/apps/purify.c @@ -27,7 +27,7 @@ #include #include -#include "../pp/sl_pp_purify.h" +#include "../pp/sl_pp_public.h" int diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 1746e20c13..2b3ebcf283 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -28,9 +28,7 @@ #include #include #include -#include "../pp/sl_pp_context.h" -#include "../pp/sl_pp_purify.h" -#include "../pp/sl_pp_token.h" +#include "../pp/sl_pp_public.h" int @@ -42,7 +40,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; - struct sl_pp_context context; + struct sl_pp_context *context; struct sl_pp_token_info *tokens; FILE *out; unsigned int i; @@ -99,7 +97,8 @@ main(int argc, free(inbuf); - if (sl_pp_context_init(&context)) { + context = sl_pp_context_create(); + if (!context) { fprintf(out, "$CONTEXERROR\n"); free(outbuf); @@ -107,10 +106,10 @@ main(int argc, return 1; } - if (sl_pp_tokenise(&context, outbuf, &tokens)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_tokenise(context, outbuf, &tokens)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(outbuf); fclose(out); return 1; @@ -312,11 +311,11 @@ main(int argc, break; case SL_PP_IDENTIFIER: - fprintf(out, "%s ", sl_pp_context_cstr(&context, tokens[i].data.identifier)); + fprintf(out, "%s ", sl_pp_context_cstr(context, tokens[i].data.identifier)); break; case SL_PP_NUMBER: - fprintf(out, "(%s) ", sl_pp_context_cstr(&context, tokens[i].data.number)); + fprintf(out, "(%s) ", sl_pp_context_cstr(context, tokens[i].data.number)); break; case SL_PP_OTHER: @@ -332,7 +331,7 @@ main(int argc, } } - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(tokens); fclose(out); diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index 50c564b470..f259431992 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -28,8 +28,7 @@ #include #include #include -#include "../pp/sl_pp_purify.h" -#include "../pp/sl_pp_version.h" +#include "../pp/sl_pp_public.h" int @@ -41,7 +40,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; - struct sl_pp_context context; + struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; unsigned int tokens_eaten; @@ -99,7 +98,8 @@ main(int argc, free(inbuf); - if (sl_pp_context_init(&context)) { + context = sl_pp_context_create(); + if (!context) { fprintf(out, "$CONTEXERROR\n"); free(outbuf); @@ -107,10 +107,10 @@ main(int argc, return 1; } - if (sl_pp_tokenise(&context, outbuf, &tokens)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_tokenise(context, outbuf, &tokens)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(outbuf); fclose(out); return 1; @@ -118,16 +118,16 @@ main(int argc, free(outbuf); - if (sl_pp_version(&context, tokens, &version, &tokens_eaten)) { - fprintf(out, "$ERROR: `%s'\n", context.error_msg); + if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { + fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(tokens); fclose(out); return -1; } - sl_pp_context_destroy(&context); + sl_pp_context_destroy(context); free(tokens); fprintf(out, -- cgit v1.2.3 From 125691dda3d261d3115bf85265428e28d2bbf6c8 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 22 Sep 2009 12:52:21 +0200 Subject: glsl/apps: Update after recent pp interface changes. --- src/glsl/apps/process.c | 8 ++++++-- src/glsl/apps/tokenise.c | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 1fdb09670c..4fff3570c1 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -330,8 +330,12 @@ main(int argc, fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data.identifier)); break; - case SL_PP_NUMBER: - fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data.number)); + case SL_PP_UINT: + fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data._uint)); + break; + + case SL_PP_FLOAT: + fprintf(out, "%s ", sl_pp_context_cstr(context, outtokens[i].data._float)); break; case SL_PP_OTHER: diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 2b3ebcf283..9f95424f5c 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -314,8 +314,12 @@ main(int argc, fprintf(out, "%s ", sl_pp_context_cstr(context, tokens[i].data.identifier)); break; - case SL_PP_NUMBER: - fprintf(out, "(%s) ", sl_pp_context_cstr(context, tokens[i].data.number)); + case SL_PP_UINT: + fprintf(out, "(%s) ", sl_pp_context_cstr(context, tokens[i].data._uint)); + break; + + case SL_PP_FLOAT: + fprintf(out, "(%s) ", sl_pp_context_cstr(context, tokens[i].data._float)); break; case SL_PP_OTHER: -- cgit v1.2.3 From e8e3fe15e1b0f75c43e197f8875a7fae1468f584 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 24 Sep 2009 10:55:37 +0200 Subject: glsl/apps: Include missing header, properly escape format strings. --- src/glsl/apps/process.c | 5 +++-- src/glsl/apps/purify.c | 1 + src/glsl/apps/tokenise.c | 5 +++-- src/glsl/apps/version.c | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 28b415c3ff..e20b68b1a9 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "../pp/sl_pp_public.h" @@ -235,11 +236,11 @@ main(int argc, break; case SL_PP_MODASSIGN: - fprintf(out, "%= "); + fprintf(out, "%%= "); break; case SL_PP_MODULO: - fprintf(out, "% "); + fprintf(out, "%% "); break; case SL_PP_LSHIFTASSIGN: diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c index 435bdbe514..53ba253022 100644 --- a/src/glsl/apps/purify.c +++ b/src/glsl/apps/purify.c @@ -27,6 +27,7 @@ #include #include +#include #include "../pp/sl_pp_public.h" diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 9f95424f5c..d6b9c4fa04 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "../pp/sl_pp_public.h" @@ -219,11 +220,11 @@ main(int argc, break; case SL_PP_MODASSIGN: - fprintf(out, "%= "); + fprintf(out, "%%= "); break; case SL_PP_MODULO: - fprintf(out, "% "); + fprintf(out, "%% "); break; case SL_PP_LSHIFTASSIGN: diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index f259431992..4570f86217 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "../pp/sl_pp_public.h" -- cgit v1.2.3 From b5c8c87eab4cbc4f05cbd98d7647b9b83607f976 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 10 Nov 2009 00:15:54 +0100 Subject: glsl/apps: Update for glsl/pp interface changes. --- src/glsl/apps/process.c | 6 ++++-- src/glsl/apps/purify.c | 6 ++++-- src/glsl/apps/tokenise.c | 6 ++++-- src/glsl/apps/version.c | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index e20b68b1a9..7f392613e0 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -41,6 +41,8 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + char errmsg[100] = ""; + unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; @@ -91,8 +93,8 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf)) { - fprintf(out, "$PURIFYERROR\n"); + if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { + fprintf(out, "$PURIFYERROR %s\n", errmsg); free(inbuf); fclose(out); diff --git a/src/glsl/apps/purify.c b/src/glsl/apps/purify.c index 53ba253022..8c01f4fc6a 100644 --- a/src/glsl/apps/purify.c +++ b/src/glsl/apps/purify.c @@ -40,6 +40,8 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + char errmsg[100] = ""; + unsigned int errline = 0; FILE *out; if (argc != 3) { @@ -84,8 +86,8 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf)) { - fprintf(out, "$PURIFYERROR\n"); + if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { + fprintf(out, "$PURIFYERROR %u: %s\n", errline, errmsg); free(inbuf); fclose(out); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index d6b9c4fa04..9dd9631a4e 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -41,6 +41,8 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + char errmsg[100] = ""; + unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; FILE *out; @@ -88,8 +90,8 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf)) { - fprintf(out, "$PURIFYERROR\n"); + if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { + fprintf(out, "$PURIFYERROR %s\n", errmsg); free(inbuf); fclose(out); diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index 4570f86217..1127dae516 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -41,6 +41,8 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char *outbuf; + char errmsg[100] = ""; + unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; @@ -89,8 +91,8 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf)) { - fprintf(out, "$PURIFYERROR\n"); + if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { + fprintf(out, "$PURIFYERROR %s\n", errmsg); free(inbuf); fclose(out); -- cgit v1.2.3 From 6199a0cf89034ab92ac61158a25902acc17604f4 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Sat, 21 Nov 2009 20:44:16 +0100 Subject: glsl/apps: No need to purify source text for tokeniser. --- src/glsl/apps/compile.c | 19 ++++--------------- src/glsl/apps/process.c | 19 ++++--------------- src/glsl/apps/tokenise.c | 19 ++++--------------- src/glsl/apps/version.c | 19 ++++--------------- 4 files changed, 16 insertions(+), 60 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/compile.c b/src/glsl/apps/compile.c index edc426528b..d16dac5868 100644 --- a/src/glsl/apps/compile.c +++ b/src/glsl/apps/compile.c @@ -41,7 +41,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char *outbuf; char errmsg[100] = ""; unsigned int errline = 0; struct sl_pp_context *context; @@ -105,35 +104,25 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { - fprintf(out, "$PURIFYERROR %s\n", errmsg); - - free(inbuf); - fclose(out); - return 1; - } - - free(inbuf); - context = sl_pp_context_create(); if (!context) { fprintf(out, "$CONTEXERROR\n"); - free(outbuf); + free(inbuf); fclose(out); return 1; } - if (sl_pp_tokenise(context, outbuf, &tokens)) { + if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(outbuf); + free(inbuf); fclose(out); return 1; } - free(outbuf); + free(inbuf); if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index 7f392613e0..2cec9a9971 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -40,7 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char *outbuf; char errmsg[100] = ""; unsigned int errline = 0; struct sl_pp_context *context; @@ -93,35 +92,25 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { - fprintf(out, "$PURIFYERROR %s\n", errmsg); - - free(inbuf); - fclose(out); - return 1; - } - - free(inbuf); - context = sl_pp_context_create(); if (!context) { fprintf(out, "$CONTEXERROR\n"); - free(outbuf); + free(inbuf); fclose(out); return 1; } - if (sl_pp_tokenise(context, outbuf, &tokens)) { + if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(outbuf); + free(inbuf); fclose(out); return 1; } - free(outbuf); + free(inbuf); if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 9dd9631a4e..eb86e3df69 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -40,7 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char *outbuf; char errmsg[100] = ""; unsigned int errline = 0; struct sl_pp_context *context; @@ -90,35 +89,25 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { - fprintf(out, "$PURIFYERROR %s\n", errmsg); - - free(inbuf); - fclose(out); - return 1; - } - - free(inbuf); - context = sl_pp_context_create(); if (!context) { fprintf(out, "$CONTEXERROR\n"); - free(outbuf); + free(inbuf); fclose(out); return 1; } - if (sl_pp_tokenise(context, outbuf, &tokens)) { + if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(outbuf); + free(inbuf); fclose(out); return 1; } - free(outbuf); + free(inbuf); for (i = 0; tokens[i].token != SL_PP_EOF; i++) { switch (tokens[i].token) { diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index 1127dae516..b1d0d6ff28 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -40,7 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char *outbuf; char errmsg[100] = ""; unsigned int errline = 0; struct sl_pp_context *context; @@ -91,35 +90,25 @@ main(int argc, memset(&options, 0, sizeof(options)); - if (sl_pp_purify(inbuf, &options, &outbuf, errmsg, sizeof(errmsg), &errline)) { - fprintf(out, "$PURIFYERROR %s\n", errmsg); - - free(inbuf); - fclose(out); - return 1; - } - - free(inbuf); - context = sl_pp_context_create(); if (!context) { fprintf(out, "$CONTEXERROR\n"); - free(outbuf); + free(inbuf); fclose(out); return 1; } - if (sl_pp_tokenise(context, outbuf, &tokens)) { + if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(outbuf); + free(inbuf); fclose(out); return 1; } - free(outbuf); + free(inbuf); if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); -- cgit v1.2.3 From 05eccfe79ec74a04630bcebff4c76accf4f85e0d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 10 Dec 2009 08:25:47 -0700 Subject: glsl/apps: remove unused vars --- src/glsl/apps/compile.c | 1 - src/glsl/apps/process.c | 2 -- src/glsl/apps/tokenise.c | 2 -- src/glsl/apps/version.c | 2 -- 4 files changed, 7 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/compile.c b/src/glsl/apps/compile.c index 63c2099e87..b1165420fb 100644 --- a/src/glsl/apps/compile.c +++ b/src/glsl/apps/compile.c @@ -49,7 +49,6 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; char errmsg[100] = ""; - unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index b793cc086d..d7bc16577e 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -40,8 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char errmsg[100] = ""; - unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index eb86e3df69..91368c32a4 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -40,8 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char errmsg[100] = ""; - unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; FILE *out; diff --git a/src/glsl/apps/version.c b/src/glsl/apps/version.c index b1d0d6ff28..6f77f230ca 100644 --- a/src/glsl/apps/version.c +++ b/src/glsl/apps/version.c @@ -40,8 +40,6 @@ main(int argc, long size; char *inbuf; struct sl_pp_purify_options options; - char errmsg[100] = ""; - unsigned int errline = 0; struct sl_pp_context *context; struct sl_pp_token_info *tokens; unsigned int version; -- cgit v1.2.3 From 9c15948125109d6eda7da25a2749680b830e8b82 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Sun, 20 Dec 2009 13:53:17 +0100 Subject: glsl/apps: Update after glsl pp interface changes. --- src/glsl/apps/process.c | 27 +++++++-------------------- src/glsl/apps/tokenise.c | 4 ++-- 2 files changed, 9 insertions(+), 22 deletions(-) (limited to 'src/glsl/apps/tokenise.c') diff --git a/src/glsl/apps/process.c b/src/glsl/apps/process.c index d7bc16577e..569890210f 100644 --- a/src/glsl/apps/process.c +++ b/src/glsl/apps/process.c @@ -41,9 +41,7 @@ main(int argc, char *inbuf; struct sl_pp_purify_options options; struct sl_pp_context *context; - struct sl_pp_token_info *tokens; unsigned int version; - unsigned int tokens_eaten; struct sl_pp_token_info *outtokens; FILE *out; unsigned int i; @@ -90,7 +88,7 @@ main(int argc, memset(&options, 0, sizeof(options)); - context = sl_pp_context_create(); + context = sl_pp_context_create(inbuf, &options); if (!context) { fprintf(out, "$CONTEXERROR\n"); @@ -99,23 +97,12 @@ main(int argc, return 1; } - if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { + if (sl_pp_version(context, &version)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); free(inbuf); fclose(out); - return 1; - } - - free(inbuf); - - if (sl_pp_version(context, tokens, &version, &tokens_eaten)) { - fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); - - sl_pp_context_destroy(context); - free(tokens); - fclose(out); return -1; } @@ -125,7 +112,7 @@ main(int argc, printf("Error: %s\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(tokens); + free(inbuf); fclose(out); return 0; } @@ -135,21 +122,21 @@ main(int argc, printf("Error: %s\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(tokens); + free(inbuf); fclose(out); return 0; } - if (sl_pp_process(context, &tokens[tokens_eaten], &outtokens)) { + if (sl_pp_process(context, &outtokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); - free(tokens); + free(inbuf); fclose(out); return -1; } - free(tokens); + free(inbuf); for (i = 0; outtokens[i].token != SL_PP_EOF; i++) { switch (outtokens[i].token) { diff --git a/src/glsl/apps/tokenise.c b/src/glsl/apps/tokenise.c index 91368c32a4..9ff73157e9 100644 --- a/src/glsl/apps/tokenise.c +++ b/src/glsl/apps/tokenise.c @@ -87,7 +87,7 @@ main(int argc, memset(&options, 0, sizeof(options)); - context = sl_pp_context_create(); + context = sl_pp_context_create(inbuf, &options); if (!context) { fprintf(out, "$CONTEXERROR\n"); @@ -96,7 +96,7 @@ main(int argc, return 1; } - if (sl_pp_tokenise(context, inbuf, &options, &tokens)) { + if (sl_pp_tokenise(context, &tokens)) { fprintf(out, "$ERROR: `%s'\n", sl_pp_context_error_message(context)); sl_pp_context_destroy(context); -- cgit v1.2.3