summaryrefslogtreecommitdiffstats
path: root/src/glsl/pp/sl_pp_line.c
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-09-04 15:16:21 +0200
committerMichal Krol <[email protected]>2009-09-07 10:12:07 +0200
commit4aa3222df315e3b36c73374e9000a6607c3b995c (patch)
tree6f8fd9d68f913fa9f15e954c7263580ccc164ddc /src/glsl/pp/sl_pp_line.c
parent0d9c5eafeb35fdd2e5009ba0b397d1acdfbd3205 (diff)
glsl: Correctly handle line numbering.
Diffstat (limited to 'src/glsl/pp/sl_pp_line.c')
-rw-r--r--src/glsl/pp/sl_pp_line.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index 3300a4785ba..b62af185bf5 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -29,16 +29,44 @@
#include "sl_pp_process.h"
+static int
+_parse_integer(const char *input,
+ unsigned int *number)
+{
+ unsigned int n = 0;
+
+ while (*input >= '0' && *input <= '9') {
+ if (n * 10 < n) {
+ /* Overflow. */
+ return -1;
+ }
+
+ n = n * 10 + (*input++ - '0');
+ }
+
+ if (*input != '\0') {
+ /* Invalid decimal number. */
+ return -1;
+ }
+
+ *number = n;
+ return 0;
+}
+
+
int
sl_pp_process_line(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
unsigned int first,
- unsigned int last)
+ unsigned int last,
+ struct sl_pp_process_state *pstate)
{
unsigned int i;
struct sl_pp_process_state state;
int line_number = -1;
int file_number = -1;
+ const char *str;
+ unsigned int line;
memset(&state, 0, sizeof(state));
for (i = first; i < last;) {
@@ -89,7 +117,22 @@ sl_pp_process_line(struct sl_pp_context *context,
free(state.out);
- /* TODO: Do something with line and file numbers. */
+ str = sl_pp_context_cstr(context, line_number);
+ if (_parse_integer(str, &line)) {
+ return -1;
+ }
+
+ if (context->line != line) {
+ struct sl_pp_token_info ti;
+
+ ti.token = SL_PP_LINE;
+ ti.data.line = line;
+ if (sl_pp_process_out(pstate, &ti)) {
+ return -1;
+ }
+ }
+
+ /* TODO: Do something with the file number. */
return 0;
}