From: Amos Jeffries Date: Fri, 11 Apr 2008 04:49:34 +0000 (+1200) Subject: Replace cnfig parser gotos with do-while loop. X-Git-Tag: SQUID_3_1_0_1~49^2~225^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f32cd13ef21593b655b0822d24bd9cfca51a5df7;p=thirdparty%2Fsquid.git Replace cnfig parser gotos with do-while loop. --- diff --git a/src/ConfigParser.cc b/src/ConfigParser.cc index d1f2e3879c..e773c27048 100644 --- a/src/ConfigParser.cc +++ b/src/ConfigParser.cc @@ -53,69 +53,64 @@ ConfigParser::strtokFile(void) char *t, *fn; LOCAL_ARRAY(char, buf, 256); -strtok_again: + do { - if (!fromFile) { - t = (strtok(NULL, w_space)); + if (!fromFile) { + t = (strtok(NULL, w_space)); - if (!t || *t == '#') { - return NULL; - } else if (*t == '\"' || *t == '\'') { - /* quote found, start reading from file */ - fn = ++t; + if (!t || *t == '#') { + return NULL; + } else if (*t == '\"' || *t == '\'') { + /* quote found, start reading from file */ + fn = ++t; - while (*t && *t != '\"' && *t != '\'') - t++; + while (*t && *t != '\"' && *t != '\'') + t++; - *t = '\0'; + *t = '\0'; - if ((wordFile = fopen(fn, "r")) == NULL) { - debugs(28, 0, "strtokFile: " << fn << " not found"); - return (NULL); - } + if ((wordFile = fopen(fn, "r")) == NULL) { + debugs(28, 0, "strtokFile: " << fn << " not found"); + return (NULL); + } #ifdef _SQUID_WIN32_ - setmode(fileno(wordFile), O_TEXT); + setmode(fileno(wordFile), O_TEXT); #endif - fromFile = 1; - } else { - return t; + fromFile = 1; + } else { + return t; + } } - } - - /* fromFile */ - if (fgets(buf, 256, wordFile) == NULL) { - /* stop reading from file */ - fclose(wordFile); - wordFile = NULL; - fromFile = 0; - goto strtok_again; - } else { - char *t2, *t3; - t = buf; - /* skip leading and trailing white space */ - t += strspn(buf, w_space); - t2 = t + strcspn(t, w_space); - t3 = t2 + strspn(t2, w_space); - - while (*t3 && *t3 != '#') { - t2 = t3 + strcspn(t3, w_space); + + /* fromFile */ + if (fgets(buf, 256, wordFile) == NULL) { + /* stop reading from file */ + fclose(wordFile); + wordFile = NULL; + fromFile = 0; + return NULL; + } else { + char *t2, *t3; + t = buf; + /* skip leading and trailing white space */ + t += strspn(buf, w_space); + t2 = t + strcspn(t, w_space); t3 = t2 + strspn(t2, w_space); - } - *t2 = '\0'; - /* skip comments */ + while (*t3 && *t3 != '#') { + t2 = t3 + strcspn(t3, w_space); + t3 = t2 + strspn(t2, w_space); + } - if (*t == '#') - goto strtok_again; + *t2 = '\0'; + } + /* skip comments */ /* skip blank lines */ - if (!*t) - goto strtok_again; + } while( *t != '#' && !*t ); - return t; - } + return t; } -