]> granicus.if.org Git - graphviz/commitdiff
smyrna: simplify inner 'load_attributes' loop
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 9 Jul 2022 15:11:44 +0000 (08:11 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 16 Jul 2022 00:06:34 +0000 (17:06 -0700)
This loop contains no `continue` statements, its counter is incremented in a
regular way, and the counter is unused outside the loop. So we can write the
loop more concisely and scope `ind` more tightly by using a `for` loop instead
of a `while` loop.

cmd/smyrna/gui/gui.c

index 8dc327b501585e59c123550b1e7e72e51ab526bb..d79747ae90e6596afcef80223f40854aebae9c32 100644 (file)
@@ -44,7 +44,6 @@ void load_attributes(void)
     char line[BUFSIZ];
     char *ss;
     char *pch;
-    int ind = 0;
     int attrcount = 0;
     static char *smyrna_attrs;
 
@@ -56,8 +55,7 @@ void load_attributes(void)
     if (file != NULL) {
        while (fgets(line, sizeof line, file) != NULL) {
            pch = strtok(line, ",");
-           ind = 0;
-           while (pch != NULL) {
+           for (int ind = 0; pch != NULL; ++ind) {
                ss = strdup(pch);
                pch = strtok(NULL, ",");
                switch (ind) {
@@ -102,7 +100,6 @@ void load_attributes(void)
                    attr[attrcount].ComboValuesCount++;
                    break;
                }
-               ind++;
            }
            attrcount++;
        }