]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Replace cnfig parser gotos with do-while loop.
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 11 Apr 2008 04:49:34 +0000 (16:49 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 11 Apr 2008 04:49:34 +0000 (16:49 +1200)
src/ConfigParser.cc

index d1f2e3879cba4dc0a60b01479c1b885402b8a478..e773c27048b6ed3c5cac2bcee7c669d1cac1775a 100644 (file)
@@ -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;
 }
-