From: Bruno Haible Date: Sun, 25 Aug 2019 09:38:22 +0000 (+0200) Subject: code style: Avoid gratuitous 'continue;' statements. X-Git-Tag: v0.21~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b794ecd23ae41a36444dbd85882f5a643df274a1;p=thirdparty%2Fgettext.git code style: Avoid gratuitous 'continue;' statements. * gettext-tools/src/file-list.c (read_names_from_file): Use 'if' instead of 'continue'. * gettext-tools/src/its.c (its_rule_list_add_from_doc): Likewise. * gettext-tools/src/locating-rule.c (locating_rule_list_add_from_file): Likewise. * gettext-tools/src/msgfmt.c (get_languages): Likewise. * gettext-tools/src/x-javascript.c (phase5_scan_xml_markup): Likewise. * gettext-tools/src/x-lua.c (phase2_getc): Likewise. * gettext-tools/src/read-desktop.c (desktop_lex): Use 'if' instead of 'switch' with few alternatives. Test for EOF first. --- diff --git a/gettext-tools/src/file-list.c b/gettext-tools/src/file-list.c index 58a527710..3d2fcaf4d 100644 --- a/gettext-tools/src/file-list.c +++ b/gettext-tools/src/file-list.c @@ -1,5 +1,5 @@ /* Reading file lists. - Copyright (C) 1995-1998, 2000-2002, 2007 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2002, 2007, 2019 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -74,10 +74,9 @@ read_names_from_file (const char *file_name) line_buf[--len] = '\0'; /* Test if we have to ignore the line. */ - if (*line_buf == '\0' || *line_buf == '#') - continue; - - string_list_append_unique (result, line_buf); + if (!(*line_buf == '\0' || *line_buf == '#')) + /* Include the line in the result. */ + string_list_append_unique (result, line_buf); } /* Free buffer allocated through getline. */ diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index d9306cd23..8adf04544 100644 --- a/gettext-tools/src/its.c +++ b/gettext-tools/src/its.c @@ -1,5 +1,5 @@ /* Internationalization Tag Set (ITS) handling - Copyright (C) 2015, 2018 Free Software Foundation, Inc. + Copyright (C) 2015, 2018-2019 Free Software Foundation, Inc. This file was written by Daiki Ueno , 2015. @@ -1427,17 +1427,17 @@ its_rule_list_add_from_doc (struct its_rule_list_ty *rules, struct its_rule_ty *rule; rule = its_rule_parse (doc, node); - if (!rule) - continue; - - if (rules->nitems == rules->nitems_max) + if (rule != NULL) { - rules->nitems_max = 2 * rules->nitems_max + 1; - rules->items = - xrealloc (rules->items, - sizeof (struct its_rule_ty *) * rules->nitems_max); + if (rules->nitems == rules->nitems_max) + { + rules->nitems_max = 2 * rules->nitems_max + 1; + rules->items = + xrealloc (rules->items, + sizeof (struct its_rule_ty *) * rules->nitems_max); + } + rules->items[rules->nitems++] = rule; } - rules->items[rules->nitems++] = rule; } return true; diff --git a/gettext-tools/src/locating-rule.c b/gettext-tools/src/locating-rule.c index f78b437ca..1b470ae81 100644 --- a/gettext-tools/src/locating-rule.c +++ b/gettext-tools/src/locating-rule.c @@ -1,5 +1,5 @@ /* XML resource locating rules - Copyright (C) 2015 Free Software Foundation, Inc. + Copyright (C) 2015, 2019 Free Software Foundation, Inc. This file was written by Daiki Ueno , 2015. @@ -331,34 +331,35 @@ locating_rule_list_add_from_file (struct locating_rule_list_ty *rules, { missing_attribute (node, "pattern"); xmlFreeDoc (doc); - continue; } - - memset (&rule, 0, sizeof (struct locating_rule_ty)); - rule.pattern = get_attribute (node, "pattern"); - if (xmlHasProp (node, BAD_CAST "name")) - rule.name = get_attribute (node, "name"); - if (xmlHasProp (node, BAD_CAST "target")) - rule.target = get_attribute (node, "target"); else { - xmlNode *n; + memset (&rule, 0, sizeof (struct locating_rule_ty)); + rule.pattern = get_attribute (node, "pattern"); + if (xmlHasProp (node, BAD_CAST "name")) + rule.name = get_attribute (node, "name"); + if (xmlHasProp (node, BAD_CAST "target")) + rule.target = get_attribute (node, "target"); + else + { + xmlNode *n; - for (n = node->children; n; n = n->next) + for (n = node->children; n; n = n->next) + { + if (xmlStrEqual (n->name, BAD_CAST "documentRule")) + document_locating_rule_list_add (&rule.doc_rules, n); + } + } + if (rules->nitems == rules->nitems_max) { - if (xmlStrEqual (n->name, BAD_CAST "documentRule")) - document_locating_rule_list_add (&rule.doc_rules, n); + rules->nitems_max = 2 * rules->nitems_max + 1; + rules->items = + xrealloc (rules->items, + sizeof (struct locating_rule_ty) * rules->nitems_max); } + memcpy (&rules->items[rules->nitems++], &rule, + sizeof (struct locating_rule_ty)); } - if (rules->nitems == rules->nitems_max) - { - rules->nitems_max = 2 * rules->nitems_max + 1; - rules->items = - xrealloc (rules->items, - sizeof (struct locating_rule_ty) * rules->nitems_max); - } - memcpy (&rules->items[rules->nitems++], &rule, - sizeof (struct locating_rule_ty)); } } diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 9dded2462..d016c47ea 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -1488,10 +1488,9 @@ get_languages (string_list_ty *languages, const char *directory) line_buf[--len] = '\0'; /* Test if we have to ignore the line. */ - if (*line_buf == '\0' || *line_buf == '#') - continue; - - add_languages (languages, desired_languages, line_buf, len); + if (!(*line_buf == '\0' || *line_buf == '#')) + /* Include the line among the languages. */ + add_languages (languages, desired_languages, line_buf, len); } free (line_buf); diff --git a/gettext-tools/src/read-desktop.c b/gettext-tools/src/read-desktop.c index 4de134f3c..31d4c851d 100644 --- a/gettext-tools/src/read-desktop.c +++ b/gettext-tools/src/read-desktop.c @@ -252,24 +252,20 @@ desktop_lex (token_ty *tp) for (;;) { c = phase2_getc (); - switch (c) + if (c == EOF || c == ']') + break; + if (c == '\n') { - default: - /* Group names may contain all ASCII characters - except for '[' and ']' and control characters. */ - if (!(c_isascii (c) && c != '[') && !c_iscntrl (c)) - break; - APPEND (c); - continue; - case '\n': po_xerror (PO_SEVERITY_WARNING, NULL, real_file_name, gram_pos.line_number, 0, false, _("unterminated group name")); break; - case EOF: case ']': - break; } - break; + /* Group names may contain all ASCII characters + except for '[' and ']' and control characters. */ + if (!(c_isascii (c) && c != '[') && !c_iscntrl (c)) + break; + APPEND (c); } /* Skip until newline. */ while (c != '\n' && c != EOF) @@ -296,15 +292,9 @@ desktop_lex (token_ty *tp) for (;;) { c = phase2_getc (); - switch (c) - { - default: - APPEND (c); - continue; - case EOF: case '\n': - break; - } - break; + if (c == EOF || c == '\n') + break; + APPEND (c); } APPEND (0); tp->type = token_type_comment; @@ -360,15 +350,9 @@ desktop_lex (token_ty *tp) for (;;) { int c2 = phase2_getc (); - switch (c2) - { - default: - APPEND (c2); - continue; - case EOF: case ']': - break; - } - break; + if (c2 == EOF || c2 == ']') + break; + APPEND (c2); } break; @@ -386,9 +370,9 @@ desktop_lex (token_ty *tp) c = phase2_getc (); switch (c) { + case ' ': + continue; default: - if (c == ' ') - continue; phase2_ungetc (c); break; case EOF: case '\n': @@ -419,9 +403,9 @@ desktop_lex (token_ty *tp) c = phase2_getc (); switch (c) { + case ' ': + continue; default: - if (c == ' ') - continue; phase2_ungetc (c); break; case EOF: diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 7ac5b2472..0a8cd2856 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -1000,56 +1000,54 @@ phase5_scan_xml_markup (token_ty *tp) } } - if (start[j] != '\0') - continue; - - /* Skip until the end marker. */ - for (;;) - { - int c; - - for (j = 0; end[j] != '\0'; j++) - { - assert (phase2_pushback_length + 1 < SIZEOF (phase2_pushback)); - c = phase2_getc (); - if (c == UEOF) - goto eof; - if (c != end[j]) - { - /* Don't push the first character back so the next - iteration start from the second character. */ - if (j > 0) - { - int k = j; + if (start[j] == '\0') + /* Skip until the end marker. */ + for (;;) + { + int c; - phase2_ungetc (c); - k--; + for (j = 0; end[j] != '\0'; j++) + { + assert (phase2_pushback_length + 1 < SIZEOF (phase2_pushback)); + c = phase2_getc (); + if (c == UEOF) + goto eof; + if (c != end[j]) + { + /* Don't push the first character back so the next + iteration start from the second character. */ + if (j > 0) + { + int k = j; - for (; k > 0; k--) - phase2_ungetc (end[k]); - } - break; - } - } + phase2_ungetc (c); + k--; - if (end[j] != '\0') - continue; + for (; k > 0; k--) + phase2_ungetc (end[k]); + } + break; + } + } - c = phase2_getc (); - if (c == UEOF) - goto eof; - if (c != '>') - { - error_with_progname = false; - error (0, 0, - _("%s:%d: warning: %s is not allowed"), - logical_file_name, line_number, - end); - error_with_progname = true; - return false; - } - return true; - } + if (end[j] == '\0') + { + c = phase2_getc (); + if (c == UEOF) + goto eof; + if (c != '>') + { + error_with_progname = false; + error (0, 0, + _("%s:%d: warning: %s is not allowed"), + logical_file_name, line_number, + end); + error_with_progname = true; + return false; + } + return true; + } + } } return false; diff --git a/gettext-tools/src/x-lua.c b/gettext-tools/src/x-lua.c index 8db7561ba..5aed25745 100644 --- a/gettext-tools/src/x-lua.c +++ b/gettext-tools/src/x-lua.c @@ -308,42 +308,42 @@ phase2_getc () break; /* Ignore leading spaces and tabs. */ - if (buflen == 0 && (c == ' ' || c == '\t')) - continue; - - comment_add (c); - - switch (c) + if (!(buflen == 0 && (c == ' ' || c == '\t'))) { - case ']': - if (!right_bracket) - { - right_bracket = true; - esigns2 = 0; - } - else + comment_add (c); + + switch (c) { - if (esigns2 == esigns) + case ']': + if (!right_bracket) { - comment_line_end (2 + esigns); - end = true; + right_bracket = true; + esigns2 = 0; } - } - break; + else + { + if (esigns2 == esigns) + { + comment_line_end (2 + esigns); + end = true; + } + } + break; - case '=': - if (right_bracket) - esigns2++; - break; + case '=': + if (right_bracket) + esigns2++; + break; - case '\n': - comment_line_end (1); - comment_start (); - lineno = line_number; - /* Intentionally not breaking. */ + case '\n': + comment_line_end (1); + comment_start (); + lineno = line_number; + /* Intentionally not breaking. */ - default: - right_bracket = false; + default: + right_bracket = false; + } } } last_comment_line = lineno;