diff options
author | Daiki Ueno <ueno@gnu.org> | 2014-12-09 12:33:47 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2014-12-09 12:33:47 +0900 |
commit | 7ac6d92bdbc3bc16837c3d4588717a2ea575666d (patch) | |
tree | 3c90298dcf32c1db7b0d21d26c02bebb0d13b42d /gettext-tools/src/x-vala.c | |
parent | 05db9dc6bbdcbda95ea2979cd5925c3bcbc49d88 (diff) | |
download | external_gettext-7ac6d92bdbc3bc16837c3d4588717a2ea575666d.zip external_gettext-7ac6d92bdbc3bc16837c3d4588717a2ea575666d.tar.gz external_gettext-7ac6d92bdbc3bc16837c3d4588717a2ea575666d.tar.bz2 |
vala: Simplify the parsing logic
* x-vala.c (phase3_get): Factor out the buffer allocation as a
macro.
Diffstat (limited to 'gettext-tools/src/x-vala.c')
-rw-r--r-- | gettext-tools/src/x-vala.c | 77 |
1 files changed, 23 insertions, 54 deletions
diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index 76b9140..4806b36 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -431,6 +431,19 @@ phase3_get (token_ty *tp) int bufpos; int last_was_backslash; +#undef APPEND +#define APPEND(c) \ + do \ + { \ + if (bufpos >= bufmax) \ + { \ + bufmax = 2 * bufmax + 10; \ + buffer = xrealloc (buffer, bufmax); \ + } \ + buffer[bufpos++] = c; \ + } \ + while (0) + if (phase3_pushback_length) { *tp = phase3_pushback[--phase3_pushback_length]; @@ -484,12 +497,7 @@ phase3_get (token_ty *tp) bufpos = 0; for (;;) { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); c = phase2_getc (); switch (c) { @@ -514,12 +522,7 @@ phase3_get (token_ty *tp) } break; } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; + APPEND (0); if (strcmp (buffer, "return") == 0) tp->type = last_token_type = token_type_return; else @@ -554,23 +557,13 @@ phase3_get (token_ty *tp) bufpos = 0; for (;;) { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); c = phase2_getc (); switch (c) { case 'e': case 'E': - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); c = phase2_getc (); if (c != '+' && c != '-') { @@ -600,12 +593,7 @@ phase3_get (token_ty *tp) } break; } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; + APPEND (0); tp->type = last_token_type = token_type_number; return; @@ -710,12 +698,7 @@ phase3_get (token_ty *tp) } phase1_ungetc (c2); } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); } } else @@ -728,12 +711,7 @@ phase3_get (token_ty *tp) if (last_was_backslash) { last_was_backslash = false; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); continue; } @@ -743,12 +721,7 @@ phase3_get (token_ty *tp) last_was_backslash = true; /* FALLTHROUGH */ default: - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; + APPEND (c); continue; case '\n': @@ -765,12 +738,7 @@ phase3_get (token_ty *tp) break; } } - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos] = 0; + APPEND (0); tp->type = last_token_type = template ? token_type_string_template : token_type_string_literal; tp->string = xstrdup (buffer); @@ -979,6 +947,7 @@ phase3_get (token_ty *tp) return; } } +#undef APPEND } static void |