Browse Source

inp_search_opening_paren(), rewrite

pre-master-46
rlar 13 years ago
parent
commit
3e3cbab668
  1. 14
      src/frontend/inpcom.c

14
src/frontend/inpcom.c

@ -1810,17 +1810,19 @@ inp_search_closing_paren(char *s)
static char * static char *
inp_search_opening_paren(char *s, char *start) inp_search_opening_paren(char *s, char *start)
{ {
int count = 1;
int count = 0;
// assert(*s == ')') // assert(*s == ')')
while ((count != 0) && (s != start)) {
s--;
while (s >= start) {
if (*s == '(') if (*s == '(')
count--; count--;
if (*s == ')') if (*s == ')')
count++; count++;
if (count == 0)
return s;
s--;
} }
return s;
return NULL;
} }
@ -1876,6 +1878,10 @@ inp_fix_ternary_operator_str(char *line, bool all)
/* test for (conditional)?... */ /* test for (conditional)?... */
if (str_ptr2[-1] == ')') { if (str_ptr2[-1] == ')') {
str_ptr = inp_search_opening_paren(str_ptr2 - 1, line); str_ptr = inp_search_opening_paren(str_ptr2 - 1, line);
if (!str_ptr) {
fprintf(stderr, "ERROR: problem parsing 'if' of ternary string %s!\n", line);
controlled_exit(EXIT_FAILURE);
}
} }
/* test for (conditional?... */ /* test for (conditional?... */
else { else {

Loading…
Cancel
Save