From 8174f5dd37ea22c5c7ad357041e1bc6cd6c88e36 Mon Sep 17 00:00:00 2001 From: Friedrich Beckmann Date: Tue, 30 May 2023 10:21:08 +0200 Subject: [PATCH] Portability: Variable initialization not at beginning of block 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 | 42 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/language/lexer/segment.c b/src/language/lexer/segment.c index 58d9af5031..4741054888 100644 --- a/src/language/lexer/segment.c +++ b/src/language/lexer/segment.c @@ -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)) -- 2.30.2