From: Bruno Haible Date: Fri, 2 Jun 2023 23:28:54 +0000 (+0200) Subject: Silence "... shadows a previous local" warnings. X-Git-Tag: v0.22~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7cd26d2221ee0e1ad3ced71587fae4a763bce86;p=thirdparty%2Fgettext.git Silence "... shadows a previous local" warnings. * gettext-tools/src/its.c (its_rule_apply): Reduce scope of local variable 'i'. (_its_collect_text_content): Rename local variable 'buffer' to 'obuffer'. (its_rule_list_extract_nodes): Reduce scope of local variable 'n'. (_its_get_content): Reduce scope of local variable 'i'. Rename local variable 'i' to 'j'. * gettext-tools/src/msgmerge.c (message_merge): Reduce scope of local variables 'i', 'len', 'cnt'. (match_domain): Reduce scope of some local variables. * gettext-tools/src/write-mo.c (write_table): Reduce scope of local variables 'j', 'm'. * gettext-tools/src/xg-arglist-parser.c (arglist_parser_done): Rename local variable 'i' to 'j'. * gettext-tools/src/x-csharp.c (phase2_getc): Reduce scope of local variable 'c'. * gettext-tools/src/x-javascript.c (phase2_getc): Likewise. * gettext-tools/src/x-python.c (phase2_getc): Likewise. * gettext-tools/src/x-lisp.c (read_object): Rename some uses of local variable 'c' to 'dmc'. * gettext-tools/src/x-elisp.c (read_object): Rename some uses of local variable 'c' to 'ch' or 'dmc'. * gettext-tools/src/x-librep.c (read_object): Likewise. * gettext-tools/src/x-scheme.c (read_object): Likewise. * gettext-tools/src/x-perl.c (extract_variable): Reduce scope of local variable 'c'. * gettext-tools/src/x-vala.c (phase3_get): Reduce scope of local variable 'c2'. --- diff --git a/gettext-tools/src/its.c b/gettext-tools/src/its.c index 7400890ff..e3e844ba3 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-2020 Free Software Foundation, Inc. + Copyright (C) 2015, 2018-2020, 2023 Free Software Foundation, Inc. This file was written by Daiki Ueno , 2015. @@ -312,7 +312,6 @@ its_rule_apply (struct its_rule_ty *rule, struct its_pool_ty *pool, xmlDoc *doc) { xmlXPathContext *context; xmlXPathObject *object; - size_t i; if (!rule->selector) { @@ -348,6 +347,8 @@ its_rule_apply (struct its_rule_ty *rule, struct its_pool_ty *pool, xmlDoc *doc) if (object->nodesetval) { xmlNodeSet *nodes = object->nodesetval; + size_t i; + for (i = 0; i < nodes->nodeNr; i++) { xmlNode *node = nodes->nodeTab[i]; @@ -632,8 +633,8 @@ _its_collect_text_content (xmlNode *node, case XML_ELEMENT_NODE: { - xmlOutputBuffer *buffer = xmlAllocOutputBuffer (NULL); - xmlTextWriter *writer = xmlNewTextWriter (buffer); + xmlOutputBuffer *obuffer = xmlAllocOutputBuffer (NULL); + xmlTextWriter *writer = xmlNewTextWriter (obuffer); char *p = _its_collect_text_content (n, whitespace, no_escape); const char *ccontent; @@ -654,7 +655,7 @@ _its_collect_text_content (xmlNode *node, if (*p != '\0') xmlTextWriterWriteRaw (writer, BAD_CAST p); xmlTextWriterEndElement (writer); - ccontent = (const char *) xmlOutputBufferGetContent (buffer); + ccontent = (const char *) xmlOutputBufferGetContent (obuffer); content = normalize_whitespace (ccontent, whitespace); xmlFreeTextWriter (writer); free (p); @@ -1595,12 +1596,10 @@ its_rule_list_extract_nodes (its_rule_list_ty *rules, { if (node->type == XML_ELEMENT_NODE) { - xmlNode *n; - if (node->properties) { - xmlAttr *attr = node->properties; - for (; attr; attr = attr->next) + xmlAttr *attr; + for (attr = node->properties; attr; attr = attr->next) { xmlNode *n = (xmlNode *) attr; if (its_rule_list_is_translatable (rules, n, 0)) @@ -1612,6 +1611,7 @@ its_rule_list_extract_nodes (its_rule_list_ty *rules, its_node_list_append (nodes, node); else { + xmlNode *n; for (n = node->children; n; n = n->next) its_rule_list_extract_nodes (rules, nodes, n); } @@ -1626,7 +1626,6 @@ _its_get_content (struct its_rule_list_ty *rules, xmlNode *node, { xmlXPathContext *context; xmlXPathObject *object; - size_t i; char *result = NULL; context = xmlXPathNewContext (node->doc); @@ -1636,19 +1635,23 @@ _its_get_content (struct its_rule_list_ty *rules, xmlNode *node, return NULL; } - for (i = 0; i < rules->nitems; i++) - { - struct its_rule_ty *rule = rules->items[i]; - if (rule->namespaces) - { - size_t i; - for (i = 0; rule->namespaces[i] != NULL; i++) - { - xmlNs *ns = rule->namespaces[i]; - xmlXPathRegisterNs (context, ns->prefix, ns->href); - } - } - } + { + size_t i; + + for (i = 0; i < rules->nitems; i++) + { + struct its_rule_ty *rule = rules->items[i]; + if (rule->namespaces) + { + size_t j; + for (j = 0; rule->namespaces[j] != NULL; j++) + { + xmlNs *ns = rule->namespaces[j]; + xmlXPathRegisterNs (context, ns->prefix, ns->href); + } + } + } + } xmlXPathSetContextNode (node, context); object = xmlXPathEvalExpression (BAD_CAST pointer, context); diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index 5051a5cea..d165a3854 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -1,6 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2010, 2012, 2014-2016, 2018-2022 Free Software - Foundation, Inc. + Copyright (C) 1995-1998, 2000-2010, 2012, 2014-2016, 2018-2023 Free Software Foundation, Inc. This file was written by Peter Miller This program is free software: you can redistribute it and/or modify @@ -970,7 +969,7 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, const char *prev_msgid; const char *prev_msgid_plural; message_ty *result; - size_t j, i; + size_t j; /* Take the msgid from the reference. When fuzzy matches are made, the definition will not be unique, but the reference will be - @@ -1020,7 +1019,6 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, struct obstack pool; const char *cp; char *newp; - size_t len, cnt; /* Clear all fields. */ memset (header_fields, '\0', sizeof (header_fields)); @@ -1033,6 +1031,8 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, { const char *endp = strchr (cp, '\n'); int terminated = endp != NULL; + size_t len; + size_t cnt; if (!terminated) { @@ -1251,14 +1251,19 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, } /* Concatenate all the various fields. */ - len = 0; - for (cnt = 0; cnt < UNKNOWN; ++cnt) - if (header_fields[cnt].string != NULL) - len += known_fields[cnt].len + header_fields[cnt].len; - len += header_fields[UNKNOWN].len; + { + size_t len; + size_t cnt; - cp = newp = XNMALLOC (len + 1, char); - newp[len] = '\0'; + len = 0; + for (cnt = 0; cnt < UNKNOWN; ++cnt) + if (header_fields[cnt].string != NULL) + len += known_fields[cnt].len + header_fields[cnt].len; + len += header_fields[UNKNOWN].len; + + cp = newp = XNMALLOC (len + 1, char); + newp[len] = '\0'; + } #define IF_FILLED(idx) \ if (header_fields[idx].string) \ @@ -1340,26 +1345,30 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, : def->msgid_plural != NULL)) result->is_fuzzy = true; - for (i = 0; i < NFORMATS; i++) - { - result->is_format[i] = ref->is_format[i]; - - /* If the reference message is marked as being a format specifier, - but the definition message is not, we check if the resulting - message would pass "msgfmt -c". If yes, then all is fine. If - not, we add a fuzzy marker, because - 1. the message needs the translator's attention, - 2. msgmerge must not transform a PO file which passes "msgfmt -c" - into a PO file which doesn't. */ - if (!result->is_fuzzy - && possible_format_p (ref->is_format[i]) - && !possible_format_p (def->is_format[i]) - && check_msgid_msgstr_format_i (ref->msgid, ref->msgid_plural, - msgstr, msgstr_len, i, ref->range, - distribution, silent_error_logger) - > 0) - result->is_fuzzy = true; - } + { + size_t i; + + for (i = 0; i < NFORMATS; i++) + { + result->is_format[i] = ref->is_format[i]; + + /* If the reference message is marked as being a format specifier, + but the definition message is not, we check if the resulting + message would pass "msgfmt -c". If yes, then all is fine. If + not, we add a fuzzy marker, because + 1. the message needs the translator's attention, + 2. msgmerge must not transform a PO file which passes "msgfmt -c" + into a PO file which doesn't. */ + if (!result->is_fuzzy + && possible_format_p (ref->is_format[i]) + && !possible_format_p (def->is_format[i]) + && check_msgid_msgstr_format_i (ref->msgid, ref->msgid_plural, + msgstr, msgstr_len, i, ref->range, + distribution, silent_error_logger) + > 0) + result->is_fuzzy = true; + } + } result->range = ref->range; /* If the definition message was assuming a certain range, but the reference @@ -1377,8 +1386,11 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy, result->do_wrap = ref->do_wrap; - for (i = 0; i < NSYNTAXCHECKS; i++) - result->do_syntax_check[i] = ref->do_syntax_check[i]; + { + size_t i; + for (i = 0; i < NSYNTAXCHECKS; i++) + result->do_syntax_check[i] = ref->do_syntax_check[i]; + } /* Insert previous msgid, commented out with "#|". Do so only when --previous is specified, for backward compatibility. @@ -1438,211 +1450,216 @@ match_domain (const char *fn1, const char *fn2, message_list_ty *resultmlp, struct statistics *stats, unsigned int *processed) { - message_ty *header_entry; - unsigned long int nplurals; - const struct expression *plural_expr; - char *untranslated_plural_msgstr; - struct plural_distribution distribution; - struct search_result { message_ty *found; bool fuzzy; } *search_results; - size_t j; - - header_entry = - message_list_search (definitions_current_list (definitions), NULL, ""); - extract_plural_expression (header_entry ? header_entry->msgstr : NULL, - &plural_expr, &nplurals); - untranslated_plural_msgstr = XNMALLOC (nplurals, char); - memset (untranslated_plural_msgstr, '\0', nplurals); - - /* Determine the plural distribution of the plural_expr formula. */ { - /* Disable error output temporarily. */ - void (*old_po_xerror) (int, const struct message_ty *, const char *, size_t, - size_t, int, const char *) - = po_xerror; - po_xerror = silent_xerror; - - if (check_plural_eval (plural_expr, nplurals, header_entry, - &distribution) > 0) - { - distribution.expr = NULL; - distribution.often = NULL; - distribution.often_length = 0; - distribution.histogram = NULL; - } + unsigned long int nplurals; + char *untranslated_plural_msgstr; + struct plural_distribution distribution; + struct search_result { message_ty *found; bool fuzzy; } *search_results; + size_t j; - po_xerror = old_po_xerror; - } + { + message_ty *header_entry; + const struct expression *plural_expr; - /* Most of the time is spent in definitions_search_fuzzy. - Perform it in a separate loop that can be parallelized by an OpenMP - capable compiler. */ - search_results = XNMALLOC (refmlp->nitems, struct search_result); - { - long int nn = refmlp->nitems; - long int jj; - - /* Tell the OpenMP capable compiler to distribute this loop across - several threads. The schedule is dynamic, because for some messages - the loop body can be executed very quickly, whereas for others it takes - a long time. - Note: The Sun Workshop 6.2 C compiler does not allow a space between - '#' and 'pragma'. */ - #ifdef _OPENMP - #pragma omp parallel for schedule(dynamic) - #endif - for (jj = 0; jj < nn; jj++) + header_entry = + message_list_search (definitions_current_list (definitions), NULL, ""); + extract_plural_expression (header_entry ? header_entry->msgstr : NULL, + &plural_expr, &nplurals); + untranslated_plural_msgstr = XNMALLOC (nplurals, char); + memset (untranslated_plural_msgstr, '\0', nplurals); + + /* Determine the plural distribution of the plural_expr formula. */ { - message_ty *refmsg = refmlp->item[jj]; - message_ty *defmsg; - - /* Because merging can take a while we print something to signal - we are not dead. */ - if (!quiet && verbosity_level <= 1 && *processed % DOT_FREQUENCY == 0) - fputc ('.', stderr); - #ifdef _OPENMP - #pragma omp atomic - #endif - (*processed)++; - - /* See if it is in the other file. */ - defmsg = - definitions_search (definitions, refmsg->msgctxt, refmsg->msgid); - if (defmsg != NULL) + /* Disable error output temporarily. */ + void (*old_po_xerror) (int, const struct message_ty *, const char *, size_t, + size_t, int, const char *) + = po_xerror; + po_xerror = silent_xerror; + + if (check_plural_eval (plural_expr, nplurals, header_entry, + &distribution) > 0) { - search_results[jj].found = defmsg; - search_results[jj].fuzzy = false; + distribution.expr = NULL; + distribution.often = NULL; + distribution.often_length = 0; + distribution.histogram = NULL; } - else if (!is_header (refmsg) - /* If the message was not defined at all, try to find a very - similar message, it could be a typo, or the suggestion may - help. */ - && use_fuzzy_matching - && ((defmsg = - definitions_search_fuzzy (definitions, - refmsg->msgctxt, - refmsg->msgid)) != NULL)) - { - search_results[jj].found = defmsg; - search_results[jj].fuzzy = true; - } - else - search_results[jj].found = NULL; + + po_xerror = old_po_xerror; } - } + } - for (j = 0; j < refmlp->nitems; j++) + /* Most of the time is spent in definitions_search_fuzzy. + Perform it in a separate loop that can be parallelized by an OpenMP + capable compiler. */ + search_results = XNMALLOC (refmlp->nitems, struct search_result); { - message_ty *refmsg = refmlp->item[j]; - - /* See if it is in the other file. - This used definitions_search. */ - if (search_results[j].found != NULL && !search_results[j].fuzzy) + long int nn = refmlp->nitems; + long int jj; + + /* Tell the OpenMP capable compiler to distribute this loop across + several threads. The schedule is dynamic, because for some messages + the loop body can be executed very quickly, whereas for others it takes + a long time. + Note: The Sun Workshop 6.2 C compiler does not allow a space between + '#' and 'pragma'. */ + #ifdef _OPENMP + #pragma omp parallel for schedule(dynamic) + #endif + for (jj = 0; jj < nn; jj++) { - message_ty *defmsg = search_results[j].found; - /* Merge the reference with the definition: take the #. and - #: comments from the reference, take the # comments from - the definition, take the msgstr from the definition. Add - this merged entry to the output message list. */ - message_ty *mp = - message_merge (defmsg, refmsg, false, &distribution); - - /* When producing output for msgfmt, omit messages that are - untranslated or fuzzy (except the header entry). */ - if (!(for_msgfmt - && (mp->msgstr[0] == '\0' /* untranslated? */ - || (mp->is_fuzzy && !is_header (mp))))) /* fuzzy? */ + message_ty *refmsg = refmlp->item[jj]; + message_ty *defmsg; + + /* Because merging can take a while we print something to signal + we are not dead. */ + if (!quiet && verbosity_level <= 1 && *processed % DOT_FREQUENCY == 0) + fputc ('.', stderr); + #ifdef _OPENMP + #pragma omp atomic + #endif + (*processed)++; + + /* See if it is in the other file. */ + defmsg = + definitions_search (definitions, refmsg->msgctxt, refmsg->msgid); + if (defmsg != NULL) { - message_list_append (resultmlp, mp); - - /* Remember that this message has been used, when we scan - later to see if anything was omitted. */ - defmsg->used = 1; + search_results[jj].found = defmsg; + search_results[jj].fuzzy = false; } - - stats->merged++; - } - else if (!is_header (refmsg)) - { - /* If the message was not defined at all, try to find a very - similar message, it could be a typo, or the suggestion may - help. This search assumed use_fuzzy_matching and used - definitions_search_fuzzy. */ - if (search_results[j].found != NULL && search_results[j].fuzzy) + else if (!is_header (refmsg) + /* If the message was not defined at all, try to find a very + similar message, it could be a typo, or the suggestion may + help. */ + && use_fuzzy_matching + && ((defmsg = + definitions_search_fuzzy (definitions, + refmsg->msgctxt, + refmsg->msgid)) != NULL)) { - message_ty *defmsg = search_results[j].found; - message_ty *mp; + search_results[jj].found = defmsg; + search_results[jj].fuzzy = true; + } + else + search_results[jj].found = NULL; + } + } - if (verbosity_level > 1) - { - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined...")); - error_message_count--; - po_gram_error_at_line (&defmsg->pos, - _("...but this definition is similar")); - } + for (j = 0; j < refmlp->nitems; j++) + { + message_ty *refmsg = refmlp->item[j]; - /* Merge the reference with the definition: take the #. and - #: comments from the reference, take the # comments from - the definition, take the msgstr from the definition. Add - this merged entry to the output message list. */ - mp = message_merge (defmsg, refmsg, true, &distribution); + /* See if it is in the other file. + This used definitions_search. */ + if (search_results[j].found != NULL && !search_results[j].fuzzy) + { + message_ty *defmsg = search_results[j].found; + /* Merge the reference with the definition: take the #. and + #: comments from the reference, take the # comments from + the definition, take the msgstr from the definition. Add + this merged entry to the output message list. */ + message_ty *mp = + message_merge (defmsg, refmsg, false, &distribution); + + /* When producing output for msgfmt, omit messages that are + untranslated or fuzzy (except the header entry). */ + if (!(for_msgfmt + && (mp->msgstr[0] == '\0' /* untranslated? */ + || (mp->is_fuzzy && !is_header (mp))))) /* fuzzy? */ + { + message_list_append (resultmlp, mp); - message_list_append (resultmlp, mp); + /* Remember that this message has been used, when we scan + later to see if anything was omitted. */ + defmsg->used = 1; + } - /* Remember that this message has been used, when we scan - later to see if anything was omitted. */ - defmsg->used = 1; + stats->merged++; + } + else if (!is_header (refmsg)) + { + /* If the message was not defined at all, try to find a very + similar message, it could be a typo, or the suggestion may + help. This search assumed use_fuzzy_matching and used + definitions_search_fuzzy. */ + if (search_results[j].found != NULL && search_results[j].fuzzy) + { + message_ty *defmsg = search_results[j].found; + message_ty *mp; - stats->fuzzied++; - if (!quiet && verbosity_level <= 1) - /* Always print a dot if we handled a fuzzy match. */ - fputc ('.', stderr); - } - else - { - message_ty *mp; - bool is_untranslated; - const char *p; - const char *pend; - - if (verbosity_level > 1) - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined in %s"), - fn1); - - mp = message_copy (refmsg); - - /* Test if mp is untranslated. (It most likely is.) */ - is_untranslated = true; - for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) - if (*p != '\0') + if (verbosity_level > 1) { - is_untranslated = false; - break; + po_gram_error_at_line (&refmsg->pos, + _("this message is used but not defined...")); + error_message_count--; + po_gram_error_at_line (&defmsg->pos, + _("...but this definition is similar")); } - if (mp->msgid_plural != NULL && is_untranslated) - { - /* Change mp->msgstr_len consecutive empty strings into - nplurals consecutive empty strings. */ - if (nplurals > mp->msgstr_len) - mp->msgstr = untranslated_plural_msgstr; - mp->msgstr_len = nplurals; - } + /* Merge the reference with the definition: take the #. and + #: comments from the reference, take the # comments from + the definition, take the msgstr from the definition. Add + this merged entry to the output message list. */ + mp = message_merge (defmsg, refmsg, true, &distribution); - /* When producing output for msgfmt, omit messages that are - untranslated or fuzzy (except the header entry). */ - if (!(for_msgfmt && (is_untranslated || mp->is_fuzzy))) - { - message_list_append (resultmlp, mp); - } + message_list_append (resultmlp, mp); - stats->missing++; - } - } - } + /* Remember that this message has been used, when we scan + later to see if anything was omitted. */ + defmsg->used = 1; - free (search_results); + stats->fuzzied++; + if (!quiet && verbosity_level <= 1) + /* Always print a dot if we handled a fuzzy match. */ + fputc ('.', stderr); + } + else + { + message_ty *mp; + bool is_untranslated; + const char *p; + const char *pend; + + if (verbosity_level > 1) + po_gram_error_at_line (&refmsg->pos, + _("this message is used but not defined in %s"), + fn1); + + mp = message_copy (refmsg); + + /* Test if mp is untranslated. (It most likely is.) */ + is_untranslated = true; + for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) + if (*p != '\0') + { + is_untranslated = false; + break; + } + + if (mp->msgid_plural != NULL && is_untranslated) + { + /* Change mp->msgstr_len consecutive empty strings into + nplurals consecutive empty strings. */ + if (nplurals > mp->msgstr_len) + mp->msgstr = untranslated_plural_msgstr; + mp->msgstr_len = nplurals; + } + + /* When producing output for msgfmt, omit messages that are + untranslated or fuzzy (except the header entry). */ + if (!(for_msgfmt && (is_untranslated || mp->is_fuzzy))) + { + message_list_append (resultmlp, mp); + } + + stats->missing++; + } + } + } + + free (search_results); + } /* Now postprocess the problematic merges. This is needed because we want the result to pass the "msgfmt -c -v" check. */ @@ -1650,6 +1667,7 @@ match_domain (const char *fn1, const char *fn2, /* message_merge sets mp->used to 1 or 2, depending on the problem. Compute the bitwise OR of all these. */ int problematic = 0; + size_t j; for (j = 0; j < resultmlp->nitems; j++) problematic |= resultmlp->item[j]->used; @@ -1720,17 +1738,21 @@ match_domain (const char *fn1, const char *fn2, /* Now that mp->is_fuzzy is finalized for all messages, remove the "previous msgid" information from all messages that are not fuzzy or are untranslated. */ - for (j = 0; j < resultmlp->nitems; j++) - { - message_ty *mp = resultmlp->item[j]; + { + size_t j; - if (!mp->is_fuzzy || mp->msgstr[0] == '\0') - { - mp->prev_msgctxt = NULL; - mp->prev_msgid = NULL; - mp->prev_msgid_plural = NULL; - } - } + for (j = 0; j < resultmlp->nitems; j++) + { + message_ty *mp = resultmlp->item[j]; + + if (!mp->is_fuzzy || mp->msgstr[0] == '\0') + { + mp->prev_msgctxt = NULL; + mp->prev_msgid = NULL; + mp->prev_msgid_plural = NULL; + } + } + } } static msgdomain_list_ty * diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index afa060a6e..5d7cc611f 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -1,5 +1,5 @@ /* Writing binary .mo files. - Copyright (C) 1995-1998, 2000-2007, 2016, 2020 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2007, 2016, 2020, 2023 Free Software Foundation, Inc. Written by Ulrich Drepper , April 1995. This program is free software: you can redistribute it and/or modify @@ -166,7 +166,6 @@ write_table (FILE *output_file, message_list_ty *mlp) size_t sysdep_tab_offset = 0; size_t end_offset; char *null; - size_t j, m; /* First pass: Move the static string pairs into an array, for sorting, and at the same time, compute the segments of the system dependent @@ -179,191 +178,201 @@ write_table (FILE *output_file, message_list_ty *mlp) n_sysdep_segments = 0; sysdep_segments = NULL; have_outdigits = false; - for (j = 0; j < mlp->nitems; j++) - { - message_ty *mp = mlp->item[j]; - size_t msgctlen; - char *msgctid; - struct interval *intervals[2]; - size_t nintervals[2]; - - /* Concatenate mp->msgctxt and mp->msgid into msgctid. */ - msgctlen = (mp->msgctxt != NULL ? strlen (mp->msgctxt) + 1 : 0); - msgctid = XNMALLOC (msgctlen + strlen (mp->msgid) + 1, char); - if (mp->msgctxt != NULL) - { - memcpy (msgctid, mp->msgctxt, msgctlen - 1); - msgctid[msgctlen - 1] = MSGCTXT_SEPARATOR; - } - strcpy (msgctid + msgctlen, mp->msgid); - msgctid_arr[j] = msgctid; - - intervals[M_ID] = NULL; - nintervals[M_ID] = 0; - intervals[M_STR] = NULL; - nintervals[M_STR] = 0; - - /* Test if mp contains system dependent strings and thus - requires the use of the .mo file minor revision 1. */ - if (possible_format_p (mp->is_format[format_c]) - || possible_format_p (mp->is_format[format_objc])) - { - /* Check whether msgid or msgstr contain ISO C 99 - format string directives. No need to check msgid_plural, because - it is not accessed by the [n]gettext() function family. */ - const char *p_end; - const char *p; - - get_sysdep_c_format_directives (mp->msgid, false, - &intervals[M_ID], &nintervals[M_ID]); - if (msgctlen > 0) - { - struct interval *id_intervals = intervals[M_ID]; - size_t id_nintervals = nintervals[M_ID]; - - if (id_nintervals > 0) - { - unsigned int i; - - for (i = 0; i < id_nintervals; i++) - { - id_intervals[i].startpos += msgctlen; - id_intervals[i].endpos += msgctlen; - } - } - } - - p_end = mp->msgstr + mp->msgstr_len; - for (p = mp->msgstr; p < p_end; p += strlen (p) + 1) - { - struct interval *part_intervals; - size_t part_nintervals; - - get_sysdep_c_format_directives (p, true, - &part_intervals, - &part_nintervals); - if (part_nintervals > 0) - { - size_t d = p - mp->msgstr; - unsigned int i; - - intervals[M_STR] = - (struct interval *) - xrealloc (intervals[M_STR], - (nintervals[M_STR] + part_nintervals) - * sizeof (struct interval)); - for (i = 0; i < part_nintervals; i++) - { - intervals[M_STR][nintervals[M_STR] + i].startpos = - d + part_intervals[i].startpos; - intervals[M_STR][nintervals[M_STR] + i].endpos = - d + part_intervals[i].endpos; - } - nintervals[M_STR] += part_nintervals; - } - } - } + { + size_t j; - if (nintervals[M_ID] > 0 || nintervals[M_STR] > 0) - { - /* System dependent string pair. */ - for (m = 0; m < 2; m++) - { - struct pre_sysdep_string *pre = - (struct pre_sysdep_string *) - xmalloc (xsum (sizeof (struct pre_sysdep_string), - xtimes (nintervals[m], - sizeof (struct pre_segment_pair)))); - const char *str; - size_t str_len; - size_t lastpos; - unsigned int i; + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + size_t msgctlen; + char *msgctid; + struct interval *intervals[2]; + size_t nintervals[2]; + + /* Concatenate mp->msgctxt and mp->msgid into msgctid. */ + msgctlen = (mp->msgctxt != NULL ? strlen (mp->msgctxt) + 1 : 0); + msgctid = XNMALLOC (msgctlen + strlen (mp->msgid) + 1, char); + if (mp->msgctxt != NULL) + { + memcpy (msgctid, mp->msgctxt, msgctlen - 1); + msgctid[msgctlen - 1] = MSGCTXT_SEPARATOR; + } + strcpy (msgctid + msgctlen, mp->msgid); + msgctid_arr[j] = msgctid; + + intervals[M_ID] = NULL; + nintervals[M_ID] = 0; + intervals[M_STR] = NULL; + nintervals[M_STR] = 0; + + /* Test if mp contains system dependent strings and thus + requires the use of the .mo file minor revision 1. */ + if (possible_format_p (mp->is_format[format_c]) + || possible_format_p (mp->is_format[format_objc])) + { + /* Check whether msgid or msgstr contain ISO C 99 + format string directives. No need to check msgid_plural, because + it is not accessed by the [n]gettext() function family. */ + const char *p_end; + const char *p; + + get_sysdep_c_format_directives (mp->msgid, false, + &intervals[M_ID], &nintervals[M_ID]); + if (msgctlen > 0) + { + struct interval *id_intervals = intervals[M_ID]; + size_t id_nintervals = nintervals[M_ID]; - if (m == M_ID) - { - str = msgctid; /* concatenation of mp->msgctxt + mp->msgid */ - str_len = strlen (msgctid) + 1; - } - else - { - str = mp->msgstr; - str_len = mp->msgstr_len; - } + if (id_nintervals > 0) + { + unsigned int i; - lastpos = 0; - pre->segmentcount = nintervals[m]; - for (i = 0; i < nintervals[m]; i++) - { - size_t length; - const char *pointer; - size_t r; + for (i = 0; i < id_nintervals; i++) + { + id_intervals[i].startpos += msgctlen; + id_intervals[i].endpos += msgctlen; + } + } + } - pre->segments[i].segptr = str + lastpos; - pre->segments[i].segsize = intervals[m][i].startpos - lastpos; + p_end = mp->msgstr + mp->msgstr_len; + for (p = mp->msgstr; p < p_end; p += strlen (p) + 1) + { + struct interval *part_intervals; + size_t part_nintervals; - length = intervals[m][i].endpos - intervals[m][i].startpos; - pointer = str + intervals[m][i].startpos; - if (length >= 2 - && pointer[0] == '<' && pointer[length - 1] == '>') - { - /* Skip the '<' and '>' markers. */ - length -= 2; - pointer += 1; - } + get_sysdep_c_format_directives (p, true, + &part_intervals, + &part_nintervals); + if (part_nintervals > 0) + { + size_t d = p - mp->msgstr; + unsigned int i; + + intervals[M_STR] = + (struct interval *) + xrealloc (intervals[M_STR], + (nintervals[M_STR] + part_nintervals) + * sizeof (struct interval)); + for (i = 0; i < part_nintervals; i++) + { + intervals[M_STR][nintervals[M_STR] + i].startpos = + d + part_intervals[i].startpos; + intervals[M_STR][nintervals[M_STR] + i].endpos = + d + part_intervals[i].endpos; + } + nintervals[M_STR] += part_nintervals; + } + } + } - for (r = 0; r < n_sysdep_segments; r++) - if (sysdep_segments[r].length == length - && memcmp (sysdep_segments[r].pointer, pointer, length) - == 0) - break; - if (r == n_sysdep_segments) - { - n_sysdep_segments++; - sysdep_segments = - (struct pre_sysdep_segment *) - xrealloc (sysdep_segments, - n_sysdep_segments - * sizeof (struct pre_sysdep_segment)); - sysdep_segments[r].length = length; - sysdep_segments[r].pointer = pointer; - } + if (nintervals[M_ID] > 0 || nintervals[M_STR] > 0) + { + /* System dependent string pair. */ + size_t m; - pre->segments[i].sysdepref = r; + for (m = 0; m < 2; m++) + { + struct pre_sysdep_string *pre = + (struct pre_sysdep_string *) + xmalloc (xsum (sizeof (struct pre_sysdep_string), + xtimes (nintervals[m], + sizeof (struct pre_segment_pair)))); + const char *str; + size_t str_len; + size_t lastpos; + unsigned int i; + + if (m == M_ID) + { + str = msgctid; /* concatenation of mp->msgctxt + mp->msgid */ + str_len = strlen (msgctid) + 1; + } + else + { + str = mp->msgstr; + str_len = mp->msgstr_len; + } - if (length == 1 && *pointer == 'I') - have_outdigits = true; + lastpos = 0; + pre->segmentcount = nintervals[m]; + for (i = 0; i < nintervals[m]; i++) + { + size_t length; + const char *pointer; + size_t r; + + pre->segments[i].segptr = str + lastpos; + pre->segments[i].segsize = intervals[m][i].startpos - lastpos; + + length = intervals[m][i].endpos - intervals[m][i].startpos; + pointer = str + intervals[m][i].startpos; + if (length >= 2 + && pointer[0] == '<' && pointer[length - 1] == '>') + { + /* Skip the '<' and '>' markers. */ + length -= 2; + pointer += 1; + } + + for (r = 0; r < n_sysdep_segments; r++) + if (sysdep_segments[r].length == length + && memcmp (sysdep_segments[r].pointer, pointer, length) + == 0) + break; + if (r == n_sysdep_segments) + { + n_sysdep_segments++; + sysdep_segments = + (struct pre_sysdep_segment *) + xrealloc (sysdep_segments, + n_sysdep_segments + * sizeof (struct pre_sysdep_segment)); + sysdep_segments[r].length = length; + sysdep_segments[r].pointer = pointer; + } + + pre->segments[i].sysdepref = r; + + if (length == 1 && *pointer == 'I') + have_outdigits = true; + + lastpos = intervals[m][i].endpos; + } + pre->segments[i].segptr = str + lastpos; + pre->segments[i].segsize = str_len - lastpos; + pre->segments[i].sysdepref = SEGMENTS_END; - lastpos = intervals[m][i].endpos; - } - pre->segments[i].segptr = str + lastpos; - pre->segments[i].segsize = str_len - lastpos; - pre->segments[i].sysdepref = SEGMENTS_END; + sysdep_msg_arr[n_sysdep_strings].str[m] = pre; + } - sysdep_msg_arr[n_sysdep_strings].str[m] = pre; - } + sysdep_msg_arr[n_sysdep_strings].id_plural = mp->msgid_plural; + sysdep_msg_arr[n_sysdep_strings].id_plural_len = + (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); + n_sysdep_strings++; + } + else + { + /* Static string pair. */ + msg_arr[nstrings].str[M_ID].pointer = msgctid; + msg_arr[nstrings].str[M_ID].length = strlen (msgctid) + 1; + msg_arr[nstrings].str[M_STR].pointer = mp->msgstr; + msg_arr[nstrings].str[M_STR].length = mp->msgstr_len; + msg_arr[nstrings].id_plural = mp->msgid_plural; + msg_arr[nstrings].id_plural_len = + (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); + nstrings++; + } - sysdep_msg_arr[n_sysdep_strings].id_plural = mp->msgid_plural; - sysdep_msg_arr[n_sysdep_strings].id_plural_len = - (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); - n_sysdep_strings++; - } - else { - /* Static string pair. */ - msg_arr[nstrings].str[M_ID].pointer = msgctid; - msg_arr[nstrings].str[M_ID].length = strlen (msgctid) + 1; - msg_arr[nstrings].str[M_STR].pointer = mp->msgstr; - msg_arr[nstrings].str[M_STR].length = mp->msgstr_len; - msg_arr[nstrings].id_plural = mp->msgid_plural; - msg_arr[nstrings].id_plural_len = - (mp->msgid_plural != NULL ? strlen (mp->msgid_plural) + 1 : 0); - nstrings++; - } + size_t m; - for (m = 0; m < 2; m++) - if (intervals[m] != NULL) - free (intervals[m]); - } + for (m = 0; m < 2; m++) + if (intervals[m] != NULL) + free (intervals[m]); + } + } + } /* Sort the table according to original string. */ if (nstrings > 0) @@ -468,11 +477,16 @@ write_table (FILE *output_file, message_list_ty *mlp) /* System dependent string descriptors. */ sysdep_tab_offset = offset; - for (m = 0; m < 2; m++) - for (j = 0; j < n_sysdep_strings; j++) - offset += sizeof (struct sysdep_string) - + sysdep_msg_arr[j].str[m]->segmentcount - * sizeof (struct segment_pair); + { + size_t m; + size_t j; + + for (m = 0; m < 2; m++) + for (j = 0; j < n_sysdep_strings; j++) + offset += sizeof (struct sysdep_string) + + sysdep_msg_arr[j].str[m]->segmentcount + * sizeof (struct segment_pair); + } } end_offset = offset; @@ -505,49 +519,57 @@ write_table (FILE *output_file, message_list_ty *mlp) /* Table for original string offsets. */ /* Here output_file is at position header.orig_tab_offset. */ - for (j = 0; j < nstrings; j++) - { - offset = roundup (offset, alignment); - orig_tab[j].length = - msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; - orig_tab[j].offset = offset; - offset += orig_tab[j].length; - /* Subtract 1 because of the terminating NUL. */ - orig_tab[j].length--; - } - if (byteswap) + { + size_t j; + for (j = 0; j < nstrings; j++) { - BSWAP32 (orig_tab[j].length); - BSWAP32 (orig_tab[j].offset); + offset = roundup (offset, alignment); + orig_tab[j].length = + msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; + orig_tab[j].offset = offset; + offset += orig_tab[j].length; + /* Subtract 1 because of the terminating NUL. */ + orig_tab[j].length--; } - fwrite (orig_tab, nstrings * sizeof (struct string_desc), 1, output_file); + if (byteswap) + for (j = 0; j < nstrings; j++) + { + BSWAP32 (orig_tab[j].length); + BSWAP32 (orig_tab[j].offset); + } + fwrite (orig_tab, nstrings * sizeof (struct string_desc), 1, output_file); + } /* Table for translated string offsets. */ /* Here output_file is at position header.trans_tab_offset. */ - for (j = 0; j < nstrings; j++) - { - offset = roundup (offset, alignment); - trans_tab[j].length = msg_arr[j].str[M_STR].length; - trans_tab[j].offset = offset; - offset += trans_tab[j].length; - /* Subtract 1 because of the terminating NUL. */ - trans_tab[j].length--; - } - if (byteswap) + { + size_t j; + for (j = 0; j < nstrings; j++) { - BSWAP32 (trans_tab[j].length); - BSWAP32 (trans_tab[j].offset); + offset = roundup (offset, alignment); + trans_tab[j].length = msg_arr[j].str[M_STR].length; + trans_tab[j].offset = offset; + offset += trans_tab[j].length; + /* Subtract 1 because of the terminating NUL. */ + trans_tab[j].length--; } - fwrite (trans_tab, nstrings * sizeof (struct string_desc), 1, output_file); + if (byteswap) + for (j = 0; j < nstrings; j++) + { + BSWAP32 (trans_tab[j].length); + BSWAP32 (trans_tab[j].offset); + } + fwrite (trans_tab, nstrings * sizeof (struct string_desc), 1, output_file); + } /* Skip this part when no hash table is needed. */ if (!omit_hash_table) { nls_uint32 *hash_tab; - unsigned int j; + size_t j; /* Here output_file is at position header.hash_tab_offset. */ @@ -589,104 +611,116 @@ write_table (FILE *output_file, message_list_ty *mlp) if (minor_revision >= 1) { - struct sysdep_segment *sysdep_segments_tab; - nls_uint32 *sysdep_tab; - size_t stoffset; - unsigned int i; - /* Here output_file is at position header.sysdep_segments_offset. */ - sysdep_segments_tab = - XNMALLOC (n_sysdep_segments, struct sysdep_segment); - for (i = 0; i < n_sysdep_segments; i++) - { - offset = roundup (offset, alignment); - /* The "+ 1" accounts for the trailing NUL byte. */ - sysdep_segments_tab[i].length = sysdep_segments[i].length + 1; - sysdep_segments_tab[i].offset = offset; - offset += sysdep_segments_tab[i].length; - } + { + struct sysdep_segment *sysdep_segments_tab; + unsigned int i; - if (byteswap) + sysdep_segments_tab = + XNMALLOC (n_sysdep_segments, struct sysdep_segment); for (i = 0; i < n_sysdep_segments; i++) { - BSWAP32 (sysdep_segments_tab[i].length); - BSWAP32 (sysdep_segments_tab[i].offset); + offset = roundup (offset, alignment); + /* The "+ 1" accounts for the trailing NUL byte. */ + sysdep_segments_tab[i].length = sysdep_segments[i].length + 1; + sysdep_segments_tab[i].offset = offset; + offset += sysdep_segments_tab[i].length; } - fwrite (sysdep_segments_tab, - n_sysdep_segments * sizeof (struct sysdep_segment), 1, - output_file); - - free (sysdep_segments_tab); - - sysdep_tab = XNMALLOC (n_sysdep_strings, nls_uint32); - stoffset = sysdep_tab_offset; - - for (m = 0; m < 2; m++) - { - /* Here output_file is at position - m == M_ID -> header.orig_sysdep_tab_offset, - m == M_STR -> header.trans_sysdep_tab_offset. */ - for (j = 0; j < n_sysdep_strings; j++) + if (byteswap) + for (i = 0; i < n_sysdep_segments; i++) { - sysdep_tab[j] = stoffset; - stoffset += sizeof (struct sysdep_string) - + sysdep_msg_arr[j].str[m]->segmentcount - * sizeof (struct segment_pair); + BSWAP32 (sysdep_segments_tab[i].length); + BSWAP32 (sysdep_segments_tab[i].offset); } - /* Write the table for original/translated sysdep string offsets. */ - if (byteswap) - for (j = 0; j < n_sysdep_strings; j++) - BSWAP32 (sysdep_tab[j]); - fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1, - output_file); - } + fwrite (sysdep_segments_tab, + n_sysdep_segments * sizeof (struct sysdep_segment), 1, + output_file); - free (sysdep_tab); + free (sysdep_segments_tab); + } - /* Here output_file is at position sysdep_tab_offset. */ + { + nls_uint32 *sysdep_tab; + size_t stoffset; + size_t m; + size_t j; - for (m = 0; m < 2; m++) - for (j = 0; j < n_sysdep_strings; j++) + sysdep_tab = XNMALLOC (n_sysdep_strings, nls_uint32); + stoffset = sysdep_tab_offset; + + for (m = 0; m < 2; m++) { - struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; - struct pre_sysdep_string *pre = msg->str[m]; - struct sysdep_string *str = - (struct sysdep_string *) - xmalloca (sizeof (struct sysdep_string) - + pre->segmentcount * sizeof (struct segment_pair)); - unsigned int i; + /* Here output_file is at position + m == M_ID -> header.orig_sysdep_tab_offset, + m == M_STR -> header.trans_sysdep_tab_offset. */ - offset = roundup (offset, alignment); - str->offset = offset; - for (i = 0; i <= pre->segmentcount; i++) - { - str->segments[i].segsize = pre->segments[i].segsize; - str->segments[i].sysdepref = pre->segments[i].sysdepref; - offset += str->segments[i].segsize; - } - if (m == M_ID && msg->id_plural_len > 0) + for (j = 0; j < n_sysdep_strings; j++) { - str->segments[pre->segmentcount].segsize += msg->id_plural_len; - offset += msg->id_plural_len; + sysdep_tab[j] = stoffset; + stoffset += sizeof (struct sysdep_string) + + sysdep_msg_arr[j].str[m]->segmentcount + * sizeof (struct segment_pair); } + /* Write the table for original/translated sysdep string offsets. */ if (byteswap) - { - BSWAP32 (str->offset); - for (i = 0; i <= pre->segmentcount; i++) - { - BSWAP32 (str->segments[i].segsize); - BSWAP32 (str->segments[i].sysdepref); - } - } - fwrite (str, - sizeof (struct sysdep_string) - + pre->segmentcount * sizeof (struct segment_pair), - 1, output_file); - - freea (str); + for (j = 0; j < n_sysdep_strings; j++) + BSWAP32 (sysdep_tab[j]); + fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1, + output_file); } + + free (sysdep_tab); + } + + /* Here output_file is at position sysdep_tab_offset. */ + + { + size_t m; + size_t j; + + for (m = 0; m < 2; m++) + for (j = 0; j < n_sysdep_strings; j++) + { + struct pre_sysdep_message *msg = &sysdep_msg_arr[j]; + struct pre_sysdep_string *pre = msg->str[m]; + struct sysdep_string *str = + (struct sysdep_string *) + xmalloca (sizeof (struct sysdep_string) + + pre->segmentcount * sizeof (struct segment_pair)); + unsigned int i; + + offset = roundup (offset, alignment); + str->offset = offset; + for (i = 0; i <= pre->segmentcount; i++) + { + str->segments[i].segsize = pre->segments[i].segsize; + str->segments[i].sysdepref = pre->segments[i].sysdepref; + offset += str->segments[i].segsize; + } + if (m == M_ID && msg->id_plural_len > 0) + { + str->segments[pre->segmentcount].segsize += msg->id_plural_len; + offset += msg->id_plural_len; + } + if (byteswap) + { + BSWAP32 (str->offset); + for (i = 0; i <= pre->segmentcount; i++) + { + BSWAP32 (str->segments[i].segsize); + BSWAP32 (str->segments[i].sysdepref); + } + } + fwrite (str, + sizeof (struct sysdep_string) + + pre->segmentcount * sizeof (struct segment_pair), + 1, output_file); + + freea (str); + } + } } /* Here output_file is at position end_offset. */ @@ -704,33 +738,43 @@ write_table (FILE *output_file, message_list_ty *mlp) memset (null, '\0', alignment); /* Now write the original strings. */ - for (j = 0; j < nstrings; j++) - { - fwrite (null, roundup (offset, alignment) - offset, 1, output_file); - offset = roundup (offset, alignment); + { + size_t j; + + for (j = 0; j < nstrings; j++) + { + fwrite (null, roundup (offset, alignment) - offset, 1, output_file); + offset = roundup (offset, alignment); - fwrite (msg_arr[j].str[M_ID].pointer, msg_arr[j].str[M_ID].length, 1, - output_file); - if (msg_arr[j].id_plural_len > 0) - fwrite (msg_arr[j].id_plural, msg_arr[j].id_plural_len, 1, + fwrite (msg_arr[j].str[M_ID].pointer, msg_arr[j].str[M_ID].length, 1, output_file); - offset += msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; - } + if (msg_arr[j].id_plural_len > 0) + fwrite (msg_arr[j].id_plural, msg_arr[j].id_plural_len, 1, + output_file); + offset += msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len; + } + } /* Now write the translated strings. */ - for (j = 0; j < nstrings; j++) - { - fwrite (null, roundup (offset, alignment) - offset, 1, output_file); - offset = roundup (offset, alignment); + { + size_t j; - fwrite (msg_arr[j].str[M_STR].pointer, msg_arr[j].str[M_STR].length, 1, - output_file); - offset += msg_arr[j].str[M_STR].length; - } + for (j = 0; j < nstrings; j++) + { + fwrite (null, roundup (offset, alignment) - offset, 1, output_file); + offset = roundup (offset, alignment); + + fwrite (msg_arr[j].str[M_STR].pointer, msg_arr[j].str[M_STR].length, 1, + output_file); + offset += msg_arr[j].str[M_STR].length; + } + } if (minor_revision >= 1) { unsigned int i; + size_t m; + size_t j; for (i = 0; i < n_sysdep_segments; i++) { @@ -770,8 +814,11 @@ write_table (FILE *output_file, message_list_ty *mlp) } freea (null); - for (j = 0; j < mlp->nitems; j++) - free (msgctid_arr[j]); + { + size_t j; + for (j = 0; j < mlp->nitems; j++) + free (msgctid_arr[j]); + } free (sysdep_msg_arr); free (msg_arr); free (msgctid_arr); diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 1985c084f..b8a420df9 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -236,11 +236,14 @@ phase2_getc () interactive behaviour when fp is connected to an interactive tty. */ unsigned char buf[MAX_PHASE1_PUSHBACK]; size_t bufcount; - int c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = (unsigned char) c; - bufcount = 1; + + { + int c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[0] = (unsigned char) c; + bufcount = 1; + } for (;;) { diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index b42d7c1ed..e961da3d3 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -651,11 +651,11 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, } for (;;) { - int c; + int ch; - c = do_getc (); + ch = do_getc (); - switch (c) + switch (ch) { case EOF: op->type = t_eof; @@ -954,208 +954,245 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, } case '?': - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else - { - c = do_getc_escaped (c, false); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - } - } - /* Impossible to deal with Emacs multibyte character stuff here. */ - op->type = t_other; - last_non_comment_line = line_number; - return; + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else + { + c = do_getc_escaped (c, false); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + } + } + /* Impossible to deal with Emacs multibyte character stuff here. */ + op->type = t_other; + last_non_comment_line = line_number; + return; + } case '#': /* Dispatch macro handling. */ - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } + { + int dmc = do_getc (); + if (dmc == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } - switch (c) - { - case '^': - c = do_getc (); - if (c == '^') - c = do_getc (); - if (c == '[') + switch (dmc) + { + case '^': { - /* Read a char table, same syntax as a vector. */ - for (;;) + int c = do_getc (); + if (c == '^') + c = do_getc (); + if (c == '[') { - struct object inner; + /* Read a char table, same syntax as a vector. */ + for (;;) + { + struct object inner; - ++nesting_depth; - read_object (&inner, false, new_backquote_flag, - null_context); - nesting_depth--; + ++nesting_depth; + read_object (&inner, false, new_backquote_flag, + null_context); + nesting_depth--; - /* Recognize end of vector. */ - if (inner.type == t_vectorclose) - { - op->type = t_other; - last_non_comment_line = line_number; - return; - } + /* Recognize end of vector. */ + if (inner.type == t_vectorclose) + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } - /* Dots and ')' are not allowed. But be tolerant. */ + /* Dots and ')' are not allowed. But be tolerant. */ - /* EOF inside vector is illegal. But be tolerant. */ - if (inner.type == t_eof) - break; + /* EOF inside vector is illegal. But be tolerant. */ + if (inner.type == t_eof) + break; - free_object (&inner); + free_object (&inner); + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + else + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + if (c != EOF) + last_non_comment_line = line_number; + return; } - op->type = t_other; - last_non_comment_line = line_number; - return; - } - else - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - if (c != EOF) - last_non_comment_line = line_number; - return; } - case '&': - /* Read a bit vector. */ - { - struct object length; - ++nesting_depth; - read_object (&length, first_in_list, new_backquote_flag, - null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&length); - } - c = do_getc (); - if (c == '"') + case '&': + /* Read a bit vector. */ { - struct object string; + struct object length; ++nesting_depth; - read_object (&string, first_in_list, new_backquote_flag, + read_object (&length, first_in_list, new_backquote_flag, null_context); nesting_depth--; - free_object (&string); + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&length); + } + { + int c = do_getc (); + if (c == '"') + { + struct object string; + ++nesting_depth; + read_object (&string, first_in_list, new_backquote_flag, + null_context); + nesting_depth--; + free_object (&string); + } + else + /* Invalid input. Be tolerant, no error message. */ + do_ungetc (c); } - else - /* Invalid input. Be tolerant, no error message. */ - do_ungetc (c); - op->type = t_other; - last_non_comment_line = line_number; - return; - - case '[': - /* Read a compiled function, same syntax as a vector. */ - case '(': - /* Read a string with properties, same syntax as a list. */ - { - struct object inner; - do_ungetc (c); - ++nesting_depth; - read_object (&inner, false, new_backquote_flag, null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); op->type = t_other; last_non_comment_line = line_number; return; - } - case '@': - /* Read a comment consisting of a given number of bytes. */ - { - unsigned int nskip = 0; + case '[': + /* Read a compiled function, same syntax as a vector. */ + case '(': + /* Read a string with properties, same syntax as a list. */ + { + struct object inner; + do_ungetc (dmc); + ++nesting_depth; + read_object (&inner, false, new_backquote_flag, null_context); + nesting_depth--; + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } - for (;;) - { - c = do_getc (); - if (!(c >= '0' && c <= '9')) - break; - nskip = 10 * nskip + (c - '0'); - } - if (c != EOF) - { - do_ungetc (c); - for (; nskip > 0; nskip--) - if (do_getc () == EOF) - break; - } - continue; - } + case '@': + /* Read a comment consisting of a given number of bytes. */ + { + unsigned int nskip = 0; + int c; - case '$': - op->type = t_other; - last_non_comment_line = line_number; - return; + for (;;) + { + c = do_getc (); + if (!(c >= '0' && c <= '9')) + break; + nskip = 10 * nskip + (c - '0'); + } + if (c != EOF) + { + do_ungetc (c); + for (; nskip > 0; nskip--) + if (do_getc () == EOF) + break; + } + continue; + } - case '\'': - case ':': - case 'S': case 's': /* XEmacs only */ - { - struct object inner; - ++nesting_depth; - read_object (&inner, false, new_backquote_flag, null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); + case '$': op->type = t_other; last_non_comment_line = line_number; return; - } - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - /* Read Common Lisp style #n# or #n=. */ - for (;;) - { - c = do_getc (); - if (!(c >= '0' && c <= '9')) - break; - } - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } - if (c == '=') + case '\'': + case ':': + case 'S': case 's': /* XEmacs only */ { + struct object inner; ++nesting_depth; - read_object (op, false, new_backquote_flag, outer_context); + read_object (&inner, false, new_backquote_flag, null_context); nesting_depth--; + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; last_non_comment_line = line_number; return; } - if (c == '#') + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* Read Common Lisp style #n# or #n=. */ { + int c; + + for (;;) + { + c = do_getc (); + if (!(c >= '0' && c <= '9')) + break; + } + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } + if (c == '=') + { + ++nesting_depth; + read_object (op, false, new_backquote_flag, outer_context); + nesting_depth--; + last_non_comment_line = line_number; + return; + } + if (c == '#') + { + op->type = t_other; + last_non_comment_line = line_number; + return; + } + if (c == 'R' || c == 'r') + { + /* Read an integer. */ + c = do_getc (); + if (c == '+' || c == '-') + c = do_getc (); + for (; c != EOF; c = do_getc ()) + if (!c_isalnum (c)) + { + do_ungetc (c); + break; + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } + /* Invalid input. Be tolerant, no error message. */ op->type = t_other; last_non_comment_line = line_number; return; } - if (c == 'R' || c == 'r') + + case 'X': case 'x': + case 'O': case 'o': + case 'B': case 'b': { /* Read an integer. */ + int c; + c = do_getc (); if (c == '+' || c == '-') c = do_getc (); @@ -1169,92 +1206,72 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, last_non_comment_line = line_number; return; } - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - case 'X': case 'x': - case 'O': case 'o': - case 'B': case 'b': - { - /* Read an integer. */ - c = do_getc (); - if (c == '+' || c == '-') - c = do_getc (); - for (; c != EOF; c = do_getc ()) - if (!c_isalnum (c)) - { - do_ungetc (c); - break; - } - op->type = t_other; - last_non_comment_line = line_number; - return; - } + case '*': /* XEmacs only */ + { + /* Read a bit-vector. */ + int c; - case '*': /* XEmacs only */ - { - /* Read a bit-vector. */ - do - c = do_getc (); - while (c == '0' || c == '1'); - if (c != EOF) - do_ungetc (c); + do + c = do_getc (); + while (c == '0' || c == '1'); + if (c != EOF) + do_ungetc (c); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '+': /* XEmacs only */ + case '-': /* XEmacs only */ + /* Simply assume every feature expression is true. */ + { + struct object inner; + ++nesting_depth; + read_object (&inner, false, new_backquote_flag, null_context); + nesting_depth--; + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + continue; + } + + default: + /* Invalid input. Be tolerant, no error message. */ op->type = t_other; last_non_comment_line = line_number; return; } - case '+': /* XEmacs only */ - case '-': /* XEmacs only */ - /* Simply assume every feature expression is true. */ - { - struct object inner; - ++nesting_depth; - read_object (&inner, false, new_backquote_flag, null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - continue; - } - - default: - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /*NOTREACHED*/ - abort (); + /*NOTREACHED*/ + abort (); + } case '.': - c = do_getc (); - if (c != EOF) + ch = do_getc (); + if (ch != EOF) { - do_ungetc (c); - if (c <= ' ' /* FIXME: Assumes ASCII compatible encoding */ - || strchr ("\"'`,(", c) != NULL) + do_ungetc (ch); + if (ch <= ' ' /* FIXME: Assumes ASCII compatible encoding */ + || strchr ("\"'`,(", ch) != NULL) { op->type = t_dot; last_non_comment_line = line_number; return; } } - c = '.'; + ch = '.'; FALLTHROUGH; default: default_label: - if (c <= ' ') /* FIXME: Assumes ASCII compatible encoding */ + if (ch <= ' ') /* FIXME: Assumes ASCII compatible encoding */ continue; /* Read a token. */ { bool symbol; op->token = XMALLOC (struct token); - symbol = read_token (op->token, c); + symbol = read_token (op->token, ch); if (symbol) { op->type = t_symbol; diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index f2807918f..f0452a07c 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -248,11 +248,14 @@ phase2_getc () interactive behaviour when fp is connected to an interactive tty. */ unsigned char buf[MAX_PHASE1_PUSHBACK]; size_t bufcount; - int c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = (unsigned char) c; - bufcount = 1; + + { + int c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[0] = (unsigned char) c; + bufcount = 1; + } for (;;) { diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 734d38807..1891a3222 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -608,11 +608,11 @@ read_object (struct object *op, flag_context_ty outer_context) } for (;;) { - int c; + int ch; - c = do_getc (); + ch = do_getc (); - switch (c) + switch (ch) { case EOF: op->type = t_eof; @@ -871,57 +871,159 @@ read_object (struct object *op, flag_context_ty outer_context) } case '?': - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else if (c == '\\') - { - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - else - { - c = do_getc_escaped (c); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - ; - } - } - op->type = t_other; - last_non_comment_line = line_number; - return; + { + int c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else if (c == '\\') + { + c = do_getc (); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + else + { + c = do_getc_escaped (c); + if (c == EOF) + /* Invalid input. Be tolerant, no error message. */ + ; + } + } + op->type = t_other; + last_non_comment_line = line_number; + return; + } case '#': /* Dispatch macro handling. */ - c = do_getc (); - if (c == EOF) - /* Invalid input. Be tolerant, no error message. */ - { - op->type = t_other; - return; - } + { + int dmc = do_getc (); + if (dmc == EOF) + /* Invalid input. Be tolerant, no error message. */ + { + op->type = t_other; + return; + } - switch (c) - { - case '!': - if (ftell (fp) == 2) - /* Skip comment until !# */ + switch (dmc) + { + case '!': + if (ftell (fp) == 2) + /* Skip comment until !# */ + { + int c; + + c = do_getc (); + for (;;) + { + if (c == EOF) + break; + if (c == '!') + { + c = do_getc (); + if (c == EOF || c == '#') + break; + } + else + c = do_getc (); + } + if (c == EOF) + { + /* EOF not allowed here. But be tolerant. */ + op->type = t_eof; + return; + } + continue; + } + FALLTHROUGH; + case '\'': + case ':': { + struct object inner; + ++nesting_depth; + read_object (&inner, null_context); + nesting_depth--; + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '[': + case '(': + { + struct object inner; + do_ungetc (dmc); + ++nesting_depth; + read_object (&inner, null_context); + nesting_depth--; + /* Dots and EOF are not allowed here. + But be tolerant. */ + free_object (&inner); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case '|': + { + int depth = 0; + int c; + + comment_start (); c = do_getc (); for (;;) { if (c == EOF) break; - if (c == '!') + if (c == '|') + { + c = do_getc (); + if (c == EOF) + break; + if (c == '#') + { + if (depth == 0) + { + comment_line_end (0); + break; + } + depth--; + comment_add ('|'); + comment_add ('#'); + c = do_getc (); + } + else + comment_add ('|'); + } + else if (c == '#') { c = do_getc (); - if (c == EOF || c == '#') + if (c == EOF) break; + comment_add ('#'); + if (c == '|') + { + depth++; + comment_add ('|'); + c = do_getc (); + } } else - c = do_getc (); + { + /* We skip all leading white space. */ + if (!(buflen == 0 && (c == ' ' || c == '\t'))) + comment_add (c); + if (c == '\n') + { + comment_line_end (1); + comment_start (); + } + c = do_getc (); + } } if (c == EOF) { @@ -929,149 +1031,57 @@ read_object (struct object *op, flag_context_ty outer_context) op->type = t_eof; return; } + last_comment_line = line_number; continue; } - FALLTHROUGH; - case '\'': - case ':': - { - struct object inner; - ++nesting_depth; - read_object (&inner, null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - case '[': - case '(': - { - struct object inner; - do_ungetc (c); - ++nesting_depth; - read_object (&inner, null_context); - nesting_depth--; - /* Dots and EOF are not allowed here. - But be tolerant. */ - free_object (&inner); + case '\\': + { + struct token token; + int first = '\\'; + read_token (&token, &first); + free_token (&token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + + case 'T': case 't': + case 'F': case 'f': op->type = t_other; last_non_comment_line = line_number; return; - } - case '|': - { - int depth = 0; - - comment_start (); - c = do_getc (); - for (;;) - { - if (c == EOF) - break; - if (c == '|') - { - c = do_getc (); - if (c == EOF) - break; - if (c == '#') - { - if (depth == 0) - { - comment_line_end (0); - break; - } - depth--; - comment_add ('|'); - comment_add ('#'); - c = do_getc (); - } - else - comment_add ('|'); - } - else if (c == '#') - { - c = do_getc (); - if (c == EOF) - break; - comment_add ('#'); - if (c == '|') - { - depth++; - comment_add ('|'); - c = do_getc (); - } - } - else - { - /* We skip all leading white space. */ - if (!(buflen == 0 && (c == ' ' || c == '\t'))) - comment_add (c); - if (c == '\n') - { - comment_line_end (1); - comment_start (); - } - c = do_getc (); - } - } - if (c == EOF) + case 'B': case 'b': + case 'O': case 'o': + case 'D': case 'd': + case 'X': case 'x': + case 'E': case 'e': + case 'I': case 'i': + { + struct token token; + do_ungetc (dmc); { - /* EOF not allowed here. But be tolerant. */ - op->type = t_eof; - return; + int c; + c = '#'; + read_token (&token, &c); + free_token (&token); } - last_comment_line = line_number; - continue; - } - - case '\\': - { - struct token token; - int first = '\\'; - read_token (&token, &first); - free_token (&token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } + op->type = t_other; + last_non_comment_line = line_number; + return; + } - case 'T': case 't': - case 'F': case 'f': - op->type = t_other; - last_non_comment_line = line_number; - return; - - case 'B': case 'b': - case 'O': case 'o': - case 'D': case 'd': - case 'X': case 'x': - case 'E': case 'e': - case 'I': case 'i': - { - struct token token; - do_ungetc (c); - c = '#'; - read_token (&token, &c); - free_token (&token); + default: + /* Invalid input. Be tolerant, no error message. */ op->type = t_other; last_non_comment_line = line_number; return; } - default: - /* Invalid input. Be tolerant, no error message. */ - op->type = t_other; - last_non_comment_line = line_number; - return; - } - - /*NOTREACHED*/ - abort (); + /*NOTREACHED*/ + abort (); + } default: /* Read a token. */ @@ -1079,7 +1089,7 @@ read_object (struct object *op, flag_context_ty outer_context) bool symbol; op->token = XMALLOC (struct token); - symbol = read_token (op->token, &c); + symbol = read_token (op->token, &ch); if (op->token->charcount == 1 && op->token->chars[0] == '.') { free_token (op->token); @@ -1097,27 +1107,29 @@ read_object (struct object *op, flag_context_ty outer_context) return; } /* Distinguish between "foo" and "foo#bar". */ - c = do_getc (); - if (c == '#') - { - struct token second_token; - - free_token (op->token); - free (op->token); - read_token (&second_token, NULL); - free_token (&second_token); - op->type = t_other; - last_non_comment_line = line_number; - return; - } - else - { - if (c != EOF) - do_ungetc (c); - op->type = t_symbol; - last_non_comment_line = line_number; - return; - } + { + int c = do_getc (); + if (c == '#') + { + struct token second_token; + + free_token (op->token); + free (op->token); + read_token (&second_token, NULL); + free_token (&second_token); + op->type = t_other; + last_non_comment_line = line_number; + return; + } + else + { + if (c != EOF) + do_ungetc (c); + op->type = t_symbol; + last_non_comment_line = line_number; + return; + } + } } } } diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 60e83f33b..4b29f08a6 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -1231,26 +1231,26 @@ read_object (struct object *op, flag_context_ty outer_context) case '#': /* Dispatch macro handling. */ { - int c; + int dmc; for (;;) { - c = do_getc (); - if (c == EOF) + dmc = do_getc (); + if (dmc == EOF) /* Invalid input. Be tolerant, no error message. */ { op->type = t_other; return; } - if (!(c >= '0' && c <= '9')) + if (!(dmc >= '0' && dmc <= '9')) break; } - switch (c) + switch (dmc) { case '(': case '"': - do_ungetc (c); + do_ungetc (dmc); FALLTHROUGH; case '\'': case ':': diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index c8b28c2b2..a329f3dd8 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -1327,7 +1327,6 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) static char *buffer; static int bufmax = 0; int bufpos = 0; - int c = first; size_t varbody_length = 0; bool maybe_hash_deref = false; bool maybe_hash_value = false; @@ -1344,111 +1343,115 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) * accepting the hash sign (#) will maybe lead to inaccurate * results. FIXME! */ - while (c == '$' || c == '*' || c == '#' || c == '@' || c == '%') - { - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - } + { + int c = first; - if (c == EOF) - { - tp->type = token_type_eof; - return; - } - - /* Hash references are treated in a special way, when looking for - our keywords. */ - if (buffer[0] == '$') - { - if (bufpos == 1) - maybe_hash_value = true; - else if (bufpos == 2 && buffer[1] == '$') - { - if (!(c == '{' - || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') - || c == '_' || c == ':' || c == '\'' || c >= 0x80)) - { - /* Special variable $$ for pid. */ - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = '\0'; - tp->string = xstrdup (buffer); + while (c == '$' || c == '*' || c == '#' || c == '@' || c == '%') + { + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + } + + if (c == EOF) + { + tp->type = token_type_eof; + return; + } + + /* Hash references are treated in a special way, when looking for + our keywords. */ + if (buffer[0] == '$') + { + if (bufpos == 1) + maybe_hash_value = true; + else if (bufpos == 2 && buffer[1] == '$') + { + if (!(c == '{' + || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') + || c == '_' || c == ':' || c == '\'' || c >= 0x80)) + { + /* Special variable $$ for pid. */ + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = '\0'; + tp->string = xstrdup (buffer); #if DEBUG_PERL - fprintf (stderr, "%s:%d: is PID ($$)\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: is PID ($$)\n", + real_file_name, line_number); #endif - phase1_ungetc (c); - return; - } - - maybe_hash_deref = true; - bufpos = 1; - } - } + phase1_ungetc (c); + return; + } - /* - * 2) Get the name of the variable. The first character is practically - * arbitrary. Punctuation and numbers automagically put a variable - * in the global namespace but that subtle difference is not interesting - * for us. - */ - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - if (c == '{') - { - /* Yuck, we cannot accept ${gettext} as a keyword... Except for - * debugging purposes it is also harmless, that we suppress the - * real name of the variable. - */ + maybe_hash_deref = true; + bufpos = 1; + } + } + + /* + * 2) Get the name of the variable. The first character is practically + * arbitrary. Punctuation and numbers automagically put a variable + * in the global namespace but that subtle difference is not interesting + * for us. + */ + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + if (c == '{') + { + /* Yuck, we cannot accept ${gettext} as a keyword... Except for + * debugging purposes it is also harmless, that we suppress the + * real name of the variable. + */ #if DEBUG_PERL - fprintf (stderr, "%s:%d: braced {variable_name}\n", - real_file_name, line_number); + fprintf (stderr, "%s:%d: braced {variable_name}\n", + real_file_name, line_number); #endif - if (extract_balanced (mlp, token_type_rbrace, true, false, - null_context, null_context_list_iterator, - 1, arglist_parser_alloc (mlp, NULL))) - { - tp->type = token_type_eof; - return; - } - buffer[bufpos++] = c; - } - else - { - while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') - || (c >= '0' && c <= '9') - || c == '_' || c == ':' || c == '\'' || c >= 0x80) - { - ++varbody_length; - if (bufpos >= bufmax) - { - bufmax = 2 * bufmax + 10; - buffer = xrealloc (buffer, bufmax); - } - buffer[bufpos++] = c; - c = phase1_getc (); - } - phase1_ungetc (c); - } + if (extract_balanced (mlp, token_type_rbrace, true, false, + null_context, null_context_list_iterator, + 1, arglist_parser_alloc (mlp, NULL))) + { + tp->type = token_type_eof; + return; + } + buffer[bufpos++] = c; + } + else + { + while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + || (c >= '0' && c <= '9') + || c == '_' || c == ':' || c == '\'' || c >= 0x80) + { + ++varbody_length; + if (bufpos >= bufmax) + { + bufmax = 2 * bufmax + 10; + buffer = xrealloc (buffer, bufmax); + } + buffer[bufpos++] = c; + c = phase1_getc (); + } + phase1_ungetc (c); + } + } /* Probably some strange Perl variable like $`. */ if (varbody_length == 0) { - c = phase1_getc (); + int c = phase1_getc (); if (c == EOF || is_whitespace (c)) phase1_ungetc (c); /* Loser. */ else diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 23a0a6bc1..dacc2c858 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -293,11 +293,14 @@ as specified in https://www.python.org/peps/pep-0263.html.\n"))); interactive behaviour when fp is connected to an interactive tty. */ unsigned char buf[MAX_PHASE1_PUSHBACK]; size_t bufcount; - int c = phase1_getc (); - if (c == EOF) - return UEOF; - buf[0] = (unsigned char) c; - bufcount = 1; + + { + int c = phase1_getc (); + if (c == EOF) + return UEOF; + buf[0] = (unsigned char) c; + bufcount = 1; + } for (;;) { diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index 2eb598340..f1ddfa50d 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -692,10 +692,10 @@ read_object (struct object *op, flag_context_ty outer_context) } for (;;) { - int c = do_getc (); + int ch = do_getc (); bool seen_underscore_prefix = false; - switch (c) + switch (ch) { case EOF: op->type = t_eof; @@ -720,7 +720,7 @@ read_object (struct object *op, flag_context_ty outer_context) comment_start (); for (;;) { - c = do_getc (); + int c = do_getc (); if (c == EOF || c == '\n') break; if (c != ';') @@ -871,18 +871,18 @@ read_object (struct object *op, flag_context_ty outer_context) case '#': /* Dispatch macro handling. */ { - c = do_getc (); - if (c == EOF) + int dmc = do_getc (); + if (dmc == EOF) /* Invalid input. Be tolerant, no error message. */ { op->type = t_other; return; } - switch (c) + switch (dmc) { case '(': /* Vector */ - do_ungetc (c); + do_ungetc (dmc); { struct object inner; ++nesting_depth; @@ -913,7 +913,7 @@ read_object (struct object *op, flag_context_ty outer_context) case 'y': { struct token token; - do_ungetc (c); + do_ungetc (dmc); read_token (&token, '#'); if ((token.charcount == 2 && (token.chars[1] == 'a' || token.chars[1] == 'c' @@ -939,7 +939,7 @@ read_object (struct object *op, flag_context_ty outer_context) && token.chars[2] == 'u' && token.chars[3] == '8')))) { - c = do_getc (); + int c = do_getc (); if (c != EOF) do_ungetc (c); if (c == '(') @@ -994,7 +994,7 @@ read_object (struct object *op, flag_context_ty outer_context) case 'I': case 'i': { struct token token; - do_ungetc (c); + do_ungetc (dmc); read_token (&token, '#'); if (is_number (&token)) { @@ -1009,7 +1009,7 @@ read_object (struct object *op, flag_context_ty outer_context) if (token.charcount == 2 && (token.chars[1] == 'e' || token.chars[1] == 'i')) { - c = do_getc (); + int c = do_getc (); if (c != EOF) do_ungetc (c); if (c == '(') @@ -1161,7 +1161,7 @@ read_object (struct object *op, flag_context_ty outer_context) /* Bit vector. */ { struct token token; - read_token (&token, c); + read_token (&token, dmc); /* The token should consists only of '0' and '1', except for the initial '*'. But be tolerant. */ free_token (&token); @@ -1179,7 +1179,7 @@ read_object (struct object *op, flag_context_ty outer_context) for (;;) { - c = do_getc (); + int c = do_getc (); if (c == EOF) break; @@ -1211,7 +1211,7 @@ read_object (struct object *op, flag_context_ty outer_context) /* Character. */ { struct token token; - c = do_getc (); + int c = do_getc (); if (c != EOF) { read_token (&token, c); @@ -1242,11 +1242,14 @@ read_object (struct object *op, flag_context_ty outer_context) n ::= DIGIT+ x ::= {'a'|'b'|'c'|'e'|'i'|'s'|'u'} */ - do - c = do_getc (); - while (c >= '0' && c <= '9'); - /* c should be one of {'a'|'b'|'c'|'e'|'i'|'s'|'u'}. - But be tolerant. */ + { + int c; + do + c = do_getc (); + while (c >= '0' && c <= '9'); + /* c should be one of {'a'|'b'|'c'|'e'|'i'|'s'|'u'}. + But be tolerant. */ + } FALLTHROUGH; case '\'': /* boot-9.scm */ case '.': /* boot-9.scm */ @@ -1373,7 +1376,7 @@ read_object (struct object *op, flag_context_ty outer_context) case '+': case '-': case '.': /* Read a number or symbol token. */ op->token = XMALLOC (struct token); - read_token (op->token, c); + read_token (op->token, ch); if (op->token->charcount == 1 && op->token->chars[0] == '.') { free_token (op->token); @@ -1399,7 +1402,7 @@ read_object (struct object *op, flag_context_ty outer_context) default: /* Read a symbol token. */ op->token = XMALLOC (struct token); - read_token (op->token, c); + read_token (op->token, ch); op->type = t_symbol; last_non_comment_line = line_number; return; diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index a89f8e0a8..64cc4fd75 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -879,21 +879,23 @@ phase3_get (token_ty *tp) case '"': { struct mixed_string_buffer msb; - int c2 = phase1_getc (); + { + int c2 = phase1_getc (); - if (c2 == '"') - { - int c3 = phase1_getc (); - if (c3 == '"') - verbatim = true; - else - { - phase1_ungetc (c3); - phase1_ungetc (c2); - } - } - else - phase2_ungetc (c2); + if (c2 == '"') + { + int c3 = phase1_getc (); + if (c3 == '"') + verbatim = true; + else + { + phase1_ungetc (c3); + phase1_ungetc (c2); + } + } + else + phase2_ungetc (c2); + } /* Start accumulating the string. */ mixed_string_buffer_init (&msb, lc_string, diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index dedb0baef..cc30bfc94 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -518,19 +518,19 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) { /* Add best_cp->xcomments to mp->comment_dot, unless already present. */ - size_t i; + size_t j; - for (i = 0; i < best_cp->xcomments.nitems; i++) + for (j = 0; j < best_cp->xcomments.nitems; j++) { - const char *xcomment = best_cp->xcomments.item[i]; + const char *xcomment = best_cp->xcomments.item[j]; bool found = false; if (mp != NULL && mp->comment_dot != NULL) { - size_t j; + size_t k; - for (j = 0; j < mp->comment_dot->nitems; j++) - if (strcmp (xcomment, mp->comment_dot->item[j]) == 0) + for (k = 0; k < mp->comment_dot->nitems; k++) + if (strcmp (xcomment, mp->comment_dot->item[k]) == 0) { found = true; break;