Portability: Variable initialization not at beginning of block
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Tue, 30 May 2023 08:21:08 +0000 (10:21 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Tue, 30 May 2023 08:21:08 +0000 (10:21 +0200)
Recent changes in segment.c result in compilation errors on older
compilers like on debian buster or MacOS.

../pspp/src/language/lexer/segment.c:1255:7:
error: a label can only be part of a statement
and a declaration is not a statement
       int eol = at_end_of_line (input, n, eof, 1);

I changed the code such that it compiles on MacOS again to
a more traditional way to avoid the compile error.

src/language/lexer/segment.c

index 58d9af503157797268e77e24398f91e702c76fdc..47410548885f2ab3cb0de6efa787bc0b762d824f 100644 (file)
@@ -803,6 +803,7 @@ segmenter_parse_id__ (struct segmenter *s, const char *input, size_t n,
             return -1;
           else if (lex_id_match (ss_cstr ("DATA"), ss_cstr (id)))
             {
+              int eol = -1;
               /* We've found BEGIN DATA.  Check whether that's the entire
                  command (either followed by a new-line or by '.' then a
                  new-line). */
@@ -819,7 +820,7 @@ segmenter_parse_id__ (struct segmenter *s, const char *input, size_t n,
                     return -1;
                 }
 
-              int eol = is_end_of_line (input, n, eof, ofs2);
+              eol = is_end_of_line (input, n, eof, ofs2);
               if (eol < 0)
                 return -1;
               else if (eol)
@@ -996,19 +997,20 @@ segmenter_parse_mid_command__ (struct segmenter *s,
         }
       else if (c_isdigit (input[1]))
         return segmenter_parse_number__ (s, input, n, eof, type, 0);
+      {
+        int eol = at_end_of_line (input, n, eof, 1);
+        if (eol < 0)
+          return -1;
 
-      int eol = at_end_of_line (input, n, eof, 1);
-      if (eol < 0)
-        return -1;
-
-      if (eol)
-        {
-          *type = SEG_END_COMMAND;
-          s->substate = SS_START_OF_COMMAND;
-        }
-      else
-        *type = SEG_PUNCT;
-      return 1;
+        if (eol)
+          {
+            *type = SEG_END_COMMAND;
+            s->substate = SS_START_OF_COMMAND;
+          }
+        else
+          *type = SEG_PUNCT;
+        return 1;
+      }
 
     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9':
@@ -1252,13 +1254,15 @@ segmenter_parse_start_of_line__ (struct segmenter *s,
          then it ends the previous command.  The difference only matters for
          deciding whether the line is part of the previous command in
          command_segmenter. */
-      int eol = at_end_of_line (input, n, eof, 1);
-      if (eol < 0)
-        return -1;
+      {
+        int eol = at_end_of_line (input, n, eof, 1);
+        if (eol < 0)
+          return -1;
 
-      *type = eol ? SEG_END_COMMAND : SEG_START_COMMAND;
-      s->substate = SS_START_OF_COMMAND;
-      return 1;
+        *type = eol ? SEG_END_COMMAND : SEG_START_COMMAND;
+        s->substate = SS_START_OF_COMMAND;
+        return 1;
+      }
 
     default:
       if (lex_uc_is_space (uc))