]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Modernize coding style: Reduce scope of local variables.
authorBruno Haible <bruno@clisp.org>
Fri, 19 Dec 2025 20:46:43 +0000 (21:46 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 19 Dec 2025 20:46:48 +0000 (21:46 +0100)
* HACKING (Coding Style): New section, copied from gnulib/HACKING.
* gettext-runtime/src/envsubst.c: Reduce scope of local variables.
* gettext-runtime/src/escapes.h: Likewise.
* gettext-runtime/src/gettext.c: Likewise.
* gettext-runtime/src/ngettext.c: Likewise.
* gettext-runtime/src/printf-command.c: Likewise.
* gettext-runtime/src/printf_gettext.c: Likewise.
* gettext-runtime/src/printf_ngettext.c: Likewise.
* gnulib-local/lib/addext.c: Likewise.
* gnulib-local/lib/backupfile.c: Likewise.
* gnulib-local/lib/gettext.h: Likewise.
* gnulib-local/lib/markup.c: Likewise.
* gnulib-local/lib/xerror.c: Likewise.
* libtextstyle/gnulib-local/lib/file-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/html-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/html-styled-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/iconv-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/memory-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/term-ostream.oo.c: Likewise.
* libtextstyle/gnulib-local/lib/term-styled-ostream.oo.c: Likewise.
* libtextstyle/lib/color.c: Likewise.
* libtextstyle/lib/misc.c: Likewise.
* gettext-tools/src/cldr-plural-exp.c: Likewise.
* gettext-tools/src/cldr-plurals.c: Likewise.
* gettext-tools/src/file-list.c: Likewise.
* gettext-tools/src/filter-quote.c: Likewise.
* gettext-tools/src/format-awk.c: Likewise.
* gettext-tools/src/format-boost.c: Likewise.
* gettext-tools/src/format-c++-brace.c: Likewise.
* gettext-tools/src/format-c.c: Likewise.
* gettext-tools/src/format-c-parse.h: Likewise.
* gettext-tools/src/format-csharp.c: Likewise.
* gettext-tools/src/format-d.c: Likewise.
* gettext-tools/src/format-elisp.c: Likewise.
* gettext-tools/src/format-gcc-internal.c: Likewise.
* gettext-tools/src/format-gfc-internal.c: Likewise.
* gettext-tools/src/format-go.c: Likewise.
* gettext-tools/src/format-java-printf.c: Likewise.
* gettext-tools/src/format-java.c: Likewise.
* gettext-tools/src/format-javascript.c: Likewise.
* gettext-tools/src/format-kde-kuit.c: Likewise.
* gettext-tools/src/format-kde.c: Likewise.
* gettext-tools/src/format-librep.c: Likewise.
* gettext-tools/src/format-lisp.c: Likewise.
* gettext-tools/src/format-lua.c: Likewise.
* gettext-tools/src/format-modula2.c: Likewise.
* gettext-tools/src/format-ocaml.c: Likewise.
* gettext-tools/src/format-pascal.c: Likewise.
* gettext-tools/src/format-perl-brace.c: Likewise.
* gettext-tools/src/format-perl.c: Likewise.
* gettext-tools/src/format-php.c: Likewise.
* gettext-tools/src/format-python-brace.c: Likewise.
* gettext-tools/src/format-python.c: Likewise.
* gettext-tools/src/format-qt-plural.c: Likewise.
* gettext-tools/src/format-qt.c: Likewise.
* gettext-tools/src/format-ruby.c: Likewise.
* gettext-tools/src/format-rust.c: Likewise.
* gettext-tools/src/format-scheme.c: Likewise.
* gettext-tools/src/format-sh-printf.c: Likewise.
* gettext-tools/src/format-sh.c: Likewise.
* gettext-tools/src/format-smalltalk.c: Likewise.
* gettext-tools/src/format-tcl.c: Likewise.
* gettext-tools/src/format.c: Likewise.
* gettext-tools/src/hostname.c: Likewise.
* gettext-tools/src/if-error.c: Likewise.
* gettext-tools/src/its.c: Likewise.
* gettext-tools/src/locating-rules.c: Likewise.
* gettext-tools/src/message.c: Likewise.
* gettext-tools/src/msgattrib.c: Likewise.
* gettext-tools/src/msgcat.c: Likewise.
* gettext-tools/src/msgcmp.c: Likewise.
* gettext-tools/src/msgcomm.c: Likewise.
* gettext-tools/src/msgconv.c: Likewise.
* gettext-tools/src/msgen.c: Likewise.
* gettext-tools/src/msgexec.c: Likewise.
* gettext-tools/src/msgfilter.c: Likewise.
* gettext-tools/src/msgfmt.c: Likewise.
* gettext-tools/src/msggrep.c: Likewise.
* gettext-tools/src/msginit.c: Likewise.
* gettext-tools/src/msgl-ascii.c: Likewise.
* gettext-tools/src/msgl-cat.c: Likewise.
* gettext-tools/src/msgl-charset.c: Likewise.
* gettext-tools/src/msgl-check.c: Likewise.
* gettext-tools/src/msgl-english.c: Likewise.
* gettext-tools/src/msgl-equal.c: Likewise.
* gettext-tools/src/msgl-fsearch.c: Likewise.
* gettext-tools/src/msgl-header.c: Likewise.
* gettext-tools/src/msgl-iconv.c: Likewise.
* gettext-tools/src/msgl-merge.c: Likewise.
* gettext-tools/src/msgl-ofn.c: Likewise.
* gettext-tools/src/msgmerge.c: Likewise.
* gettext-tools/src/msgunfmt.c: Likewise.
* gettext-tools/src/msguniq.c: Likewise.
* gettext-tools/src/open-catalog.c: Likewise.
* gettext-tools/src/plural-count.c: Likewise.
* gettext-tools/src/po-charset.c: Likewise.
* gettext-tools/src/po-time.c: Likewise.
* gettext-tools/src/read-catalog.c: Likewise.
* gettext-tools/src/read-catalog-abstract.c: Likewise.
* gettext-tools/src/read-catalog-file.c: Likewise.
* gettext-tools/src/read-catalog-special.c: Likewise.
* gettext-tools/src/read-csharp.c: Likewise.
* gettext-tools/src/read-desktop.c: Likewise.
* gettext-tools/src/read-java.c: Likewise.
* gettext-tools/src/read-mo.c: Likewise.
* gettext-tools/src/read-po-lex.c: Likewise.
* gettext-tools/src/read-properties.c: Likewise.
* gettext-tools/src/read-resources.c: Likewise.
* gettext-tools/src/read-stringtable.c: Likewise.
* gettext-tools/src/read-tcl.c: Likewise.
* gettext-tools/src/recode-sr-latin.c: Likewise.
* gettext-tools/src/search-path.c: Likewise.
* gettext-tools/src/str-list.c: Likewise.
* gettext-tools/src/urlget.c: Likewise.
* gettext-tools/src/write-catalog.c: Likewise.
* gettext-tools/src/write-csharp.c: Likewise.
* gettext-tools/src/write-desktop.c: Likewise.
* gettext-tools/src/write-java.c: Likewise.
* gettext-tools/src/write-mo.c: Likewise.
* gettext-tools/src/write-po.c: Likewise.
* gettext-tools/src/write-properties.c: Likewise.
* gettext-tools/src/write-qt.c: Likewise.
* gettext-tools/src/write-resources.c: Likewise.
* gettext-tools/src/write-stringtable.c: Likewise.
* gettext-tools/src/write-tcl.c: Likewise.
* gettext-tools/src/write-xml.c: Likewise.
* gettext-tools/src/x-awk.c: Likewise.
* gettext-tools/src/x-c.c: Likewise.
* gettext-tools/src/x-csharp.c: Likewise.
* gettext-tools/src/x-d.c: Likewise.
* gettext-tools/src/x-desktop.c: Likewise.
* gettext-tools/src/x-elisp.c: Likewise.
* gettext-tools/src/x-go.c: Likewise.
* gettext-tools/src/x-java.c: Likewise.
* gettext-tools/src/x-javascript.c: Likewise.
* gettext-tools/src/x-librep.c: Likewise.
* gettext-tools/src/x-lisp.c: Likewise.
* gettext-tools/src/x-lua.c: Likewise.
* gettext-tools/src/x-modula2.c: Likewise.
* gettext-tools/src/x-ocaml.c: Likewise.
* gettext-tools/src/x-perl.c: Likewise.
* gettext-tools/src/x-php.c: Likewise.
* gettext-tools/src/x-po.c: Likewise.
* gettext-tools/src/x-python.c: Likewise.
* gettext-tools/src/x-rst.c: Likewise.
* gettext-tools/src/x-ruby.c: Likewise.
* gettext-tools/src/x-rust.c: Likewise.
* gettext-tools/src/x-scheme.c: Likewise.
* gettext-tools/src/x-sh.c: Likewise.
* gettext-tools/src/x-smalltalk.c: Likewise.
* gettext-tools/src/x-tcl.c: Likewise.
* gettext-tools/src/x-typescript-impl.h: Likewise.
* gettext-tools/src/x-vala.c: Likewise.
* gettext-tools/src/x-ycp.c: Likewise.
* gettext-tools/src/xerror-handler.c: Likewise.
* gettext-tools/src/xg-arglist-callshape.c: Likewise.
* gettext-tools/src/xg-arglist-context.c: Likewise.
* gettext-tools/src/xg-arglist-parser.c: Likewise.
* gettext-tools/src/xg-check.c: Likewise.
* gettext-tools/src/xg-encoding.c: Likewise.
* gettext-tools/src/xg-message.c: Likewise.
* gettext-tools/src/xg-mixed-string.c: Likewise.
* gettext-tools/src/xgettext.c: Likewise.

165 files changed:
HACKING
gettext-runtime/src/envsubst.c
gettext-runtime/src/escapes.h
gettext-runtime/src/gettext.c
gettext-runtime/src/ngettext.c
gettext-runtime/src/printf-command.c
gettext-runtime/src/printf_gettext.c
gettext-runtime/src/printf_ngettext.c
gettext-tools/src/cldr-plural-exp.c
gettext-tools/src/cldr-plurals.c
gettext-tools/src/file-list.c
gettext-tools/src/filter-quote.c
gettext-tools/src/format-awk.c
gettext-tools/src/format-boost.c
gettext-tools/src/format-c++-brace.c
gettext-tools/src/format-c-parse.h
gettext-tools/src/format-c.c
gettext-tools/src/format-csharp.c
gettext-tools/src/format-d.c
gettext-tools/src/format-elisp.c
gettext-tools/src/format-gcc-internal.c
gettext-tools/src/format-gfc-internal.c
gettext-tools/src/format-go.c
gettext-tools/src/format-java-printf.c
gettext-tools/src/format-java.c
gettext-tools/src/format-javascript.c
gettext-tools/src/format-kde-kuit.c
gettext-tools/src/format-kde.c
gettext-tools/src/format-librep.c
gettext-tools/src/format-lisp.c
gettext-tools/src/format-lua.c
gettext-tools/src/format-modula2.c
gettext-tools/src/format-ocaml.c
gettext-tools/src/format-pascal.c
gettext-tools/src/format-perl-brace.c
gettext-tools/src/format-perl.c
gettext-tools/src/format-php.c
gettext-tools/src/format-python-brace.c
gettext-tools/src/format-python.c
gettext-tools/src/format-qt-plural.c
gettext-tools/src/format-qt.c
gettext-tools/src/format-ruby.c
gettext-tools/src/format-rust.c
gettext-tools/src/format-scheme.c
gettext-tools/src/format-sh-printf.c
gettext-tools/src/format-sh.c
gettext-tools/src/format-smalltalk.c
gettext-tools/src/format-tcl.c
gettext-tools/src/format.c
gettext-tools/src/hostname.c
gettext-tools/src/if-error.c
gettext-tools/src/its.c
gettext-tools/src/locating-rules.c
gettext-tools/src/message.c
gettext-tools/src/msgattrib.c
gettext-tools/src/msgcat.c
gettext-tools/src/msgcmp.c
gettext-tools/src/msgcomm.c
gettext-tools/src/msgconv.c
gettext-tools/src/msgen.c
gettext-tools/src/msgexec.c
gettext-tools/src/msgfilter.c
gettext-tools/src/msgfmt.c
gettext-tools/src/msggrep.c
gettext-tools/src/msginit.c
gettext-tools/src/msgl-ascii.c
gettext-tools/src/msgl-cat.c
gettext-tools/src/msgl-charset.c
gettext-tools/src/msgl-check.c
gettext-tools/src/msgl-english.c
gettext-tools/src/msgl-equal.c
gettext-tools/src/msgl-fsearch.c
gettext-tools/src/msgl-header.c
gettext-tools/src/msgl-iconv.c
gettext-tools/src/msgl-merge.c
gettext-tools/src/msgl-ofn.c
gettext-tools/src/msgmerge.c
gettext-tools/src/msgunfmt.c
gettext-tools/src/msguniq.c
gettext-tools/src/open-catalog.c
gettext-tools/src/plural-count.c
gettext-tools/src/po-charset.c
gettext-tools/src/po-time.c
gettext-tools/src/read-catalog-abstract.c
gettext-tools/src/read-catalog-file.c
gettext-tools/src/read-catalog-special.c
gettext-tools/src/read-catalog.c
gettext-tools/src/read-csharp.c
gettext-tools/src/read-desktop.c
gettext-tools/src/read-java.c
gettext-tools/src/read-mo.c
gettext-tools/src/read-po-lex.c
gettext-tools/src/read-properties.c
gettext-tools/src/read-resources.c
gettext-tools/src/read-stringtable.c
gettext-tools/src/read-tcl.c
gettext-tools/src/recode-sr-latin.c
gettext-tools/src/search-path.c
gettext-tools/src/str-list.c
gettext-tools/src/urlget.c
gettext-tools/src/write-catalog.c
gettext-tools/src/write-csharp.c
gettext-tools/src/write-desktop.c
gettext-tools/src/write-java.c
gettext-tools/src/write-mo.c
gettext-tools/src/write-po.c
gettext-tools/src/write-properties.c
gettext-tools/src/write-qt.c
gettext-tools/src/write-resources.c
gettext-tools/src/write-stringtable.c
gettext-tools/src/write-tcl.c
gettext-tools/src/write-xml.c
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-csharp.c
gettext-tools/src/x-d.c
gettext-tools/src/x-desktop.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-go.c
gettext-tools/src/x-java.c
gettext-tools/src/x-javascript.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-lua.c
gettext-tools/src/x-modula2.c
gettext-tools/src/x-ocaml.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c
gettext-tools/src/x-po.c
gettext-tools/src/x-python.c
gettext-tools/src/x-rst.c
gettext-tools/src/x-ruby.c
gettext-tools/src/x-rust.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-smalltalk.c
gettext-tools/src/x-tcl.c
gettext-tools/src/x-typescript-impl.h
gettext-tools/src/x-vala.c
gettext-tools/src/x-ycp.c
gettext-tools/src/xerror-handler.c
gettext-tools/src/xg-arglist-callshape.c
gettext-tools/src/xg-arglist-context.c
gettext-tools/src/xg-arglist-parser.c
gettext-tools/src/xg-check.c
gettext-tools/src/xg-encoding.c
gettext-tools/src/xg-message.c
gettext-tools/src/xg-mixed-string.c
gettext-tools/src/xgettext.c
gnulib-local/lib/addext.c
gnulib-local/lib/backupfile.c
gnulib-local/lib/gettext.h
gnulib-local/lib/markup.c
gnulib-local/lib/xerror.c
libtextstyle/gnulib-local/lib/file-ostream.oo.c
libtextstyle/gnulib-local/lib/html-ostream.oo.c
libtextstyle/gnulib-local/lib/html-styled-ostream.oo.c
libtextstyle/gnulib-local/lib/iconv-ostream.oo.c
libtextstyle/gnulib-local/lib/memory-ostream.oo.c
libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.c
libtextstyle/gnulib-local/lib/ostream.oo.c
libtextstyle/gnulib-local/lib/term-ostream.oo.c
libtextstyle/gnulib-local/lib/term-styled-ostream.oo.c
libtextstyle/lib/color.c
libtextstyle/lib/misc.c

diff --git a/HACKING b/HACKING
index 40bbe46027048941f8fd38ad9d9c178df5b50ee2..6073d329d5336f5fa82db24812d1d57b23b9b950 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -461,6 +461,63 @@ build results here:
   https://gitlab.com/gnu-gettext/ci-distcheck/-/jobs?scope=finished
 
 
+Coding Style
+============
+
+For C source code:
+
+* Follow the portability guidelines
+  https://www.gnu.org/software/gnulib/manual/html_node/Portability-guidelines.html
+
+* Use mixed declarations and statements, as appropriate. (This is supported
+  since C99.)
+
+* Note: You can't put a label before a declaration, such as in
+    retry:
+      int foo = ...;
+  This is supported only in C23 or newer. Instead, add an empty statement:
+    retry: ;
+      int foo = ...;
+  Similarly, you can't put a declaration immediately after a case label, such
+  as in
+    case 1:
+      int foo = ...;
+      ...
+      break;
+  Again, this is supported only in C23 or newer. Instead, use a sub-block:
+    case 1:
+      {
+        int foo = ...;
+        ...
+      }
+      break;
+
+* In function definitions and blocks, the pre-C99 style "declare all variables
+  upfront" is discouraged.
+  Instead, the following style elements are encouraged (for local non-static
+  variables):
+    - Move the declaration of a variable to its initialization.
+    - Reduce the scope of variables:
+      . If a variable is only used in a sub-block, declare it in that sub-block.
+      . If a variable is only used in several sub-blocks and has a separate
+        initialization in each of the sub-blocks, declare it in each of these
+        sub-blocks. It's actually several independent variables.
+      . If a variable is only used in a small part of a function definition or
+        block (say, 1/3 of it or less), you may surround that part (including
+        the variable's initialization) with braces, so that it becomes clear
+        that the variable is not used in the rest of the function / block.
+    - Usually, try to declare and initialize variables right when they are
+      needed for the first time, not several computation steps before.
+  The rationale is:
+    - It follows the general principle "Put related things close together."
+    - A function with 3 blocks that each has 4 variables is easier to
+      understand than a function that has 12 variables, and where the
+      reader has to find out which variable is used where.
+    - Variables may represent state, and it is the state and the control flow
+      that contribute to the complexity of a function.
+  Only static variables are better kept declared upfront in a function or block.
+
+
 Submitting patches
 ==================
 
index 541e517497ace1c73fa2901b82b65fd9953237a2..76070ea737d3c68efff75187ec43fdd19fa4bf1d 100644 (file)
@@ -53,11 +53,6 @@ static void subst_from_stdin (void);
 int
 main (int argc, char *argv[])
 {
-  /* Default values for command line options.  */
-  bool show_variables = false;
-  bool do_help = false;
-  bool do_version = false;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -72,6 +67,11 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool show_variables = false;
+  bool do_help = false;
+  bool do_version = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -82,24 +82,26 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'v':
-        show_variables = true;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-      }
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'v':
+          show_variables = true;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -247,15 +249,12 @@ find_variables (const char *string,
   for (; *string != '\0';)
     if (*string++ == '$')
       {
-        const char *variable_start;
-        const char *variable_end;
-        bool valid;
-        char c;
-
         if (*string == '{')
           string++;
 
-        variable_start = string;
+        const char *variable_start = string;
+        char c;
+
         c = *string;
         if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
           {
@@ -263,8 +262,9 @@ find_variables (const char *string,
               c = *++string;
             while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
                    || (c >= '0' && c <= '9') || c == '_');
-            variable_end = string;
+            const char *variable_end = string;
 
+            bool valid;
             if (variable_start[-1] == '{')
               {
                 if (*string == '}')
@@ -328,10 +328,8 @@ string_list_append (string_list_ty *slp, const char *s)
   /* Grow the list.  */
   if (slp->nitems >= slp->nitems_max)
     {
-      size_t nbytes;
-
       slp->nitems_max = slp->nitems_max * 2 + 4;
-      nbytes = slp->nitems_max * sizeof (slp->item[0]);
+      size_t nbytes = slp->nitems_max * sizeof (slp->item[0]);
       slp->item = (const char **) xrealloc (slp->item, nbytes);
     }
 
@@ -361,9 +359,7 @@ string_list_sort (string_list_ty *slp)
 MAYBE_UNUSED static inline int
 string_list_member (const string_list_ty *slp, const char *s)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strcmp (slp->item[j], s) == 0)
       return 1;
   return 0;
@@ -373,10 +369,8 @@ string_list_member (const string_list_ty *slp, const char *s)
 static int
 sorted_string_list_member (const string_list_ty *slp, const char *s)
 {
-  size_t j1, j2;
-
-  j1 = 0;
-  j2 = slp->nitems;
+  size_t j1 = 0;
+  size_t j2 = slp->nitems;
   if (j2 > 0)
     {
       /* Binary search.  */
@@ -405,9 +399,7 @@ sorted_string_list_member (const string_list_ty *slp, const char *s)
 MAYBE_UNUSED static inline void
 string_list_destroy (string_list_ty *slp)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     free ((char *) slp->item[j]);
   if (slp->item != NULL)
     free (slp->item);
@@ -465,10 +457,10 @@ do_ungetc (int c)
 static void
 subst_from_stdin ()
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       c = do_getc ();
       if (c == EOF)
         break;
@@ -486,10 +478,8 @@ subst_from_stdin ()
             }
           if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
             {
-              struct string_buffer buffer;
-              bool valid;
-
               /* Accumulate the VARIABLE in buffer.  */
+              struct string_buffer buffer;
               sb_init (&buffer);
               do
                 {
@@ -499,6 +489,7 @@ subst_from_stdin ()
               while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
                      || (c >= '0' && c <= '9') || c == '_');
 
+              bool valid;
               if (opening_brace)
                 {
                   if (c == '}')
index 2af7375603cf2ff27993d2d5b79c3f0068d381f1..4b2b8e54cb2820c3191df85533a55b5f02fc9019 100644 (file)
@@ -1,6 +1,5 @@
 /* Expand escape sequences in a string.
-   Copyright (C) 1995-1997, 2000-2007, 2012, 2018-2020 Free Software
-   Foundation, Inc.
+   Copyright (C) 1995-1997, 2000-2007, 2012, 2018-2020, 2025 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, May 1995.
 
    This program is free software: you can redistribute it and/or modify
@@ -42,92 +41,90 @@ expand_escapes (const char *str, bool *backslash_c_seen)
       ++cp;
     }
 
-  {
-    char *retval = XNMALLOC (strlen (str), char);
+  char *retval = XNMALLOC (strlen (str), char);
 
-    memcpy (retval, str, cp - str);
-    {
-      char *rp = retval + (cp - str);
+  memcpy (retval, str, cp - str);
+  {
+    char *rp = retval + (cp - str);
 
-      do
-        {
-          /* Here cp[0] == '\\'.  */
-          switch (*++cp)
+    do
+      {
+        /* Here cp[0] == '\\'.  */
+        switch (*++cp)
+          {
+          case 'a':               /* alert */
+            *rp++ = '\a';
+            ++cp;
+            break;
+          case 'b':               /* backspace */
+            *rp++ = '\b';
+            ++cp;
+            break;
+          case 'f':               /* form feed */
+            *rp++ = '\f';
+            ++cp;
+            break;
+          case 'n':               /* new line */
+            *rp++ = '\n';
+            ++cp;
+            break;
+          case 'r':               /* carriage return */
+            *rp++ = '\r';
+            ++cp;
+            break;
+          case 't':               /* horizontal tab */
+            *rp++ = '\t';
+            ++cp;
+            break;
+          case 'v':               /* vertical tab */
+            *rp++ = '\v';
+            ++cp;
+            break;
+          case '\\':
+            *rp++ = '\\';
+            ++cp;
+            break;
+          case '0': case '1': case '2': case '3':
+          case '4': case '5': case '6': case '7':
             {
-            case 'a':               /* alert */
-              *rp++ = '\a';
-              ++cp;
-              break;
-            case 'b':               /* backspace */
-              *rp++ = '\b';
-              ++cp;
-              break;
-            case 'f':               /* form feed */
-              *rp++ = '\f';
-              ++cp;
-              break;
-            case 'n':               /* new line */
-              *rp++ = '\n';
-              ++cp;
-              break;
-            case 'r':               /* carriage return */
-              *rp++ = '\r';
-              ++cp;
-              break;
-            case 't':               /* horizontal tab */
-              *rp++ = '\t';
-              ++cp;
-              break;
-            case 'v':               /* vertical tab */
-              *rp++ = '\v';
-              ++cp;
-              break;
-            case '\\':
-              *rp++ = '\\';
-              ++cp;
-              break;
-            case '0': case '1': case '2': case '3':
-            case '4': case '5': case '6': case '7':
-              {
-                int ch = *cp++ - '0';
-
-                if (*cp >= '0' && *cp <= '7')
-                  {
-                    ch *= 8;
-                    ch += *cp++ - '0';
+              int ch = *cp++ - '0';
 
-                    if (*cp >= '0' && *cp <= '7')
-                      {
-                        ch *= 8;
-                        ch += *cp++ - '0';
-                      }
-                  }
-                *rp++ = ch;
-              }
-              break;
-            case 'c':
-              if (backslash_c_seen != NULL)
+              if (*cp >= '0' && *cp <= '7')
                 {
-                  *backslash_c_seen = true;
-                  ++cp;
-                  break;
+                  ch *= 8;
+                  ch += *cp++ - '0';
+
+                  if (*cp >= '0' && *cp <= '7')
+                    {
+                      ch *= 8;
+                      ch += *cp++ - '0';
+                    }
                 }
-              FALLTHROUGH;
-            default:
-              *rp++ = '\\';
-              break;
+              *rp++ = ch;
             }
+            break;
+          case 'c':
+            if (backslash_c_seen != NULL)
+              {
+                *backslash_c_seen = true;
+                ++cp;
+                break;
+              }
+            FALLTHROUGH;
+          default:
+            *rp++ = '\\';
+            break;
+          }
 
-          /* Find the next escape sequence.  */
-          while (cp[0] != '\0' && cp[0] != '\\')
-            *rp++ = *cp++;
-        }
-      while (cp[0] != '\0');
-
-      /* Terminate the resulting string.  */
-      *rp = '\0';
-    }
+        /* Find the next escape sequence.  */
+        while (cp[0] != '\0' && cp[0] != '\\')
+          *rp++ = *cp++;
+      }
+    while (cp[0] != '\0');
 
-    return retval;
+    /* Terminate the resulting string.  */
+    *rp = '\0';
   }
+
+  return retval;
 }
index 3409d095b790a1c357771c13314361eed6acd53a..a2d3a434b0d1baaff15d0e4d8b4caef27b9bf211 100644 (file)
@@ -52,18 +52,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char *argv[])
 {
-  const char *msgid;
-
-  /* Default values for command line options.  */
-  bool do_help = false;
-  bool do_shell = false;
-  bool do_version = false;
-  const char *domain = getenv ("TEXTDOMAIN");
-  const char *domaindir = getenv ("TEXTDOMAINDIR");
-  const char *context = NULL;
-  inhibit_added_newline = false;
-  do_expand = false;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -78,6 +66,16 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_shell = false;
+  bool do_version = false;
+  const char *domain = getenv ("TEXTDOMAIN");
+  const char *domaindir = getenv ("TEXTDOMAINDIR");
+  const char *context = NULL;
+  inhibit_added_newline = false;
+  do_expand = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -93,39 +91,41 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'c':
-        context = optarg;
-        break;
-      case 'd':
-        domain = optarg;
-        break;
-      case 'e':
-        do_expand = true;
-        break;
-      case 'E':
-        /* Ignore.  Just for compatibility.  */
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'n':
-        inhibit_added_newline = true;
-        break;
-      case 's':
-        do_shell = true;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-      }
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'c':
+          context = optarg;
+          break;
+        case 'd':
+          domain = optarg;
+          break;
+        case 'e':
+          do_expand = true;
+          break;
+        case 'E':
+          /* Ignore.  Just for compatibility.  */
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'n':
+          inhibit_added_newline = true;
+          break;
+        case 's':
+          do_shell = true;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -170,7 +170,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
             error (EXIT_FAILURE, 0, _("missing arguments"));
         }
 
-      msgid = argv[optind++];
+      const char *msgid = argv[optind++];
 
       /* Expand escape sequences if enabled.  */
       if (do_expand)
@@ -210,7 +210,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
           /* We have to simulate 'echo'.  All arguments are strings.  */
           do
             {
-              msgid = argv[optind++];
+              const char *msgid = argv[optind++];
 
               /* Expand escape sequences if enabled.  */
               if (do_expand)
index 2d7b104c33bf497043998fe623d7214870aea304..af9c7ac5ecdaede932d9e37ba948db08596891ae 100644 (file)
@@ -49,19 +49,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char *argv[])
 {
-  const char *msgid;
-  const char *msgid_plural;
-  const char *count;
-  unsigned long n;
-
-  /* Default values for command line options.  */
-  bool do_help = false;
-  bool do_version = false;
-  const char *domain = getenv ("TEXTDOMAIN");
-  const char *domaindir = getenv ("TEXTDOMAINDIR");
-  const char *context = NULL;
-  do_expand = false;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -76,6 +63,14 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  const char *domain = getenv ("TEXTDOMAIN");
+  const char *domaindir = getenv ("TEXTDOMAINDIR");
+  const char *context = NULL;
+  do_expand = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -89,33 +84,35 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'c':
-        context = optarg;
-        break;
-      case 'd':
-        domain = optarg;
-        break;
-      case 'e':
-        do_expand = true;
-        break;
-      case 'E':
-        /* Ignore.  Just for compatibility.  */
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-      }
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'c':
+          context = optarg;
+          break;
+        case 'd':
+          domain = optarg;
+          break;
+        case 'e':
+          do_expand = true;
+          break;
+        case 'E':
+          /* Ignore.  Just for compatibility.  */
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -157,13 +154,14 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
 
   /* Now the mandatory command line options.  */
-  msgid = argv[optind++];
-  msgid_plural = argv[optind++];
-  count = argv[optind++];
+  const char *msgid = argv[optind++];
+  const char *msgid_plural = argv[optind++];
+  const char *count = argv[optind++];
 
   if (optind != argc)
     abort ();
 
+  unsigned long n;
   {
     char *endp;
     unsigned long tmp_val;
index 92767bd5cd9dd39d668e1ef10b32b467c74ec33b..4d5cd6c3049648ee5d55af39dcdfa9365496f391 100644 (file)
@@ -441,9 +441,7 @@ apply_format_string (const struct format_string *fmts,
                      size_t argc, char *argv[])
 {
   size_t npieces = fmts->npieces;
-  size_t i;
-
-  for (i = 0; i < npieces; i++)
+  for (size_t i = 0; i < npieces; i++)
     {
       struct format_piece *piece = &fmts->pieces[i];
 
@@ -457,10 +455,10 @@ apply_format_string (const struct format_string *fmts,
       else
         {
           /* Convert and print an argument.  */
-          char *arg;
           char zero[2] = { '0', '\0' };
           char *empty = zero + 1;
 
+          char *arg;
           if (piece->arg_number - 1 < argc)
             arg = argv[piece->arg_number - 1];
           else
@@ -485,9 +483,9 @@ apply_format_string (const struct format_string *fmts,
                  multibyte character.  */
               {
                 mbstate_t state;
-                char32_t wc;
-
                 mbszero (&state);
+
+                char32_t wc;
                 size_t ret = mbrtoc32 (&wc, arg, strnlen1 (arg, MB_CUR_MAX), &state);
                 arg[(int) ret >= 0 ? ret : 1] = '\0';
               }
@@ -514,9 +512,9 @@ apply_format_string (const struct format_string *fmts,
                        Use the first first multibyte character, if arg starts
                        with a valid multibyte character.  */
                     mbstate_t state;
-                    char32_t wc;
-
                     mbszero (&state);
+
+                    char32_t wc;
                     size_t ret = mbrtoc32 (&wc, arg + 1, strnlen1 (arg + 1, MB_CUR_MAX), &state);
                     if ((int) ret > 0)
                       arg_value = wc;
@@ -582,9 +580,9 @@ apply_format_string (const struct format_string *fmts,
                        Use the first first multibyte character, if arg starts
                        with a valid multibyte character.  */
                     mbstate_t state;
-                    char32_t wc;
-
                     mbszero (&state);
+
+                    char32_t wc;
                     size_t ret = mbrtoc32 (&wc, arg + 1, strnlen1 (arg + 1, MB_CUR_MAX), &state);
                     if ((int) ret > 0)
                       arg_value = wc;
index e054c028519f3e80eb871cbd8bbec3af2b4a710b..85f0646a899b70c3e5c7efe685c48c61dff472d4 100644 (file)
@@ -48,13 +48,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char *argv[])
 {
-  /* Default values for command line options.  */
-  bool do_help = false;
-  bool do_version = false;
-  const char *domain = getenv ("TEXTDOMAIN");
-  const char *domaindir = getenv ("TEXTDOMAINDIR");
-  const char *context = NULL;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -69,6 +62,11 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  const char *context = NULL;
+
   /* Parse command line options.  */
   {
     BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -80,24 +78,26 @@ main (int argc, char *argv[])
     };
     END_ALLOW_OMITTING_FIELD_INITIALIZERS
     start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-    int optchar;
-    while ((optchar = get_next_option ()) != -1)
-      switch (optchar)
-        {
-        case '\0':          /* Long option with key == 0.  */
-          break;
-        case 'c':
-          context = optarg;
-          break;
-        case 'h':
-          do_help = true;
-          break;
-        case 'V':
-          do_version = true;
-          break;
-        default:
-          usage (EXIT_FAILURE);
-        }
+    {
+      int optchar;
+      while ((optchar = get_next_option ()) != -1)
+        switch (optchar)
+          {
+          case '\0':          /* Long option with key == 0.  */
+            break;
+          case 'c':
+            context = optarg;
+            break;
+          case 'h':
+            do_help = true;
+            break;
+          case 'V':
+            do_version = true;
+            break;
+          default:
+            usage (EXIT_FAILURE);
+          }
+    }
   }
 
   /* Version information is requested.  */
@@ -136,6 +136,10 @@ There is NO WARRANTY, to the extent permitted by law.\n\
      format string happens to consume a different number of arguments.  */
   size_t args_each_round = printf_consumed_arguments (format);
 
+  /* Consider the environment variables.  */
+  const char *domain = getenv ("TEXTDOMAIN");
+  const char *domaindir = getenv ("TEXTDOMAINDIR");
+
   if (domain != NULL && domain[0] != '\0')
     {
       /* Bind domain to appropriate directory.  */
index 30ae3e329a065d3773395f51ca2123b77d46b00e..169e9e6a5fce92ea48f79bd271e3e28377cfc685 100644 (file)
@@ -53,13 +53,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char *argv[])
 {
-  /* Default values for command line options.  */
-  bool do_help = false;
-  bool do_version = false;
-  const char *domain = getenv ("TEXTDOMAIN");
-  const char *domaindir = getenv ("TEXTDOMAINDIR");
-  const char *context = NULL;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -74,6 +67,11 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  const char *context = NULL;
+
   /* Parse command line options.  */
   {
     BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -85,24 +83,26 @@ main (int argc, char *argv[])
     };
     END_ALLOW_OMITTING_FIELD_INITIALIZERS
     start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-    int optchar;
-    while ((optchar = get_next_option ()) != -1)
-      switch (optchar)
-        {
-        case '\0':          /* Long option with key == 0.  */
-          break;
-        case 'c':
-          context = optarg;
-          break;
-        case 'h':
-          do_help = true;
-          break;
-        case 'V':
-          do_version = true;
-          break;
-        default:
-          usage (EXIT_FAILURE);
-        }
+    {
+      int optchar;
+      while ((optchar = get_next_option ()) != -1)
+        switch (optchar)
+          {
+          case '\0':          /* Long option with key == 0.  */
+            break;
+          case 'c':
+            context = optarg;
+            break;
+          case 'h':
+            do_help = true;
+            break;
+          case 'V':
+            do_version = true;
+            break;
+          default:
+            usage (EXIT_FAILURE);
+          }
+    }
   }
 
   /* Version information is requested.  */
@@ -165,6 +165,10 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       (args_consumed_1 >= args_consumed_2 ? args_consumed_1 : args_consumed_2);
   }
 
+  /* Consider the environment variables.  */
+  const char *domain = getenv ("TEXTDOMAIN");
+  const char *domaindir = getenv ("TEXTDOMAINDIR");
+
   if (domain != NULL && domain[0] != '\0')
     {
       /* Bind domain to appropriate directory.  */
index 0c8a9a270f5807e8c196ddc62bc5f36460e0690b..5a58abbd30c75078e106bfb4cadda1578ffa16eb 100644 (file)
@@ -110,8 +110,7 @@ eval_relation (struct cldr_plural_relation_ty *relation)
     case 'n': case 'i':
       {
         /* Coerce decimal values in ranges into integers.  */
-        size_t i;
-        for (i = 0; i < relation->ranges->nitems; i++)
+        for (size_t i = 0; i < relation->ranges->nitems; i++)
           {
             struct cldr_plural_range_ty *range = relation->ranges->items[i];
             if (range->start->type == CLDR_PLURAL_OPERAND_DECIMAL)
@@ -139,8 +138,7 @@ eval_relation (struct cldr_plural_relation_ty *relation)
            integer, turn relations whose operand is either 'f', 't',
            'v', or 'w' into a constant truth value.  */
         /* FIXME: check mod?  */
-        size_t i;
-        for (i = 0; i < relation->ranges->nitems; i++)
+        for (size_t i = 0; i < relation->ranges->nitems; i++)
           {
             struct cldr_plural_range_ty *range = relation->ranges->items[i];
             if ((relation->type == CLDR_PLURAL_RELATION_EQUAL
@@ -297,8 +295,7 @@ find_largest_number (struct cldr_plural_condition_ty *condition)
   else if (condition->type == CLDR_PLURAL_CONDITION_RELATION)
     {
       int number = 0;
-      size_t i;
-      for (i = 0; i < condition->value.relation->ranges->nitems; i++)
+      for (size_t i = 0; i < condition->value.relation->ranges->nitems; i++)
         {
           struct cldr_plural_operand_ty *operand;
 
@@ -328,12 +325,12 @@ apply_condition (struct cldr_plural_condition_ty *condition, int value)
   else if (condition->type == CLDR_PLURAL_CONDITION_RELATION)
     {
       struct cldr_plural_relation_ty *relation = condition->value.relation;
-      int number = value;
-      size_t i;
 
+      int number = value;
       if (relation->expression->mod > 0)
         number %= relation->expression->mod;
-      for (i = 0; i < relation->ranges->nitems; i++)
+
+      for (size_t i = 0; i < relation->ranges->nitems; i++)
         {
           struct cldr_plural_range_ty *range = relation->ranges->items[i];
           if (range->start->value.ival <= number
@@ -362,11 +359,10 @@ print_relation (struct cldr_plural_relation_ty *relation,
 {
   if (relation->type == CLDR_PLURAL_RELATION_EQUAL)
     {
-      size_t i;
       if (parent == CLDR_PLURAL_CONDITION_AND
           && relation->ranges->nitems > 1)
         fputc ('(', fp);
-      for (i = 0; i < relation->ranges->nitems; i++)
+      for (size_t i = 0; i < relation->ranges->nitems; i++)
         {
           struct cldr_plural_range_ty *range = relation->ranges->items[i];
           if (i > 0)
@@ -405,11 +401,10 @@ print_relation (struct cldr_plural_relation_ty *relation,
     }
   else
     {
-      size_t i;
       if (parent == CLDR_PLURAL_CONDITION_OR
           && relation->ranges->nitems > 1)
         fputc ('(', fp);
-      for (i = 0; i < relation->ranges->nitems; i++)
+      for (size_t i = 0; i < relation->ranges->nitems; i++)
         {
           struct cldr_plural_range_ty *range = relation->ranges->items[i];
           if (i > 0)
@@ -554,13 +549,8 @@ static print_condition_function_ty print_condition_functions[] =
 void
 cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
 {
-  size_t i;
-  size_t count;
-  size_t nplurals;
-  int modulus_max = 0;
-
   /* Prune trivial conditions.  */
-  for (i = 0; i < rules->nitems; i++)
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       struct cldr_plural_rule_ty *rule = rules->items[i];
       eval_condition (rule->condition);
@@ -575,7 +565,8 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
         corresponding bit if it evaluates true  */
 
   /* Find the largest modulus.  */
-  for (i = 0; i < rules->nitems; i++)
+  int modulus_max = 0;
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       struct cldr_plural_rule_ty *rule = rules->items[i];
       int modulus = find_largest_modulus (rule->condition);
@@ -590,14 +581,14 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
   if (modulus_max > 0)
     {
       bool *values = XNMALLOC (modulus_max, bool);
-
       memset (values, 0, sizeof (bool) * modulus_max);
+
+      size_t i;
       for (i = 0; i < rules->nitems; i++)
         {
           struct cldr_plural_rule_ty *rule = rules->items[i];
-          int j;
 
-          for (j = 0; j < modulus_max; j++)
+          for (int j = 0; j < modulus_max; j++)
             {
               bool result = apply_condition (rule->condition, j + 1);
               if (result)
@@ -605,6 +596,7 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
             }
 
           /* Check if all bits are set.  Then we can omit one more rule.  */
+          int j;
           for (j = 0; j < modulus_max; j++)
             if (values[j] == false)
               break;
@@ -618,7 +610,8 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
         cldr_plural_rule_free (rules->items[--rules->nitems]);
     }
 
-  for (i = 0, nplurals = 1; i < rules->nitems; i++)
+  size_t nplurals = 1;
+  for (size_t i = 0; i < rules->nitems; i++)
     if (RULE_PRINTABLE_P (rules->items[i]))
       nplurals++;
 
@@ -632,22 +625,21 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
   /* If we have only one printable rule, apply some heuristics.  */
   if (nplurals == 2)
     {
-      struct cldr_plural_condition_ty *condition;
-      size_t j;
-
-      for (j = 0; j < rules->nitems; j++)
-        if (RULE_PRINTABLE_P (rules->items[j]))
+      size_t i;
+      for (i = 0; i < rules->nitems; i++)
+        if (RULE_PRINTABLE_P (rules->items[i]))
           break;
 
-      condition = rules->items[j]->condition;
-      for (j = 0; j < SIZEOF (print_condition_functions); j++)
+      struct cldr_plural_condition_ty *condition = rules->items[i]->condition;
+      for (size_t j = 0; j < SIZEOF (print_condition_functions); j++)
         if (print_condition_functions[j] (condition, fp))
           return;
     }
 
   /* If there are more printable rules, build a ternary operator.  */
   fprintf (fp, "nplurals=%lu; plural=(", (unsigned long) nplurals);
-  for (i = 0, count = 0; i < rules->nitems; i++)
+  size_t count = 0;
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       struct cldr_plural_rule_ty *rule = rules->items[i];
       if (print_condition (rule->condition,
@@ -657,9 +649,7 @@ cldr_plural_rule_list_print (struct cldr_plural_rule_list_ty *rules, FILE *fp)
           && rules->nitems > 1)
         {
           bool printable_left = false;
-          size_t j;
-
-          for (j = i + 1; j < rules->nitems; j++)
+          for (size_t j = i + 1; j < rules->nitems; j++)
             if (RULE_PRINTABLE_P (rules->items[j]))
               printable_left = true;
 
index acddd0ff36cc3bf7526d82d9a936569fd01925ed..5a5b81fe7f5cb601fe379a3e9a77a86bc786d73b 100644 (file)
@@ -44,21 +44,17 @@ extract_rules (FILE *fp,
                const char *real_filename, const char *logical_filename,
                const char *locale)
 {
-  xmlDocPtr doc;
-  xmlNodePtr node, n;
-  size_t locale_length;
-  struct string_buffer buffer;
-
-  sb_init (&buffer);
-
-  doc = xmlReadFd (fileno (fp), logical_filename, NULL,
-                   XML_PARSE_NONET
-                   | XML_PARSE_NOWARNING
-                   | XML_PARSE_NOBLANKS);
+  xmlDocPtr doc = xmlReadFd (fileno (fp), logical_filename, NULL,
+                             XML_PARSE_NONET
+                             | XML_PARSE_NOWARNING
+                             | XML_PARSE_NOBLANKS);
   if (doc == NULL)
     error (EXIT_FAILURE, 0, _("Could not parse file %s as XML"), logical_filename);
 
-  node = xmlDocGetRootElement (doc);
+  struct string_buffer buffer;
+  sb_init (&buffer);
+
+  xmlNode *node = xmlDocGetRootElement (doc);
   if (!node || !xmlStrEqual (node->name, BAD_CAST "supplementalData"))
     {
       error_at_line (0, 0,
@@ -69,83 +65,84 @@ extract_rules (FILE *fp,
       goto out;
     }
 
-  for (n = node->children; n; n = n->next)
-    {
-      if (n->type == XML_ELEMENT_NODE
-          && xmlStrEqual (n->name, BAD_CAST "plurals"))
-        break;
-    }
-  if (!n)
-    {
-      error (0, 0, _("The element <%s> does not contain a <%s> element"),
-             "supplementalData", "plurals");
-      goto out;
-    }
+  {
+    xmlNode *n;
 
-  locale_length = strlen (locale);
-  for (n = n->children; n; n = n->next)
-    {
-      xmlChar *locales;
-      xmlChar *cp;
-      xmlNodePtr n2;
-      bool found = false;
+    for (n = node->children; n; n = n->next)
+      {
+        if (n->type == XML_ELEMENT_NODE
+            && xmlStrEqual (n->name, BAD_CAST "plurals"))
+          break;
+      }
+    if (!n)
+      {
+        error (0, 0, _("The element <%s> does not contain a <%s> element"),
+               "supplementalData", "plurals");
+        goto out;
+      }
 
-      if (n->type == XML_ELEMENT_NODE
-          && xmlStrEqual (n->name, BAD_CAST "pluralRules"))
-        {
-          if (!xmlHasProp (n, BAD_CAST "locales"))
-            {
+    size_t locale_length = strlen (locale);
+    for (n = n->children; n; n = n->next)
+      {
+        if (n->type == XML_ELEMENT_NODE
+            && xmlStrEqual (n->name, BAD_CAST "pluralRules"))
+          {
+            if (!xmlHasProp (n, BAD_CAST "locales"))
               error_at_line (0, 0,
                              logical_filename,
                              xmlGetLineNo (n),
                              _("The element <%s> does not have attribute <%s>"),
                              "pluralRules", "locales");
-            }
-          else
-            {
-              cp = locales = xmlGetProp (n, BAD_CAST "locales");
-              while (*cp != '\0')
+            else
+              {
+                xmlChar *locales = xmlGetProp (n, BAD_CAST "locales");
+                bool found = false;
                 {
-                  while (c_isspace (*cp))
-                    cp++;
-                  if (xmlStrncmp (cp, BAD_CAST locale, locale_length) == 0
-                      && (*(cp + locale_length) == '\0'
-                          || c_isspace (*(cp + locale_length))))
+                  xmlChar *cp = locales;
+                  while (*cp != '\0')
                     {
-                      found = true;
-                      break;
+                      while (c_isspace (*cp))
+                        cp++;
+                      if (xmlStrncmp (cp, BAD_CAST locale, locale_length) == 0
+                          && (*(cp + locale_length) == '\0'
+                              || c_isspace (*(cp + locale_length))))
+                        {
+                          found = true;
+                          break;
+                        }
+                      while (*cp && !c_isspace (*cp))
+                        cp++;
                     }
-                  while (*cp && !c_isspace (*cp))
-                    cp++;
                 }
-              xmlFree (locales);
-
-              if (found)
-                for (n2 = n->children; n2; n2 = n2->next)
-                  {
-                    if (n2->type == XML_ELEMENT_NODE
-                        && xmlStrEqual (n2->name, BAD_CAST "pluralRule"))
-                      {
-                        if (!xmlHasProp (n2, BAD_CAST "count"))
-                          {
-                            error_at_line (0, 0,
-                                           logical_filename,
-                                           xmlGetLineNo (n2),
-                                           _("The element <%s> does not have attribute <%s>"),
-                                           "pluralRule", "count");
-                            break;
-                          }
-
-                        xmlChar *count = xmlGetProp (n2, BAD_CAST "count");
-                        xmlChar *content = xmlNodeGetContent (n2);
-                        sb_xappendf (&buffer, "%s: %s; ", count, content);
-                        xmlFree (count);
-                        xmlFree (content);
-                      }
-                  }
-            }
-        }
-    }
+                xmlFree (locales);
+
+                if (found)
+                  for (xmlNode *n2 = n->children; n2; n2 = n2->next)
+                    {
+                      if (n2->type == XML_ELEMENT_NODE
+                          && xmlStrEqual (n2->name, BAD_CAST "pluralRule"))
+                        {
+                          if (!xmlHasProp (n2, BAD_CAST "count"))
+                            {
+                              error_at_line (0, 0,
+                                             logical_filename,
+                                             xmlGetLineNo (n2),
+                                             _("The element <%s> does not have attribute <%s>"),
+                                             "pluralRule", "count");
+                              break;
+                            }
+
+                          xmlChar *count = xmlGetProp (n2, BAD_CAST "count");
+                          xmlChar *content = xmlNodeGetContent (n2);
+                          sb_xappendf (&buffer, "%s: %s; ", count, content);
+                          xmlFree (count);
+                          xmlFree (content);
+                        }
+                    }
+              }
+          }
+      }
+  }
 
   {
     /* Scrub the last semicolon, if any.  */
@@ -211,10 +208,6 @@ or by email to <%s>.\n"),
 int
 main (int argc, char **argv)
 {
-  bool opt_cldr_format = false;
-  bool do_help = false;
-  bool do_version = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
 
@@ -230,6 +223,11 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool opt_cldr_format = false;
+  bool do_help = false;
+  bool do_version = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -240,29 +238,31 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
 
-      case 'c':
-        opt_cldr_format = true;
-        break;
+        case 'c':
+          opt_cldr_format = true;
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+        default:
+          usage (EXIT_FAILURE);
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -289,30 +289,27 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       /* Two arguments: Read CLDR rules from a file.  */
       const char *locale = argv[optind];
       const char *logical_filename = argv[optind + 1];
-      char *extracted_rules;
-      FILE *fp;
 
       LIBXML_TEST_VERSION
 
-      fp = fopen (logical_filename, "r");
+      FILE *fp = fopen (logical_filename, "r");
       if (fp == NULL)
-        error (1, 0, _("%s cannot be read"), logical_filename);
+        error (EXIT_FAILURE, 0, _("%s cannot be read"), logical_filename);
 
-      extracted_rules = extract_rules (fp, logical_filename, logical_filename,
-                                       locale);
+      char *extracted_rules =
+        extract_rules (fp, logical_filename, logical_filename, locale);
       fclose (fp);
       if (extracted_rules == NULL)
-        error (1, 0, _("cannot extract rules for %s"), locale);
+        error (EXIT_FAILURE, 0, _("cannot extract rules for %s"), locale);
 
       if (opt_cldr_format)
         printf ("%s\n", extracted_rules);
       else
         {
-          struct cldr_plural_rule_list_ty *result;
-
-          result = cldr_plural_parse (extracted_rules);
+          struct cldr_plural_rule_list_ty *result =
+            cldr_plural_parse (extracted_rules);
           if (result == NULL)
-            error (1, 0, _("cannot parse CLDR rule"));
+            error (EXIT_FAILURE, 0, _("cannot parse CLDR rule"));
 
           cldr_plural_rule_list_print (result, stdout);
           cldr_plural_rule_list_free (result);
@@ -326,16 +323,13 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       size_t line_size = 0;
       for (;;)
         {
-          int line_len;
-          struct cldr_plural_rule_list_ty *result;
-
-          line_len = getline (&line, &line_size, stdin);
+          int line_len = getline (&line, &line_size, stdin);
           if (line_len < 0)
             break;
           if (line_len > 0 && line[line_len - 1] == '\n')
             line[--line_len] = '\0';
 
-          result = cldr_plural_parse (line);
+          struct cldr_plural_rule_list_ty *result = cldr_plural_parse (line);
           if (result)
             {
               cldr_plural_rule_list_print (result, stdout);
@@ -347,7 +341,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
   else
     {
-      error (1, 0, _("extra operand %s"), argv[optind]);
+      error (EXIT_FAILURE, 0, _("extra operand %s"), argv[optind]);
     }
 
   return 0;
index 44fc475d95c6b2822f7a19e9f285d55ca9bf5c45..9d9f54e4054b68cb2ac10d57d330f510d8af7acf 100644 (file)
 string_list_ty *
 read_names_from_file (const char *file_name)
 {
-  size_t line_len = 0;
-  char *line_buf = NULL;
   FILE *fp;
-  string_list_ty *result;
-
   if (strcmp (file_name, "-") == 0)
     fp = stdin;
   else
@@ -51,8 +47,10 @@ read_names_from_file (const char *file_name)
                _("error while opening \"%s\" for reading"), file_name);
     }
 
-  result = string_list_alloc ();
+  string_list_ty *result = string_list_alloc ();
 
+  size_t line_len = 0;
+  char *line_buf = NULL;
   while (!feof (fp))
     {
       /* Read next line from file.  */
index e0f7b167d0955ca69903cac4adf68aad15c0ca1c..7f9c1270f12b59ffc95573a0bd0dbf2df5e9ea85 100644 (file)
@@ -99,13 +99,9 @@ convert_ascii_quote_to_unicode (const char *input, size_t input_len,
                                 char **output_p, size_t *output_len_p,
                                 bool bold)
 {
-  const char *p;
-  size_t quote_count;
-  struct result result;
-
   /* Count the number of quotation characters.  */
-  quote_count = 0;
-  for (p = input; p < input + input_len; p++)
+  size_t quote_count = 0;
+  for (const char *p = input; p < input + input_len; p++)
     {
       size_t len;
 
@@ -119,6 +115,7 @@ convert_ascii_quote_to_unicode (const char *input, size_t input_len,
     }
 
   /* Large enough.  */
+  struct result result;
   result.output = XNMALLOC (input_len - quote_count
                             + (bold ? 7 : 3) * quote_count + 1,
                             char);
index 3ca648bb4c838aebbb70d719138bf51e2af71cfa..37011da97578bdbea18726894a03919f3923454c 100644 (file)
@@ -93,30 +93,25 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
+        size_t number = 0;
         if (c_isdigit (*format))
           {
             const char *f = format;
@@ -154,10 +149,9 @@ format_parse (const char *format, bool translated, char *fdi,
         /* Parse width.  */
         if (*format == '*')
           {
-            size_t width_number = 0;
-
             format++;
 
+            size_t width_number = 0;
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -239,10 +233,9 @@ format_parse (const char *format, bool translated, char *fdi,
 
             if (*format == '*')
               {
-                size_t precision_number = 0;
-
                 format++;
 
+                size_t precision_number = 0;
                 if (c_isdigit (*format))
                   {
                     const char *f = format;
@@ -318,6 +311,7 @@ format_parse (const char *format, bool translated, char *fdi,
               }
           }
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -412,21 +406,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -456,7 +448,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -503,68 +495,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
+              {
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -592,8 +589,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -602,8 +597,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -645,18 +640,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 314a45de5bc7928ddaeecdec37e0c0b0dad8ded5..46f70d4ff18e1c3fe9620c7824edbbfb7202e0bb 100644 (file)
@@ -114,43 +114,39 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
         if (*format == '%')
           format++;
         else
           {
-            bool brackets = false;
             bool done = false;
-            size_t number = 0;
             enum format_arg_type type = FAT_NONE;
 
+            bool brackets = false;
             if (*format == '|')
               {
                 format++;
                 brackets = true;
               }
 
+            size_t number = 0;
             if (c_isdigit (*format) && *format != '0')
               {
                 const char *f = format;
@@ -520,21 +516,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2 || type2 == FAT_ANY)
               type_both = type1;
             else if (type1 == FAT_ANY)
@@ -566,7 +560,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -613,68 +607,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -702,8 +701,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -712,8 +709,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -755,18 +752,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 5c59be038f71e991f4af0bdf6714b39665445994..a796b0bd389effbe9e1d10da4223c7187f28ee38 100644 (file)
@@ -208,16 +208,13 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
@@ -233,14 +230,6 @@ format_parse (const char *format, bool translated, char *fdi,
           {
             /* A replacement field.  */
             size_t arg_array_index;
-            bool have_sign = false;
-            bool have_hash_flag = false;
-            bool have_zero_flag = false;
-            bool have_precision = false;
-            bool have_L_flag = false;
-            char type_spec;
-            unsigned int type;
-            unsigned int presentation;
 
             /* Parse arg-id.  */
             if (c_isdigit (*format))
@@ -309,8 +298,8 @@ format_parse (const char *format, bool translated, char *fdi,
                 unnumbered_arg_count++;
               }
 
-            type = FAT_ANY;
-            presentation = 0;
+            unsigned int type = FAT_ANY;
+            unsigned int presentation = 0;
 
             if (*format == ':')
               {
@@ -326,6 +315,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   format++;
 
                 /* Parse sign.  */
+                bool have_sign = false;
                 if (*format == '+' || *format == '-' || *format == ' ')
                   {
                     format++;
@@ -333,6 +323,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
 
                 /* Parse '#' flag.  */
+                bool have_hash_flag = false;
                 if (*format == '#')
                   {
                     format++;
@@ -340,6 +331,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
 
                 /* Parse '0' flag.  */
+                bool have_zero_flag = false;
                 if (*format == '0')
                   {
                     format++;
@@ -435,6 +427,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
 
                 /* Parse precision.  */
+                bool have_precision = false;
                 if (*format == '.')
                   {
                     format++;
@@ -534,6 +527,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
 
                 /* Parse 'L' flag.  */
+                bool have_L_flag = false;
                 if (*format == 'L')
                   {
                     format++;
@@ -541,7 +535,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
 
                 /* Parse type.  */
-                type_spec = '\0';
+                char type_spec = '\0';
                 if (*format != '\0' && *format != '}')
                   {
                     type_spec = *format;
@@ -785,19 +779,18 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             unsigned int type1 = spec.numbered[i].type;
             unsigned int type2 = spec.numbered[j-1].type;
+
             unsigned int type_both = type1 & type2;
 
             if (type_both == FAT_NONE)
@@ -829,7 +822,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -927,86 +920,91 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check that the argument types are not being restricted in the msgstr,
-         and that the presentation does not get changed in the msgstr.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                unsigned int type_difference = spec1->numbered[i].type & ~spec2->numbered[j].type;
-                if (type_difference != 0)
-                  {
-                    if (error_logger)
-                      {
-                        char buf[MAX_TYPE_DESCRIPTION_LEN];
-                        get_type_description (buf, type_difference);
-                        error_logger (error_logger_data,
-                                      _("The format specification for argument %zu in '%s' is applicable to the types %s, but the format specification for argument %zu in '%s' is not."),
-                                      spec1->numbered[i].number, pretty_msgid, buf,
-                                      spec2->numbered[j].number, pretty_msgstr);
-                      }
-                    err = true;
-                    break;
-                  }
-                unsigned int presentation_difference =
-                  spec2->numbered[j].presentation & ~spec1->numbered[i].presentation;
-                if (presentation_difference != 0)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("The format specification for argument %zu in '%s' uses a different presentation than the format specification for argument %zu in '%s'."),
-                                    spec2->numbered[j].number, pretty_msgstr,
-                                    spec1->numbered[i].number, pretty_msgid);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check that the argument types are not being restricted in the msgstr,
+         and that the presentation does not get changed in the msgstr.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  unsigned int type_difference = spec1->numbered[i].type & ~spec2->numbered[j].type;
+                  if (type_difference != 0)
+                    {
+                      if (error_logger)
+                        {
+                          char buf[MAX_TYPE_DESCRIPTION_LEN];
+                          get_type_description (buf, type_difference);
+                          error_logger (error_logger_data,
+                                        _("The format specification for argument %zu in '%s' is applicable to the types %s, but the format specification for argument %zu in '%s' is not."),
+                                        spec1->numbered[i].number, pretty_msgid, buf,
+                                        spec2->numbered[j].number, pretty_msgstr);
+                        }
+                      err = true;
+                      break;
+                    }
+                  unsigned int presentation_difference =
+                    spec2->numbered[j].presentation & ~spec1->numbered[i].presentation;
+                  if (presentation_difference != 0)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("The format specification for argument %zu in '%s' uses a different presentation than the format specification for argument %zu in '%s'."),
+                                      spec2->numbered[j].number, pretty_msgstr,
+                                      spec1->numbered[i].number, pretty_msgid);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -1034,8 +1032,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -1044,11 +1040,10 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
-      char buf[MAX_TYPE_DESCRIPTION_LEN];
 
       if (i > 0)
         printf (" ");
@@ -1056,8 +1051,11 @@ format_print (void *descr)
         abort ();
       for (; last < number; last++)
         printf ("_ ");
-      get_type_description (buf, spec->numbered[i].type);
-      printf ("%s", buf);
+      {
+        char buf[MAX_TYPE_DESCRIPTION_LEN];
+        get_type_description (buf, spec->numbered[i].type);
+        printf ("%s", buf);
+      }
       last = number + 1;
     }
   printf (")");
@@ -1070,18 +1068,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 66cc808c982b9805cbc639d38789a9a3993d45ef..54e5a891eb84004506622b242f24c8e8b1d4c347 100644 (file)
@@ -181,11 +181,8 @@ format_parse_entrails (const char *format, bool translated,
                        struct spec *result)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_arg_count;
-  struct numbered_arg *numbered;
-  size_t allocated;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.unnumbered_arg_count = 0;
@@ -193,26 +190,20 @@ format_parse_entrails (const char *format, bool translated,
   spec.unlikely_intentional = false;
   spec.sysdep_directives_count = 0;
   spec.sysdep_directives = NULL;
-  numbered_arg_count = 0;
-  numbered = NULL;
-  allocated = 0;
+  size_t numbered_arg_count = 0;
+  struct numbered_arg *numbered = NULL;
+  size_t allocated = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.unnumbered_arg_count == 0 || numbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        format_arg_type_t type;
-        /* Relevant for the conversion characters d, i, b, o, u, x, X, n.  */
-        format_arg_type_t integer_size;
-        /* Relevant for the conversion characters a, A, e, E, f, F, g, G.  */
-        format_arg_type_t floatingpoint_size;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
+        size_t number = 0;
         if (c_isdigit (*format))
           {
             const char *f = format;
@@ -436,6 +427,8 @@ format_parse_entrails (const char *format, bool translated,
               }
           }
 
+        format_arg_type_t type;
+
         if (!SYSDEP_SEGMENTS_PROCESSED && *format == '<')
           {
             spec.sysdep_directives =
@@ -608,6 +601,11 @@ format_parse_entrails (const char *format, bool translated,
           }
         else
           {
+            /* Relevant for the conversion characters d, i, b, o, u, x, X, n.  */
+            format_arg_type_t integer_size;
+            /* Relevant for the conversion characters a, A, e, E, f, F, g, G.  */
+            format_arg_type_t floatingpoint_size;
+
             /* Parse size.  */
             integer_size = 0;
             floatingpoint_size = 0;
@@ -879,21 +877,19 @@ format_parse_entrails (const char *format, bool translated,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (numbered, numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < numbered_arg_count; i++)
         if (j > 0 && numbered[i].number == numbered[j-1].number)
           {
             format_arg_type_t type1 = numbered[i].type;
             format_arg_type_t type2 = numbered[j-1].type;
-            format_arg_type_t type_both;
 
+            format_arg_type_t type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -927,9 +923,7 @@ format_parse_entrails (const char *format, bool translated,
      numbered one.  */
   if (numbered_arg_count > 0)
     {
-      size_t i;
-
-      for (i = 0; i < numbered_arg_count; i++)
+      for (size_t i = 0; i < numbered_arg_count; i++)
         if (numbered[i].number != i + 1)
           {
             *invalid_reason = INVALID_IGNORED_ARGUMENT (numbered[i].number, i + 1);
@@ -942,7 +936,7 @@ format_parse_entrails (const char *format, bool translated,
       allocated = spec.unnumbered_arg_count;
       spec.unnumbered = XNMALLOC (allocated, struct unnumbered_arg);
       IF_OOM (spec.unnumbered, goto bad_format;)
-      for (i = 0; i < spec.unnumbered_arg_count; i++)
+      for (size_t i = 0; i < spec.unnumbered_arg_count; i++)
         spec.unnumbered[i].type = numbered[i].type;
       free (numbered);
       numbered_arg_count = 0;
index 0ce64306f848733ef5c4dbe7948083b654389944..cb2514a20409ee3e3921521ca22f0f4a0a3534c8 100644 (file)
@@ -63,9 +63,8 @@ format_parse (const char *format, bool translated, bool objc_extensions,
               char *fdi, char **invalid_reason)
 {
   struct spec result_buf;
-  struct spec *result;
-
-  result = format_parse_entrails (format, translated, objc_extensions, fdi, invalid_reason, &result_buf);
+  struct spec *result =
+    format_parse_entrails (format, translated, objc_extensions, fdi, invalid_reason, &result_buf);
 
   if (result != NULL)
     {
@@ -127,7 +126,6 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
   struct spec *spec1 = (struct spec *) msgid_descr;
   struct spec *spec2 = (struct spec *) msgstr_descr;
   bool err = false;
-  size_t i;
 
   /* Check the argument types are the same.  */
   if (equality
@@ -141,7 +139,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
       err = true;
     }
   else
-    for (i = 0; i < spec2->unnumbered_arg_count; i++)
+    for (size_t i = 0; i < spec2->unnumbered_arg_count; i++)
       if (spec1->unnumbered[i].type != spec2->unnumbered[i].type)
         {
           if (error_logger)
@@ -191,9 +189,8 @@ get_sysdep_c_format_directives (const char *string, bool translated,
     {
       size_t n = descr->sysdep_directives_count;
       struct interval *intervals = XNMALLOC (n, struct interval);
-      size_t i;
 
-      for (i = 0; i < n; i++)
+      for (size_t i = 0; i < n; i++)
         {
           intervals[i].startpos = descr->sysdep_directives[2 * i] - string;
           intervals[i].endpos = descr->sysdep_directives[2 * i + 1] - string;
@@ -225,7 +222,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -234,7 +230,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->unnumbered_arg_count; i++)
+  for (size_t i = 0; i < spec->unnumbered_arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -344,18 +340,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_c_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_c_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 4bcb741f050902652293337ea74b2b1f97fc03b8..7128620183fefef3e3eead12e7ea370a3e66066b 100644 (file)
@@ -55,9 +55,8 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.numbered_arg_count = 0;
 
@@ -73,10 +72,9 @@ format_parse (const char *format, bool translated, char *fdi,
           else
             {
               /* A directive.  */
-              size_t number;
-
               spec.directives++;
 
+              size_t number;
               if (!c_isdigit (*format))
                 {
                   *invalid_reason =
@@ -162,7 +160,7 @@ format_parse (const char *format, bool translated, char *fdi,
         }
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -229,7 +227,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -238,7 +235,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -254,18 +251,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 599f993706b6323ef3c69672ff1430d3aa3700e5..7ef695e0ca875f8411333724158753f564d7409f 100644 (file)
@@ -187,26 +187,33 @@ verify_element (const struct format_arg * e)
 static void
 verify_list (const struct format_arg_list *list)
 {
-  size_t i;
-  size_t total_repcount;
-
   ASSERT (list->initial.count <= list->initial.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->initial.count; i++)
-    {
-      verify_element (&list->initial.element[i]);
-      total_repcount += list->initial.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->initial.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->initial.count; i++)
+      {
+        verify_element (&list->initial.element[i]);
+        total_repcount += list->initial.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->initial.length);
+  }
 
   ASSERT (list->repeated.count <= list->repeated.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->repeated.count; i++)
-    {
-      verify_element (&list->repeated.element[i]);
-      total_repcount += list->repeated.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->repeated.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->repeated.count; i++)
+      {
+        verify_element (&list->repeated.element[i]);
+        total_repcount += list->repeated.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->repeated.length);
+  }
 }
 
 /* Assertion macro.  Could be defined to empty for speed.  */
@@ -228,14 +235,12 @@ free_element (struct format_arg *element)
 static void
 free_list (struct format_arg_list *list)
 {
-  size_t i;
-
-  for (i = 0; i < list->initial.count; i++)
+  for (size_t i = 0; i < list->initial.count; i++)
     free_element (&list->initial.element[i]);
   if (list->initial.element != NULL)
     free (list->initial.element);
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -261,49 +266,49 @@ copy_element (struct format_arg *newelement,
 static struct format_arg_list *
 copy_list (const struct format_arg_list *list)
 {
-  struct format_arg_list *newlist;
-  size_t length;
-  size_t i;
-
   VERIFY_LIST (list);
 
-  newlist = XMALLOC (struct format_arg_list);
+  struct format_arg_list *newlist = XMALLOC (struct format_arg_list);
 
   newlist->initial.count = newlist->initial.allocated = list->initial.count;
-  length = 0;
-  if (list->initial.count == 0)
-    newlist->initial.element = NULL;
-  else
-    {
-      newlist->initial.element =
-        XNMALLOC (newlist->initial.allocated, struct format_arg);
-      for (i = 0; i < list->initial.count; i++)
-        {
-          copy_element (&newlist->initial.element[i],
-                        &list->initial.element[i]);
-          length += list->initial.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->initial.length);
-  newlist->initial.length = length;
+  {
+    size_t length = 0;
+    if (list->initial.count == 0)
+      newlist->initial.element = NULL;
+    else
+      {
+        newlist->initial.element =
+          XNMALLOC (newlist->initial.allocated, struct format_arg);
+        for (size_t i = 0; i < list->initial.count; i++)
+          {
+            copy_element (&newlist->initial.element[i],
+                          &list->initial.element[i]);
+            length += list->initial.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->initial.length);
+    newlist->initial.length = length;
+  }
 
   newlist->repeated.count = newlist->repeated.allocated = list->repeated.count;
-  length = 0;
-  if (list->repeated.count == 0)
-    newlist->repeated.element = NULL;
-  else
-    {
-      newlist->repeated.element =
-        XNMALLOC (newlist->repeated.allocated, struct format_arg);
-      for (i = 0; i < list->repeated.count; i++)
-        {
-          copy_element (&newlist->repeated.element[i],
-                        &list->repeated.element[i]);
-          length += list->repeated.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->repeated.length);
-  newlist->repeated.length = length;
+  {
+    size_t length = 0;
+    if (list->repeated.count == 0)
+      newlist->repeated.element = NULL;
+    else
+      {
+        newlist->repeated.element =
+          XNMALLOC (newlist->repeated.allocated, struct format_arg);
+        for (size_t i = 0; i < list->repeated.count; i++)
+          {
+            copy_element (&newlist->repeated.element[i],
+                          &list->repeated.element[i]);
+            length += list->repeated.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->repeated.length);
+    newlist->repeated.length = length;
+  }
 
   VERIFY_LIST (newlist);
 
@@ -330,34 +335,35 @@ static bool
 equal_list (const struct format_arg_list *list1,
             const struct format_arg_list *list2)
 {
-  size_t n, i;
-
   VERIFY_LIST (list1);
   VERIFY_LIST (list2);
 
-  n = list1->initial.count;
-  if (n != list2->initial.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->initial.element[i];
-      const struct format_arg * e2 = &list2->initial.element[i];
-
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+  {
+    size_t n = list1->initial.count;
+    if (n != list2->initial.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->initial.element[i];
+        const struct format_arg * e2 = &list2->initial.element[i];
 
-  n = list1->repeated.count;
-  if (n != list2->repeated.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->repeated.element[i];
-      const struct format_arg * e2 = &list2->repeated.element[i];
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
+  {
+    size_t n = list1->repeated.count;
+    if (n != list2->repeated.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->repeated.element[i];
+        const struct format_arg * e2 = &list2->repeated.element[i];
 
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
 
   return true;
 }
@@ -434,54 +440,56 @@ grow_repeated_alloc (struct format_arg_list *list)
 static void
 normalize_outermost_list (struct format_arg_list *list)
 {
-  size_t n, i, j;
-
   /* Step 1: Combine adjacent elements.
      Copy from i to j, keeping 0 <= j <= i.  */
-
-  n = list->initial.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->initial.element[i],
-                          &list->initial.element[j-1]))
-      {
-        list->initial.element[j-1].repcount +=
-          list->initial.element[i].repcount;
-        free_element (&list->initial.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->initial.element[j] = list->initial.element[i];
-        j++;
-      }
-  list->initial.count = j;
-
-  n = list->repeated.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->repeated.element[i],
-                          &list->repeated.element[j-1]))
-      {
-        list->repeated.element[j-1].repcount +=
-          list->repeated.element[i].repcount;
-        free_element (&list->repeated.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->repeated.element[j] = list->repeated.element[i];
-        j++;
-      }
-  list->repeated.count = j;
+  {
+    size_t n = list->initial.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->initial.element[i],
+                            &list->initial.element[j-1]))
+        {
+          list->initial.element[j-1].repcount +=
+            list->initial.element[i].repcount;
+          free_element (&list->initial.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->initial.element[j] = list->initial.element[i];
+          j++;
+        }
+    list->initial.count = j;
+  }
+  {
+    size_t n = list->repeated.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->repeated.element[i],
+                            &list->repeated.element[j-1]))
+        {
+          list->repeated.element[j-1].repcount +=
+            list->repeated.element[i].repcount;
+          free_element (&list->repeated.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->repeated.element[j] = list->repeated.element[i];
+          j++;
+        }
+    list->repeated.count = j;
+  }
 
   /* Nothing more to be done if the loop segment is empty.  */
   if (list->repeated.count > 0)
     {
-      size_t m, repcount0_extra;
+      size_t repcount0_extra;
 
       /* Step 2: Reduce the loop period.  */
-      n = list->repeated.count;
+      size_t n = list->repeated.count;
       repcount0_extra = 0;
       if (n > 1
           && equal_element (&list->repeated.element[0],
@@ -492,13 +500,13 @@ normalize_outermost_list (struct format_arg_list *list)
         }
       /* Proceed as if the loop period were n, with
          list->repeated.element[0].repcount incremented by repcount0_extra.  */
-      for (m = 2; m <= n / 2; m++)
+      for (size_t m = 2; m <= n / 2; m++)
         if ((n % m) == 0)
           {
             /* m is a divisor of n.  Try to reduce the loop period to n.  */
             bool ok = true;
 
-            for (i = 0; i < n - m; i++)
+            for (size_t i = 0; i < n - m; i++)
               if (!((list->repeated.element[i].repcount
                      + (i == 0 ? repcount0_extra : 0)
                      == list->repeated.element[i+m].repcount)
@@ -510,7 +518,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 }
             if (ok)
               {
-                for (i = m; i < n; i++)
+                for (size_t i = m; i < n; i++)
                   free_element (&list->repeated.element[i]);
                 if (n < list->repeated.count)
                   list->repeated.element[m] = list->repeated.element[n];
@@ -561,7 +569,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 {
                   size_t newcount = list->repeated.count + 1;
                   ensure_repeated_alloc (list, newcount);
-                  for (i = newcount - 1; i > 0; i--)
+                  for (size_t i = newcount - 1; i > 0; i--)
                     list->repeated.element[i] = list->repeated.element[i-1];
                   list->repeated.count = newcount;
                   copy_element (&list->repeated.element[0],
@@ -597,19 +605,21 @@ normalize_outermost_list (struct format_arg_list *list)
 static void
 normalize_list (struct format_arg_list *list)
 {
-  size_t n, i;
-
   VERIFY_LIST (list);
 
   /* First normalize all elements, recursively.  */
-  n = list->initial.count;
-  for (i = 0; i < n; i++)
-    if (list->initial.element[i].type & FAT_ELEMENTWISE)
-      normalize_list (list->initial.element[i].list);
-  n = list->repeated.count;
-  for (i = 0; i < n; i++)
-    if (list->repeated.element[i].type & FAT_ELEMENTWISE)
-      normalize_list (list->repeated.element[i].list);
+  {
+    size_t n = list->initial.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->initial.element[i].type & FAT_ELEMENTWISE)
+        normalize_list (list->initial.element[i].list);
+  }
+  {
+    size_t n = list->repeated.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->repeated.element[i].type & FAT_ELEMENTWISE)
+        normalize_list (list->repeated.element[i].list);
+  }
 
   /* Then normalize the top level list.  */
   normalize_outermost_list (list);
@@ -629,9 +639,7 @@ normalize_list (struct format_arg_list *list)
 static struct format_arg_list *
 make_unconstrained_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -655,9 +663,7 @@ make_unconstrained_list ()
 static struct format_arg_list *
 make_empty_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -690,16 +696,17 @@ is_empty_list (const struct format_arg_list *list)
 static void
 unfold_loop (struct format_arg_list *list, size_t m)
 {
-  size_t i, j, k;
-
   if (m > 1)
     {
       size_t newcount = list->repeated.count * m;
       ensure_repeated_alloc (list, newcount);
-      i = list->repeated.count;
-      for (k = 1; k < m; k++)
-        for (j = 0; j < list->repeated.count; j++, i++)
-          copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+      size_t i = list->repeated.count;
+      for (size_t k = 1; k < m; k++)
+        for (size_t j = 0; j < list->repeated.count; j++)
+          {
+            copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+            i++;
+          }
       list->repeated.count = newcount;
       list->repeated.length = list->repeated.length * m;
     }
@@ -718,11 +725,9 @@ rotate_loop (struct format_arg_list *list, size_t m)
     {
       /* Instead of multiple copies of list->repeated.element[0], a single
          copy with higher repcount is appended to list->initial.  */
-      size_t i, newcount;
-
-      newcount = list->initial.count + 1;
+      size_t newcount = list->initial.count + 1;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
+      size_t i = list->initial.count;
       copy_element (&list->initial.element[i], &list->repeated.element[0]);
       list->initial.element[i].repcount = m - list->initial.length;
       list->initial.count = newcount;
@@ -754,21 +759,23 @@ rotate_loop (struct format_arg_list *list, size_t m)
          plus the s first elements of list->repeated,
          plus, if t > 0, a splitoff of list->repeated.element[s].  */
       {
-        size_t i, j, k, newcount;
-
-        i = list->initial.count;
-        newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
+        size_t i = list->initial.count;
+        size_t newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
         ensure_initial_alloc (list, newcount);
-        for (k = 0; k < q; k++)
-          for (j = 0; j < list->repeated.count; j++, i++)
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
-        for (j = 0; j < s; j++, i++)
-          copy_element (&list->initial.element[i], &list->repeated.element[j]);
+        for (size_t k = 0; k < q; k++)
+          for (size_t j = 0; j < list->repeated.count; j++)
+            {
+              copy_element (&list->initial.element[i], &list->repeated.element[j]);
+              i++;
+            }
+        for (size_t j = 0; j < s; j++)
+          {
+            copy_element (&list->initial.element[i], &list->repeated.element[j]);
+            i++;
+          }
         if (t > 0)
           {
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
+            copy_element (&list->initial.element[i], &list->repeated.element[s]);
             list->initial.element[i].repcount = t;
             i++;
           }
@@ -787,17 +794,20 @@ rotate_loop (struct format_arg_list *list, size_t m)
       /* And rotate list->repeated.  */
       if (r > 0)
         {
-          size_t i, j, oldcount, newcount;
-          struct format_arg *newelement;
-
-          oldcount = list->repeated.count;
-          newcount = list->repeated.count + (t > 0 ? 1 : 0);
-          newelement = XNMALLOC (newcount, struct format_arg);
-          i = 0;
-          for (j = s; j < oldcount; j++, i++)
-            newelement[i] = list->repeated.element[j];
-          for (j = 0; j < s; j++, i++)
-            newelement[i] = list->repeated.element[j];
+          size_t oldcount = list->repeated.count;
+          size_t newcount = list->repeated.count + (t > 0 ? 1 : 0);
+          struct format_arg *newelement = XNMALLOC (newcount, struct format_arg);
+          size_t i = 0;
+          for (size_t j = s; j < oldcount; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
+          for (size_t j = 0; j < s; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
           if (t > 0)
             {
               copy_element (&newelement[oldcount], &newelement[0]);
@@ -819,12 +829,6 @@ rotate_loop (struct format_arg_list *list, size_t m)
 static size_t
 initial_splitelement (struct format_arg_list *list, size_t n)
 {
-  size_t s;
-  size_t t;
-  size_t oldrepcount;
-  size_t newcount;
-  size_t i;
-
   VERIFY_LIST (list);
 
   if (n > list->initial.length)
@@ -835,6 +839,8 @@ initial_splitelement (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -846,10 +852,10 @@ initial_splitelement (struct format_arg_list *list, size_t n)
   ASSERT (s < list->initial.count);
 
   /* Split the entry into two entries.  */
-  oldrepcount = list->initial.element[s].repcount;
-  newcount = list->initial.count + 1;
+  size_t oldrepcount = list->initial.element[s].repcount;
+  size_t newcount = list->initial.count + 1;
   ensure_initial_alloc (list, newcount);
-  for (i = list->initial.count - 1; i > s; i--)
+  for (size_t i = list->initial.count - 1; i > s; i--)
     list->initial.element[i+1] = list->initial.element[i];
   copy_element (&list->initial.element[s+1], &list->initial.element[s]);
   list->initial.element[s].repcount = t;
@@ -871,8 +877,6 @@ initial_unshare (struct format_arg_list *list, size_t n)
        initial_splitelement (list, n);
        initial_splitelement (list, n + 1);
    */
-  size_t s;
-  size_t t;
 
   VERIFY_LIST (list);
 
@@ -884,6 +888,8 @@ initial_unshare (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -902,9 +908,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
       ensure_initial_alloc (list, newcount);
       if (t == 0 || t == oldrepcount - 1)
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+1] = list->initial.element[i];
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
           if (t == 0)
@@ -920,9 +924,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
         }
       else
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+2] = list->initial.element[i];
           copy_element (&list->initial.element[s+2], &list->initial.element[s]);
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
@@ -1016,13 +1018,14 @@ append_repeated_to_initial (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       /* Move list->repeated over to list->initial.  */
-      size_t i, j, newcount;
-
-      newcount = list->initial.count + list->repeated.count;
+      size_t newcount = list->initial.count + list->repeated.count;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
-      for (j = 0; j < list->repeated.count; j++, i++)
-        list->initial.element[i] = list->repeated.element[j];
+      size_t i = list->initial.count;
+      for (size_t j = 0; j < list->repeated.count; j++)
+        {
+          list->initial.element[i] = list->repeated.element[j];
+          i++;
+        }
       list->initial.count = newcount;
       list->initial.length = list->initial.length + list->repeated.length;
       free (list->repeated.element);
@@ -1135,20 +1138,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 4: Elementwise intersection of list1->initial, list2->initial.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->initial.element; c1 = list1->initial.count;
-    e2 = list2->initial.element; c2 = list2->initial.count;
+    struct format_arg *e1 = list1->initial.element;
+    size_t c1 = list1->initial.count;
+    struct format_arg *e2 = list2->initial.element;
+    size_t c2 = list2->initial.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->initial.  */
         grow_initial_alloc (result);
-        re = &result->initial.element[result->initial.count];
+        struct format_arg *re = &result->initial.element[result->initial.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1223,20 +1221,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 5: Elementwise intersection of list1->repeated, list2->repeated.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->repeated.element; c1 = list1->repeated.count;
-    e2 = list2->repeated.element; c2 = list2->repeated.count;
+    struct format_arg *e1 = list1->repeated.element;
+    size_t c1 = list1->repeated.count;
+    struct format_arg *e2 = list2->repeated.element;
+    size_t c2 = list2->repeated.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->repeated.  */
         grow_repeated_alloc (result);
-        re = &result->repeated.element[result->repeated.count];
+        struct format_arg *re = &result->repeated.element[result->repeated.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1374,50 +1367,57 @@ make_union_with_empty_list (struct format_arg_list *list)
 MAYBE_UNUSED static bool
 is_required (const struct format_arg_list *list, size_t n)
 {
-  size_t s;
   size_t t;
 
   /* We'll check whether the first n+1 presence flags are FCT_REQUIRED.  */
   t = n + 1;
 
   /* Walk the list->initial segment.  */
-  for (s = 0;
-       s < list->initial.count && t >= list->initial.element[s].repcount;
-       t -= list->initial.element[s].repcount, s++)
-    if (list->initial.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->initial.count)
-    {
+    for (s = 0;
+         s < list->initial.count && t >= list->initial.element[s].repcount;
+         t -= list->initial.element[s].repcount, s++)
       if (list->initial.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->initial.count)
+      {
+        if (list->initial.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* Walk the list->repeated segment.  */
   if (list->repeated.count == 0)
     return false;
 
-  for (s = 0;
-       s < list->repeated.count && t >= list->repeated.element[s].repcount;
-       t -= list->repeated.element[s].repcount, s++)
-    if (list->repeated.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->repeated.count)
-    {
+    for (s = 0;
+         s < list->repeated.count && t >= list->repeated.element[s].repcount;
+         t -= list->repeated.element[s].repcount, s++)
       if (list->repeated.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->repeated.count)
+      {
+        if (list->repeated.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* The list->repeated segment consists only of FCT_REQUIRED.  So,
      regardless how many more passes through list->repeated would be
@@ -1432,8 +1432,6 @@ is_required (const struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_required_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t i, rest;
-
   if (list == NULL)
     return NULL;
 
@@ -1449,12 +1447,15 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 
   initial_splitelement (list, n + 1);
 
-  for (i = 0, rest = n + 1; rest > 0; )
-    {
-      list->initial.element[i].presence = FCT_REQUIRED;
-      rest -= list->initial.element[i].repcount;
-      i++;
-    }
+  {
+    size_t i = 0;
+    for (size_t rest = n + 1; rest > 0; )
+      {
+        list->initial.element[i].presence = FCT_REQUIRED;
+        rest -= list->initial.element[i].repcount;
+        i++;
+      }
+  }
 
   VERIFY_LIST (list);
 
@@ -1469,9 +1470,6 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_end_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t s, i;
-  enum format_cdr_type n_presence;
-
   if (list == NULL)
     return NULL;
 
@@ -1481,20 +1479,20 @@ add_end_constraint (struct format_arg_list *list, size_t n)
     /* list is already constrained to have at most length n.  */
     return list;
 
-  s = initial_splitelement (list, n);
-  n_presence =
+  size_t s = initial_splitelement (list, n);
+  enum format_cdr_type n_presence =
     (s < list->initial.count
      ? /* n < list->initial.length */ list->initial.element[s].presence
      : /* n >= list->initial.length */ list->repeated.element[0].presence);
 
-  for (i = s; i < list->initial.count; i++)
+  for (size_t i = s; i < list->initial.count; i++)
     {
       list->initial.length -= list->initial.element[i].repcount;
       free_element (&list->initial.element[i]);
     }
   list->initial.count = s;
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -1521,22 +1519,20 @@ add_type_constraint (struct format_arg_list *list,
                      enum format_arg_type type,
                      struct format_arg_list *sublist)
 {
-  size_t s;
-  struct format_arg newconstraint;
-
   if (list == NULL)
     return NULL;
 
   /* Through the previous add_required_constraint, we can assume
      list->initial.length >= n2+1.  */
 
-  s = initial_splitelement (list, n1);
-  initial_splitelement (list, n2 + 1);
-
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
   newconstraint.list = sublist;
 
+  size_t s = initial_splitelement (list, n1);
+  initial_splitelement (list, n2 + 1);
+
   /* Modify the elements that represent the indices n1..n2.  */
   size_t n = n1;
   while (n <= n2)
@@ -1573,37 +1569,36 @@ add_repeated_opt_type_constraint (struct format_arg_list *list,
                                   enum format_arg_type type,
                                   struct format_arg_list *sublist)
 {
-
-  size_t s;
-  struct format_arg newconstraint;
-
   if (list == NULL)
     return NULL;
 
-  s = initial_splitelement (list, n);
-
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
   newconstraint.list = sublist;
 
   /* Modify the initial elements that represent the indices >= n.  */
-  for (; s < list->initial.count; s++)
-    {
-      struct format_arg tmpelement;
-      if (!make_intersected_element (&tmpelement,
-                                     &list->initial.element[s], &newconstraint))
-        {
-          list = add_end_constraint (list, n);
-          goto done;
-        }
-      free_element (&list->initial.element[s]);
-      list->initial.element[s].type = tmpelement.type;
-      list->initial.element[s].list = tmpelement.list;
-      n += list->initial.element[s].repcount;
-    }
+  {
+    size_t s = initial_splitelement (list, n);
+
+    for (; s < list->initial.count; s++)
+      {
+        struct format_arg tmpelement;
+        if (!make_intersected_element (&tmpelement,
+                                       &list->initial.element[s], &newconstraint))
+          {
+            list = add_end_constraint (list, n);
+            goto done;
+          }
+        free_element (&list->initial.element[s]);
+        list->initial.element[s].type = tmpelement.type;
+        list->initial.element[s].list = tmpelement.list;
+        n += list->initial.element[s].repcount;
+      }
+  }
 
   /* Modify the repeated elements.  */
-  for (s = 0; s < list->repeated.count; s++)
+  for (size_t s = 0; s < list->repeated.count; s++)
     {
       struct format_arg tmpelement;
       if (!make_intersected_element (&tmpelement,
@@ -1623,7 +1618,6 @@ add_repeated_opt_type_constraint (struct format_arg_list *list,
     VERIFY_LIST (list);
 
   return list;
-
 }
 
 
@@ -1704,13 +1698,13 @@ parse_upto (struct spec *spec,
 
       if (c == '%')
         {
-          bool likely_intentional = true;
-
           FDI_SET (format - 1, FMTDIR_START);
 
           /* Count number of directives.  */
           spec->directives++;
 
+          bool likely_intentional = true;
+
           if (*format == '\0')
             {
               *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
@@ -1723,17 +1717,11 @@ parse_upto (struct spec *spec,
           else
             {
               /* A directive.  */
+
+              /* Parse position.  */
               size_t first_number = 0;
               size_t second_number = 0;
               bool second_is_last = false;
-              size_t width_number = 0;
-              bool width_from_arg = false;
-              size_t precision_number = 0;
-              bool precision_from_arg = false;
-              bool separator_digits_from_arg = false;
-              bool separator_char_from_arg = false;
-
-              /* Parse position.  */
               if (c_isdigit (*format))
                 {
                   const char *f = format;
@@ -1809,6 +1797,8 @@ parse_upto (struct spec *spec,
                 }
 
               /* Parse width.  */
+              size_t width_number = 0;
+              bool width_from_arg = false;
               if (c_isdigit (*format))
                 {
                   do format++; while (c_isdigit (*format));
@@ -1845,6 +1835,8 @@ parse_upto (struct spec *spec,
                 }
 
               /* Parse precision.  */
+              size_t precision_number = 0;
+              bool precision_from_arg = false;
               if (*format == '.')
                 {
                   format++;
@@ -1886,6 +1878,8 @@ parse_upto (struct spec *spec,
                 }
 
               /* Parse separator.  */
+              bool separator_digits_from_arg = false;
+              bool separator_char_from_arg = false;
               if (*format == ',')
                 {
                   format++;
@@ -2170,8 +2164,6 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
-
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.list = make_unconstrained_list ();
@@ -2191,7 +2183,7 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Normalize the result.  */
   normalize_list (spec.list);
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -2360,12 +2352,10 @@ print_element (struct format_arg *element)
 static void
 print_list (struct format_arg_list *list)
 {
-  size_t i, j;
-
   printf ("(");
 
-  for (i = 0; i < list->initial.count; i++)
-    for (j = 0; j < list->initial.element[i].repcount; j++)
+  for (size_t i = 0; i < list->initial.count; i++)
+    for (size_t j = 0; j < list->initial.element[i].repcount; j++)
       {
         if (i > 0 || j > 0)
           printf (" ");
@@ -2375,8 +2365,8 @@ print_list (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       printf (" |");
-      for (i = 0; i < list->repeated.count; i++)
-        for (j = 0; j < list->repeated.element[i].repcount; j++)
+      for (size_t i = 0; i < list->repeated.count; i++)
+        for (size_t j = 0; j < list->repeated.element[i].repcount; j++)
           {
             printf (" ");
             print_element (&list->repeated.element[i]);
@@ -2407,18 +2397,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index a9d2363149ef00b9799aa48202076a64cdadcbdb..2aa152f8cd5935d85c1f9be0f0024e35df839648 100644 (file)
@@ -94,27 +94,22 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  struct spec *result;
-  size_t number;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  number = 1;
+  size_t numbered_allocated = 0;
+  size_t number = 1;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
         if (c_isdigit (*format))
           {
@@ -191,6 +186,7 @@ format_parse (const char *format, bool translated, char *fdi,
               }
           }
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -250,21 +246,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -294,7 +288,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -341,68 +335,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -430,8 +429,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -440,8 +437,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -483,18 +480,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 74d53441a12d369210c5e88d63d6d9a0344a7ee2..25c6ea8840c4f93642aac6962ff6d7f891c45427 100644 (file)
@@ -197,24 +197,18 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  size_t in_quote_group;
-  size_t in_color_group;
-  size_t in_url_group;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
   spec.uses_err_no = false;
   spec.uses_current_locus = false;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
-  in_quote_group = 0;
-  in_color_group = 0;
-  in_url_group = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
+  size_t in_quote_group = 0;
+  size_t in_color_group = 0;
+  size_t in_url_group = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
@@ -273,16 +267,6 @@ format_parse (const char *format, bool translated, char *fdi,
         else
           {
             size_t number = 0;
-            unsigned int flag_q = 0;
-            unsigned int flag_l = 0;
-            unsigned int flag_w = 0;
-            unsigned int flag_z = 0;
-            unsigned int flag_t = 0;
-            unsigned int flag_plus = 0;
-            unsigned int flag_sharp = 0;
-            format_arg_type_t size;
-            format_arg_type_t type;
-
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -309,6 +293,13 @@ format_parse (const char *format, bool translated, char *fdi,
               }
 
             /* Parse flags and size.  */
+            unsigned int flag_q = 0;
+            unsigned int flag_l = 0;
+            unsigned int flag_w = 0;
+            unsigned int flag_z = 0;
+            unsigned int flag_t = 0;
+            unsigned int flag_plus = 0;
+            unsigned int flag_sharp = 0;
             for (;; format++)
               {
                 switch (*format)
@@ -357,13 +348,15 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
                 break;
               }
-            size = (flag_l == 2 ? FAT_SIZE_LONGLONG :
-                    flag_l == 1 ? FAT_SIZE_LONG :
-                    flag_w ? FAT_SIZE_WIDE :
-                    flag_z ? FAT_SIZE_SIZE :
-                    flag_t ? FAT_SIZE_PTRDIFF :
-                    0);
+            format_arg_type_t size =
+              (flag_l == 2 ? FAT_SIZE_LONGLONG :
+               flag_l == 1 ? FAT_SIZE_LONG :
+               flag_w ? FAT_SIZE_WIDE :
+               flag_z ? FAT_SIZE_SIZE :
+               flag_t ? FAT_SIZE_PTRDIFF :
+               0);
 
+            format_arg_type_t type;
             if (*format == 'c')
               type = FAT_CHAR;
             else if (*format == 's')
@@ -398,10 +391,9 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
                 else if (*format == '*')
                   {
-                    size_t precision_number = 0;
-
                     format++;
 
+                    size_t precision_number = 0;
                     if (c_isdigit (*format))
                       {
                         const char *f = format;
@@ -687,21 +679,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             format_arg_type_t type1 = spec.numbered[i].type;
             format_arg_type_t type2 = spec.numbered[j-1].type;
-            format_arg_type_t type_both;
 
+            format_arg_type_t type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -731,7 +721,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -770,68 +760,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
+              {
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   /* Check that the use of err_no is the same.  */
@@ -893,8 +888,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -903,8 +896,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -1043,18 +1036,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index fc44ecf66dd1818914444d8f2c38e77f7c997199..78e472390045168fe38227ee0106a4a534e5a956 100644 (file)
@@ -116,19 +116,14 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_arg_count;
-  size_t numbered_allocated;
-  struct numbered_arg *numbered;
-  struct spec *result;
-  size_t number;
 
+  struct spec spec;
   spec.directives = 0;
-  numbered_arg_count = 0;
-  numbered_allocated = 0;
-  numbered = NULL;
+  size_t numbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  struct numbered_arg *numbered = NULL;
   spec.uses_currentloc = false;
-  number = 1;
+  size_t number = 1;
 
   for (; *format != '\0';)
     if (*format++ == '%')
@@ -139,8 +134,6 @@ format_parse (const char *format, bool translated, char *fdi,
 
         if (*format != '%')
           {
-            format_arg_type_t type;
-
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -166,6 +159,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
               }
 
+            format_arg_type_t type;
             if (*format == 'C')
               {
                 type = FAT_VOID;
@@ -228,21 +222,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (numbered, numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < numbered_arg_count; i++)
         if (j > 0 && numbered[i].number == numbered[j-1].number)
           {
             format_arg_type_t type1 = numbered[i].type;
             format_arg_type_t type2 = numbered[j-1].type;
-            format_arg_type_t type_both;
 
+            format_arg_type_t type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -274,35 +266,27 @@ format_parse (const char *format, bool translated, char *fdi,
 
   /* Verify that the format string uses all arguments up to the highest
      numbered one.  */
-  {
-    size_t i;
-
-    for (i = 0; i < numbered_arg_count; i++)
-      if (numbered[i].number != i + 1)
-        {
-          *invalid_reason =
-            xasprintf (_("The string refers to argument number %zu but ignores argument number %zu."), numbered[i].number, i + 1);
-          goto bad_format;
-        }
-  }
+  for (size_t i = 0; i < numbered_arg_count; i++)
+    if (numbered[i].number != i + 1)
+      {
+        *invalid_reason =
+          xasprintf (_("The string refers to argument number %zu but ignores argument number %zu."), numbered[i].number, i + 1);
+        goto bad_format;
+      }
 
   /* So now the numbered arguments array is equivalent to a sequence
      of unnumbered arguments.  Eliminate the FAT_VOID placeholders.  */
   {
-    size_t i;
-
     spec.unnumbered_arg_count = 0;
-    for (i = 0; i < numbered_arg_count; i++)
+    for (size_t i = 0; i < numbered_arg_count; i++)
       if (numbered[i].type != FAT_VOID)
         spec.unnumbered_arg_count++;
 
     if (spec.unnumbered_arg_count > 0)
       {
-        size_t j;
-
         spec.unnumbered = XNMALLOC (spec.unnumbered_arg_count, struct unnumbered_arg);
-        j = 0;
-        for (i = 0; i < numbered_arg_count; i++)
+        size_t j = 0;
+        for (size_t i = 0; i < numbered_arg_count; i++)
           if (numbered[i].type != FAT_VOID)
             spec.unnumbered[j++].type = numbered[i].type;
       }
@@ -311,7 +295,7 @@ format_parse (const char *format, bool translated, char *fdi,
   }
   free (numbered);
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -347,7 +331,6 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
   struct spec *spec1 = (struct spec *) msgid_descr;
   struct spec *spec2 = (struct spec *) msgstr_descr;
   bool err = false;
-  size_t i;
 
   /* Check the argument types are the same.  */
   if (equality
@@ -361,7 +344,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
       err = true;
     }
   else
-    for (i = 0; i < spec2->unnumbered_arg_count; i++)
+    for (size_t i = 0; i < spec2->unnumbered_arg_count; i++)
       if (spec1->unnumbered[i].type != spec2->unnumbered[i].type)
         {
           if (error_logger)
@@ -413,7 +396,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -422,7 +404,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->unnumbered_arg_count; i++)
+  for (size_t i = 0; i < spec->unnumbered_arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -468,18 +450,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 8644506ae2e97e90b7ac9059db86760562ac796e..4eb6adb643cf1e24a3e59753ed0843a0c9e97190 100644 (file)
@@ -118,27 +118,22 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t allocated;
-  struct spec *result;
-  size_t number;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  allocated = 0;
-  number = 1;
+  size_t allocated = 0;
+  size_t number = 1;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
         /* Parse flags.  */
         while (*format == ' ' || *format == '+' || *format == '-'
@@ -391,6 +386,7 @@ format_parse (const char *format, bool translated, char *fdi,
 
        parse_specifier:
         /* Parse the specifier.  */
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -472,21 +468,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             format_arg_type_t type1 = spec.numbered[i].type;
             format_arg_type_t type2 = spec.numbered[j-1].type;
-            format_arg_type_t type_both = type1 & type2;
 
+            format_arg_type_t type_both = type1 & type2;
             if (type_both == FAT_NONE)
               {
                 /* Incompatible types.  */
@@ -513,7 +507,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -566,68 +560,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -655,8 +654,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -665,8 +662,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -709,18 +706,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 4a32a9a9be2eda41bca37a9c316000f62ea025a7..7ea59e299d5e43fdcbe9b8901d79db5356e1937c 100644 (file)
@@ -145,31 +145,23 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  struct spec *result;
-  size_t unnumbered_arg_count;
-  size_t last_arg_number;
 
+  struct spec spec;
   spec.directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
-  last_arg_number = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
+  size_t last_arg_number = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        unsigned int flags;
-        format_arg_type_t type;
-        unsigned int invalid_flags;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
 
+        size_t number = 0;
         if (*format == '<')
           {
             if (last_arg_number == 0)
@@ -206,9 +198,8 @@ format_parse (const char *format, bool translated, char *fdi,
               }
           }
 
-        flags = 0;
-
         /* Parse flags.  */
+        unsigned int flags = 0;
         for (;;)
           {
             if (*format == '#')
@@ -282,6 +273,8 @@ format_parse (const char *format, bool translated, char *fdi,
           }
 
         /* Parse conversion.  */
+        format_arg_type_t type;
+        unsigned int invalid_flags;
         switch (*format)
           {
           case '%':
@@ -462,21 +455,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -506,7 +497,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -545,68 +536,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
+              {
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -634,7 +630,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -643,7 +638,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -678,18 +673,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 9ed457cfab921c9afbe48e1ce244e26e1ce38331..5d3619f93851b48e183ca2c09b06520b3b6784e0 100644 (file)
@@ -158,32 +158,26 @@ message_format_parse (const char *format, char *fdi, struct spec *spec,
       HANDLE_QUOTE;
       if (!quoting && *format == '{')
         {
-          unsigned int depth;
-          const char *element_start;
-          const char *element_end;
-          size_t n;
-          char *element_alloced;
-          char *element;
-          size_t number;
-          enum format_arg_type type;
-
           FDI_SET (format, FMTDIR_START);
           spec->directives++;
 
-          element_start = ++format;
-          depth = 0;
-          for (; *format != '\0'; format++)
-            {
-              if (*format == '{')
-                depth++;
-              else if (*format == '}')
-                {
-                  if (depth == 0)
-                    break;
-                  else
-                    depth--;
-                }
-            }
+          const char *element_start = ++format;
+          unsigned int depth;
+          {
+            depth = 0;
+            for (; *format != '\0'; format++)
+              {
+                if (*format == '{')
+                  depth++;
+                else if (*format == '}')
+                  {
+                    if (depth == 0)
+                      break;
+                    else
+                      depth--;
+                  }
+              }
+          }
           if (*format == '\0')
             {
               *invalid_reason =
@@ -191,12 +185,16 @@ message_format_parse (const char *format, char *fdi, struct spec *spec,
               FDI_SET (format - 1, FMTDIR_ERROR);
               return false;
             }
-          element_end = format++;
+          const char *element_end = format++;
 
-          n = element_end - element_start;
-          element = element_alloced = (char *) xmalloca (n + 1);
-          memcpy (element, element_start, n);
-          element[n] = '\0';
+          char *element_alloced;
+          char *element;
+          {
+            size_t n = element_end - element_start;
+            element = element_alloced = (char *) xmalloca (n + 1);
+            memcpy (element, element_start, n);
+            element[n] = '\0';
+          }
 
           if (!c_isdigit (*element))
             {
@@ -206,7 +204,7 @@ message_format_parse (const char *format, char *fdi, struct spec *spec,
               freea (element_alloced);
               return false;
             }
-          number = 0;
+          size_t number = 0;
           do
             {
               number = 10 * number + (*element - '0');
@@ -214,7 +212,7 @@ message_format_parse (const char *format, char *fdi, struct spec *spec,
             }
           while (c_isdigit (*element));
 
-          type = FAT_OBJECT;
+          enum format_arg_type type = FAT_OBJECT;
           if (*element == '\0')
             ;
           else if (str_startswith (element, ",time")
@@ -532,13 +530,9 @@ choice_format_parse (const char *format, struct spec *spec,
     {
       /* Don't bother looking too precisely into the syntax of the number.
          It can contain various Unicode characters.  */
-      bool number_nonempty;
-      char *msgformat;
-      char *mp;
-      bool msgformat_valid;
 
       /* Parse number.  */
-      number_nonempty = false;
+      bool number_nonempty = false;
       while (*format != '\0'
              && !(!quoting && (*format == '<' || *format == '#'
                                || str_startswith (format, "\\u2264")
@@ -584,17 +578,18 @@ choice_format_parse (const char *format, struct spec *spec,
         }
       HANDLE_QUOTE;
 
-      msgformat = (char *) xmalloca (strlen (format) + 1);
-      mp = msgformat;
-
-      while (*format != '\0' && !(!quoting && *format == '|'))
-        {
-          *mp++ = *format++;
-          HANDLE_QUOTE;
-        }
-      *mp = '\0';
+      char *msgformat = (char *) xmalloca (strlen (format) + 1);
+      {
+        char *mp = msgformat;
+        while (*format != '\0' && !(!quoting && *format == '|'))
+          {
+            *mp++ = *format++;
+            HANDLE_QUOTE;
+          }
+        *mp = '\0';
+      }
 
-      msgformat_valid =
+      bool msgformat_valid =
         message_format_parse (msgformat, NULL, spec, invalid_reason);
 
       freea (msgformat);
@@ -626,8 +621,6 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
-
   spec.directives = 0;
   spec.numbered_arg_count = 0;
   spec.allocated = 0;
@@ -639,21 +632,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2 || type2 == FAT_OBJECT)
               type_both = type1;
             else if (type1 == FAT_OBJECT)
@@ -685,7 +676,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -724,68 +715,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument {%zu}, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument {%zu} doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument {%zu}, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument {%zu} are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument {%zu} doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument {%zu} are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -813,8 +809,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -823,8 +817,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 0;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 0;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -860,18 +854,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 5652091ddeb583dfb4740ccd9726b8095a357111..e11c2eb65b7ad65c1bba50ab9bd27ef4bc6e7cbb 100644 (file)
@@ -95,30 +95,25 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
+        size_t number = 0;
         if (c_isdigit (*format))
           {
             const char *f = format;
@@ -180,6 +175,7 @@ format_parse (const char *format, bool translated, char *fdi,
             do format++; while (c_isdigit (*format));
           }
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -274,21 +270,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -318,7 +312,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -365,70 +359,75 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+            if (cmp > 0)
+              {
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
               {
-                if (!(spec1->numbered[i].type == spec2->numbered[j].type
-                      || (!equality
-                          && (spec1->numbered[i].type == FAT_ANY
-                              || spec2->numbered[i].type == FAT_ANY))))
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (!(spec1->numbered[i].type == spec2->numbered[j].type
+                        || (!equality
+                            && (spec1->numbered[i].type == FAT_ANY
+                                || spec2->numbered[i].type == FAT_ANY))))
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -456,7 +455,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -464,33 +462,33 @@ format_print (void *descr)
       return;
     }
 
-      printf ("(");
-      for (i = 0; i < spec->numbered_arg_count; i++)
+  printf ("(");
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
+    {
+      if (i > 0)
+        printf (" ");
+      switch (spec->numbered[i].type)
         {
-          if (i > 0)
-            printf (" ");
-          switch (spec->numbered[i].type)
-            {
-            case FAT_ANY:
-              printf ("*");
-              break;
-            case FAT_CHARACTER:
-              printf ("c");
-              break;
-            case FAT_STRING:
-              printf ("s");
-              break;
-            case FAT_INTEGER:
-              printf ("i");
-              break;
-            case FAT_FLOAT:
-              printf ("f");
-              break;
-            default:
-              abort ();
-            }
+        case FAT_ANY:
+          printf ("*");
+          break;
+        case FAT_CHARACTER:
+          printf ("c");
+          break;
+        case FAT_STRING:
+          printf ("s");
+          break;
+        case FAT_INTEGER:
+          printf ("i");
+          break;
+        case FAT_FLOAT:
+          printf ("f");
+          break;
+        default:
+          abort ();
         }
-      printf (")");
+    }
+  printf (")");
 }
 
 int
@@ -500,18 +498,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 8a39dc33459558a759c1418454769a99d0aa4750..893583e92a00c7c46a6485c0d75c15dc95ad2b60 100644 (file)
@@ -111,7 +111,6 @@ is_reference (const char *input)
   const char *str = input;
   const char *str_limit = str + strlen (input);
   ucs4_t uc;
-  int i;
 
   str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
   assert (uc == '&');
@@ -150,27 +149,40 @@ is_reference (const char *input)
   else
     {
       /* EntityRef */
-      for (i = 0; i < SIZEOF (name_chars1); i++)
-        if (name_chars1[i].start <= uc && uc <= name_chars1[i].end)
-          break;
+      {
+        bool isNameStartChar = false;
+        for (int i = 0; i < SIZEOF (name_chars1); i++)
+          if (name_chars1[i].start <= uc && uc <= name_chars1[i].end)
+            {
+              isNameStartChar = true;
+              break;
+            }
 
-      if (i == SIZEOF (name_chars1))
-        return false;
+        if (!isNameStartChar)
+          return false;
+      }
 
       while (str < str_limit)
         {
           str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
-          for (i = 0; i < SIZEOF (name_chars1); i++)
+
+          bool isNameChar = false;
+          for (int i = 0; i < SIZEOF (name_chars1); i++)
             if (name_chars1[i].start <= uc && uc <= name_chars1[i].end)
-              break;
-          if (i == SIZEOF (name_chars1))
-            {
-              for (i = 0; i < SIZEOF (name_chars2); i++)
-                if (name_chars2[i].start <= uc && uc <= name_chars2[i].end)
+              {
+                isNameChar = true;
+                break;
+              }
+          if (!isNameChar)
+            for (int i = 0; i < SIZEOF (name_chars2); i++)
+              if (name_chars2[i].start <= uc && uc <= name_chars2[i].end)
+                {
+                  isNameChar = true;
                   break;
-              if (i == SIZEOF (name_chars2))
-                return false;
-            }
+                }
+
+          if (!isNameChar)
+            return false;
         }
       return uc == ';';
     }
@@ -184,18 +196,13 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
-  const char *str;
-  const char *str_limit;
-  size_t amp_count;
-  char *buffer, *bp;
-
   spec.base = NULL;
 
   /* Preprocess the input, putting the content in a <gt:kuit> element.  */
-  str = format;
-  str_limit = str + strlen (format);
+  const char *str = format;
+  const char *str_limit = str + strlen (format);
 
+  size_t amp_count;
   for (amp_count = 0; str < str_limit; amp_count++)
     {
       const char *amp = strchrnul (str, '&');
@@ -204,37 +211,38 @@ format_parse (const char *format, bool translated, char *fdi,
       str = amp + 1;
     }
 
-  buffer = xmalloc (amp_count * 4
-                    + strlen (format)
-                    + strlen ("<gt:kuit xmlns:gt=\"" XML_NS "\"></gt:kuit>")
-                    + 1);
+  char *buffer =
+    xmalloc (amp_count * 4
+             + strlen (format)
+             + strlen ("<gt:kuit xmlns:gt=\"" XML_NS "\"></gt:kuit>")
+             + 1);
   *buffer = '\0';
 
-  bp = buffer;
-  bp = stpcpy (bp, "<gt:kuit xmlns:gt=\"" XML_NS "\">");
-  str = format;
-  while (str < str_limit)
-    {
-      const char *amp = strchrnul (str, '&');
+  {
+    char *bp = buffer;
+    bp = stpcpy (bp, "<gt:kuit xmlns:gt=\"" XML_NS "\">");
+    str = format;
+    while (str < str_limit)
+      {
+        const char *amp = strchrnul (str, '&');
+
+        bp = stpncpy (bp, str, amp - str);
+        if (*amp != '&')
+          break;
 
-      bp = stpncpy (bp, str, amp - str);
-      if (*amp != '&')
-        break;
-
-      bp = stpcpy (bp, is_reference (amp) ? "&" : "&amp;");
-      str = amp + 1;
-    }
-  stpcpy (bp, "</gt:kuit>");
+        bp = stpcpy (bp, is_reference (amp) ? "&" : "&amp;");
+        str = amp + 1;
+      }
+    stpcpy (bp, "</gt:kuit>");
+  }
 
 #if FORMAT_KDE_KUIT_USE_LIBXML2
     {
-      xmlDocPtr doc;
-
-      doc = xmlReadMemory (buffer, strlen (buffer), "", NULL,
-                           XML_PARSE_NONET
-                           | XML_PARSE_NOWARNING
-                           | XML_PARSE_NOERROR
-                           | XML_PARSE_NOBLANKS);
+      xmlDocPtr doc = xmlReadMemory (buffer, strlen (buffer), "", NULL,
+                                     XML_PARSE_NONET
+                                     | XML_PARSE_NOWARNING
+                                     | XML_PARSE_NOERROR
+                                     | XML_PARSE_NOBLANKS);
       if (doc == NULL)
         {
           const xmlError *err = xmlGetLastError ();
@@ -252,10 +260,11 @@ format_parse (const char *format, bool translated, char *fdi,
 #elif FORMAT_KDE_KUIT_USE_FALLBACK_MARKUP
     {
       markup_parser_ty parser;
-      markup_parse_context_ty *context;
-
       memset (&parser, 0, sizeof (markup_parser_ty));
-      context = markup_parse_context_new (&parser, 0, NULL);
+
+      markup_parse_context_ty *context =
+        markup_parse_context_new (&parser, 0, NULL);
+
       if (!markup_parse_context_parse (context, buffer, strlen (buffer)))
         {
           *invalid_reason =
@@ -288,7 +297,7 @@ format_parse (const char *format, bool translated, char *fdi,
   if (spec.base == NULL)
     return NULL;
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -354,9 +363,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  struct kde_spec *kspec;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -364,7 +370,7 @@ format_print (void *descr)
       return;
     }
 
-  kspec = (struct kde_spec *) spec->base;
+  struct kde_spec *kspec = (struct kde_spec *) spec->base;
 
   if (kspec == NULL)
     {
@@ -373,8 +379,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < kspec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < kspec->numbered_arg_count; i++)
     {
       size_t number = kspec->numbered[i].number;
 
@@ -397,18 +403,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index a46d7a95a398900c0fc0dedc4379b3bd58f5e316..d1ce802ad7a2140caa6c0cae9093949f7bbe61b8 100644 (file)
@@ -70,14 +70,12 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
+  size_t numbered_allocated = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
@@ -87,12 +85,10 @@ format_parse (const char *format, bool translated, char *fdi,
         if (*format > '0' && *format <= '9')
           {
             /* A directive.  */
-            size_t number;
-
             FDI_SET (dir_start, FMTDIR_START);
             spec.directives++;
 
-            number = *format - '0';
+            size_t number = *format - '0';
             while (format[1] >= '0' && format[1] <= '9')
               {
                 number = 10 * number + (format[1] - '0');
@@ -116,12 +112,11 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           ;
@@ -141,10 +136,7 @@ format_parse (const char *format, bool translated, char *fdi,
      {1,...,n} \ {m}.  */
   if (spec.numbered_arg_count > 0)
     {
-      size_t i;
-
-      i = 0;
-      for (; i < spec.numbered_arg_count; i++)
+      for (size_t i = 0; i < spec.numbered_arg_count; i++)
         if (spec.numbered[i].number > i + 1)
           {
             size_t first_gap = i + 1;
@@ -161,7 +153,7 @@ format_parse (const char *format, bool translated, char *fdi,
           }
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -200,13 +192,13 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
       size_t missing = 0; /* only used if !equality */
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -282,8 +274,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -292,8 +282,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -316,18 +306,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 54afac586921ab531ab5e1d24a1c3609840c9e6c..c825da49f107eef671c4ac631dd58d486d161827 100644 (file)
@@ -91,27 +91,22 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  struct spec *result;
-  size_t number;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  number = 1;
+  size_t numbered_allocated = 0;
+  size_t number = 1;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
         if (c_isdigit (*format))
           {
@@ -158,6 +153,7 @@ format_parse (const char *format, bool translated, char *fdi,
               }
           }
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -214,21 +210,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -258,7 +252,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -305,68 +299,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -394,8 +393,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -404,8 +401,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -444,18 +441,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index b17793fd80f7828f2d91867a27f96c24f8c5d844..b492a9b009ece73aed71f6444e09f7fa0615d4a3 100644 (file)
@@ -157,26 +157,33 @@ verify_element (const struct format_arg * e)
 static void
 verify_list (const struct format_arg_list *list)
 {
-  size_t i;
-  size_t total_repcount;
-
   ASSERT (list->initial.count <= list->initial.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->initial.count; i++)
-    {
-      verify_element (&list->initial.element[i]);
-      total_repcount += list->initial.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->initial.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->initial.count; i++)
+      {
+        verify_element (&list->initial.element[i]);
+        total_repcount += list->initial.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->initial.length);
+  }
 
   ASSERT (list->repeated.count <= list->repeated.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->repeated.count; i++)
-    {
-      verify_element (&list->repeated.element[i]);
-      total_repcount += list->repeated.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->repeated.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->repeated.count; i++)
+      {
+        verify_element (&list->repeated.element[i]);
+        total_repcount += list->repeated.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->repeated.length);
+  }
 }
 
 /* Assertion macro.  Could be defined to empty for speed.  */
@@ -198,14 +205,12 @@ free_element (struct format_arg *element)
 static void
 free_list (struct format_arg_list *list)
 {
-  size_t i;
-
-  for (i = 0; i < list->initial.count; i++)
+  for (size_t i = 0; i < list->initial.count; i++)
     free_element (&list->initial.element[i]);
   if (list->initial.element != NULL)
     free (list->initial.element);
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -231,49 +236,49 @@ copy_element (struct format_arg *newelement,
 static struct format_arg_list *
 copy_list (const struct format_arg_list *list)
 {
-  struct format_arg_list *newlist;
-  size_t length;
-  size_t i;
-
   VERIFY_LIST (list);
 
-  newlist = XMALLOC (struct format_arg_list);
+  struct format_arg_list *newlist = XMALLOC (struct format_arg_list);
 
   newlist->initial.count = newlist->initial.allocated = list->initial.count;
-  length = 0;
-  if (list->initial.count == 0)
-    newlist->initial.element = NULL;
-  else
-    {
-      newlist->initial.element =
-        XNMALLOC (newlist->initial.allocated, struct format_arg);
-      for (i = 0; i < list->initial.count; i++)
-        {
-          copy_element (&newlist->initial.element[i],
-                        &list->initial.element[i]);
-          length += list->initial.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->initial.length);
-  newlist->initial.length = length;
+  {
+    size_t length = 0;
+    if (list->initial.count == 0)
+      newlist->initial.element = NULL;
+    else
+      {
+        newlist->initial.element =
+          XNMALLOC (newlist->initial.allocated, struct format_arg);
+        for (size_t i = 0; i < list->initial.count; i++)
+          {
+            copy_element (&newlist->initial.element[i],
+                          &list->initial.element[i]);
+            length += list->initial.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->initial.length);
+    newlist->initial.length = length;
+  }
 
   newlist->repeated.count = newlist->repeated.allocated = list->repeated.count;
-  length = 0;
-  if (list->repeated.count == 0)
-    newlist->repeated.element = NULL;
-  else
-    {
-      newlist->repeated.element =
-        XNMALLOC (newlist->repeated.allocated, struct format_arg);
-      for (i = 0; i < list->repeated.count; i++)
-        {
-          copy_element (&newlist->repeated.element[i],
-                        &list->repeated.element[i]);
-          length += list->repeated.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->repeated.length);
-  newlist->repeated.length = length;
+  {
+    size_t length = 0;
+    if (list->repeated.count == 0)
+      newlist->repeated.element = NULL;
+    else
+      {
+        newlist->repeated.element =
+          XNMALLOC (newlist->repeated.allocated, struct format_arg);
+        for (size_t i = 0; i < list->repeated.count; i++)
+          {
+            copy_element (&newlist->repeated.element[i],
+                          &list->repeated.element[i]);
+            length += list->repeated.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->repeated.length);
+    newlist->repeated.length = length;
+  }
 
   VERIFY_LIST (newlist);
 
@@ -299,34 +304,35 @@ static bool
 equal_list (const struct format_arg_list *list1,
             const struct format_arg_list *list2)
 {
-  size_t n, i;
-
   VERIFY_LIST (list1);
   VERIFY_LIST (list2);
 
-  n = list1->initial.count;
-  if (n != list2->initial.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->initial.element[i];
-      const struct format_arg * e2 = &list2->initial.element[i];
-
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+  {
+    size_t n = list1->initial.count;
+    if (n != list2->initial.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->initial.element[i];
+        const struct format_arg * e2 = &list2->initial.element[i];
 
-  n = list1->repeated.count;
-  if (n != list2->repeated.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->repeated.element[i];
-      const struct format_arg * e2 = &list2->repeated.element[i];
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
+  {
+    size_t n = list1->repeated.count;
+    if (n != list2->repeated.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->repeated.element[i];
+        const struct format_arg * e2 = &list2->repeated.element[i];
 
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
 
   return true;
 }
@@ -403,54 +409,56 @@ grow_repeated_alloc (struct format_arg_list *list)
 static void
 normalize_outermost_list (struct format_arg_list *list)
 {
-  size_t n, i, j;
-
   /* Step 1: Combine adjacent elements.
      Copy from i to j, keeping 0 <= j <= i.  */
-
-  n = list->initial.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->initial.element[i],
-                          &list->initial.element[j-1]))
-      {
-        list->initial.element[j-1].repcount +=
-          list->initial.element[i].repcount;
-        free_element (&list->initial.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->initial.element[j] = list->initial.element[i];
-        j++;
-      }
-  list->initial.count = j;
-
-  n = list->repeated.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->repeated.element[i],
-                          &list->repeated.element[j-1]))
-      {
-        list->repeated.element[j-1].repcount +=
-          list->repeated.element[i].repcount;
-        free_element (&list->repeated.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->repeated.element[j] = list->repeated.element[i];
-        j++;
-      }
-  list->repeated.count = j;
+  {
+    size_t n = list->initial.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->initial.element[i],
+                            &list->initial.element[j-1]))
+        {
+          list->initial.element[j-1].repcount +=
+            list->initial.element[i].repcount;
+          free_element (&list->initial.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->initial.element[j] = list->initial.element[i];
+          j++;
+        }
+    list->initial.count = j;
+  }
+  {
+    size_t n = list->repeated.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->repeated.element[i],
+                            &list->repeated.element[j-1]))
+        {
+          list->repeated.element[j-1].repcount +=
+            list->repeated.element[i].repcount;
+          free_element (&list->repeated.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->repeated.element[j] = list->repeated.element[i];
+          j++;
+        }
+    list->repeated.count = j;
+  }
 
   /* Nothing more to be done if the loop segment is empty.  */
   if (list->repeated.count > 0)
     {
-      size_t m, repcount0_extra;
+      size_t repcount0_extra;
 
       /* Step 2: Reduce the loop period.  */
-      n = list->repeated.count;
+      size_t n = list->repeated.count;
       repcount0_extra = 0;
       if (n > 1
           && equal_element (&list->repeated.element[0],
@@ -461,13 +469,13 @@ normalize_outermost_list (struct format_arg_list *list)
         }
       /* Proceed as if the loop period were n, with
          list->repeated.element[0].repcount incremented by repcount0_extra.  */
-      for (m = 2; m <= n / 2; m++)
+      for (size_t m = 2; m <= n / 2; m++)
         if ((n % m) == 0)
           {
             /* m is a divisor of n.  Try to reduce the loop period to n.  */
             bool ok = true;
 
-            for (i = 0; i < n - m; i++)
+            for (size_t i = 0; i < n - m; i++)
               if (!((list->repeated.element[i].repcount
                      + (i == 0 ? repcount0_extra : 0)
                      == list->repeated.element[i+m].repcount)
@@ -479,7 +487,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 }
             if (ok)
               {
-                for (i = m; i < n; i++)
+                for (size_t i = m; i < n; i++)
                   free_element (&list->repeated.element[i]);
                 if (n < list->repeated.count)
                   list->repeated.element[m] = list->repeated.element[n];
@@ -530,7 +538,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 {
                   size_t newcount = list->repeated.count + 1;
                   ensure_repeated_alloc (list, newcount);
-                  for (i = newcount - 1; i > 0; i--)
+                  for (size_t i = newcount - 1; i > 0; i--)
                     list->repeated.element[i] = list->repeated.element[i-1];
                   list->repeated.count = newcount;
                   copy_element (&list->repeated.element[0],
@@ -566,19 +574,21 @@ normalize_outermost_list (struct format_arg_list *list)
 static void
 normalize_list (struct format_arg_list *list)
 {
-  size_t n, i;
-
   VERIFY_LIST (list);
 
   /* First normalize all elements, recursively.  */
-  n = list->initial.count;
-  for (i = 0; i < n; i++)
-    if (list->initial.element[i].type == FAT_LIST)
-      normalize_list (list->initial.element[i].list);
-  n = list->repeated.count;
-  for (i = 0; i < n; i++)
-    if (list->repeated.element[i].type == FAT_LIST)
-      normalize_list (list->repeated.element[i].list);
+  {
+    size_t n = list->initial.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->initial.element[i].type == FAT_LIST)
+        normalize_list (list->initial.element[i].list);
+  }
+  {
+    size_t n = list->repeated.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->repeated.element[i].type == FAT_LIST)
+        normalize_list (list->repeated.element[i].list);
+  }
 
   /* Then normalize the top level list.  */
   normalize_outermost_list (list);
@@ -598,9 +608,7 @@ normalize_list (struct format_arg_list *list)
 static struct format_arg_list *
 make_unconstrained_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -624,9 +632,7 @@ make_unconstrained_list ()
 static struct format_arg_list *
 make_empty_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -659,16 +665,17 @@ is_empty_list (const struct format_arg_list *list)
 static void
 unfold_loop (struct format_arg_list *list, size_t m)
 {
-  size_t i, j, k;
-
   if (m > 1)
     {
       size_t newcount = list->repeated.count * m;
       ensure_repeated_alloc (list, newcount);
-      i = list->repeated.count;
-      for (k = 1; k < m; k++)
-        for (j = 0; j < list->repeated.count; j++, i++)
-          copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+      size_t i = list->repeated.count;
+      for (size_t k = 1; k < m; k++)
+        for (size_t j = 0; j < list->repeated.count; j++)
+          {
+            copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+            i++;
+          }
       list->repeated.count = newcount;
       list->repeated.length = list->repeated.length * m;
     }
@@ -687,11 +694,9 @@ rotate_loop (struct format_arg_list *list, size_t m)
     {
       /* Instead of multiple copies of list->repeated.element[0], a single
          copy with higher repcount is appended to list->initial.  */
-      size_t i, newcount;
-
-      newcount = list->initial.count + 1;
+      size_t newcount = list->initial.count + 1;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
+      size_t i = list->initial.count;
       copy_element (&list->initial.element[i], &list->repeated.element[0]);
       list->initial.element[i].repcount = m - list->initial.length;
       list->initial.count = newcount;
@@ -723,21 +728,23 @@ rotate_loop (struct format_arg_list *list, size_t m)
          plus the s first elements of list->repeated,
          plus, if t > 0, a splitoff of list->repeated.element[s].  */
       {
-        size_t i, j, k, newcount;
-
-        i = list->initial.count;
-        newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
+        size_t i = list->initial.count;
+        size_t newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
         ensure_initial_alloc (list, newcount);
-        for (k = 0; k < q; k++)
-          for (j = 0; j < list->repeated.count; j++, i++)
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
-        for (j = 0; j < s; j++, i++)
-          copy_element (&list->initial.element[i], &list->repeated.element[j]);
+        for (size_t k = 0; k < q; k++)
+          for (size_t j = 0; j < list->repeated.count; j++)
+            {
+              copy_element (&list->initial.element[i], &list->repeated.element[j]);
+              i++;
+            }
+        for (size_t j = 0; j < s; j++)
+          {
+            copy_element (&list->initial.element[i], &list->repeated.element[j]);
+            i++;
+          }
         if (t > 0)
           {
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
+            copy_element (&list->initial.element[i], &list->repeated.element[s]);
             list->initial.element[i].repcount = t;
             i++;
           }
@@ -756,17 +763,20 @@ rotate_loop (struct format_arg_list *list, size_t m)
       /* And rotate list->repeated.  */
       if (r > 0)
         {
-          size_t i, j, oldcount, newcount;
-          struct format_arg *newelement;
-
-          oldcount = list->repeated.count;
-          newcount = list->repeated.count + (t > 0 ? 1 : 0);
-          newelement = XNMALLOC (newcount, struct format_arg);
-          i = 0;
-          for (j = s; j < oldcount; j++, i++)
-            newelement[i] = list->repeated.element[j];
-          for (j = 0; j < s; j++, i++)
-            newelement[i] = list->repeated.element[j];
+          size_t oldcount = list->repeated.count;
+          size_t newcount = list->repeated.count + (t > 0 ? 1 : 0);
+          struct format_arg *newelement = XNMALLOC (newcount, struct format_arg);
+          size_t i = 0;
+          for (size_t j = s; j < oldcount; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
+          for (size_t j = 0; j < s; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
           if (t > 0)
             {
               copy_element (&newelement[oldcount], &newelement[0]);
@@ -788,12 +798,6 @@ rotate_loop (struct format_arg_list *list, size_t m)
 static size_t
 initial_splitelement (struct format_arg_list *list, size_t n)
 {
-  size_t s;
-  size_t t;
-  size_t oldrepcount;
-  size_t newcount;
-  size_t i;
-
   VERIFY_LIST (list);
 
   if (n > list->initial.length)
@@ -804,6 +808,8 @@ initial_splitelement (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -815,10 +821,10 @@ initial_splitelement (struct format_arg_list *list, size_t n)
   ASSERT (s < list->initial.count);
 
   /* Split the entry into two entries.  */
-  oldrepcount = list->initial.element[s].repcount;
-  newcount = list->initial.count + 1;
+  size_t oldrepcount = list->initial.element[s].repcount;
+  size_t newcount = list->initial.count + 1;
   ensure_initial_alloc (list, newcount);
-  for (i = list->initial.count - 1; i > s; i--)
+  for (size_t i = list->initial.count - 1; i > s; i--)
     list->initial.element[i+1] = list->initial.element[i];
   copy_element (&list->initial.element[s+1], &list->initial.element[s]);
   list->initial.element[s].repcount = t;
@@ -840,8 +846,6 @@ initial_unshare (struct format_arg_list *list, size_t n)
        initial_splitelement (list, n);
        initial_splitelement (list, n + 1);
    */
-  size_t s;
-  size_t t;
 
   VERIFY_LIST (list);
 
@@ -853,6 +857,8 @@ initial_unshare (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -871,9 +877,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
       ensure_initial_alloc (list, newcount);
       if (t == 0 || t == oldrepcount - 1)
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+1] = list->initial.element[i];
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
           if (t == 0)
@@ -889,9 +893,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
         }
       else
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+2] = list->initial.element[i];
           copy_element (&list->initial.element[s+2], &list->initial.element[s]);
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
@@ -922,10 +924,8 @@ shift_list (struct format_arg_list *list, size_t n)
 
   if (n > 0)
     {
-      size_t i;
-
       grow_initial_alloc (list);
-      for (i = list->initial.count; i > 0; i--)
+      for (size_t i = list->initial.count; i > 0; i--)
         list->initial.element[i] = list->initial.element[i-1];
       list->initial.element[0].repcount = n;
       list->initial.element[0].presence = FCT_REQUIRED;
@@ -1053,13 +1053,14 @@ append_repeated_to_initial (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       /* Move list->repeated over to list->initial.  */
-      size_t i, j, newcount;
-
-      newcount = list->initial.count + list->repeated.count;
+      size_t newcount = list->initial.count + list->repeated.count;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
-      for (j = 0; j < list->repeated.count; j++, i++)
-        list->initial.element[i] = list->repeated.element[j];
+      size_t i = list->initial.count;
+      for (size_t j = 0; j < list->repeated.count; j++)
+        {
+          list->initial.element[i] = list->repeated.element[j];
+          i++;
+        }
       list->initial.count = newcount;
       list->initial.length = list->initial.length + list->repeated.length;
       free (list->repeated.element);
@@ -1172,20 +1173,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 4: Elementwise intersection of list1->initial, list2->initial.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->initial.element; c1 = list1->initial.count;
-    e2 = list2->initial.element; c2 = list2->initial.count;
+    struct format_arg *e1 = list1->initial.element;
+    size_t c1 = list1->initial.count;
+    struct format_arg *e2 = list2->initial.element;
+    size_t c2 = list2->initial.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->initial.  */
         grow_initial_alloc (result);
-        re = &result->initial.element[result->initial.count];
+        struct format_arg *re = &result->initial.element[result->initial.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1260,20 +1256,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 5: Elementwise intersection of list1->repeated, list2->repeated.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->repeated.element; c1 = list1->repeated.count;
-    e2 = list2->repeated.element; c2 = list2->repeated.count;
+    struct format_arg *e1 = list1->repeated.element;
+    size_t c1 = list1->repeated.count;
+    struct format_arg *e2 = list2->repeated.element;
+    size_t c2 = list2->repeated.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->repeated.  */
         grow_repeated_alloc (result);
-        re = &result->repeated.element[result->repeated.count];
+        struct format_arg *re = &result->repeated.element[result->repeated.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1549,20 +1540,13 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
   /* Step 4: Elementwise union of list1->initial, list2->initial.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->initial.element; c1 = list1->initial.count;
-    e2 = list2->initial.element; c2 = list2->initial.count;
+    struct format_arg *e1 = list1->initial.element; size_t c1 = list1->initial.count;
+    struct format_arg *e2 = list2->initial.element; size_t c2 = list2->initial.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->initial.  */
         grow_initial_alloc (result);
-        re = &result->initial.element[result->initial.count];
+        struct format_arg *re = &result->initial.element[result->initial.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Union of the argument types.  */
@@ -1593,11 +1577,9 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
         if (e1->presence == FCT_REQUIRED)
           {
-            struct format_arg *re;
-
             /* Ensure room in result->initial.  */
             grow_initial_alloc (result);
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e1);
             re->presence = FCT_OPTIONAL;
             re->repcount = 1;
@@ -1615,9 +1597,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
         ensure_initial_alloc (result, result->initial.count + c1);
         while (c1 > 0)
           {
-            struct format_arg *re;
-
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e1);
             result->initial.count++;
             result->initial.length += re->repcount;
@@ -1633,11 +1613,9 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
         if (e2->presence == FCT_REQUIRED)
           {
-            struct format_arg *re;
-
             /* Ensure room in result->initial.  */
             grow_initial_alloc (result);
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e2);
             re->presence = FCT_OPTIONAL;
             re->repcount = 1;
@@ -1655,9 +1633,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
         ensure_initial_alloc (result, result->initial.count + c2);
         while (c2 > 0)
           {
-            struct format_arg *re;
-
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e2);
             result->initial.count++;
             result->initial.length += re->repcount;
@@ -1671,20 +1647,15 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
   if (list1->repeated.length > 0 && list2->repeated.length > 0)
     /* Step 5: Elementwise union of list1->repeated, list2->repeated.  */
     {
-      struct format_arg *e1;
-      struct format_arg *e2;
-      size_t c1;
-      size_t c2;
-
-      e1 = list1->repeated.element; c1 = list1->repeated.count;
-      e2 = list2->repeated.element; c2 = list2->repeated.count;
+      struct format_arg *e1 = list1->repeated.element;
+      size_t c1 = list1->repeated.count;
+      struct format_arg *e2 = list2->repeated.element;
+      size_t c2 = list2->repeated.count;
       while (c1 > 0 && c2 > 0)
         {
-          struct format_arg *re;
-
           /* Ensure room in result->repeated.  */
           grow_repeated_alloc (result);
-          re = &result->repeated.element[result->repeated.count];
+          struct format_arg *re = &result->repeated.element[result->repeated.count];
           re->repcount = MIN (e1->repcount, e2->repcount);
 
           /* Union of the argument types.  */
@@ -1712,13 +1683,11 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     {
       /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the
          initial segment.  Just copy the repeated segment of list1.  */
-      size_t i;
-
       result->repeated.count = list1->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
         XNMALLOC (result->repeated.allocated, struct format_arg);
-      for (i = 0; i < list1->repeated.count; i++)
+      for (size_t i = 0; i < list1->repeated.count; i++)
         copy_element (&result->repeated.element[i],
                       &list1->repeated.element[i]);
       result->repeated.length = list1->repeated.length;
@@ -1727,13 +1696,11 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     {
       /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the
          initial segment.  Just copy the repeated segment of list2.  */
-      size_t i;
-
       result->repeated.count = list2->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
         XNMALLOC (result->repeated.allocated, struct format_arg);
-      for (i = 0; i < list2->repeated.count; i++)
+      for (size_t i = 0; i < list2->repeated.count; i++)
         copy_element (&result->repeated.element[i],
                       &list2->repeated.element[i]);
       result->repeated.length = list2->repeated.length;
@@ -1812,50 +1779,57 @@ union (struct format_arg_list *list1, struct format_arg_list *list2)
 static bool
 is_required (const struct format_arg_list *list, size_t n)
 {
-  size_t s;
   size_t t;
 
   /* We'll check whether the first n+1 presence flags are FCT_REQUIRED.  */
   t = n + 1;
 
   /* Walk the list->initial segment.  */
-  for (s = 0;
-       s < list->initial.count && t >= list->initial.element[s].repcount;
-       t -= list->initial.element[s].repcount, s++)
-    if (list->initial.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->initial.count)
-    {
+    for (s = 0;
+         s < list->initial.count && t >= list->initial.element[s].repcount;
+         t -= list->initial.element[s].repcount, s++)
       if (list->initial.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->initial.count)
+      {
+        if (list->initial.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* Walk the list->repeated segment.  */
   if (list->repeated.count == 0)
     return false;
 
-  for (s = 0;
-       s < list->repeated.count && t >= list->repeated.element[s].repcount;
-       t -= list->repeated.element[s].repcount, s++)
-    if (list->repeated.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->repeated.count)
-    {
+    for (s = 0;
+         s < list->repeated.count && t >= list->repeated.element[s].repcount;
+         t -= list->repeated.element[s].repcount, s++)
       if (list->repeated.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->repeated.count)
+      {
+        if (list->repeated.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* The list->repeated segment consists only of FCT_REQUIRED.  So,
      regardless how many more passes through list->repeated would be
@@ -1870,8 +1844,6 @@ is_required (const struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_required_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t i, rest;
-
   if (list == NULL)
     return NULL;
 
@@ -1887,12 +1859,15 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 
   initial_splitelement (list, n + 1);
 
-  for (i = 0, rest = n + 1; rest > 0; )
-    {
-      list->initial.element[i].presence = FCT_REQUIRED;
-      rest -= list->initial.element[i].repcount;
-      i++;
-    }
+  {
+    size_t i = 0;
+    for (size_t rest = n + 1; rest > 0; )
+      {
+        list->initial.element[i].presence = FCT_REQUIRED;
+        rest -= list->initial.element[i].repcount;
+        i++;
+      }
+  }
 
   VERIFY_LIST (list);
 
@@ -1907,9 +1882,6 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_end_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t s, i;
-  enum format_cdr_type n_presence;
-
   if (list == NULL)
     return NULL;
 
@@ -1919,20 +1891,20 @@ add_end_constraint (struct format_arg_list *list, size_t n)
     /* list is already constrained to have at most length n.  */
     return list;
 
-  s = initial_splitelement (list, n);
-  n_presence =
+  size_t s = initial_splitelement (list, n);
+  enum format_cdr_type n_presence =
     (s < list->initial.count
      ? /* n < list->initial.length */ list->initial.element[s].presence
      : /* n >= list->initial.length */ list->repeated.element[0].presence);
 
-  for (i = s; i < list->initial.count; i++)
+  for (size_t i = s; i < list->initial.count; i++)
     {
       list->initial.length -= list->initial.element[i].repcount;
       free_element (&list->initial.element[i]);
     }
   list->initial.count = s;
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -1956,20 +1928,19 @@ static struct format_arg_list *
 add_type_constraint (struct format_arg_list *list, size_t n,
                      enum format_arg_type type)
 {
-  size_t s;
-  struct format_arg newconstraint;
-  struct format_arg tmpelement;
-
   if (list == NULL)
     return NULL;
 
   /* Through the previous add_required_constraint, we can assume
      list->initial.length >= n+1.  */
 
-  s = initial_unshare (list, n);
+  size_t s = initial_unshare (list, n);
 
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
+
+  struct format_arg tmpelement;
   if (!make_intersected_element (&tmpelement,
                                  &list->initial.element[s], &newconstraint))
     list = add_end_constraint (list, n);
@@ -1996,21 +1967,20 @@ add_listtype_constraint (struct format_arg_list *list, size_t n,
                          enum format_arg_type type,
                          struct format_arg_list *sublist)
 {
-  size_t s;
-  struct format_arg newconstraint;
-  struct format_arg tmpelement;
-
   if (list == NULL)
     return NULL;
 
   /* Through the previous add_required_constraint, we can assume
      list->initial.length >= n+1.  */
 
-  s = initial_unshare (list, n);
+  size_t s = initial_unshare (list, n);
 
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
   newconstraint.list = sublist;
+
+  struct format_arg tmpelement;
   if (!make_intersected_element (&tmpelement,
                                  &list->initial.element[s], &newconstraint))
     list = add_end_constraint (list, n);
@@ -2060,10 +2030,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
     return make_empty_list ();
   else
     {
-      struct format_arg_list *listlist;
-
-      listlist = XMALLOC (struct format_arg_list);
-
+      struct format_arg_list *listlist = XMALLOC (struct format_arg_list);
       listlist->initial.count = 0;
       listlist->initial.allocated = 0;
       listlist->initial.element = NULL;
@@ -2097,16 +2064,13 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
 static struct format_arg_list *
 make_repeated_list (struct format_arg_list *sublist, size_t period)
 {
-  struct segment tmp;
-  struct segment *srcseg;
-  struct format_arg_list *list;
-  size_t p, n, i, si, ti, j, sj, tj, splitindex, newcount;
-  bool ended;
-
   VERIFY_LIST (sublist);
 
   ASSERT (period > 0);
 
+  struct segment *srcseg;
+  struct segment tmp;
+  size_t p;
   if (sublist->repeated.count == 0)
     {
       /* L is a finite list.  */
@@ -2134,16 +2098,22 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
       tmp.count = sublist->initial.count + sublist->repeated.count;
       tmp.allocated = tmp.count;
       tmp.element = XNMALLOC (tmp.allocated, struct format_arg);
-      for (i = 0; i < sublist->initial.count; i++)
-        tmp.element[i] = sublist->initial.element[i];
-      for (j = 0; j < sublist->repeated.count; i++, j++)
-        tmp.element[i] = sublist->repeated.element[j];
+      {
+        size_t i;
+        for (i = 0; i < sublist->initial.count; i++)
+          tmp.element[i] = sublist->initial.element[i];
+        for (size_t j = 0; j < sublist->repeated.count; j++)
+          {
+            tmp.element[i] = sublist->repeated.element[j];
+            i++;
+          }
+      }
       tmp.length = sublist->initial.length + sublist->repeated.length;
 
       srcseg = &tmp;
     }
 
-  n = srcseg->length;
+  size_t n = srcseg->length;
 
   /* Example: n = 7, p = 2
      Let L = (A B C D E F G).
@@ -2158,7 +2128,7 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
      Or by a single incremental intersection operation, going from left
      to right.  */
 
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -2176,109 +2146,121 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
        list->initial.element[i] = srcseg->element[i] & list->initial.element[j];
    */
 
-  ended = false;
-
-  i = 0, ti = 0, si = 0;
-  while (i < p)
-    {
-      size_t k = MIN (srcseg->element[si].repcount - ti, p - i);
-
-      /* Ensure room in list->initial.  */
-      grow_initial_alloc (list);
-      copy_element (&list->initial.element[list->initial.count],
-                    &srcseg->element[si]);
-      list->initial.element[list->initial.count].repcount = k;
-      list->initial.count++;
-      list->initial.length += k;
+  bool ended = false;
 
-      i += k;
-      ti += k;
-      if (ti == srcseg->element[si].repcount)
-        {
-          ti = 0;
-          si++;
-        }
-    }
-
-  ASSERT (list->initial.count > 0);
-  if (list->initial.element[0].presence == FCT_REQUIRED)
-    {
-      initial_splitelement (list, 1);
-      ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
-      ASSERT (list->initial.element[0].repcount == 1);
-      list->initial.element[0].presence = FCT_OPTIONAL;
-    }
+  {
+    size_t i = 0;
+    size_t ti = 0;
+    size_t si = 0;
+    while (i < p)
+      {
+        size_t k = MIN (srcseg->element[si].repcount - ti, p - i);
+
+        /* Ensure room in list->initial.  */
+        grow_initial_alloc (list);
+        copy_element (&list->initial.element[list->initial.count],
+                      &srcseg->element[si]);
+        list->initial.element[list->initial.count].repcount = k;
+        list->initial.count++;
+        list->initial.length += k;
+
+        i += k;
+        ti += k;
+        if (ti == srcseg->element[si].repcount)
+          {
+            ti = 0;
+            si++;
+          }
+      }
 
-  j = 0, tj = 0, sj = 0;
-  while (i < n)
-    {
-      size_t k =
-        MIN (srcseg->element[si].repcount - ti,
-             list->initial.element[sj].repcount - tj);
+    ASSERT (list->initial.count > 0);
+    if (list->initial.element[0].presence == FCT_REQUIRED)
+      {
+        initial_splitelement (list, 1);
+        ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
+        ASSERT (list->initial.element[0].repcount == 1);
+        list->initial.element[0].presence = FCT_OPTIONAL;
+      }
 
-      /* Ensure room in list->initial.  */
-      grow_initial_alloc (list);
-      if (!make_intersected_element (&list->initial.element[list->initial.count],
-                                     &srcseg->element[si],
-                                     &list->initial.element[sj]))
-        {
-          if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
-            {
-              /* Contradiction.  Backtrack.  */
-              list = backtrack_in_initial (list);
-              ASSERT (list != NULL); /* at least the empty list is valid */
-              return list;
-            }
-          else
-            {
-              /* The list ends here.  */
-              ended = true;
-              break;
-            }
-        }
-      list->initial.element[list->initial.count].repcount = k;
-      list->initial.count++;
-      list->initial.length += k;
+    size_t j = 0;
+    size_t tj = 0;
+    size_t sj = 0;
+    while (i < n)
+      {
+        size_t k =
+          MIN (srcseg->element[si].repcount - ti,
+               list->initial.element[sj].repcount - tj);
+
+        /* Ensure room in list->initial.  */
+        grow_initial_alloc (list);
+        if (!make_intersected_element (&list->initial.element[list->initial.count],
+                                       &srcseg->element[si],
+                                       &list->initial.element[sj]))
+          {
+            if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
+              {
+                /* Contradiction.  Backtrack.  */
+                list = backtrack_in_initial (list);
+                ASSERT (list != NULL); /* at least the empty list is valid */
+                return list;
+              }
+            else
+              {
+                /* The list ends here.  */
+                ended = true;
+                break;
+              }
+          }
+        list->initial.element[list->initial.count].repcount = k;
+        list->initial.count++;
+        list->initial.length += k;
 
-      i += k;
-      ti += k;
-      if (ti == srcseg->element[si].repcount)
-        {
-          ti = 0;
-          si++;
-        }
+        i += k;
+        ti += k;
+        if (ti == srcseg->element[si].repcount)
+          {
+            ti = 0;
+            si++;
+          }
 
-      j += k;
-      tj += k;
-      if (tj == list->initial.element[sj].repcount)
-        {
-          tj = 0;
-          sj++;
-        }
-    }
-  if (!ended)
-    ASSERT (list->initial.length == n);
+        j += k;
+        tj += k;
+        if (tj == list->initial.element[sj].repcount)
+          {
+            tj = 0;
+            sj++;
+          }
+      }
+    if (!ended)
+      ASSERT (list->initial.length == n);
+  }
 
   /* Add optional exit points at 0, period, 2*period etc.
      FIXME: Not sure this is correct in all cases.  */
-  for (i = 0; i < list->initial.length; i += period)
+  for (size_t i = 0; i < list->initial.length; i += period)
     {
-      si = initial_unshare (list, i);
+      size_t si = initial_unshare (list, i);
       list->initial.element[si].presence = FCT_OPTIONAL;
     }
 
   if (!ended)
     {
       /* Now split off the repeated part.  */
-      splitindex = initial_splitelement (list, n - p);
-      newcount = list->initial.count - splitindex;
+      size_t splitindex = initial_splitelement (list, n - p);
+      size_t newcount = list->initial.count - splitindex;
       if (newcount > list->repeated.allocated)
         {
           list->repeated.allocated = newcount;
           list->repeated.element = XNMALLOC (newcount, struct format_arg);
         }
-      for (i = splitindex, j = 0; j < newcount; i++, j++)
-        list->repeated.element[j] = list->initial.element[i];
+      {
+        size_t i = splitindex;
+        for (size_t j = 0; j < newcount; j++)
+          {
+            list->repeated.element[j] = list->initial.element[i];
+            i++;
+          }
+      }
       list->repeated.count = newcount;
       list->repeated.length = p;
       list->initial.count = splitindex;
@@ -2468,17 +2450,14 @@ parse_upto (const char **formatp,
   for (; *format != '\0'; )
     if (*format++ == '~')
       {
-        bool colon_p = false;
-        bool atsign_p = false;
-        size_t paramcount = 0;
-        struct param *params = NULL;
-
         FDI_SET (format - 1, FMTDIR_START);
 
         /* Count number of directives.  */
         spec->directives++;
 
         /* Parse parameters.  */
+        size_t paramcount = 0;
+        struct param *params = NULL;
         for (;;)
           {
             enum param_type type = PT_NIL;
@@ -2564,6 +2543,8 @@ parse_upto (const char **formatp,
           }
 
         /* Parse modifiers.  */
+        bool colon_p = false;
+        bool atsign_p = false;
         for (;;)
           {
             if (*format == ':')
@@ -2882,9 +2863,6 @@ parse_upto (const char **formatp,
               }
             else if (atsign_p)
               {
-                struct format_arg_list *nil_list;
-                struct format_arg_list *union_list;
-
                 if (!check_params (&list, paramcount, params, 0, NULL,
                                    spec->directives, invalid_reason))
                   {
@@ -2896,7 +2874,8 @@ parse_upto (const char **formatp,
                 *escapep = escape;
 
                 /* First alternative: argument is NIL.  */
-                nil_list = (list != NULL ? copy_list (list) : NULL);
+                struct format_arg_list *nil_list =
+                  (list != NULL ? copy_list (list) : NULL);
                 if (position >= 0)
                   {
                     struct format_arg_list *empty_list = make_empty_list ();
@@ -2906,6 +2885,7 @@ parse_upto (const char **formatp,
                   }
 
                 /* Second alternative: use sub-format.  */
+                struct format_arg_list *union_list;
                 {
                   int sub_position = position;
                   struct format_arg_list *sub_list =
@@ -2947,9 +2927,6 @@ parse_upto (const char **formatp,
               }
             else if (colon_p)
               {
-                int union_position;
-                struct format_arg_list *union_list;
-
                 if (!check_params (&list, paramcount, params, 0, NULL,
                                    spec->directives, invalid_reason))
                   {
@@ -2962,8 +2939,8 @@ parse_upto (const char **formatp,
 
                 *formatp = format;
                 *escapep = escape;
-                union_position = -2;
-                union_list = NULL;
+                int union_position = -2;
+                struct format_arg_list *union_list = NULL;
 
                 /* First alternative.  */
                 {
@@ -3034,11 +3011,6 @@ parse_upto (const char **formatp,
               }
             else
               {
-                int arg_position;
-                int union_position;
-                struct format_arg_list *union_list;
-                bool last_alternative;
-
                 if (!check_params (&list, paramcount, params, 1, I,
                                    spec->directives, invalid_reason))
                   {
@@ -3047,7 +3019,7 @@ parse_upto (const char **formatp,
                   }
 
                 /* If there was no first parameter, an argument is consumed.  */
-                arg_position = -1;
+                int arg_position = -1;
                 if (!(paramcount >= 1 && params[0].type != PT_NIL))
                   if (position >= 0)
                     {
@@ -3058,9 +3030,9 @@ parse_upto (const char **formatp,
                 *formatp = format;
                 *escapep = escape;
 
-                union_position = -2;
-                union_list = NULL;
-                last_alternative = false;
+                int union_position = -2;
+                struct format_arg_list *union_list = NULL;
+                bool last_alternative = false;
                 for (;;)
                   {
                     /* Next alternative.  */
@@ -3171,12 +3143,12 @@ parse_upto (const char **formatp,
               if (colon_p)
                 {
                   /* Each iteration uses a new sublist.  */
-                  struct format_arg_list *listlist;
 
                   /* ~{ catches ~^.  */
                   sub_list = union (sub_list, sub_escape);
 
-                  listlist = make_repeated_list_of_lists (sub_list);
+                  struct format_arg_list *listlist =
+                    make_repeated_list_of_lists (sub_list);
 
                   sub_list = listlist;
                 }
@@ -3184,7 +3156,6 @@ parse_upto (const char **formatp,
                 {
                   /* Each iteration's arguments are all concatenated in a
                      single list.  */
-                  struct format_arg_list *looplist;
 
                   /* FIXME: This is far from correct.  Test cases:
                      abc~{~^~}
@@ -3198,6 +3169,7 @@ parse_upto (const char **formatp,
                   /* ~{ catches ~^.  */
                   sub_list = union (sub_list, sub_escape);
 
+                  struct format_arg_list *looplist;
                   if (sub_list == NULL)
                     looplist = make_empty_list ();
                   else
@@ -3424,13 +3396,11 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
-  int position = 0;
-  struct format_arg_list *escape;
-
   spec.directives = 0;
   spec.list = make_unconstrained_list ();
-  escape = NULL;
+
+  int position = 0;
+  struct format_arg_list *escape = NULL;
 
   if (!parse_upto (&format, &position, &spec.list, &escape,
                    NULL, &spec, '\0', false,
@@ -3452,7 +3422,7 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Normalize the result.  */
   normalize_list (spec.list);
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -3592,12 +3562,10 @@ print_element (struct format_arg *element)
 static void
 print_list (struct format_arg_list *list)
 {
-  size_t i, j;
-
   printf ("(");
 
-  for (i = 0; i < list->initial.count; i++)
-    for (j = 0; j < list->initial.element[i].repcount; j++)
+  for (size_t i = 0; i < list->initial.count; i++)
+    for (size_t j = 0; j < list->initial.element[i].repcount; j++)
       {
         if (i > 0 || j > 0)
           printf (" ");
@@ -3607,8 +3575,8 @@ print_list (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       printf (" |");
-      for (i = 0; i < list->repeated.count; i++)
-        for (j = 0; j < list->repeated.element[i].repcount; j++)
+      for (size_t i = 0; i < list->repeated.count; i++)
+        for (size_t j = 0; j < list->repeated.element[i].repcount; j++)
           {
             printf (" ");
             print_element (&list->repeated.element[i]);
@@ -3639,18 +3607,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 5edfdd7fb61a6c41ece8f07e75aa7b6a51b4b55b..126befbd8ca563db5e848d39b1f2ecfc482633c8 100644 (file)
@@ -78,14 +78,12 @@ format_parse (const char *format, bool translated, char *fdi,
 
   const char *format_start = format;
   const char *fatstr = format;
-  struct spec spec;
-  struct spec *result;
-  size_t format_args_allocated;
 
+  struct spec spec;
   spec.directives = 0;
   spec.format_args_count = 0;
   spec.format_args = NULL;
-  format_args_allocated = 0;
+  size_t format_args_allocated = 0;
 
   for (; *fatstr != '\0';)
     {
@@ -96,8 +94,6 @@ format_parse (const char *format, bool translated, char *fdi,
 
           if (*fatstr != '%')
             {
-              enum format_arg_type type;
-
               /* Parse width. */
               if (c_isdigit (*fatstr))
                 {
@@ -119,6 +115,7 @@ format_parse (const char *format, bool translated, char *fdi,
                     }
                 }
 
+              enum format_arg_type type;
               switch (*fatstr)
                 {
                 case 'c':
@@ -178,7 +175,7 @@ format_parse (const char *format, bool translated, char *fdi,
         }
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -239,11 +236,9 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
         }
       else
         {
-          size_t i;
-
           /* Check that the argument types are the same.  */
           if (!err)
-            for (i = 0; i < n2; i++)
+            for (size_t i = 0; i < n2; i++)
               {
                 if (spec1->format_args[i] != spec2->format_args[i])
                   {
@@ -282,7 +277,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -291,7 +285,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->format_args_count; i++)
+  for (size_t i = 0; i < spec->format_args_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -326,18 +320,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index ca74abbb5610364932bdcab2d376b535b17f7737..949065e745237f0cce47d4c3c09ee46ee8a0101f 100644 (file)
@@ -71,14 +71,12 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t args_allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.arg_count = 0;
   spec.args = NULL;
-  args_allocated = 0;
+  size_t args_allocated = 0;
 
   for (; *format != '\0';)
     {
@@ -93,8 +91,6 @@ format_parse (const char *format, bool translated, char *fdi,
 
               if (*format != '%')
                 {
-                  enum format_arg_type type;
-
                   /* Parse flags.  */
                   if (*format == '-')
                     format++;
@@ -105,6 +101,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   while (c_isdigit (*format))
                     format++;
 
+                  enum format_arg_type type;
                   switch (*format)
                     {
                     case 's':
@@ -149,7 +146,7 @@ format_parse (const char *format, bool translated, char *fdi,
         }
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -210,11 +207,9 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
         }
       else
         {
-          size_t i;
-
           /* Check that the argument types are the same.  */
           if (!err)
-            for (i = 0; i < n2; i++)
+            for (size_t i = 0; i < n2; i++)
               {
                 if (spec1->args[i] != spec2->args[i])
                   {
@@ -255,7 +250,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -264,7 +258,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->arg_count; i++)
+  for (size_t i = 0; i < spec->arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -296,18 +290,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index cec56fd077920e97808423fa1a8ba6d8e2b3c933..9419db6ab2cd67a4181294e2923e169b0ac458d2 100644 (file)
@@ -147,8 +147,7 @@ destroy_spec (struct spec *spec)
 {
   if (spec->numbered != NULL)
     {
-      size_t i;
-      for (i = spec->numbered_arg_count; i > 0; )
+      for (size_t i = spec->numbered_arg_count; i > 0; )
         {
           --i;
           if (spec->numbered[i].type == FAT_FORMAT_STRING)
@@ -263,27 +262,22 @@ parse_upto (struct spec *spec,
 {
   const char *format = *formatp;
   const char *const format_start = format;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
 
   spec->directives = 0;
   spec->numbered_arg_count = 0;
   spec->numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec->numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        format_arg_type_t type;
-        char *signature = NULL;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec->directives++;
 
+        size_t number = 0;
         if (translated && c_isdigit (*format))
           {
             const char *f = format;
@@ -317,10 +311,9 @@ parse_upto (struct spec *spec,
         /* Parse width.  */
         if (*format == '*')
           {
-            size_t width_number = 0;
-
             format++;
 
+            size_t width_number = 0;
             if (translated && c_isdigit (*format))
               {
                 const char *f = format;
@@ -402,10 +395,9 @@ parse_upto (struct spec *spec,
 
             if (*format == '*')
               {
-                size_t precision_number = 0;
-
                 format++;
 
+                size_t precision_number = 0;
                 if (translated && c_isdigit (*format))
                   {
                     const char *f = format;
@@ -499,6 +491,8 @@ parse_upto (struct spec *spec,
             format++;
           }
 
+        format_arg_type_t type;
+        char *signature = NULL;
         switch (*format)
           {
           case 'd':
@@ -782,21 +776,19 @@ parse_upto (struct spec *spec,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec->numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec->numbered, spec->numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec->numbered_arg_count; i++)
         if (j > 0 && spec->numbered[i].number == spec->numbered[j-1].number)
           {
             format_arg_type_t type1 = spec->numbered[i].type;
             format_arg_type_t type2 = spec->numbered[j-1].type;
-            format_arg_type_t type_both;
 
+            format_arg_type_t type_both;
             if (((type1 == type2)
                  && (type1 != FAT_FORMAT_STRING
                      || strcmp (spec->numbered[i].signature,
@@ -849,12 +841,11 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
 
   if (!parse_upto (&spec, &format, '\0', translated, fdi, invalid_reason))
     return NULL;
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -887,77 +878,82 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check that the argument types are essentially the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                format_arg_type_t type1 = spec1->numbered[i].type;
-                format_arg_type_t type2 = spec2->numbered[j].type;
-
-                if (!(((type1 == type2)
-                       && (type1 != FAT_FORMAT_STRING
-                           || strcmp (spec1->numbered[i].signature,
-                                      spec2->numbered[j].signature) == 0))
-                      || ((type2 & FAT_OPTIONAL_OCAML_SYNTAX) != 0
-                          && (type2 & ~FAT_OPTIONAL_OCAML_SYNTAX)
-                             == (type1 & ~FAT_OCAML_SYNTAX))))
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check that the argument types are essentially the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  format_arg_type_t type1 = spec1->numbered[i].type;
+                  format_arg_type_t type2 = spec2->numbered[j].type;
+
+                  if (!(((type1 == type2)
+                         && (type1 != FAT_FORMAT_STRING
+                             || strcmp (spec1->numbered[i].signature,
+                                        spec2->numbered[j].signature) == 0))
+                        || ((type2 & FAT_OPTIONAL_OCAML_SYNTAX) != 0
+                            && (type2 & ~FAT_OPTIONAL_OCAML_SYNTAX)
+                               == (type1 & ~FAT_OCAML_SYNTAX))))
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -985,8 +981,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -995,8 +989,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -1063,18 +1057,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, true, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, true, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index f6e83259e3f650498b74bf157c128e2c892fa507..99129ce901fed7b2c5e873bd0033bd87029f3f41 100644 (file)
@@ -100,12 +100,6 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  size_t directives;
-  size_t numbered_arg_count;
-  struct numbered_arg *numbered;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
   enum arg_index
   {
@@ -114,11 +108,11 @@ format_parse (const char *format, bool translated, char *fdi,
     index_unknown       /* index is only known at run time */
   };
 
-  directives = 0;
-  numbered_arg_count = 0;
-  numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t directives = 0;
+  size_t numbered_arg_count = 0;
+  struct numbered_arg *numbered = NULL;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
@@ -132,8 +126,6 @@ format_parse (const char *format, bool translated, char *fdi,
             /* A complex directive.  */
             enum arg_index main_arg = index_unnumbered;
             size_t main_number = 0;
-            enum format_arg_type type;
-
             if (c_isdigit (*format) || *format == ':')
               {
                 const char *f = format;
@@ -216,6 +208,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   }
               }
 
+            enum format_arg_type type;
             switch (c_tolower (*format))
               {
               case 'd': case 'u': case 'x':
@@ -280,21 +273,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (numbered, numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < numbered_arg_count; i++)
         if (j > 0 && numbered[i].number == numbered[j-1].number)
           {
             enum format_arg_type type1 = numbered[i].type;
             enum format_arg_type type2 = numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -324,7 +315,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   result->directives = directives;
   result->numbered_arg_count = numbered_arg_count;
   result->numbered = numbered;
@@ -365,68 +356,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -454,8 +450,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -464,8 +458,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 0;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 0;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -504,18 +498,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index fa49165948927eaa0fd64538bd88c88112d4b6cd..100ca3ae891b93892d5b115a97a5b131ff9e5bcd 100644 (file)
@@ -60,14 +60,12 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t named_allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.named_arg_count = 0;
   spec.named = NULL;
-  named_allocated = 0;
+  size_t named_allocated = 0;
 
   for (; *format != '\0';)
     if (*format++ == '{')
@@ -85,14 +83,13 @@ format_parse (const char *format, bool translated, char *fdi,
             if (c == '}')
               {
                 /* A directive.  */
-                char *name;
+                FDI_SET (format - 1, FMTDIR_START);
+
                 const char *name_start = format;
                 const char *name_end = f;
                 size_t n = name_end - name_start;
 
-                FDI_SET (format - 1, FMTDIR_START);
-
-                name = XNMALLOC (n + 1, char);
+                char *name = XNMALLOC (n + 1, char);
                 memcpy (name, name_start, n);
                 name[n] = '\0';
 
@@ -116,12 +113,11 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           free (spec.named[i].name);
@@ -134,7 +130,7 @@ format_parse (const char *format, bool translated, char *fdi,
       spec.named_arg_count = j;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -146,8 +142,7 @@ format_free (void *descr)
 
   if (spec->named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         free (spec->named[i].name);
       free (spec->named);
     }
@@ -173,7 +168,6 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->named_arg_count + spec2->named_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->named_arg_count;
       size_t n2 = spec2->named_arg_count;
 
@@ -181,6 +175,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
          Additional arguments in spec2 are allowed; they expand to themselves
          (including the surrounding braces) at runtime.
          Both arrays are sorted.  We search for the differences.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -233,7 +228,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -242,7 +236,7 @@ format_print (void *descr)
     }
 
   printf ("{");
-  for (i = 0; i < spec->named_arg_count; i++)
+  for (size_t i = 0; i < spec->named_arg_count; i++)
     {
       if (i > 0)
         printf (", ");
@@ -258,18 +252,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 2816d11c084f8c1e69b6b16bf377b9bf800f516f..fd10af17d444be719fa7bbf3f01b25a1e51d884a 100644 (file)
@@ -133,34 +133,23 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  size_t directives;
-  size_t likely_intentional_directives;
-  size_t numbered_arg_count;
-  struct numbered_arg *numbered;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
-  directives = 0;
-  likely_intentional_directives = 0;
-  numbered_arg_count = 0;
-  numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t directives = 0;
+  size_t likely_intentional_directives = 0;
+  size_t numbered_arg_count = 0;
+  struct numbered_arg *numbered = NULL;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        size_t number = 0;
-        bool vectorize = false;
-        format_arg_type_t type;
-        format_arg_type_t size;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         directives++;
+        bool likely_intentional = true;
 
+        size_t number = 0;
         if (c_isnonzerodigit (*format))
           {
             const char *f = format;
@@ -190,6 +179,7 @@ format_parse (const char *format, bool translated, char *fdi,
           }
 
         /* Parse vector.  */
+        bool vectorize = false;
         if (*format == 'v')
           {
             format++;
@@ -268,10 +258,9 @@ format_parse (const char *format, bool translated, char *fdi,
         /* Parse width.  */
         if (*format == '*')
           {
-            size_t width_number = 0;
-
             format++;
 
+            size_t width_number = 0;
             if (c_isnonzerodigit (*format))
               {
                 const char *f = format;
@@ -315,10 +304,9 @@ format_parse (const char *format, bool translated, char *fdi,
 
             if (*format == '*')
               {
-                size_t precision_number = 0;
-
                 format++;
 
+                size_t precision_number = 0;
                 if (c_isnonzerodigit (*format))
                   {
                     const char *f = format;
@@ -355,7 +343,7 @@ format_parse (const char *format, bool translated, char *fdi,
           }
 
         /* Parse size.  */
-        size = 0;
+        format_arg_type_t size = 0;
         if (*format == 'h')
           {
             size = FAT_SIZE_SHORT;
@@ -403,6 +391,7 @@ format_parse (const char *format, bool translated, char *fdi,
               }
           }
 
+        format_arg_type_t type;
         switch (*format)
           {
           case '%':
@@ -483,21 +472,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (numbered, numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < numbered_arg_count; i++)
         if (j > 0 && numbered[i].number == numbered[j-1].number)
           {
             format_arg_type_t type1 = numbered[i].type;
             format_arg_type_t type2 = numbered[j-1].type;
-            format_arg_type_t type_both;
 
+            format_arg_type_t type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -527,7 +514,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   result->directives = directives;
   result->likely_intentional_directives = likely_intentional_directives;
   result->numbered_arg_count = numbered_arg_count;
@@ -577,68 +564,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -666,8 +658,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -676,8 +666,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -749,18 +739,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 9a577ff9ccfccdd776c9a3ef901a0174c5821c48..42bda22ebff0827e7ec793603667eb85c8f9a37a 100644 (file)
@@ -96,37 +96,27 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  size_t directives;
-  size_t likely_intentional_directives;
-  size_t numbered_arg_count;
-  struct numbered_arg *numbered;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
-  directives = 0;
-  likely_intentional_directives = 0;
-  numbered_arg_count = 0;
-  numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t directives = 0;
+  size_t likely_intentional_directives = 0;
+  size_t numbered_arg_count = 0;
+  struct numbered_arg *numbered = NULL;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         directives++;
+        bool likely_intentional = true;
 
         if (*format != '%')
           {
             /* A complex directive.  */
-            size_t number;
-            enum format_arg_type type;
 
-            number = ++unnumbered_arg_count;
+            size_t number = ++unnumbered_arg_count;
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -204,6 +194,7 @@ format_parse (const char *format, bool translated, char *fdi,
             if (*format == 'l')
               format++;
 
+            enum format_arg_type type;
             switch (*format)
               {
               case 'b': case 'd': case 'u': case 'o': case 'x': case 'X':
@@ -254,21 +245,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (numbered, numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < numbered_arg_count; i++)
         if (j > 0 && numbered[i].number == numbered[j-1].number)
           {
             enum format_arg_type type1 = numbered[i].type;
             enum format_arg_type type2 = numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -298,7 +287,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   result->directives = directives;
   result->likely_intentional_directives = likely_intentional_directives;
   result->numbered_arg_count = numbered_arg_count;
@@ -348,68 +337,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
+              {
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -437,8 +431,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -447,8 +439,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -487,18 +479,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index ddb543d44b396f94c473e3457a20c9ac6171b856..971cb798da2798d936f0bb570fa99b985d442f72 100644 (file)
@@ -152,8 +152,7 @@ parse_directive (struct spec *spec,
 {
   const char *format = *formatp;
   const char *const format_start = format;
-  const char *name_start;
-  const char *name_end;
+
   char c;
 
   c = *++format;
@@ -164,7 +163,7 @@ parse_directive (struct spec *spec,
       return true;
     }
 
-  name_start = format;
+  const char *name_start = format;
   if (parse_named_field (spec, &format, fdi, invalid_reason)
       || parse_numeric_field (spec, &format, fdi, invalid_reason))
     {
@@ -256,7 +255,7 @@ parse_directive (struct spec *spec,
           return false;
         }
     }
-  name_end = format;
+  const char *name_end = format;
 
   if (*format == ':')
     {
@@ -295,9 +294,7 @@ parse_directive (struct spec *spec,
              [[fill]align][sign][#][0][minimumwidth][.precision][type]  */
 
           /* Look ahead two characters to skip [[fill]align].  */
-          int c1, c2;
-
-          c1 = format[0];
+          int c1 = format[0];
           if (c1 == '\0')
             {
               *invalid_reason =
@@ -307,7 +304,7 @@ parse_directive (struct spec *spec,
               return false;
             }
 
-          c2 = format[1];
+          int c2 = format[1];
 
           if (c2 == '<' || c2 == '>' || c2 == '=' || c2 == '^')
             format += 2;
@@ -362,11 +359,10 @@ parse_directive (struct spec *spec,
 
   if (toplevel != NULL)
     {
-      char *name;
-      size_t n = name_end - name_start;
-
       FDI_SET (name_start - 1, FMTDIR_START);
 
+      size_t n = name_end - name_start;
+      char *name;
       if (n == 0)
         {
           if (toplevel->numbered_arg_counter > 0)
@@ -448,14 +444,12 @@ format_parse (const char *format, bool translated,
               char *fdi, char **invalid_reason)
 {
   struct spec spec;
-  struct toplevel_counters toplevel;
-  struct spec *result;
-
   spec.directives = 0;
   spec.named_arg_count = 0;
   spec.allocated = 0;
   spec.named = NULL;
 
+  struct toplevel_counters toplevel;
   toplevel.numbered_arg_counter = 0;
   toplevel.unnamed_arg_counter = 0;
   if (!parse_upto (&spec, &format, &toplevel, '\0', fdi, invalid_reason))
@@ -467,12 +461,11 @@ format_parse (const char *format, bool translated,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           free (spec.named[i].name);
@@ -485,7 +478,7 @@ format_parse (const char *format, bool translated,
       spec.named_arg_count = j;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -530,12 +523,12 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->named_arg_count + spec2->named_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->named_arg_count;
       size_t n2 = spec2->named_arg_count;
 
       /* Check the argument names in spec2 are contained in those of spec1.
          Both arrays are sorted.  We search for the first difference.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -596,7 +589,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -605,7 +597,7 @@ format_print (void *descr)
     }
 
   printf ("{");
-  for (i = 0; i < spec->named_arg_count; i++)
+  for (size_t i = 0; i < spec->named_arg_count; i++)
     {
       if (i > 0)
         printf (", ");
@@ -621,18 +613,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 4dab1a9d3f6a3d567433ec75777d3d329cc5964e..e4d773bc7d01a2136bf3aec467c37a2e13ab49d2 100644 (file)
@@ -115,60 +115,53 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.named_arg_count = 0;
   spec.unnamed_arg_count = 0;
   spec.named = NULL;
   spec.unnamed = NULL;
-  allocated = 0;
+  size_t allocated = 0;
 
   for (; *format != '\0';)
     if (*format++ == '%')
       {
         /* A directive.  */
-        char *name = NULL;
-        bool zero_precision = false;
-        enum format_arg_type type;
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
+        char *name = NULL;
         if (*format == '(')
           {
+            const char *name_start = ++format;
             size_t depth;
-            const char *name_start;
-            const char *name_end;
-            size_t n;
-
-            name_start = ++format;
-            depth = 0;
-            for (; *format != '\0'; format++)
-              {
-                if (*format == '(')
-                  depth++;
-                else if (*format == ')')
-                  {
-                    if (depth == 0)
-                      break;
-                    else
-                      depth--;
-                  }
-              }
+            {
+              depth = 0;
+              for (; *format != '\0'; format++)
+                {
+                  if (*format == '(')
+                    depth++;
+                  else if (*format == ')')
+                    {
+                      if (depth == 0)
+                        break;
+                      else
+                        depth--;
+                    }
+                }
+            }
             if (*format == '\0')
               {
                 *invalid_reason = INVALID_UNTERMINATED_DIRECTIVE ();
                 FDI_SET (format - 1, FMTDIR_ERROR);
                 goto bad_format;
               }
-            name_end = format++;
+            const char *name_end = format++;
 
-            n = name_end - name_start;
+            size_t n = name_end - name_start;
             name = XNMALLOC (n + 1, char);
             memcpy (name, name_start, n);
             name[n] = '\0';
@@ -208,6 +201,7 @@ format_parse (const char *format, bool translated, char *fdi,
             do format++; while (c_isdigit (*format));
           }
 
+        bool zero_precision = false;
         if (*format == '.')
           {
             format++;
@@ -249,6 +243,7 @@ format_parse (const char *format, bool translated, char *fdi,
         if (*format == 'h' || *format == 'l' || *format == 'L')
           format++;
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -336,21 +331,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           {
             enum format_arg_type type1 = spec.named[i].type;
             enum format_arg_type type2 = spec.named[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2 || type2 == FAT_ANY)
               type_both = type1;
             else if (type1 == FAT_ANY)
@@ -383,15 +376,14 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
  bad_format:
   if (spec.named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec.named_arg_count; i++)
+      for (size_t i = 0; i < spec.named_arg_count; i++)
         free (spec.named[i].name);
       free (spec.named);
     }
@@ -407,8 +399,7 @@ format_free (void *descr)
 
   if (spec->named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         free (spec->named[i].name);
       free (spec->named);
     }
@@ -462,75 +453,78 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
     {
       if (spec1->named_arg_count + spec2->named_arg_count > 0)
         {
-          size_t i, j;
           size_t n1 = spec1->named_arg_count;
           size_t n2 = spec2->named_arg_count;
 
           /* Check the argument names in spec2 are contained in those of spec1.
              Both arrays are sorted.  We search for the first difference.  */
-          for (i = 0, j = 0; i < n1 || j < n2; )
-            {
-              int cmp = (i >= n1 ? 1 :
-                         j >= n2 ? -1 :
-                         strcmp (spec1->named[i].name, spec2->named[j].name));
-
-              if (cmp > 0)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"),
-                                  spec2->named[j].name, pretty_msgstr,
-                                  pretty_msgid);
-                  err = true;
-                  break;
-                }
-              else if (cmp < 0)
-                {
-                  if (equality)
-                    {
-                      if (error_logger)
-                        error_logger (error_logger_data,
-                                      _("a format specification for argument '%s' doesn't exist in '%s'"),
-                                      spec1->named[i].name, pretty_msgstr);
-                      err = true;
-                      break;
-                    }
-                  else
-                    i++;
-                }
-              else
-                j++, i++;
-            }
-          /* Check the argument types are the same.  */
-          if (!err)
-            for (i = 0, j = 0; j < n2; )
+          {
+            size_t i, j;
+            for (i = 0, j = 0; i < n1 || j < n2; )
               {
-                if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0)
+                int cmp = (i >= n1 ? 1 :
+                           j >= n2 ? -1 :
+                           strcmp (spec1->named[i].name, spec2->named[j].name));
+
+                if (cmp > 0)
                   {
-                    if (!(spec1->named[i].type == spec2->named[j].type
-                          || (!equality
-                              && (spec1->named[i].type == FAT_ANY
-                                  || spec2->named[j].type == FAT_ANY))))
+                    if (error_logger)
+                      error_logger (error_logger_data,
+                                    _("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"),
+                                    spec2->named[j].name, pretty_msgstr,
+                                    pretty_msgid);
+                    err = true;
+                    break;
+                  }
+                else if (cmp < 0)
+                  {
+                    if (equality)
                       {
                         if (error_logger)
                           error_logger (error_logger_data,
-                                        _("format specifications in '%s' and '%s' for argument '%s' are not the same"),
-                                        pretty_msgid, pretty_msgstr,
-                                        spec2->named[j].name);
+                                        _("a format specification for argument '%s' doesn't exist in '%s'"),
+                                        spec1->named[i].name, pretty_msgstr);
                         err = true;
                         break;
                       }
-                    j++, i++;
+                    else
+                      i++;
                   }
                 else
-                  i++;
+                  j++, i++;
               }
+          }
+          /* Check the argument types are the same.  */
+          if (!err)
+            {
+              size_t i, j;
+              for (i = 0, j = 0; j < n2; )
+                {
+                  if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0)
+                    {
+                      if (!(spec1->named[i].type == spec2->named[j].type
+                            || (!equality
+                                && (spec1->named[i].type == FAT_ANY
+                                    || spec2->named[j].type == FAT_ANY))))
+                        {
+                          if (error_logger)
+                            error_logger (error_logger_data,
+                                          _("format specifications in '%s' and '%s' for argument '%s' are not the same"),
+                                          pretty_msgid, pretty_msgstr,
+                                          spec2->named[j].name);
+                          err = true;
+                          break;
+                        }
+                      j++, i++;
+                    }
+                  else
+                    i++;
+                }
+            }
         }
 
       if (spec1->unnamed_arg_count + spec2->unnamed_arg_count > 0)
         {
-          size_t i;
-
           /* Check the argument types are the same.  */
           if (spec1->unnamed_arg_count != spec2->unnamed_arg_count)
             {
@@ -541,7 +535,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
               err = true;
             }
           else
-            for (i = 0; i < spec2->unnamed_arg_count; i++)
+            for (size_t i = 0; i < spec2->unnamed_arg_count; i++)
               if (!(spec1->unnamed[i].type == spec2->unnamed[i].type
                     || (!equality
                         && (spec1->unnamed[i].type == FAT_ANY
@@ -604,7 +598,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -618,7 +611,7 @@ format_print (void *descr)
         abort ();
 
       printf ("{");
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         {
           if (i > 0)
             printf (", ");
@@ -649,7 +642,7 @@ format_print (void *descr)
   else
     {
       printf ("(");
-      for (i = 0; i < spec->unnamed_arg_count; i++)
+      for (size_t i = 0; i < spec->unnamed_arg_count; i++)
         {
           if (i > 0)
             printf (" ");
@@ -685,18 +678,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index eb994f1415f114d42edf0a545871bfe12a74f0e3..b7d2ef248a271141bb581ab6f80aef82752b19ba 100644 (file)
@@ -47,9 +47,8 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
 
   for (; *format != '\0';)
@@ -70,7 +69,7 @@ format_parse (const char *format, bool translated, char *fdi,
           }
       }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -158,18 +157,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index deb01389432b66c7657fc2321efd068fa633441c..eee4f17aa320e7d7dfe48244e033fef29f7ffa0e 100644 (file)
@@ -67,9 +67,8 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.simple = true;
   spec.arg_count = 0;
@@ -88,14 +87,12 @@ format_parse (const char *format, bool translated, char *fdi,
         if (*format >= '0' && *format <= '9')
           {
             /* A directive.  */
-            size_t number;
-
             FDI_SET (dir_start, FMTDIR_START);
             spec.directives++;
             if (locale_flag)
               spec.simple = false;
 
-            number = *format - '0';
+            size_t number = *format - '0';
             if (format[1] >= '0' && format[1] <= '9')
               {
                 number = 10 * number + (format[1] - '0');
@@ -113,7 +110,7 @@ format_parse (const char *format, bool translated, char *fdi,
           }
       }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -142,7 +139,6 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
   struct spec *spec1 = (struct spec *) msgid_descr;
   struct spec *spec2 = (struct spec *) msgstr_descr;
   bool err = false;
-  size_t i;
 
   if (spec1->simple && !spec2->simple)
     {
@@ -154,7 +150,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
     }
 
   if (!err)
-    for (i = 0; i < spec1->arg_count || i < spec2->arg_count; i++)
+    for (size_t i = 0; i < spec1->arg_count || i < spec2->arg_count; i++)
       {
         bool arg_used1 = (i < spec1->arg_count && spec1->args_used[i]);
         bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]);
@@ -204,7 +200,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -213,7 +208,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->arg_count; i++)
+  for (size_t i = 0; i < spec->arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -232,18 +227,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 1e11dcb7577dd2dc10ff67c17d46a157938a54c9..a5844e07b00c653324d8bbcb48f5b9f02fa9d585 100644 (file)
@@ -153,27 +153,27 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t unnumbered_arg_count;
-  size_t named_allocated;
-  size_t numbered_allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.named_arg_count = 0;
   spec.numbered_arg_count = 0;
   spec.named = NULL;
   spec.numbered = NULL;
-  unnumbered_arg_count = 0;
-  named_allocated = 0;
-  numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
+  size_t named_allocated = 0;
+  size_t numbered_allocated = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format++ == '%')
       {
         /* A directive.  */
+        FDI_SET (format - 1, FMTDIR_START);
+        spec.directives++;
+        bool likely_intentional = true;
+
         char *name = NULL;
         size_t number = 0;
 
@@ -185,13 +185,6 @@ format_parse (const char *format, bool translated, char *fdi,
         size_t precision_number = 0;
         bool precision_takenext = false;
 
-        enum format_arg_type type;
-
-        bool likely_intentional = true;
-
-        FDI_SET (format - 1, FMTDIR_START);
-        spec.directives++;
-
         for (;;)
           {
             if (*format == ' '
@@ -221,10 +214,6 @@ format_parse (const char *format, bool translated, char *fdi,
 
             if (*format == '<')
               {
-                const char *name_start;
-                const char *name_end;
-                size_t n;
-
                 if ((spec.numbered_arg_count > 0
                      || number > 0 || width_number > 0 || precision_number > 0)
                     || (unnumbered_arg_count > 0
@@ -241,7 +230,7 @@ format_parse (const char *format, bool translated, char *fdi,
                     goto bad_format;
                   }
 
-                name_start = ++format;
+                const char *name_start = ++format;
                 for (; *format != '\0'; format++)
                   if (*format == '>')
                     break;
@@ -251,9 +240,9 @@ format_parse (const char *format, bool translated, char *fdi,
                     FDI_SET (format - 1, FMTDIR_ERROR);
                     goto bad_format;
                   }
-                name_end = format++;
+                const char *name_end = format++;
 
-                n = name_end - name_start;
+                size_t n = name_end - name_start;
                 name = XNMALLOC (n + 1, char);
                 memcpy (name, name_start, n);
                 name[n] = '\0';
@@ -510,6 +499,7 @@ format_parse (const char *format, bool translated, char *fdi,
             break;
           }
 
+        enum format_arg_type type;
         switch (*format)
           {
           case '%':
@@ -546,10 +536,6 @@ format_parse (const char *format, bool translated, char *fdi,
             break;
           case '{':
             {
-              const char *name_start;
-              const char *name_end;
-              size_t n;
-
               if ((spec.numbered_arg_count > 0
                    || number > 0 || width_number > 0 || precision_number > 0)
                   || (unnumbered_arg_count > 0
@@ -566,7 +552,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   goto bad_format;
                 }
 
-              name_start = ++format;
+              const char *name_start = ++format;
               for (; *format != '\0'; format++)
                 if (*format == '}')
                   break;
@@ -576,9 +562,9 @@ format_parse (const char *format, bool translated, char *fdi,
                   FDI_SET (format - 1, FMTDIR_ERROR);
                   goto bad_format;
                 }
-              name_end = format;
+              const char *name_end = format;
 
-              n = name_end - name_start;
+              size_t n = name_end - name_start;
               name = XNMALLOC (n + 1, char);
               memcpy (name, name_start, n);
               name[n] = '\0';
@@ -726,21 +712,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -773,21 +757,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           {
             enum format_arg_type type1 = spec.named[i].type;
             enum format_arg_type type2 = spec.named[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -818,15 +800,14 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
  bad_format:
   if (spec.named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec.named_arg_count; i++)
+      for (size_t i = 0; i < spec.named_arg_count; i++)
         free (spec.named[i].name);
       free (spec.named);
     }
@@ -842,8 +823,7 @@ format_free (void *descr)
 
   if (spec->named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         free (spec->named[i].name);
       free (spec->named);
     }
@@ -897,72 +877,75 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
     {
       if (spec1->named_arg_count + spec2->named_arg_count > 0)
         {
-          size_t i, j;
           size_t n1 = spec1->named_arg_count;
           size_t n2 = spec2->named_arg_count;
 
           /* Check the argument names in spec2 are contained in those of spec1.
              Both arrays are sorted.  We search for the first difference.  */
-          for (i = 0, j = 0; i < n1 || j < n2; )
-            {
-              int cmp = (i >= n1 ? 1 :
-                         j >= n2 ? -1 :
-                         strcmp (spec1->named[i].name, spec2->named[j].name));
-
-              if (cmp > 0)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"),
-                                  spec2->named[j].name, pretty_msgstr,
-                                  pretty_msgid);
-                  err = true;
-                  break;
-                }
-              else if (cmp < 0)
-                {
-                  if (equality)
-                    {
-                      if (error_logger)
-                        error_logger (error_logger_data,
-                                      _("a format specification for argument '%s' doesn't exist in '%s'"),
-                                      spec1->named[i].name, pretty_msgstr);
-                      err = true;
-                      break;
-                    }
-                  else
-                    i++;
-                }
-              else
-                j++, i++;
-            }
-          /* Check the argument types are the same.  */
-          if (!err)
-            for (i = 0, j = 0; j < n2; )
+          {
+            size_t i, j;
+            for (i = 0, j = 0; i < n1 || j < n2; )
               {
-                if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0)
+                int cmp = (i >= n1 ? 1 :
+                           j >= n2 ? -1 :
+                           strcmp (spec1->named[i].name, spec2->named[j].name));
+
+                if (cmp > 0)
+                  {
+                    if (error_logger)
+                      error_logger (error_logger_data,
+                                    _("a format specification for argument '%s', as in '%s', doesn't exist in '%s'"),
+                                    spec2->named[j].name, pretty_msgstr,
+                                    pretty_msgid);
+                    err = true;
+                    break;
+                  }
+                else if (cmp < 0)
                   {
-                    if (!(spec1->named[i].type == spec2->named[j].type))
+                    if (equality)
                       {
                         if (error_logger)
                           error_logger (error_logger_data,
-                                        _("format specifications in '%s' and '%s' for argument '%s' are not the same"),
-                                        pretty_msgid, pretty_msgstr,
-                                        spec2->named[j].name);
+                                        _("a format specification for argument '%s' doesn't exist in '%s'"),
+                                        spec1->named[i].name, pretty_msgstr);
                         err = true;
                         break;
                       }
-                    j++, i++;
+                    else
+                      i++;
                   }
                 else
-                  i++;
+                  j++, i++;
               }
+          }
+          /* Check the argument types are the same.  */
+          if (!err)
+            {
+              size_t i, j;
+              for (i = 0, j = 0; j < n2; )
+                {
+                  if (strcmp (spec1->named[i].name, spec2->named[j].name) == 0)
+                    {
+                      if (!(spec1->named[i].type == spec2->named[j].type))
+                        {
+                          if (error_logger)
+                            error_logger (error_logger_data,
+                                          _("format specifications in '%s' and '%s' for argument '%s' are not the same"),
+                                          pretty_msgid, pretty_msgstr,
+                                          spec2->named[j].name);
+                          err = true;
+                          break;
+                        }
+                      j++, i++;
+                    }
+                  else
+                    i++;
+                }
+            }
         }
 
       if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
         {
-          size_t i;
-
           /* Check the argument types are the same.  */
           if (spec1->numbered_arg_count != spec2->numbered_arg_count)
             {
@@ -973,7 +956,7 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
               err = true;
             }
           else
-            for (i = 0; i < spec2->numbered_arg_count; i++)
+            for (size_t i = 0; i < spec2->numbered_arg_count; i++)
               if (!(spec1->numbered[i].type == spec2->numbered[i].type))
                 {
                   if (error_logger)
@@ -1010,7 +993,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -1024,7 +1006,7 @@ format_print (void *descr)
         abort ();
 
       printf ("({");
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         {
           if (i > 0)
             printf (", ");
@@ -1054,11 +1036,9 @@ format_print (void *descr)
     }
   else
     {
-      size_t last;
-
       printf ("(");
-      last = 1;
-      for (i = 0; i < spec->numbered_arg_count; i++)
+      size_t last = 1;
+      for (size_t i = 0; i < spec->numbered_arg_count; i++)
         {
           size_t number = spec->numbered[i].number;
 
@@ -1101,18 +1081,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 29e16cc84edb4076598615b5d9a144e048e64824..1f178d85d0cebf889e0c2ef6b45ad40d96e1d8db 100644 (file)
@@ -123,21 +123,15 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  size_t named_allocated;
-  size_t numbered_allocated;
-  bool seen_numbered_args;
-  size_t unnumbered_arg_count;
-  struct spec *result;
-
   spec.directives = 0;
   spec.named_arg_count = 0;
   spec.numbered_arg_count = 0;
   spec.named = NULL;
   spec.numbered = NULL;
-  named_allocated = 0;
-  numbered_allocated = 0;
-  seen_numbered_args = false;
-  unnumbered_arg_count = 0;
+  size_t named_allocated = 0;
+  size_t numbered_allocated = 0;
+  bool seen_numbered_args = false;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     {
@@ -155,8 +149,8 @@ format_parse (const char *format, bool translated, char *fdi,
             {
               const char *const format_start = format;
               bool seen_identifier_or_keyword = false;
-              unsigned int arg_id;
 
+              unsigned int arg_id;
               if (c_isdigit (*format))
                 {
                   /* Numbered and unnumbered specifications are exclusive.  */
@@ -259,9 +253,7 @@ format_parse (const char *format, bool translated, char *fdi,
                      [[fill]align][sign][#][0][minimumwidth][.precision][type]  */
 
                   /* Look ahead two characters to skip [[fill]align].  */
-                  int c1, c2;
-
-                  c1 = format[0];
+                  int c1 = format[0];
                   if (c1 == '\0')
                     {
                       *invalid_reason =
@@ -271,7 +263,7 @@ format_parse (const char *format, bool translated, char *fdi,
                       goto bad_format;
                     }
 
-                  c2 = format[1];
+                  int c2 = format[1];
 
                   if (c2 == '<' || c2 == '>' || c2 == '^')
                     format += 2;
@@ -350,12 +342,11 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           ;
@@ -371,12 +362,11 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           free (spec.named[i].name);
@@ -389,15 +379,14 @@ format_parse (const char *format, bool translated, char *fdi,
       spec.named_arg_count = j;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
  bad_format:
   if (spec.named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec.named_arg_count; i++)
+      for (size_t i = 0; i < spec.named_arg_count; i++)
         free (spec.named[i].name);
       free (spec.named);
     }
@@ -413,8 +402,7 @@ format_free (void *descr)
 
   if (spec->named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         free (spec->named[i].name);
       free (spec->named);
     }
@@ -441,12 +429,12 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->named_arg_count + spec2->named_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->named_arg_count;
       size_t n2 = spec2->named_arg_count;
 
       /* Check the argument names in spec2 are contained in those of spec1.
          Both arrays are sorted.  We search for the first difference.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -484,13 +472,13 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
       size_t missing = 0; /* only used if !equality */
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -566,8 +554,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i, j;
 
   if (spec == NULL)
     {
@@ -576,7 +562,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 0;
+  size_t last = 0;
+  size_t i;
   for (i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
@@ -590,7 +577,7 @@ format_print (void *descr)
       printf ("*");
       last = number + 1;
     }
-  for (j = 0; j < spec->named_arg_count; j++)
+  for (size_t j = 0; j < spec->named_arg_count; j++)
     {
       if (i > 0 || j > 0)
         printf (" ");
@@ -606,18 +593,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index aae4db3e429df822ecc836285472ae50c65ef742..b943413d844ba8cc69cb3bf57a89d72e3394de4a 100644 (file)
@@ -159,26 +159,33 @@ verify_element (const struct format_arg * e)
 static void
 verify_list (const struct format_arg_list *list)
 {
-  size_t i;
-  size_t total_repcount;
-
   ASSERT (list->initial.count <= list->initial.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->initial.count; i++)
-    {
-      verify_element (&list->initial.element[i]);
-      total_repcount += list->initial.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->initial.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->initial.count; i++)
+      {
+        verify_element (&list->initial.element[i]);
+        total_repcount += list->initial.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->initial.length);
+  }
 
   ASSERT (list->repeated.count <= list->repeated.allocated);
-  total_repcount = 0;
-  for (i = 0; i < list->repeated.count; i++)
-    {
-      verify_element (&list->repeated.element[i]);
-      total_repcount += list->repeated.element[i].repcount;
-    }
-  ASSERT (total_repcount == list->repeated.length);
+  {
+    size_t total_repcount;
+
+    total_repcount = 0;
+    for (size_t i = 0; i < list->repeated.count; i++)
+      {
+        verify_element (&list->repeated.element[i]);
+        total_repcount += list->repeated.element[i].repcount;
+      }
+
+    ASSERT (total_repcount == list->repeated.length);
+  }
 }
 
 /* Assertion macro.  Could be defined to empty for speed.  */
@@ -200,14 +207,12 @@ free_element (struct format_arg *element)
 static void
 free_list (struct format_arg_list *list)
 {
-  size_t i;
-
-  for (i = 0; i < list->initial.count; i++)
+  for (size_t i = 0; i < list->initial.count; i++)
     free_element (&list->initial.element[i]);
   if (list->initial.element != NULL)
     free (list->initial.element);
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -233,49 +238,49 @@ copy_element (struct format_arg *newelement,
 static struct format_arg_list *
 copy_list (const struct format_arg_list *list)
 {
-  struct format_arg_list *newlist;
-  size_t length;
-  size_t i;
-
   VERIFY_LIST (list);
 
-  newlist = XMALLOC (struct format_arg_list);
+  struct format_arg_list *newlist = XMALLOC (struct format_arg_list);
 
   newlist->initial.count = newlist->initial.allocated = list->initial.count;
-  length = 0;
-  if (list->initial.count == 0)
-    newlist->initial.element = NULL;
-  else
-    {
-      newlist->initial.element =
-        XNMALLOC (newlist->initial.allocated, struct format_arg);
-      for (i = 0; i < list->initial.count; i++)
-        {
-          copy_element (&newlist->initial.element[i],
-                        &list->initial.element[i]);
-          length += list->initial.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->initial.length);
-  newlist->initial.length = length;
+  {
+    size_t length = 0;
+    if (list->initial.count == 0)
+      newlist->initial.element = NULL;
+    else
+      {
+        newlist->initial.element =
+          XNMALLOC (newlist->initial.allocated, struct format_arg);
+        for (size_t i = 0; i < list->initial.count; i++)
+          {
+            copy_element (&newlist->initial.element[i],
+                          &list->initial.element[i]);
+            length += list->initial.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->initial.length);
+    newlist->initial.length = length;
+  }
 
   newlist->repeated.count = newlist->repeated.allocated = list->repeated.count;
-  length = 0;
-  if (list->repeated.count == 0)
-    newlist->repeated.element = NULL;
-  else
-    {
-      newlist->repeated.element =
-        XNMALLOC (newlist->repeated.allocated, struct format_arg);
-      for (i = 0; i < list->repeated.count; i++)
-        {
-          copy_element (&newlist->repeated.element[i],
-                        &list->repeated.element[i]);
-          length += list->repeated.element[i].repcount;
-        }
-    }
-  ASSERT (length == list->repeated.length);
-  newlist->repeated.length = length;
+  {
+    size_t length = 0;
+    if (list->repeated.count == 0)
+      newlist->repeated.element = NULL;
+    else
+      {
+        newlist->repeated.element =
+          XNMALLOC (newlist->repeated.allocated, struct format_arg);
+        for (size_t i = 0; i < list->repeated.count; i++)
+          {
+            copy_element (&newlist->repeated.element[i],
+                          &list->repeated.element[i]);
+            length += list->repeated.element[i].repcount;
+          }
+      }
+    ASSERT (length == list->repeated.length);
+    newlist->repeated.length = length;
+  }
 
   VERIFY_LIST (newlist);
 
@@ -301,34 +306,35 @@ static bool
 equal_list (const struct format_arg_list *list1,
             const struct format_arg_list *list2)
 {
-  size_t n, i;
-
   VERIFY_LIST (list1);
   VERIFY_LIST (list2);
 
-  n = list1->initial.count;
-  if (n != list2->initial.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->initial.element[i];
-      const struct format_arg * e2 = &list2->initial.element[i];
-
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+  {
+    size_t n = list1->initial.count;
+    if (n != list2->initial.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->initial.element[i];
+        const struct format_arg * e2 = &list2->initial.element[i];
 
-  n = list1->repeated.count;
-  if (n != list2->repeated.count)
-    return false;
-  for (i = 0; i < n; i++)
-    {
-      const struct format_arg * e1 = &list1->repeated.element[i];
-      const struct format_arg * e2 = &list2->repeated.element[i];
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
+  {
+    size_t n = list1->repeated.count;
+    if (n != list2->repeated.count)
+      return false;
+    for (size_t i = 0; i < n; i++)
+      {
+        const struct format_arg * e1 = &list1->repeated.element[i];
+        const struct format_arg * e2 = &list2->repeated.element[i];
 
-      if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
-        return false;
-    }
+        if (!(e1->repcount == e2->repcount && equal_element (e1, e2)))
+          return false;
+      }
+  }
 
   return true;
 }
@@ -405,54 +411,56 @@ grow_repeated_alloc (struct format_arg_list *list)
 static void
 normalize_outermost_list (struct format_arg_list *list)
 {
-  size_t n, i, j;
-
   /* Step 1: Combine adjacent elements.
      Copy from i to j, keeping 0 <= j <= i.  */
-
-  n = list->initial.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->initial.element[i],
-                          &list->initial.element[j-1]))
-      {
-        list->initial.element[j-1].repcount +=
-          list->initial.element[i].repcount;
-        free_element (&list->initial.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->initial.element[j] = list->initial.element[i];
-        j++;
-      }
-  list->initial.count = j;
-
-  n = list->repeated.count;
-  for (i = j = 0; i < n; i++)
-    if (j > 0
-        && equal_element (&list->repeated.element[i],
-                          &list->repeated.element[j-1]))
-      {
-        list->repeated.element[j-1].repcount +=
-          list->repeated.element[i].repcount;
-        free_element (&list->repeated.element[i]);
-      }
-    else
-      {
-        if (j < i)
-          list->repeated.element[j] = list->repeated.element[i];
-        j++;
-      }
-  list->repeated.count = j;
+  {
+    size_t n = list->initial.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->initial.element[i],
+                            &list->initial.element[j-1]))
+        {
+          list->initial.element[j-1].repcount +=
+            list->initial.element[i].repcount;
+          free_element (&list->initial.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->initial.element[j] = list->initial.element[i];
+          j++;
+        }
+    list->initial.count = j;
+  }
+  {
+    size_t n = list->repeated.count;
+    size_t i, j;
+    for (i = j = 0; i < n; i++)
+      if (j > 0
+          && equal_element (&list->repeated.element[i],
+                            &list->repeated.element[j-1]))
+        {
+          list->repeated.element[j-1].repcount +=
+            list->repeated.element[i].repcount;
+          free_element (&list->repeated.element[i]);
+        }
+      else
+        {
+          if (j < i)
+            list->repeated.element[j] = list->repeated.element[i];
+          j++;
+        }
+    list->repeated.count = j;
+  }
 
   /* Nothing more to be done if the loop segment is empty.  */
   if (list->repeated.count > 0)
     {
-      size_t m, repcount0_extra;
+      size_t repcount0_extra;
 
       /* Step 2: Reduce the loop period.  */
-      n = list->repeated.count;
+      size_t n = list->repeated.count;
       repcount0_extra = 0;
       if (n > 1
           && equal_element (&list->repeated.element[0],
@@ -463,13 +471,13 @@ normalize_outermost_list (struct format_arg_list *list)
         }
       /* Proceed as if the loop period were n, with
          list->repeated.element[0].repcount incremented by repcount0_extra.  */
-      for (m = 2; m <= n / 2; m++)
+      for (size_t m = 2; m <= n / 2; m++)
         if ((n % m) == 0)
           {
             /* m is a divisor of n.  Try to reduce the loop period to n.  */
             bool ok = true;
 
-            for (i = 0; i < n - m; i++)
+            for (size_t i = 0; i < n - m; i++)
               if (!((list->repeated.element[i].repcount
                      + (i == 0 ? repcount0_extra : 0)
                      == list->repeated.element[i+m].repcount)
@@ -481,7 +489,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 }
             if (ok)
               {
-                for (i = m; i < n; i++)
+                for (size_t i = m; i < n; i++)
                   free_element (&list->repeated.element[i]);
                 if (n < list->repeated.count)
                   list->repeated.element[m] = list->repeated.element[n];
@@ -532,7 +540,7 @@ normalize_outermost_list (struct format_arg_list *list)
                 {
                   size_t newcount = list->repeated.count + 1;
                   ensure_repeated_alloc (list, newcount);
-                  for (i = newcount - 1; i > 0; i--)
+                  for (size_t i = newcount - 1; i > 0; i--)
                     list->repeated.element[i] = list->repeated.element[i-1];
                   list->repeated.count = newcount;
                   copy_element (&list->repeated.element[0],
@@ -568,19 +576,21 @@ normalize_outermost_list (struct format_arg_list *list)
 static void
 normalize_list (struct format_arg_list *list)
 {
-  size_t n, i;
-
   VERIFY_LIST (list);
 
   /* First normalize all elements, recursively.  */
-  n = list->initial.count;
-  for (i = 0; i < n; i++)
-    if (list->initial.element[i].type == FAT_LIST)
-      normalize_list (list->initial.element[i].list);
-  n = list->repeated.count;
-  for (i = 0; i < n; i++)
-    if (list->repeated.element[i].type == FAT_LIST)
-      normalize_list (list->repeated.element[i].list);
+  {
+    size_t n = list->initial.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->initial.element[i].type == FAT_LIST)
+        normalize_list (list->initial.element[i].list);
+  }
+  {
+    size_t n = list->repeated.count;
+    for (size_t i = 0; i < n; i++)
+      if (list->repeated.element[i].type == FAT_LIST)
+        normalize_list (list->repeated.element[i].list);
+  }
 
   /* Then normalize the top level list.  */
   normalize_outermost_list (list);
@@ -600,9 +610,7 @@ normalize_list (struct format_arg_list *list)
 static struct format_arg_list *
 make_unconstrained_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -626,9 +634,7 @@ make_unconstrained_list ()
 static struct format_arg_list *
 make_empty_list ()
 {
-  struct format_arg_list *list;
-
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -661,16 +667,17 @@ is_empty_list (const struct format_arg_list *list)
 static void
 unfold_loop (struct format_arg_list *list, size_t m)
 {
-  size_t i, j, k;
-
   if (m > 1)
     {
       size_t newcount = list->repeated.count * m;
       ensure_repeated_alloc (list, newcount);
-      i = list->repeated.count;
-      for (k = 1; k < m; k++)
-        for (j = 0; j < list->repeated.count; j++, i++)
-          copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+      size_t i = list->repeated.count;
+      for (size_t k = 1; k < m; k++)
+        for (size_t j = 0; j < list->repeated.count; j++)
+          {
+            copy_element (&list->repeated.element[i], &list->repeated.element[j]);
+            i++;
+          }
       list->repeated.count = newcount;
       list->repeated.length = list->repeated.length * m;
     }
@@ -689,11 +696,9 @@ rotate_loop (struct format_arg_list *list, size_t m)
     {
       /* Instead of multiple copies of list->repeated.element[0], a single
          copy with higher repcount is appended to list->initial.  */
-      size_t i, newcount;
-
-      newcount = list->initial.count + 1;
+      size_t newcount = list->initial.count + 1;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
+      size_t i = list->initial.count;
       copy_element (&list->initial.element[i], &list->repeated.element[0]);
       list->initial.element[i].repcount = m - list->initial.length;
       list->initial.count = newcount;
@@ -725,21 +730,23 @@ rotate_loop (struct format_arg_list *list, size_t m)
          plus the s first elements of list->repeated,
          plus, if t > 0, a splitoff of list->repeated.element[s].  */
       {
-        size_t i, j, k, newcount;
-
-        i = list->initial.count;
-        newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
+        size_t i = list->initial.count;
+        size_t newcount = i + q * list->repeated.count + s + (t > 0 ? 1 : 0);
         ensure_initial_alloc (list, newcount);
-        for (k = 0; k < q; k++)
-          for (j = 0; j < list->repeated.count; j++, i++)
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
-        for (j = 0; j < s; j++, i++)
-          copy_element (&list->initial.element[i], &list->repeated.element[j]);
+        for (size_t k = 0; k < q; k++)
+          for (size_t j = 0; j < list->repeated.count; j++)
+            {
+              copy_element (&list->initial.element[i], &list->repeated.element[j]);
+              i++;
+            }
+        for (size_t j = 0; j < s; j++)
+          {
+            copy_element (&list->initial.element[i], &list->repeated.element[j]);
+            i++;
+          }
         if (t > 0)
           {
-            copy_element (&list->initial.element[i],
-                          &list->repeated.element[j]);
+            copy_element (&list->initial.element[i], &list->repeated.element[s]);
             list->initial.element[i].repcount = t;
             i++;
           }
@@ -758,17 +765,20 @@ rotate_loop (struct format_arg_list *list, size_t m)
       /* And rotate list->repeated.  */
       if (r > 0)
         {
-          size_t i, j, oldcount, newcount;
-          struct format_arg *newelement;
-
-          oldcount = list->repeated.count;
-          newcount = list->repeated.count + (t > 0 ? 1 : 0);
-          newelement = XNMALLOC (newcount, struct format_arg);
-          i = 0;
-          for (j = s; j < oldcount; j++, i++)
-            newelement[i] = list->repeated.element[j];
-          for (j = 0; j < s; j++, i++)
-            newelement[i] = list->repeated.element[j];
+          size_t oldcount = list->repeated.count;
+          size_t newcount = list->repeated.count + (t > 0 ? 1 : 0);
+          struct format_arg *newelement = XNMALLOC (newcount, struct format_arg);
+          size_t i = 0;
+          for (size_t j = s; j < oldcount; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
+          for (size_t j = 0; j < s; j++)
+            {
+              newelement[i] = list->repeated.element[j];
+              i++;
+            }
           if (t > 0)
             {
               copy_element (&newelement[oldcount], &newelement[0]);
@@ -790,12 +800,6 @@ rotate_loop (struct format_arg_list *list, size_t m)
 static size_t
 initial_splitelement (struct format_arg_list *list, size_t n)
 {
-  size_t s;
-  size_t t;
-  size_t oldrepcount;
-  size_t newcount;
-  size_t i;
-
   VERIFY_LIST (list);
 
   if (n > list->initial.length)
@@ -806,6 +810,8 @@ initial_splitelement (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -817,10 +823,10 @@ initial_splitelement (struct format_arg_list *list, size_t n)
   ASSERT (s < list->initial.count);
 
   /* Split the entry into two entries.  */
-  oldrepcount = list->initial.element[s].repcount;
-  newcount = list->initial.count + 1;
+  size_t oldrepcount = list->initial.element[s].repcount;
+  size_t newcount = list->initial.count + 1;
   ensure_initial_alloc (list, newcount);
-  for (i = list->initial.count - 1; i > s; i--)
+  for (size_t i = list->initial.count - 1; i > s; i--)
     list->initial.element[i+1] = list->initial.element[i];
   copy_element (&list->initial.element[s+1], &list->initial.element[s]);
   list->initial.element[s].repcount = t;
@@ -842,8 +848,6 @@ initial_unshare (struct format_arg_list *list, size_t n)
        initial_splitelement (list, n);
        initial_splitelement (list, n + 1);
    */
-  size_t s;
-  size_t t;
 
   VERIFY_LIST (list);
 
@@ -855,6 +859,8 @@ initial_unshare (struct format_arg_list *list, size_t n)
     }
 
   /* Determine how many entries of list->initial need to be skipped.  */
+  size_t s;
+  size_t t;
   for (t = n, s = 0;
        s < list->initial.count && t >= list->initial.element[s].repcount;
        t -= list->initial.element[s].repcount, s++)
@@ -873,9 +879,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
       ensure_initial_alloc (list, newcount);
       if (t == 0 || t == oldrepcount - 1)
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+1] = list->initial.element[i];
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
           if (t == 0)
@@ -891,9 +895,7 @@ initial_unshare (struct format_arg_list *list, size_t n)
         }
       else
         {
-          size_t i;
-
-          for (i = list->initial.count - 1; i > s; i--)
+          for (size_t i = list->initial.count - 1; i > s; i--)
             list->initial.element[i+2] = list->initial.element[i];
           copy_element (&list->initial.element[s+2], &list->initial.element[s]);
           copy_element (&list->initial.element[s+1], &list->initial.element[s]);
@@ -924,10 +926,8 @@ shift_list (struct format_arg_list *list, size_t n)
 
   if (n > 0)
     {
-      size_t i;
-
       grow_initial_alloc (list);
-      for (i = list->initial.count; i > 0; i--)
+      for (size_t i = list->initial.count; i > 0; i--)
         list->initial.element[i] = list->initial.element[i-1];
       list->initial.element[0].repcount = n;
       list->initial.element[0].presence = FCT_REQUIRED;
@@ -1065,13 +1065,14 @@ append_repeated_to_initial (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       /* Move list->repeated over to list->initial.  */
-      size_t i, j, newcount;
-
-      newcount = list->initial.count + list->repeated.count;
+      size_t newcount = list->initial.count + list->repeated.count;
       ensure_initial_alloc (list, newcount);
-      i = list->initial.count;
-      for (j = 0; j < list->repeated.count; j++, i++)
-        list->initial.element[i] = list->repeated.element[j];
+      size_t i = list->initial.count;
+      for (size_t j = 0; j < list->repeated.count; j++)
+        {
+          list->initial.element[i] = list->repeated.element[j];
+          i++;
+        }
       list->initial.count = newcount;
       list->initial.length = list->initial.length + list->repeated.length;
       free (list->repeated.element);
@@ -1184,20 +1185,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 4: Elementwise intersection of list1->initial, list2->initial.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->initial.element; c1 = list1->initial.count;
-    e2 = list2->initial.element; c2 = list2->initial.count;
+    struct format_arg *e1 = list1->initial.element;
+    size_t c1 = list1->initial.count;
+    struct format_arg *e2 = list2->initial.element;
+    size_t c2 = list2->initial.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->initial.  */
         grow_initial_alloc (result);
-        re = &result->initial.element[result->initial.count];
+        struct format_arg *re = &result->initial.element[result->initial.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1272,20 +1268,15 @@ make_intersected_list (struct format_arg_list *list1,
 
   /* Step 5: Elementwise intersection of list1->repeated, list2->repeated.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->repeated.element; c1 = list1->repeated.count;
-    e2 = list2->repeated.element; c2 = list2->repeated.count;
+    struct format_arg *e1 = list1->repeated.element;
+    size_t c1 = list1->repeated.count;
+    struct format_arg *e2 = list2->repeated.element;
+    size_t c2 = list2->repeated.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->repeated.  */
         grow_repeated_alloc (result);
-        re = &result->repeated.element[result->repeated.count];
+        struct format_arg *re = &result->repeated.element[result->repeated.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Intersect the argument types.  */
@@ -1571,20 +1562,13 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
   /* Step 4: Elementwise union of list1->initial, list2->initial.  */
   {
-    struct format_arg *e1;
-    struct format_arg *e2;
-    size_t c1;
-    size_t c2;
-
-    e1 = list1->initial.element; c1 = list1->initial.count;
-    e2 = list2->initial.element; c2 = list2->initial.count;
+    struct format_arg *e1 = list1->initial.element; size_t c1 = list1->initial.count;
+    struct format_arg *e2 = list2->initial.element; size_t c2 = list2->initial.count;
     while (c1 > 0 && c2 > 0)
       {
-        struct format_arg *re;
-
         /* Ensure room in result->initial.  */
         grow_initial_alloc (result);
-        re = &result->initial.element[result->initial.count];
+        struct format_arg *re = &result->initial.element[result->initial.count];
         re->repcount = MIN (e1->repcount, e2->repcount);
 
         /* Union of the argument types.  */
@@ -1615,11 +1599,9 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
         if (e1->presence == FCT_REQUIRED)
           {
-            struct format_arg *re;
-
             /* Ensure room in result->initial.  */
             grow_initial_alloc (result);
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e1);
             re->presence = FCT_OPTIONAL;
             re->repcount = 1;
@@ -1637,9 +1619,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
         ensure_initial_alloc (result, result->initial.count + c1);
         while (c1 > 0)
           {
-            struct format_arg *re;
-
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e1);
             result->initial.count++;
             result->initial.length += re->repcount;
@@ -1655,11 +1635,9 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
 
         if (e2->presence == FCT_REQUIRED)
           {
-            struct format_arg *re;
-
             /* Ensure room in result->initial.  */
             grow_initial_alloc (result);
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e2);
             re->presence = FCT_OPTIONAL;
             re->repcount = 1;
@@ -1677,9 +1655,7 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
         ensure_initial_alloc (result, result->initial.count + c2);
         while (c2 > 0)
           {
-            struct format_arg *re;
-
-            re = &result->initial.element[result->initial.count];
+            struct format_arg *re = &result->initial.element[result->initial.count];
             copy_element (re, e2);
             result->initial.count++;
             result->initial.length += re->repcount;
@@ -1693,20 +1669,15 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
   if (list1->repeated.length > 0 && list2->repeated.length > 0)
     /* Step 5: Elementwise union of list1->repeated, list2->repeated.  */
     {
-      struct format_arg *e1;
-      struct format_arg *e2;
-      size_t c1;
-      size_t c2;
-
-      e1 = list1->repeated.element; c1 = list1->repeated.count;
-      e2 = list2->repeated.element; c2 = list2->repeated.count;
+      struct format_arg *e1 = list1->repeated.element;
+      size_t c1 = list1->repeated.count;
+      struct format_arg *e2 = list2->repeated.element;
+      size_t c2 = list2->repeated.count;
       while (c1 > 0 && c2 > 0)
         {
-          struct format_arg *re;
-
           /* Ensure room in result->repeated.  */
           grow_repeated_alloc (result);
-          re = &result->repeated.element[result->repeated.count];
+          struct format_arg *re = &result->repeated.element[result->repeated.count];
           re->repcount = MIN (e1->repcount, e2->repcount);
 
           /* Union of the argument types.  */
@@ -1734,13 +1705,11 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     {
       /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the
          initial segment.  Just copy the repeated segment of list1.  */
-      size_t i;
-
       result->repeated.count = list1->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
         XNMALLOC (result->repeated.allocated, struct format_arg);
-      for (i = 0; i < list1->repeated.count; i++)
+      for (size_t i = 0; i < list1->repeated.count; i++)
         copy_element (&result->repeated.element[i],
                       &list1->repeated.element[i]);
       result->repeated.length = list1->repeated.length;
@@ -1749,13 +1718,11 @@ make_union_list (struct format_arg_list *list1, struct format_arg_list *list2)
     {
       /* Turning FCT_REQUIRED into FCT_OPTIONAL was already handled in the
          initial segment.  Just copy the repeated segment of list2.  */
-      size_t i;
-
       result->repeated.count = list2->repeated.count;
       result->repeated.allocated = result->repeated.count;
       result->repeated.element =
         XNMALLOC (result->repeated.allocated, struct format_arg);
-      for (i = 0; i < list2->repeated.count; i++)
+      for (size_t i = 0; i < list2->repeated.count; i++)
         copy_element (&result->repeated.element[i],
                       &list2->repeated.element[i]);
       result->repeated.length = list2->repeated.length;
@@ -1834,50 +1801,57 @@ union (struct format_arg_list *list1, struct format_arg_list *list2)
 static bool
 is_required (const struct format_arg_list *list, size_t n)
 {
-  size_t s;
   size_t t;
 
   /* We'll check whether the first n+1 presence flags are FCT_REQUIRED.  */
   t = n + 1;
 
   /* Walk the list->initial segment.  */
-  for (s = 0;
-       s < list->initial.count && t >= list->initial.element[s].repcount;
-       t -= list->initial.element[s].repcount, s++)
-    if (list->initial.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->initial.count)
-    {
+    for (s = 0;
+         s < list->initial.count && t >= list->initial.element[s].repcount;
+         t -= list->initial.element[s].repcount, s++)
       if (list->initial.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->initial.count)
+      {
+        if (list->initial.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* Walk the list->repeated segment.  */
   if (list->repeated.count == 0)
     return false;
 
-  for (s = 0;
-       s < list->repeated.count && t >= list->repeated.element[s].repcount;
-       t -= list->repeated.element[s].repcount, s++)
-    if (list->repeated.element[s].presence != FCT_REQUIRED)
-      return false;
-
-  if (t == 0)
-    return true;
+  {
+    size_t s;
 
-  if (s < list->repeated.count)
-    {
+    for (s = 0;
+         s < list->repeated.count && t >= list->repeated.element[s].repcount;
+         t -= list->repeated.element[s].repcount, s++)
       if (list->repeated.element[s].presence != FCT_REQUIRED)
         return false;
-      else
-        return true;
-    }
+
+    if (t == 0)
+      return true;
+
+    if (s < list->repeated.count)
+      {
+        if (list->repeated.element[s].presence != FCT_REQUIRED)
+          return false;
+        else
+          return true;
+      }
+  }
 
   /* The list->repeated segment consists only of FCT_REQUIRED.  So,
      regardless how many more passes through list->repeated would be
@@ -1892,8 +1866,6 @@ is_required (const struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_required_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t i, rest;
-
   if (list == NULL)
     return NULL;
 
@@ -1909,12 +1881,15 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 
   initial_splitelement (list, n + 1);
 
-  for (i = 0, rest = n + 1; rest > 0; )
-    {
-      list->initial.element[i].presence = FCT_REQUIRED;
-      rest -= list->initial.element[i].repcount;
-      i++;
-    }
+  {
+    size_t i = 0;
+    for (size_t rest = n + 1; rest > 0; )
+      {
+        list->initial.element[i].presence = FCT_REQUIRED;
+        rest -= list->initial.element[i].repcount;
+        i++;
+      }
+  }
 
   VERIFY_LIST (list);
 
@@ -1929,9 +1904,6 @@ add_required_constraint (struct format_arg_list *list, size_t n)
 static struct format_arg_list *
 add_end_constraint (struct format_arg_list *list, size_t n)
 {
-  size_t s, i;
-  enum format_cdr_type n_presence;
-
   if (list == NULL)
     return NULL;
 
@@ -1941,20 +1913,20 @@ add_end_constraint (struct format_arg_list *list, size_t n)
     /* list is already constrained to have at most length n.  */
     return list;
 
-  s = initial_splitelement (list, n);
-  n_presence =
+  size_t s = initial_splitelement (list, n);
+  enum format_cdr_type n_presence =
     (s < list->initial.count
      ? /* n < list->initial.length */ list->initial.element[s].presence
      : /* n >= list->initial.length */ list->repeated.element[0].presence);
 
-  for (i = s; i < list->initial.count; i++)
+  for (size_t i = s; i < list->initial.count; i++)
     {
       list->initial.length -= list->initial.element[i].repcount;
       free_element (&list->initial.element[i]);
     }
   list->initial.count = s;
 
-  for (i = 0; i < list->repeated.count; i++)
+  for (size_t i = 0; i < list->repeated.count; i++)
     free_element (&list->repeated.element[i]);
   if (list->repeated.element != NULL)
     free (list->repeated.element);
@@ -1978,20 +1950,19 @@ static struct format_arg_list *
 add_type_constraint (struct format_arg_list *list, size_t n,
                      enum format_arg_type type)
 {
-  size_t s;
-  struct format_arg newconstraint;
-  struct format_arg tmpelement;
-
   if (list == NULL)
     return NULL;
 
   /* Through the previous add_required_constraint, we can assume
      list->initial.length >= n+1.  */
 
-  s = initial_unshare (list, n);
+  size_t s = initial_unshare (list, n);
 
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
+
+  struct format_arg tmpelement;
   if (!make_intersected_element (&tmpelement,
                                  &list->initial.element[s], &newconstraint))
     list = add_end_constraint (list, n);
@@ -2018,21 +1989,20 @@ add_listtype_constraint (struct format_arg_list *list, size_t n,
                          enum format_arg_type type,
                          struct format_arg_list *sublist)
 {
-  size_t s;
-  struct format_arg newconstraint;
-  struct format_arg tmpelement;
-
   if (list == NULL)
     return NULL;
 
   /* Through the previous add_required_constraint, we can assume
      list->initial.length >= n+1.  */
 
-  s = initial_unshare (list, n);
+  size_t s = initial_unshare (list, n);
 
+  struct format_arg newconstraint;
   newconstraint.presence = FCT_OPTIONAL;
   newconstraint.type = type;
   newconstraint.list = sublist;
+
+  struct format_arg tmpelement;
   if (!make_intersected_element (&tmpelement,
                                  &list->initial.element[s], &newconstraint))
     list = add_end_constraint (list, n);
@@ -2082,10 +2052,7 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
     return make_empty_list ();
   else
     {
-      struct format_arg_list *listlist;
-
-      listlist = XMALLOC (struct format_arg_list);
-
+      struct format_arg_list *listlist = XMALLOC (struct format_arg_list);
       listlist->initial.count = 0;
       listlist->initial.allocated = 0;
       listlist->initial.element = NULL;
@@ -2119,16 +2086,13 @@ make_repeated_list_of_lists (struct format_arg_list *sublist)
 static struct format_arg_list *
 make_repeated_list (struct format_arg_list *sublist, size_t period)
 {
-  struct segment tmp;
-  struct segment *srcseg;
-  struct format_arg_list *list;
-  size_t p, n, i, si, ti, j, sj, tj, splitindex, newcount;
-  bool ended;
-
   VERIFY_LIST (sublist);
 
   ASSERT (period > 0);
 
+  struct segment *srcseg;
+  struct segment tmp;
+  size_t p;
   if (sublist->repeated.count == 0)
     {
       /* L is a finite list.  */
@@ -2156,16 +2120,22 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
       tmp.count = sublist->initial.count + sublist->repeated.count;
       tmp.allocated = tmp.count;
       tmp.element = XNMALLOC (tmp.allocated, struct format_arg);
-      for (i = 0; i < sublist->initial.count; i++)
-        tmp.element[i] = sublist->initial.element[i];
-      for (j = 0; j < sublist->repeated.count; i++, j++)
-        tmp.element[i] = sublist->repeated.element[j];
+      {
+        size_t i;
+        for (i = 0; i < sublist->initial.count; i++)
+          tmp.element[i] = sublist->initial.element[i];
+        for (size_t j = 0; j < sublist->repeated.count; j++)
+          {
+            tmp.element[i] = sublist->repeated.element[j];
+            i++;
+          }
+      }
       tmp.length = sublist->initial.length + sublist->repeated.length;
 
       srcseg = &tmp;
     }
 
-  n = srcseg->length;
+  size_t n = srcseg->length;
 
   /* Example: n = 7, p = 2
      Let L = (A B C D E F G).
@@ -2180,7 +2150,7 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
      Or by a single incremental intersection operation, going from left
      to right.  */
 
-  list = XMALLOC (struct format_arg_list);
+  struct format_arg_list *list = XMALLOC (struct format_arg_list);
   list->initial.count = 0;
   list->initial.allocated = 0;
   list->initial.element = NULL;
@@ -2198,109 +2168,121 @@ make_repeated_list (struct format_arg_list *sublist, size_t period)
        list->initial.element[i] = srcseg->element[i] & list->initial.element[j];
    */
 
-  ended = false;
-
-  i = 0, ti = 0, si = 0;
-  while (i < p)
-    {
-      size_t k = MIN (srcseg->element[si].repcount - ti, p - i);
-
-      /* Ensure room in list->initial.  */
-      grow_initial_alloc (list);
-      copy_element (&list->initial.element[list->initial.count],
-                    &srcseg->element[si]);
-      list->initial.element[list->initial.count].repcount = k;
-      list->initial.count++;
-      list->initial.length += k;
+  bool ended = false;
 
-      i += k;
-      ti += k;
-      if (ti == srcseg->element[si].repcount)
-        {
-          ti = 0;
-          si++;
-        }
-    }
-
-  ASSERT (list->initial.count > 0);
-  if (list->initial.element[0].presence == FCT_REQUIRED)
-    {
-      initial_splitelement (list, 1);
-      ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
-      ASSERT (list->initial.element[0].repcount == 1);
-      list->initial.element[0].presence = FCT_OPTIONAL;
-    }
+  {
+    size_t i = 0;
+    size_t ti = 0;
+    size_t si = 0;
+    while (i < p)
+      {
+        size_t k = MIN (srcseg->element[si].repcount - ti, p - i);
+
+        /* Ensure room in list->initial.  */
+        grow_initial_alloc (list);
+        copy_element (&list->initial.element[list->initial.count],
+                      &srcseg->element[si]);
+        list->initial.element[list->initial.count].repcount = k;
+        list->initial.count++;
+        list->initial.length += k;
+
+        i += k;
+        ti += k;
+        if (ti == srcseg->element[si].repcount)
+          {
+            ti = 0;
+            si++;
+          }
+      }
 
-  j = 0, tj = 0, sj = 0;
-  while (i < n)
-    {
-      size_t k =
-        MIN (srcseg->element[si].repcount - ti,
-             list->initial.element[sj].repcount - tj);
+    ASSERT (list->initial.count > 0);
+    if (list->initial.element[0].presence == FCT_REQUIRED)
+      {
+        initial_splitelement (list, 1);
+        ASSERT (list->initial.element[0].presence == FCT_REQUIRED);
+        ASSERT (list->initial.element[0].repcount == 1);
+        list->initial.element[0].presence = FCT_OPTIONAL;
+      }
 
-      /* Ensure room in list->initial.  */
-      grow_initial_alloc (list);
-      if (!make_intersected_element (&list->initial.element[list->initial.count],
-                                     &srcseg->element[si],
-                                     &list->initial.element[sj]))
-        {
-          if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
-            {
-              /* Contradiction.  Backtrack.  */
-              list = backtrack_in_initial (list);
-              ASSERT (list != NULL); /* at least the empty list is valid */
-              return list;
-            }
-          else
-            {
-              /* The list ends here.  */
-              ended = true;
-              break;
-            }
-        }
-      list->initial.element[list->initial.count].repcount = k;
-      list->initial.count++;
-      list->initial.length += k;
+    size_t j = 0;
+    size_t tj = 0;
+    size_t sj = 0;
+    while (i < n)
+      {
+        size_t k =
+          MIN (srcseg->element[si].repcount - ti,
+               list->initial.element[sj].repcount - tj);
+
+        /* Ensure room in list->initial.  */
+        grow_initial_alloc (list);
+        if (!make_intersected_element (&list->initial.element[list->initial.count],
+                                       &srcseg->element[si],
+                                       &list->initial.element[sj]))
+          {
+            if (list->initial.element[list->initial.count].presence == FCT_REQUIRED)
+              {
+                /* Contradiction.  Backtrack.  */
+                list = backtrack_in_initial (list);
+                ASSERT (list != NULL); /* at least the empty list is valid */
+                return list;
+              }
+            else
+              {
+                /* The list ends here.  */
+                ended = true;
+                break;
+              }
+          }
+        list->initial.element[list->initial.count].repcount = k;
+        list->initial.count++;
+        list->initial.length += k;
 
-      i += k;
-      ti += k;
-      if (ti == srcseg->element[si].repcount)
-        {
-          ti = 0;
-          si++;
-        }
+        i += k;
+        ti += k;
+        if (ti == srcseg->element[si].repcount)
+          {
+            ti = 0;
+            si++;
+          }
 
-      j += k;
-      tj += k;
-      if (tj == list->initial.element[sj].repcount)
-        {
-          tj = 0;
-          sj++;
-        }
-    }
-  if (!ended)
-    ASSERT (list->initial.length == n);
+        j += k;
+        tj += k;
+        if (tj == list->initial.element[sj].repcount)
+          {
+            tj = 0;
+            sj++;
+          }
+      }
+    if (!ended)
+      ASSERT (list->initial.length == n);
+  }
 
   /* Add optional exit points at 0, period, 2*period etc.
      FIXME: Not sure this is correct in all cases.  */
-  for (i = 0; i < list->initial.length; i += period)
+  for (size_t i = 0; i < list->initial.length; i += period)
     {
-      si = initial_unshare (list, i);
+      size_t si = initial_unshare (list, i);
       list->initial.element[si].presence = FCT_OPTIONAL;
     }
 
   if (!ended)
     {
       /* Now split off the repeated part.  */
-      splitindex = initial_splitelement (list, n - p);
-      newcount = list->initial.count - splitindex;
+      size_t splitindex = initial_splitelement (list, n - p);
+      size_t newcount = list->initial.count - splitindex;
       if (newcount > list->repeated.allocated)
         {
           list->repeated.allocated = newcount;
           list->repeated.element = XNMALLOC (newcount, struct format_arg);
         }
-      for (i = splitindex, j = 0; j < newcount; i++, j++)
-        list->repeated.element[j] = list->initial.element[i];
+      {
+        size_t i = splitindex;
+        for (size_t j = 0; j < newcount; j++)
+          {
+            list->repeated.element[j] = list->initial.element[i];
+            i++;
+          }
+      }
       list->repeated.count = newcount;
       list->repeated.length = p;
       list->initial.count = splitindex;
@@ -2470,17 +2452,14 @@ parse_upto (const char **formatp,
   for (; *format != '\0'; )
     if (*format++ == '~')
       {
-        bool colon_p = false;
-        bool atsign_p = false;
-        size_t paramcount = 0;
-        struct param *params = NULL;
-
         FDI_SET (format - 1, FMTDIR_START);
 
         /* Count number of directives.  */
         spec->directives++;
 
         /* Parse parameters.  */
+        size_t paramcount = 0;
+        struct param *params = NULL;
         for (;;)
           {
             enum param_type type = PT_NIL;
@@ -2566,6 +2545,8 @@ parse_upto (const char **formatp,
           }
 
         /* Parse modifiers.  */
+        bool colon_p = false;
+        bool atsign_p = false;
         for (;;)
           {
             if (*format == ':')
@@ -2878,9 +2859,6 @@ parse_upto (const char **formatp,
               }
             else if (atsign_p)
               {
-                struct format_arg_list *nil_list;
-                struct format_arg_list *union_list;
-
                 if (!check_params (&list, paramcount, params, 0, NULL,
                                    spec->directives, invalid_reason))
                   {
@@ -2892,7 +2870,8 @@ parse_upto (const char **formatp,
                 *escapep = escape;
 
                 /* First alternative: argument is NIL.  */
-                nil_list = (list != NULL ? copy_list (list) : NULL);
+                struct format_arg_list *nil_list =
+                  (list != NULL ? copy_list (list) : NULL);
                 if (position >= 0)
                   {
                     struct format_arg_list *empty_list = make_empty_list ();
@@ -2902,6 +2881,7 @@ parse_upto (const char **formatp,
                   }
 
                 /* Second alternative: use sub-format.  */
+                struct format_arg_list *union_list;
                 {
                   int sub_position = position;
                   struct format_arg_list *sub_list =
@@ -2943,9 +2923,6 @@ parse_upto (const char **formatp,
               }
             else if (colon_p)
               {
-                int union_position;
-                struct format_arg_list *union_list;
-
                 if (!check_params (&list, paramcount, params, 0, NULL,
                                    spec->directives, invalid_reason))
                   {
@@ -2958,8 +2935,8 @@ parse_upto (const char **formatp,
 
                 *formatp = format;
                 *escapep = escape;
-                union_position = -2;
-                union_list = NULL;
+                int union_position = -2;
+                struct format_arg_list *union_list = NULL;
 
                 /* First alternative.  */
                 {
@@ -3030,11 +3007,6 @@ parse_upto (const char **formatp,
               }
             else
               {
-                int arg_position;
-                int union_position;
-                struct format_arg_list *union_list;
-                bool last_alternative;
-
                 if (!check_params (&list, paramcount, params, 1, I,
                                    spec->directives, invalid_reason))
                   {
@@ -3043,7 +3015,7 @@ parse_upto (const char **formatp,
                   }
 
                 /* If there was no first parameter, an argument is consumed.  */
-                arg_position = -1;
+                int arg_position = -1;
                 if (!(paramcount >= 1 && params[0].type != PT_NIL))
                   if (position >= 0)
                     {
@@ -3054,9 +3026,9 @@ parse_upto (const char **formatp,
                 *formatp = format;
                 *escapep = escape;
 
-                union_position = -2;
-                union_list = NULL;
-                last_alternative = false;
+                int union_position = -2;
+                struct format_arg_list *union_list = NULL;
+                bool last_alternative = false;
                 for (;;)
                   {
                     /* Next alternative.  */
@@ -3167,12 +3139,12 @@ parse_upto (const char **formatp,
               if (colon_p)
                 {
                   /* Each iteration uses a new sublist.  */
-                  struct format_arg_list *listlist;
 
                   /* ~{ catches ~^.  */
                   sub_list = union (sub_list, sub_escape);
 
-                  listlist = make_repeated_list_of_lists (sub_list);
+                  struct format_arg_list *listlist =
+                    make_repeated_list_of_lists (sub_list);
 
                   sub_list = listlist;
                 }
@@ -3180,7 +3152,6 @@ parse_upto (const char **formatp,
                 {
                   /* Each iteration's arguments are all concatenated in a
                      single list.  */
-                  struct format_arg_list *looplist;
 
                   /* FIXME: This is far from correct.  Test cases:
                      abc~{~^~}
@@ -3194,6 +3165,7 @@ parse_upto (const char **formatp,
                   /* ~{ catches ~^.  */
                   sub_list = union (sub_list, sub_escape);
 
+                  struct format_arg_list *looplist;
                   if (sub_list == NULL)
                     looplist = make_empty_list ();
                   else
@@ -3346,13 +3318,11 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   struct spec spec;
-  struct spec *result;
-  int position = 0;
-  struct format_arg_list *escape;
-
   spec.directives = 0;
   spec.list = make_unconstrained_list ();
-  escape = NULL;
+
+  int position = 0;
+  struct format_arg_list *escape = NULL;
 
   if (!parse_upto (&format, &position, &spec.list, &escape,
                    NULL, &spec, '\0', false,
@@ -3374,7 +3344,7 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Normalize the result.  */
   normalize_list (spec.list);
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 }
@@ -3514,12 +3484,10 @@ print_element (struct format_arg *element)
 static void
 print_list (struct format_arg_list *list)
 {
-  size_t i, j;
-
   printf ("(");
 
-  for (i = 0; i < list->initial.count; i++)
-    for (j = 0; j < list->initial.element[i].repcount; j++)
+  for (size_t i = 0; i < list->initial.count; i++)
+    for (size_t j = 0; j < list->initial.element[i].repcount; j++)
       {
         if (i > 0 || j > 0)
           printf (" ");
@@ -3529,8 +3497,8 @@ print_list (struct format_arg_list *list)
   if (list->repeated.count > 0)
     {
       printf (" |");
-      for (i = 0; i < list->repeated.count; i++)
-        for (j = 0; j < list->repeated.element[i].repcount; j++)
+      for (size_t i = 0; i < list->repeated.count; i++)
+        for (size_t j = 0; j < list->repeated.element[i].repcount; j++)
           {
             printf (" ");
             print_element (&list->repeated.element[i]);
@@ -3561,18 +3529,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 72156b9a57606713e49fc606bfed94b043a8ec2c..fb221962acc92b3fde9966df59e316e564425b60 100644 (file)
@@ -119,34 +119,28 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  size_t unnumbered_arg_count;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  unnumbered_arg_count = 0;
+  size_t numbered_allocated = 0;
+  size_t unnumbered_arg_count = 0;
 
   for (; *format != '\0';)
     /* Invariant: spec.numbered_arg_count == 0 || unnumbered_arg_count == 0.  */
     if (*format == '%')
       {
         /* A directive.  */
-        bool likely_intentional = true;
-
         FDI_SET (format, FMTDIR_START);
         format++;
         spec.directives++;
+        bool likely_intentional = true;
 
         if (*format != '%')
           {
             size_t number = 0;
-            enum format_arg_type type;
-
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -202,6 +196,7 @@ format_parse (const char *format, bool translated, char *fdi,
                   format++;
               }
 
+            enum format_arg_type type;
             switch (*format)
               {
               case 'c':
@@ -364,21 +359,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   else if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -408,7 +401,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -455,68 +448,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -544,8 +542,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -554,8 +550,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -597,18 +593,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 8c395508ee3628860d23aac95882f81f3c35f9f6..12089c5691ee1913ec598f34d4d75a592682fbd0 100644 (file)
@@ -86,31 +86,24 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t named_allocated;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.named_arg_count = 0;
   spec.named = NULL;
-  named_allocated = 0;
+  size_t named_allocated = 0;
 
   for (; *format != '\0';)
     if (*format++ == '$')
       {
         /* A variable substitution.  */
-        char *name;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
 
+        char *name;
         if (*format == '{')
           {
-            const char *name_start;
-            const char *name_end;
-            size_t n;
-
-            name_start = ++format;
+            const char *name_start = ++format;
             for (; *format != '\0'; format++)
               {
                 if (*format == '}')
@@ -143,9 +136,9 @@ format_parse (const char *format, bool translated, char *fdi,
                 FDI_SET (format - 1, FMTDIR_ERROR);
                 goto bad_format;
               }
-            name_end = format++;
+            const char *name_end = format++;
 
-            n = name_end - name_start;
+            size_t n = name_end - name_start;
             if (n == 0)
               {
                 *invalid_reason = INVALID_EMPTY_VARIABLE ();
@@ -158,17 +151,13 @@ format_parse (const char *format, bool translated, char *fdi,
           }
         else if (c_isalpha (*format) || *format == '_')
           {
-            const char *name_start;
-            const char *name_end;
-            size_t n;
-
-            name_start = format;
+            const char *name_start = format;
             do
               format++;
             while (*format != '\0' && (c_isalnum (*format) || *format == '_'));
-            name_end = format;
+            const char *name_end = format;
 
-            n = name_end - name_start;
+            size_t n = name_end - name_start;
             name = XNMALLOC (n + 1, char);
             memcpy (name, name_start, n);
             name[n] = '\0';
@@ -210,12 +199,11 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the named argument array, and eliminate duplicates.  */
   if (spec.named_arg_count > 1)
     {
-      size_t i, j;
-
       qsort (spec.named, spec.named_arg_count, sizeof (struct named_arg),
              named_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
+      size_t i, j;
       for (i = j = 0; i < spec.named_arg_count; i++)
         if (j > 0 && strcmp (spec.named[i].name, spec.named[j-1].name) == 0)
           free (spec.named[i].name);
@@ -228,15 +216,14 @@ format_parse (const char *format, bool translated, char *fdi,
       spec.named_arg_count = j;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
  bad_format:
   if (spec.named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec.named_arg_count; i++)
+      for (size_t i = 0; i < spec.named_arg_count; i++)
         free (spec.named[i].name);
       free (spec.named);
     }
@@ -250,8 +237,7 @@ format_free (void *descr)
 
   if (spec->named != NULL)
     {
-      size_t i;
-      for (i = 0; i < spec->named_arg_count; i++)
+      for (size_t i = 0; i < spec->named_arg_count; i++)
         free (spec->named[i].name);
       free (spec->named);
     }
@@ -277,12 +263,12 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->named_arg_count + spec2->named_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->named_arg_count;
       size_t n2 = spec2->named_arg_count;
 
       /* Check the argument names in spec2 are contained in those of spec1.
          Both arrays are sorted.  We search for the first difference.  */
+      size_t i, j;
       for (i = 0, j = 0; i < n1 || j < n2; )
         {
           int cmp = (i >= n1 ? 1 :
@@ -343,7 +329,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -352,7 +337,7 @@ format_print (void *descr)
     }
 
   printf ("{");
-  for (i = 0; i < spec->named_arg_count; i++)
+  for (size_t i = 0; i < spec->named_arg_count; i++)
     {
       if (i > 0)
         printf (", ");
@@ -368,18 +353,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 6ec84a53d437bdfd5f432c59857ab79d92094803..6a4f8088d91e53d64a22daf0976523b36f956053 100644 (file)
@@ -49,9 +49,8 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  struct spec *result;
 
+  struct spec spec;
   spec.directives = 0;
   spec.arg_count = 0;
 
@@ -95,7 +94,7 @@ format_parse (const char *format, bool translated, char *fdi,
         FDI_SET (format - 1, FMTDIR_END);
       }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -127,9 +126,8 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
   struct spec *spec1 = (struct spec *) msgid_descr;
   struct spec *spec2 = (struct spec *) msgstr_descr;
   bool err = false;
-  size_t i;
 
-  for (i = 0; i < spec1->arg_count || i < spec2->arg_count; i++)
+  for (size_t i = 0; i < spec1->arg_count || i < spec2->arg_count; i++)
     {
       bool arg_used1 = (i < spec1->arg_count && spec1->args_used[i]);
       bool arg_used2 = (i < spec2->arg_count && spec2->args_used[i]);
@@ -187,7 +185,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -196,7 +193,7 @@ format_print (void *descr)
     }
 
   printf ("(");
-  for (i = 0; i < spec->arg_count; i++)
+  for (size_t i = 0; i < spec->arg_count; i++)
     {
       if (i > 0)
         printf (" ");
@@ -215,18 +212,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index 77ae630f7e9bd394432c0564849e5c66fe42518e..b0eb8f9c71edcff81a4b097039413209c484a358 100644 (file)
@@ -97,39 +97,29 @@ format_parse (const char *format, bool translated, char *fdi,
               char **invalid_reason)
 {
   const char *const format_start = format;
-  struct spec spec;
-  size_t numbered_allocated;
-  struct spec *result;
-  bool seen_numbered_arg;
-  bool seen_unnumbered_arg;
-  size_t number;
 
+  struct spec spec;
   spec.directives = 0;
   spec.likely_intentional_directives = 0;
   spec.numbered_arg_count = 0;
   spec.numbered = NULL;
-  numbered_allocated = 0;
-  seen_numbered_arg = false;
-  seen_unnumbered_arg = false;
-  number = 1;
+  size_t numbered_allocated = 0;
+  bool seen_numbered_arg = false;
+  bool seen_unnumbered_arg = false;
+  size_t number = 1;
 
   for (; *format != '\0';)
     /* Invariant: !seen_numbered_arg || !seen_unnumbered_arg.  */
     if (*format++ == '%')
       {
         /* A directive.  */
-        bool likely_intentional = true;
-
         FDI_SET (format - 1, FMTDIR_START);
         spec.directives++;
+        bool likely_intentional = true;
 
         if (*format != '%')
           {
-            bool is_numbered_arg;
-            bool short_flag;
-            enum format_arg_type type;
-
-            is_numbered_arg = false;
+            bool is_numbered_arg = false;
             if (c_isdigit (*format))
               {
                 const char *f = format;
@@ -234,12 +224,13 @@ format_parse (const char *format, bool translated, char *fdi,
               }
 
             /* Parse optional size specification.  */
-            short_flag = false;
+            bool short_flag = false;
             if (*format == 'h')
               short_flag = true, format++;
             else if (*format == 'l')
               format++;
 
+            enum format_arg_type type;
             switch (*format)
               {
               case 'c':
@@ -294,21 +285,19 @@ format_parse (const char *format, bool translated, char *fdi,
   /* Sort the numbered argument array, and eliminate duplicates.  */
   if (spec.numbered_arg_count > 1)
     {
-      size_t i, j;
-      bool err;
-
       qsort (spec.numbered, spec.numbered_arg_count,
              sizeof (struct numbered_arg), numbered_arg_compare);
 
       /* Remove duplicates: Copy from i to j, keeping 0 <= j <= i.  */
-      err = false;
+      bool err = false;
+      size_t i, j;
       for (i = j = 0; i < spec.numbered_arg_count; i++)
         if (j > 0 && spec.numbered[i].number == spec.numbered[j-1].number)
           {
             enum format_arg_type type1 = spec.numbered[i].type;
             enum format_arg_type type2 = spec.numbered[j-1].type;
-            enum format_arg_type type_both;
 
+            enum format_arg_type type_both;
             if (type1 == type2)
               type_both = type1;
             else
@@ -338,7 +327,7 @@ format_parse (const char *format, bool translated, char *fdi,
         goto bad_format;
     }
 
-  result = XMALLOC (struct spec);
+  struct spec *result = XMALLOC (struct spec);
   *result = spec;
   return result;
 
@@ -385,68 +374,73 @@ format_check (void *msgid_descr, void *msgstr_descr, bool equality,
 
   if (spec1->numbered_arg_count + spec2->numbered_arg_count > 0)
     {
-      size_t i, j;
       size_t n1 = spec1->numbered_arg_count;
       size_t n2 = spec2->numbered_arg_count;
 
       /* Check that the argument numbers are the same.
          Both arrays are sorted.  We search for the first difference.  */
-      for (i = 0, j = 0; i < n1 || j < n2; )
-        {
-          int cmp = (i >= n1 ? 1 :
-                     j >= n2 ? -1 :
-                     spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
-                     spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
-                     0);
-
-          if (cmp > 0)
-            {
-              if (error_logger)
-                error_logger (error_logger_data,
-                              _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
-                              spec2->numbered[j].number, pretty_msgstr,
-                              pretty_msgid);
-              err = true;
-              break;
-            }
-          else if (cmp < 0)
-            {
-              if (equality)
-                {
-                  if (error_logger)
-                    error_logger (error_logger_data,
-                                  _("a format specification for argument %zu doesn't exist in '%s'"),
-                                  spec1->numbered[i].number, pretty_msgstr);
-                  err = true;
-                  break;
-                }
-              else
-                i++;
-            }
-          else
-            j++, i++;
-        }
-      /* Check the argument types are the same.  */
-      if (!err)
-        for (i = 0, j = 0; j < n2; )
+      {
+        size_t i, j;
+        for (i = 0, j = 0; i < n1 || j < n2; )
           {
-            if (spec1->numbered[i].number == spec2->numbered[j].number)
+            int cmp = (i >= n1 ? 1 :
+                       j >= n2 ? -1 :
+                       spec1->numbered[i].number > spec2->numbered[j].number ? 1 :
+                       spec1->numbered[i].number < spec2->numbered[j].number ? -1 :
+                       0);
+
+            if (cmp > 0)
               {
-                if (spec1->numbered[i].type != spec2->numbered[j].type)
+                if (error_logger)
+                  error_logger (error_logger_data,
+                                _("a format specification for argument %zu, as in '%s', doesn't exist in '%s'"),
+                                spec2->numbered[j].number, pretty_msgstr,
+                                pretty_msgid);
+                err = true;
+                break;
+              }
+            else if (cmp < 0)
+              {
+                if (equality)
                   {
                     if (error_logger)
                       error_logger (error_logger_data,
-                                    _("format specifications in '%s' and '%s' for argument %zu are not the same"),
-                                    pretty_msgid, pretty_msgstr,
-                                    spec2->numbered[j].number);
+                                    _("a format specification for argument %zu doesn't exist in '%s'"),
+                                    spec1->numbered[i].number, pretty_msgstr);
                     err = true;
                     break;
                   }
-                j++, i++;
+                else
+                  i++;
               }
             else
-              i++;
+              j++, i++;
           }
+      }
+      /* Check the argument types are the same.  */
+      if (!err)
+        {
+          size_t i, j;
+          for (i = 0, j = 0; j < n2; )
+            {
+              if (spec1->numbered[i].number == spec2->numbered[j].number)
+                {
+                  if (spec1->numbered[i].type != spec2->numbered[j].type)
+                    {
+                      if (error_logger)
+                        error_logger (error_logger_data,
+                                      _("format specifications in '%s' and '%s' for argument %zu are not the same"),
+                                      pretty_msgid, pretty_msgstr,
+                                      spec2->numbered[j].number);
+                      err = true;
+                      break;
+                    }
+                  j++, i++;
+                }
+              else
+                i++;
+            }
+        }
     }
 
   return err;
@@ -474,8 +468,6 @@ static void
 format_print (void *descr)
 {
   struct spec *spec = (struct spec *) descr;
-  size_t last;
-  size_t i;
 
   if (spec == NULL)
     {
@@ -484,8 +476,8 @@ format_print (void *descr)
     }
 
   printf ("(");
-  last = 1;
-  for (i = 0; i < spec->numbered_arg_count; i++)
+  size_t last = 1;
+  for (size_t i = 0; i < spec->numbered_arg_count; i++)
     {
       size_t number = spec->numbered[i].number;
 
@@ -533,18 +525,14 @@ main ()
     {
       char *line = NULL;
       size_t line_size = 0;
-      int line_len;
-      char *invalid_reason;
-      void *descr;
-
-      line_len = getline (&line, &line_size, stdin);
+      int line_len = getline (&line, &line_size, stdin);
       if (line_len < 0)
         break;
       if (line_len > 0 && line[line_len - 1] == '\n')
         line[--line_len] = '\0';
 
-      invalid_reason = NULL;
-      descr = format_parse (line, false, NULL, &invalid_reason);
+      char *invalid_reason = NULL;
+      void *descr = format_parse (line, false, NULL, &invalid_reason);
 
       format_print (descr);
       printf ("\n");
index bf3d74ebc7d4688c6baad90273453a7939fc2da0..9812d7e99f49270ce39676a801498f67b35e06cf 100644 (file)
@@ -104,24 +104,22 @@ check_msgid_msgstr_format_i (const char *msgid, const char *msgid_plural,
     {
       const char *pretty_msgid =
         (msgid_plural != NULL ? "msgid_plural" : "msgid");
-      char buf[18+1];
-      const char *pretty_msgstr = "msgstr";
       bool has_plural_translations = (strlen (msgstr) + 1 < msgstr_len);
       const char *p_end = msgstr + msgstr_len;
+
       const char *p;
       unsigned int j;
-
       for (p = msgstr, j = 0; p < p_end; p += strlen (p) + 1, j++)
         {
-          void *msgstr_descr;
-
+          char buf[18+1];
+          const char *pretty_msgstr = "msgstr";
           if (msgid_plural != NULL)
             {
               sprintf (buf, "msgstr[%u]", j);
               pretty_msgstr = buf;
             }
 
-          msgstr_descr = parser->parse (p, true, NULL, &invalid_reason);
+          void *msgstr_descr = parser->parse (p, true, NULL, &invalid_reason);
 
           if (msgstr_descr != NULL)
             {
@@ -186,7 +184,6 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
                            formatstring_error_logger_t error_logger, void *error_logger_data)
 {
   int seen_errors = 0;
-  size_t i;
 
   /* We check only those messages for which the msgid's is_format flag
      is one of 'yes' or 'possible'.  We don't check msgids with is_format
@@ -194,7 +191,7 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
      msgids with is_format 'undecided' because that would introduce too
      many checks, thus forcing the programmer to add "xgettext: no-c-format"
      anywhere where a translator wishes to use a percent sign.  */
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     if (possible_format_p (is_format[i]))
       seen_errors += check_msgid_msgstr_format_i (msgid, msgid_plural,
                                                   msgstr, msgstr_len, i,
index 5bc22bfa42cd22af87ff9ca0c292213813784972..7eacc796bec21c9727409fc13145df285f03f082 100644 (file)
@@ -118,9 +118,6 @@ static void print_hostname (void);
 int
 main (int argc, char *argv[])
 {
-  bool do_help;
-  bool do_version;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -136,9 +133,9 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
   format = default_format;
 
   /* Parse command line options.  */
@@ -154,31 +151,33 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'f':
-        format = long_format;
-        break;
-      case 's':
-        format = short_format;
-        break;
-      case 'i':
-        format = ip_format;
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'f':
+          format = long_format;
+          break;
+        case 's':
+          format = short_format;
+          break;
+        case 'i':
+          format = ip_format;
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -265,22 +264,22 @@ xgethostname ()
 #ifdef WIN32_NATIVE
   char hostname[MAX_COMPUTERNAME_LENGTH+1];
   DWORD size = sizeof (hostname);
-
   if (!GetComputerName (hostname, &size))
     error (EXIT_FAILURE, 0, _("could not get host name"));
+
   return xstrdup (hostname);
 #elif HAVE_GETHOSTNAME
   char hostname[MAXHOSTNAMELEN+1];
-
   if (gethostname (hostname, MAXHOSTNAMELEN) < 0)
     error (EXIT_FAILURE, errno, _("could not get host name"));
   hostname[MAXHOSTNAMELEN] = '\0';
+
   return xstrdup (hostname);
 #else
   struct utsname utsname;
-
   if (uname (&utsname) < 0)
     error (EXIT_FAILURE, errno, _("could not get host name"));
+
   return xstrdup (utsname.nodename);
 #endif
 }
@@ -349,10 +348,7 @@ ipv6_is_linklocal (const struct in6_addr *addr)
 static void
 print_hostname ()
 {
-  char *hostname;
-  char *dot;
-
-  hostname = xgethostname ();
+  char *hostname = xgethostname ();
 
   switch (format)
     {
@@ -363,9 +359,11 @@ print_hostname ()
 
     case short_format:
       /* Print only the part before the first dot.  */
-      dot = strchr (hostname, '.');
-      if (dot != NULL)
-        *dot = '\0';
+      {
+        char *dot = strchr (hostname, '.');
+        if (dot != NULL)
+          *dot = '\0';
+      }
       printf ("%s\n", hostname);
       break;
 
@@ -375,21 +373,17 @@ print_hostname ()
          getnameinfo() is not even needed.  */
       {
         struct addrinfo hints;
-        struct addrinfo *res;
-        int ret;
-
         memset (&hints, 0, sizeof (hints));
         hints.ai_family = AF_UNSPEC; /* either AF_INET or AF_INET6 is ok */
         hints.ai_socktype = SOCK_STREAM; /* or SOCK_DGRAM or 0 */
         hints.ai_protocol = 0; /* any protocol is ok */
         hints.ai_flags = AI_CANONNAME;
 
-        ret = getaddrinfo (hostname, NULL, &hints, &res);
+        struct addrinfo *res;
+        int ret = getaddrinfo (hostname, NULL, &hints, &res);
         if (ret == 0)
           {
-            struct addrinfo *p;
-
-            for (p = res; p != NULL; p = p->ai_next)
+            for (struct addrinfo *p = res; p != NULL; p = p->ai_next)
               {
                 /* Typically p->ai_socktype == SOCK_STREAM, p->ai_protocol == IPPROTO_TCP,
                    or        p->ai_socktype == SOCK_DGRAM, p->ai_protocol == IPPROTO_UDP.  */
@@ -406,15 +400,12 @@ print_hostname ()
 #elif HAVE_GETHOSTBYNAME
       /* Look for netwide usable hostname and aliases using gethostbyname().  */
       {
-        struct hostent *h;
-        size_t i;
-
-        h = gethostbyname (hostname);
+        struct hostent *h = gethostbyname (hostname);
         if (h != NULL)
           {
             printf ("%s\n", h->h_name);
             if (h->h_aliases != NULL)
-              for (i = 0; h->h_aliases[i] != NULL; i++)
+              for (size_t i = 0; h->h_aliases[i] != NULL; i++)
                 printf ("%s\n", h->h_aliases[i]);
           }
         else
@@ -431,22 +422,17 @@ print_hostname ()
          getnameinfo().  */
       {
         struct addrinfo hints;
-        struct addrinfo *res;
-        int ret;
-        char host[1025];
-
         memset (&hints, 0, sizeof (hints));
         hints.ai_family = AF_UNSPEC; /* either AF_INET or AF_INET6 is ok */
         hints.ai_socktype = SOCK_STREAM; /* or SOCK_DGRAM */
         hints.ai_protocol = 0; /* any protocol is ok */
         hints.ai_flags = 0;
 
-        ret = getaddrinfo (hostname, NULL, &hints, &res);
+        struct addrinfo *res;
+        int ret = getaddrinfo (hostname, NULL, &hints, &res);
         if (ret == 0)
           {
-            struct addrinfo *p;
-
-            for (p = res; p != NULL; p = p->ai_next)
+            for (struct addrinfo *p = res; p != NULL; p = p->ai_next)
               {
                 /* Typically p->ai_socktype == SOCK_STREAM, p->ai_protocol == IPPROTO_TCP,
                    or        p->ai_socktype == SOCK_DGRAM, p->ai_protocol == IPPROTO_UDP.  */
@@ -459,14 +445,17 @@ print_hostname ()
                           && ipv6_is_linklocal (&((const struct sockaddr_in6 *) p->ai_addr)->sin6_addr))
 # endif
                    ) )
-                  if (getnameinfo (p->ai_addr, p->ai_addrlen,
-                                   host, sizeof (host),
-                                   NULL, 0,
-                                   NI_NUMERICHOST)
-                      == 0)
-                    {
-                      printf ("[%.*s]\n", (int) sizeof (host), host);
-                    }
+                  {
+                    char host[1025];
+                    if (getnameinfo (p->ai_addr, p->ai_addrlen,
+                                     host, sizeof (host),
+                                     NULL, 0,
+                                     NI_NUMERICHOST)
+                        == 0)
+                      {
+                        printf ("[%.*s]\n", (int) sizeof (host), host);
+                      }
+                  }
               }
 
             freeaddrinfo (res);
@@ -475,12 +464,9 @@ print_hostname ()
 #elif HAVE_GETHOSTBYNAME
       /* Look for netwide usable IP addresses using gethostbyname().  */
       {
-        struct hostent *h;
-        size_t i;
-
-        h = gethostbyname (hostname);
+        struct hostent *h = gethostbyname (hostname);
         if (h != NULL && h->h_addr_list != NULL)
-          for (i = 0; h->h_addr_list[i] != NULL; i++)
+          for (size_t i = 0; h->h_addr_list[i] != NULL; i++)
             {
 # if HAVE_IPV6
               if (h->h_addrtype == AF_INET6)
index 54d05b06e9ffcf253bdb198bf9c1938d7268c4b7..36a3016bdd52b31092659dbcff26d9d277826222 100644 (file)
@@ -110,7 +110,6 @@ if_error (int severity,
           bool multiline, const char *format, ...)
 {
   va_list args;
-
   va_start (args, format);
   if_verror (severity, filename, lineno, column, multiline, format, args);
   va_end (args);
index 57572a8185008eea44eeda18817dcd35d130ad1f..1f6e60cda13ccab96374fbe02ca430b06b2b99bd 100644 (file)
@@ -108,7 +108,6 @@ static void
 generic_error (void *data, const char *message, ...)
 {
   va_list args;
-
   va_start (args, message);
   vfprintf (stderr, message, args);
   va_end (args);
@@ -136,7 +135,6 @@ its_value_list_append (struct its_value_list_ty *values,
                        const char *value)
 {
   struct its_value_ty _value;
-
   _value.name = xstrdup (name);
   _value.value = xstrdup (value);
 
@@ -155,9 +153,7 @@ static const char *
 its_value_list_get_value (struct its_value_list_ty *values,
                           const char *name)
 {
-  size_t i;
-
-  for (i = 0; i < values->nitems; i++)
+  for (size_t i = 0; i < values->nitems; i++)
     {
       struct its_value_ty *value = &values->items[i];
       if (strcmp (value->name, name) == 0)
@@ -172,7 +168,6 @@ its_value_list_set_value (struct its_value_list_ty *values,
                           const char *value)
 {
   size_t i;
-
   for (i = 0; i < values->nitems; i++)
     {
       struct its_value_ty *_value = &values->items[i];
@@ -192,13 +187,11 @@ static void
 its_value_list_merge (struct its_value_list_ty *values,
                       struct its_value_list_ty *other)
 {
-  size_t i;
-
-  for (i = 0; i < other->nitems; i++)
+  for (size_t i = 0; i < other->nitems; i++)
     {
       struct its_value_ty *other_value = &other->items[i];
-      size_t j;
 
+      size_t j;
       for (j = 0; j < values->nitems; j++)
         {
           struct its_value_ty *value = &values->items[j];
@@ -220,9 +213,7 @@ its_value_list_merge (struct its_value_list_ty *values,
 static void
 its_value_list_destroy (struct its_value_list_ty *values)
 {
-  size_t i;
-
-  for (i = 0; i < values->nitems; i++)
+  for (size_t i = 0; i < values->nitems; i++)
     {
       free (values->items[i].name);
       free (values->items[i].value);
@@ -240,8 +231,6 @@ struct its_pool_ty
 static struct its_value_list_ty *
 its_pool_alloc_value_list (struct its_pool_ty *pool)
 {
-  struct its_value_list_ty *values;
-
   if (pool->nitems == pool->nitems_max)
     {
       pool->nitems_max = 2 * pool->nitems_max + 1;
@@ -250,7 +239,7 @@ its_pool_alloc_value_list (struct its_pool_ty *pool)
                   sizeof (struct its_value_list_ty) * pool->nitems_max);
     }
 
-  values = &pool->items[pool->nitems++];
+  struct its_value_list_ty *values = &pool->items[pool->nitems++];
   memset (values, 0, sizeof (struct its_value_list_ty));
   return values;
 }
@@ -262,10 +251,8 @@ its_pool_get_value_for_node (struct its_pool_ty *pool, xmlNode *node,
   intptr_t index = (intptr_t) node->_private;
   if (index > 0)
     {
-      struct its_value_list_ty *values;
-
       assert (index <= pool->nitems);
-      values = &pool->items[index - 1];
+      struct its_value_list_ty *values = &pool->items[index - 1];
 
       return its_value_list_get_value (values, name);
     }
@@ -275,9 +262,7 @@ its_pool_get_value_for_node (struct its_pool_ty *pool, xmlNode *node,
 static void
 its_pool_destroy (struct its_pool_ty *pool)
 {
-  size_t i;
-
-  for (i = 0; i < pool->nitems; i++)
+  for (size_t i = 0; i < pool->nitems; i++)
     its_value_list_destroy (&pool->items[i]);
   free (pool->items);
 }
@@ -349,8 +334,7 @@ its_rule_destructor (struct its_rule_ty *rule)
   its_value_list_destroy (&rule->values);
   if (rule->namespaces)
     {
-      size_t i;
-      for (i = 0; rule->namespaces[i] != NULL; i++)
+      for (size_t i = 0; rule->namespaces[i] != NULL; i++)
         xmlFreeNs (rule->namespaces[i]);
       free (rule->namespaces);
     }
@@ -359,16 +343,13 @@ its_rule_destructor (struct its_rule_ty *rule)
 static void
 its_rule_apply (struct its_rule_ty *rule, struct its_pool_ty *pool, xmlDoc *doc)
 {
-  xmlXPathContext *context;
-  xmlXPathObject *object;
-
   if (!rule->selector)
     {
       error (0, 0, _("selector is not specified"));
       return;
     }
 
-  context = xmlXPathNewContext (doc);
+  xmlXPathContext *context = xmlXPathNewContext (doc);
   if (!context)
     {
       error (0, 0, _("cannot create XPath context"));
@@ -377,15 +358,14 @@ its_rule_apply (struct its_rule_ty *rule, struct its_pool_ty *pool, xmlDoc *doc)
 
   if (rule->namespaces)
     {
-      size_t i;
-      for (i = 0; rule->namespaces[i] != NULL; i++)
+      for (size_t i = 0; rule->namespaces[i] != NULL; i++)
         {
           xmlNs *ns = rule->namespaces[i];
           xmlXPathRegisterNs (context, ns->prefix, ns->href);
         }
     }
 
-  object = xmlXPathEval (BAD_CAST rule->selector, context);
+  xmlXPathObject *object = xmlXPathEval (BAD_CAST rule->selector, context);
   if (!object)
     {
       xmlXPathFreeContext (context);
@@ -396,18 +376,17 @@ 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++)
+      for (size_t i = 0; i < nodes->nodeNr; i++)
         {
           xmlNode *node = nodes->nodeTab[i];
-          struct its_value_list_ty *values;
 
           /* We can't store VALUES in NODE, since the address can
              change when realloc()ed.  */
           intptr_t index = (intptr_t) node->_private;
-
           assert (index <= pool->nitems);
+
+          struct its_value_list_ty *values;
           if (index > 0)
             values = &pool->items[index - 1];
           else
@@ -427,12 +406,9 @@ its_rule_apply (struct its_rule_ty *rule, struct its_pool_ty *pool, xmlDoc *doc)
 static char *
 _its_get_attribute (xmlNode *node, const char *attr, const char *namespace)
 {
-  xmlChar *value;
-  char *result;
-
-  value = xmlGetNsProp (node, BAD_CAST attr, BAD_CAST namespace);
+  xmlChar *value = xmlGetNsProp (node, BAD_CAST attr, BAD_CAST namespace);
 
-  result = xstrdup ((const char *) value);
+  char *result = xstrdup ((const char *) value);
   xmlFree (value);
 
   return result;
@@ -456,41 +432,34 @@ normalize_whitespace (const char *text, enum its_whitespace_type_ty whitespace)
         char *result = xstrdup (text);
         /* Go through the string, shrinking it, reading from *p++
            and writing to *out++.  (result <= out <= p.)  */
-        const char *start_of_paragraph;
-        char *out;
-
-        out = result;
-        for (start_of_paragraph = result; *start_of_paragraph != '\0';)
+        char *out = result;
+        for (const char *start_of_paragraph = result; *start_of_paragraph != '\0';)
           {
             const char *end_of_paragraph;
             const char *next_paragraph;
 
             /* Find the next paragraph boundary.  */
-            {
-              const char *p;
-
-              for (p = start_of_paragraph;;)
+            for (const char *p = start_of_paragraph;;)
+              {
+                const char *nl = strchrnul (p, '\n');
+                if (*nl == '\0')
+                  {
+                    end_of_paragraph = nl;
+                    next_paragraph = end_of_paragraph;
+                    break;
+                  }
+                p = nl + 1;
                 {
-                  const char *nl = strchrnul (p, '\n');
-                  if (*nl == '\0')
+                  const char *past_whitespace = p + strspn (p, " \t\n");
+                  if (memchr (p, '\n', past_whitespace - p) != NULL)
                     {
                       end_of_paragraph = nl;
-                      next_paragraph = end_of_paragraph;
+                      next_paragraph = past_whitespace;
                       break;
                     }
-                  p = nl + 1;
-                  {
-                    const char *past_whitespace = p + strspn (p, " \t\n");
-                    if (memchr (p, '\n', past_whitespace - p) != NULL)
-                      {
-                        end_of_paragraph = nl;
-                        next_paragraph = past_whitespace;
-                        break;
-                      }
-                    p = past_whitespace;
-                  }
+                  p = past_whitespace;
                 }
-            }
+              }
 
             /* Normalize whitespaces in the paragraph.  */
             {
@@ -534,11 +503,9 @@ normalize_whitespace (const char *text, enum its_whitespace_type_ty whitespace)
          at the beginning nor the end of the text.  */
       {
         char *result = xstrdup (text);
-        char *out;
-        const char *p;
 
-        out = result;
-        for (p = result; *p != '\0';)
+        char *out = result;
+        for (const char *p = result; *p != '\0';)
           {
             if (*p == ' ' || *p == '\t' || *p == '\n')
               {
@@ -559,11 +526,8 @@ normalize_whitespace (const char *text, enum its_whitespace_type_ty whitespace)
 static char *
 _its_encode_special_chars (const char *content, bool is_attribute)
 {
-  const char *str;
   size_t amount = 0;
-  char *result, *p;
-
-  for (str = content; *str != '\0'; str++)
+  for (const char *str = content; *str != '\0'; str++)
     {
       switch (*str)
         {
@@ -588,34 +552,36 @@ _its_encode_special_chars (const char *content, bool is_attribute)
         }
     }
 
-  result = XNMALLOC (amount + 1, char);
+  char *result = XNMALLOC (amount + 1, char);
   *result = '\0';
-  p = result;
-  for (str = content; *str != '\0'; str++)
-    {
-      switch (*str)
-        {
-        case '&':
-          p = stpcpy (p, "&amp;");
-          break;
-        case '<':
-          p = stpcpy (p, "&lt;");
-          break;
-        case '>':
-          p = stpcpy (p, "&gt;");
-          break;
-        case '"':
-          if (is_attribute)
-            p = stpcpy (p, "&quot;");
-          else
-            *p++ = '"';
-          break;
-        default:
-          *p++ = *str;
-          break;
-        }
-    }
-  *p = '\0';
+  {
+    char *p = result;
+    for (const char *str = content; *str != '\0'; str++)
+      {
+        switch (*str)
+          {
+          case '&':
+            p = stpcpy (p, "&amp;");
+            break;
+          case '<':
+            p = stpcpy (p, "&lt;");
+            break;
+          case '>':
+            p = stpcpy (p, "&gt;");
+            break;
+          case '"':
+            if (is_attribute)
+              p = stpcpy (p, "&quot;");
+            else
+              *p++ = '"';
+            break;
+          default:
+            *p++ = *str;
+            break;
+          }
+      }
+    *p = '\0';
+  }
   return result;
 }
 
@@ -625,11 +591,9 @@ _its_collect_text_content (xmlNode *node,
                            bool do_escape)
 {
   struct string_buffer buffer;
-  xmlNode *n;
-
   sb_init (&buffer);
 
-  for (n = node->children; n; n = n->next)
+  for (xmlNode *n = node->children; n; n = n->next)
     {
       char *content = NULL;
 
@@ -639,12 +603,11 @@ _its_collect_text_content (xmlNode *node,
         case XML_CDATA_SECTION_NODE:
           {
             xmlChar *xcontent = xmlNodeGetContent (n);
-            char *econtent;
-            const char *ccontent;
 
             /* We can't expect xmlTextWriterWriteString() encode
                special characters as we write text outside of the
                element.  */
+            char *econtent;
             if (do_escape)
               econtent =
                 _its_encode_special_chars ((const char *) xcontent,
@@ -655,7 +618,7 @@ _its_collect_text_content (xmlNode *node,
 
             /* Skip whitespaces at the beginning of the text, if this
                is the first node.  */
-            ccontent = econtent;
+            const char *ccontent = econtent;
             if (whitespace == ITS_WHITESPACE_NORMALIZE && !n->prev)
               ccontent = ccontent + strspn (ccontent, " \t\n");
             content =
@@ -684,9 +647,7 @@ _its_collect_text_content (xmlNode *node,
           {
             xmlOutputBuffer *obuffer = xmlAllocOutputBuffer (NULL);
             xmlTextWriter *writer = xmlNewTextWriter (obuffer);
-            char *p = _its_collect_text_content (n, whitespace,
-                                                 do_escape);
-            const char *ccontent;
+            char *p = _its_collect_text_content (n, whitespace, do_escape);
 
             xmlTextWriterStartElement (writer, BAD_CAST n->name);
             if (n->properties)
@@ -704,7 +665,8 @@ _its_collect_text_content (xmlNode *node,
             if (*p != '\0')
               xmlTextWriterWriteRaw (writer, BAD_CAST p);
             xmlTextWriterEndElement (writer);
-            ccontent = (const char *) xmlOutputBufferGetContent (obuffer);
+
+            const char *ccontent = (const char *) xmlOutputBufferGetContent (obuffer);
             content = normalize_whitespace (ccontent, whitespace);
             xmlFreeTextWriter (writer);
             free (p);
@@ -741,8 +703,6 @@ _its_error_missing_attribute (xmlNode *node, const char *attribute)
 static void
 its_translate_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
 {
-  char *prop;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -755,13 +715,16 @@ its_translate_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
-
-  prop = _its_get_attribute (node, "translate", NULL);
-  its_value_list_append (&rule->values, "translate", prop);
-  free (prop);
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
+  {
+    char *prop = _its_get_attribute (node, "translate", NULL);
+    its_value_list_append (&rule->values, "translate", prop);
+    free (prop);
+  }
 }
 
 static struct its_value_list_ty *
@@ -776,9 +739,7 @@ its_translate_rule_eval (struct its_rule_ty *rule, struct its_pool_ty *pool,
                        translate="no" for attributes.
      - Inheritance for element nodes: Textual content of element,
        including content of child elements, but excluding attributes.  */
-  struct its_value_list_ty *result;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   switch (node->type)
     {
@@ -801,21 +762,17 @@ its_translate_rule_eval (struct its_rule_ty *rule, struct its_pool_ty *pool,
     case XML_ELEMENT_NODE:
       /* Inherit from the parent elements.  */
       {
-        const char *value;
-
         /* A local attribute overrides the global rule.  */
         if (xmlHasNsProp (node, BAD_CAST "translate", BAD_CAST ITS_NS))
           {
-            char *prop;
-
-            prop = _its_get_attribute (node, "translate", ITS_NS);
+            char *prop = _its_get_attribute (node, "translate", ITS_NS);
             its_value_list_append (result, "translate", prop);
             free (prop);
             return result;
           }
 
         /* Check value for the current node.  */
-        value = its_pool_get_value_for_node (pool, node, "translate");
+        const char *value = its_pool_get_value_for_node (pool, node, "translate");
         if (value != NULL)
           {
             its_value_list_set_value (result, "translate", value);
@@ -829,9 +786,8 @@ its_translate_rule_eval (struct its_rule_ty *rule, struct its_pool_ty *pool,
           its_value_list_append (result, "translate", "yes");
         else
           {
-            struct its_value_list_ty *values;
-
-            values = its_translate_rule_eval (rule, pool, node->parent);
+            struct its_value_list_ty *values =
+              its_translate_rule_eval (rule, pool, node->parent);
             its_value_list_merge (result, values);
             its_value_list_destroy (values);
             free (values);
@@ -862,9 +818,6 @@ static struct its_rule_class_ty its_translate_rule_class =
 static void
 its_localization_note_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
 {
-  char *prop;
-  xmlNode *n;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -877,10 +830,13 @@ its_localization_note_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
 
+  xmlNode *n;
   for (n = node->children; n; n = n->next)
     {
       if (n->type == XML_ELEMENT_NODE
@@ -889,10 +845,12 @@ its_localization_note_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
         break;
     }
 
-  prop = _its_get_attribute (node, "locNoteType", NULL);
-  if (prop)
-    its_value_list_append (&rule->values, "locNoteType", prop);
-  free (prop);
+  {
+    char *prop = _its_get_attribute (node, "locNoteType", NULL);
+    if (prop)
+      its_value_list_append (&rule->values, "locNoteType", prop);
+    free (prop);
+  }
 
   if (n)
     {
@@ -904,7 +862,7 @@ its_localization_note_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
     }
   else if (xmlHasProp (node, BAD_CAST "locNotePointer"))
     {
-      prop = _its_get_attribute (node, "locNotePointer", NULL);
+      char *prop = _its_get_attribute (node, "locNotePointer", NULL);
       its_value_list_append (&rule->values, "locNotePointer", prop);
       free (prop);
     }
@@ -923,29 +881,27 @@ its_localization_note_rule_eval (struct its_rule_ty *rule,
      - Default values: none
      - Inheritance for element nodes: Textual content of element,
        including content of child elements, but excluding attributes.  */
-  struct its_value_list_ty *result;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   switch (node->type)
     {
     case XML_ATTRIBUTE_NODE:
       /* Attribute nodes don't inherit from the parent elements.  */
       {
-        const char *value;
-
-        value = its_pool_get_value_for_node (pool, node, "locNoteType");
+        const char *value = its_pool_get_value_for_node (pool, node, "locNoteType");
         if (value != NULL)
           its_value_list_set_value (result, "locNoteType", value);
-
-        value = its_pool_get_value_for_node (pool, node, "locNote");
+      }
+      {
+        const char *value = its_pool_get_value_for_node (pool, node, "locNote");
         if (value != NULL)
           {
             its_value_list_set_value (result, "locNote", value);
             return result;
           }
-
-        value = its_pool_get_value_for_node (pool, node, "locNotePointer");
+      }
+      {
+        const char *value = its_pool_get_value_for_node (pool, node, "locNotePointer");
         if (value != NULL)
           {
             its_value_list_set_value (result, "locNotePointer", value);
@@ -957,18 +913,14 @@ its_localization_note_rule_eval (struct its_rule_ty *rule,
     case XML_ELEMENT_NODE:
       /* Inherit from the parent elements.  */
       {
-        const char *value;
-
         /* Local attributes overrides the global rule.  */
         if (xmlHasNsProp (node, BAD_CAST "locNote", BAD_CAST ITS_NS)
             || xmlHasNsProp (node, BAD_CAST "locNoteRef", BAD_CAST ITS_NS)
             || xmlHasNsProp (node, BAD_CAST "locNoteType", BAD_CAST ITS_NS))
           {
-            char *prop;
-
             if (xmlHasNsProp (node, BAD_CAST "locNote", BAD_CAST ITS_NS))
               {
-                prop = _its_get_attribute (node, "locNote", ITS_NS);
+                char *prop = _its_get_attribute (node, "locNote", ITS_NS);
                 its_value_list_append (result, "locNote", prop);
                 free (prop);
               }
@@ -977,7 +929,7 @@ its_localization_note_rule_eval (struct its_rule_ty *rule,
 
             if (xmlHasNsProp (node, BAD_CAST "locNoteType", BAD_CAST ITS_NS))
               {
-                prop = _its_get_attribute (node, "locNoteType", ITS_NS);
+                char *prop = _its_get_attribute (node, "locNoteType", ITS_NS);
                 its_value_list_append (result, "locNoteType", prop);
                 free (prop);
               }
@@ -986,23 +938,27 @@ its_localization_note_rule_eval (struct its_rule_ty *rule,
           }
 
         /* Check value for the current node.  */
-        value = its_pool_get_value_for_node (pool, node, "locNoteType");
-        if (value != NULL)
-          its_value_list_set_value (result, "locNoteType", value);
-
-        value = its_pool_get_value_for_node (pool, node, "locNote");
-        if (value != NULL)
-          {
-            its_value_list_set_value (result, "locNote", value);
-            return result;
-          }
-
-        value = its_pool_get_value_for_node (pool, node, "locNotePointer");
-        if (value != NULL)
-          {
-            its_value_list_set_value (result, "locNotePointer", value);
-            return result;
-          }
+        {
+          const char *value = its_pool_get_value_for_node (pool, node, "locNoteType");
+          if (value != NULL)
+            its_value_list_set_value (result, "locNoteType", value);
+        }
+        {
+          const char *value = its_pool_get_value_for_node (pool, node, "locNote");
+          if (value != NULL)
+            {
+              its_value_list_set_value (result, "locNote", value);
+              return result;
+            }
+        }
+        {
+          const char *value = its_pool_get_value_for_node (pool, node, "locNotePointer");
+          if (value != NULL)
+            {
+              its_value_list_set_value (result, "locNotePointer", value);
+              return result;
+            }
+        }
 
         /* Recursively check value for the parent node.  */
         if (node->parent == NULL
@@ -1010,9 +966,8 @@ its_localization_note_rule_eval (struct its_rule_ty *rule,
           return result;
         else
           {
-            struct its_value_list_ty *values;
-
-            values = its_localization_note_rule_eval (rule, pool, node->parent);
+            struct its_value_list_ty *values =
+              its_localization_note_rule_eval (rule, pool, node->parent);
             its_value_list_merge (result, values);
             its_value_list_destroy (values);
             free (values);
@@ -1045,8 +1000,6 @@ static void
 its_element_within_text_rule_constructor (struct its_rule_ty *rule,
                                           xmlNode *node)
 {
-  char *prop;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -1059,13 +1012,16 @@ its_element_within_text_rule_constructor (struct its_rule_ty *rule,
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
-
-  prop = _its_get_attribute (node, "withinText", NULL);
-  its_value_list_append (&rule->values, "withinText", prop);
-  free (prop);
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
+  {
+    char *prop = _its_get_attribute (node, "withinText", NULL);
+    its_value_list_append (&rule->values, "withinText", prop);
+    free (prop);
+  }
 }
 
 static struct its_value_list_ty *
@@ -1079,10 +1035,7 @@ its_element_within_text_rule_eval (struct its_rule_ty *rule,
      - Global, rule-based selection: Yes
      - Default values: withinText="no"
      - Inheritance for element nodes: none  */
-  struct its_value_list_ty *result;
-  const char *value;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   if (node->type != XML_ELEMENT_NODE)
     return result;
@@ -1090,9 +1043,7 @@ its_element_within_text_rule_eval (struct its_rule_ty *rule,
   /* A local attribute overrides the global rule.  */
   if (xmlHasNsProp (node, BAD_CAST "withinText", BAD_CAST ITS_NS))
     {
-      char *prop;
-
-      prop = _its_get_attribute (node, "withinText", ITS_NS);
+      char *prop = _its_get_attribute (node, "withinText", ITS_NS);
       its_value_list_append (result, "withinText", prop);
       free (prop);
       return result;
@@ -1100,9 +1051,11 @@ its_element_within_text_rule_eval (struct its_rule_ty *rule,
 
   /* Doesn't inherit from the parent elements, and the default value
      is "no".  */
-  value = its_pool_get_value_for_node (pool, node, "withinText");
-  if (value != NULL)
-    its_value_list_set_value (result, "withinText", value);
+  {
+    const char *value = its_pool_get_value_for_node (pool, node, "withinText");
+    if (value != NULL)
+      its_value_list_set_value (result, "withinText", value);
+  }
 
   return result;
 }
@@ -1124,8 +1077,6 @@ static void
 its_preserve_space_rule_constructor (struct its_rule_ty *rule,
                                      xmlNode *node)
 {
-  char *prop;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -1138,30 +1089,33 @@ its_preserve_space_rule_constructor (struct its_rule_ty *rule,
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
-
-  prop = _its_get_attribute (node, "space", NULL);
-  if (prop
-      && !(strcmp (prop, "preserve") ==0 
-           || strcmp (prop, "default") == 0
-           /* gettext extension: remove leading/trailing whitespaces only.  */
-           || (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
-               && strcmp (prop, "trim") == 0)
-           /* gettext extension: same as default except keeping
-              paragraph boundaries.  */
-           || (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
-               && strcmp (prop, "paragraph") == 0)))
-    {
-      error (0, 0, _("invalid attribute value \"%s\" for \"%s\""),
-             prop, "space");
-      free (prop);
-      return;
-    }
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
+  {
+    char *prop = _its_get_attribute (node, "space", NULL);
+    if (prop
+        && !(strcmp (prop, "preserve") ==0
+             || strcmp (prop, "default") == 0
+             /* gettext extension: remove leading/trailing whitespaces only.  */
+             || (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
+                 && strcmp (prop, "trim") == 0)
+             /* gettext extension: same as default except keeping
+                paragraph boundaries.  */
+             || (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
+                 && strcmp (prop, "paragraph") == 0)))
+      {
+        error (0, 0, _("invalid attribute value \"%s\" for \"%s\""),
+               prop, "space");
+        free (prop);
+        return;
+      }
 
-  its_value_list_append (&rule->values, "space", prop);
-  free (prop);
+    its_value_list_append (&rule->values, "space", prop);
+    free (prop);
+  }
 }
 
 static struct its_value_list_ty *
@@ -1176,11 +1130,7 @@ its_preserve_space_rule_eval (struct its_rule_ty *rule,
      - Default values: space="default"
      - Inheritance for element nodes: Textual content of element,
        including attributes and child elements.  */
-  struct its_value_list_ty *result;
-  struct its_value_list_ty *values;
-  const char *value;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   if (node->type != XML_ELEMENT_NODE)
     return result;
@@ -1197,12 +1147,14 @@ its_preserve_space_rule_eval (struct its_rule_ty *rule,
     }
 
   /* Check value for the current node.  */
-  value = its_pool_get_value_for_node (pool, node, "space");
-  if (value != NULL)
-    {
-      its_value_list_set_value (result, "space", value);
-      return result;
-    }
+  {
+    const char *value = its_pool_get_value_for_node (pool, node, "space");
+    if (value != NULL)
+      {
+        its_value_list_set_value (result, "space", value);
+        return result;
+      }
+  }
 
   if (node->parent == NULL
       || node->parent->type != XML_ELEMENT_NODE)
@@ -1213,7 +1165,8 @@ its_preserve_space_rule_eval (struct its_rule_ty *rule,
     }
 
   /* Recursively check value for the parent node.  */
-  values = its_preserve_space_rule_eval (rule, pool, node->parent);
+  struct its_value_list_ty *values =
+    its_preserve_space_rule_eval (rule, pool, node->parent);
   its_value_list_merge (result, values);
   its_value_list_destroy (values);
   free (values);
@@ -1237,8 +1190,6 @@ static struct its_rule_class_ty its_preserve_space_rule_class =
 static void
 its_extension_context_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
 {
-  char *prop;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -1251,17 +1202,20 @@ its_extension_context_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
-
-  prop = _its_get_attribute (node, "contextPointer", NULL);
-  its_value_list_append (&rule->values, "contextPointer", prop);
-  free (prop);
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
+  {
+    char *prop = _its_get_attribute (node, "contextPointer", NULL);
+    its_value_list_append (&rule->values, "contextPointer", prop);
+    free (prop);
+  }
 
   if (xmlHasProp (node, BAD_CAST "textPointer"))
     {
-      prop = _its_get_attribute (node, "textPointer", NULL);
+      char *prop = _its_get_attribute (node, "textPointer", NULL);
       its_value_list_append (&rule->values, "textPointer", prop);
       free (prop);
     }
@@ -1277,20 +1231,20 @@ its_extension_context_rule_eval (struct its_rule_ty *rule,
      - Global, rule-based selection: Yes
      - Default values: none
      - Inheritance for element nodes: none  */
-  struct its_value_list_ty *result;
-  const char *value;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   /* Doesn't inherit from the parent elements, and the default value
      is None.  */
-  value = its_pool_get_value_for_node (pool, node, "contextPointer");
-  if (value != NULL)
-    its_value_list_set_value (result, "contextPointer", value);
-
-  value = its_pool_get_value_for_node (pool, node, "textPointer");
-  if (value != NULL)
-    its_value_list_set_value (result, "textPointer", value);
+  {
+    const char *value = its_pool_get_value_for_node (pool, node, "contextPointer");
+    if (value != NULL)
+      its_value_list_set_value (result, "contextPointer", value);
+  }
+  {
+    const char *value = its_pool_get_value_for_node (pool, node, "textPointer");
+    if (value != NULL)
+      its_value_list_set_value (result, "textPointer", value);
+  }
 
   return result;
 }
@@ -1311,8 +1265,6 @@ static struct its_rule_class_ty its_extension_context_rule_class =
 static void
 its_extension_escape_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
 {
-  char *prop;
-
   if (!xmlHasProp (node, BAD_CAST "selector"))
     {
       _its_error_missing_attribute (node, "selector");
@@ -1325,17 +1277,20 @@ its_extension_escape_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
       return;
     }
 
-  prop = _its_get_attribute (node, "selector", NULL);
-  if (prop)
-    rule->selector = prop;
-
-  prop = _its_get_attribute (node, "escape", NULL);
-  its_value_list_append (&rule->values, "escape", prop);
-  free (prop);
+  {
+    char *prop = _its_get_attribute (node, "selector", NULL);
+    if (prop)
+      rule->selector = prop;
+  }
+  {
+    char *prop = _its_get_attribute (node, "escape", NULL);
+    its_value_list_append (&rule->values, "escape", prop);
+    free (prop);
+  }
 
   if (xmlHasProp (node, BAD_CAST "unescape-if"))
     {
-      prop = _its_get_attribute (node, "unescape-if", NULL);
+      char *prop = _its_get_attribute (node, "unescape-if", NULL);
       its_value_list_append (&rule->values, "unescape-if", prop);
       free (prop);
     }
@@ -1352,9 +1307,7 @@ its_extension_escape_rule_eval (struct its_rule_ty *rule,
      - Default values: escape="no" unescape-if="no" (handled in the caller)
      - Inheritance for element nodes: Textual content of element,
        including content of child elements, but excluding attributes.  */
-  struct its_value_list_ty *result;
-
-  result = XCALLOC (1, struct its_value_list_ty);
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
   switch (node->type)
     {
@@ -1374,8 +1327,6 @@ its_extension_escape_rule_eval (struct its_rule_ty *rule,
     case XML_ELEMENT_NODE:
       /* Inherit from the parent elements.  */
       {
-        const char *value;
-
         /* A local attribute overrides the global rule.  */
         if (xmlHasNsProp (node, BAD_CAST "escape", BAD_CAST GT_NS)
             || xmlHasNsProp (node, BAD_CAST "unescape-if", BAD_CAST GT_NS))
@@ -1415,24 +1366,27 @@ its_extension_escape_rule_eval (struct its_rule_ty *rule,
           }
 
         /* Check value for the current node.  */
-        value = its_pool_get_value_for_node (pool, node, "unescape-if");
-        if (value != NULL)
-          its_value_list_set_value (result, "unescape-if", value);
+        {
+          const char *value = its_pool_get_value_for_node (pool, node, "unescape-if");
+          if (value != NULL)
+            its_value_list_set_value (result, "unescape-if", value);
+        }
 
-        value = its_pool_get_value_for_node (pool, node, "escape");
-        if (value != NULL)
-          {
-            its_value_list_set_value (result, "escape", value);
-            return result;
-          }
+        {
+          const char *value = its_pool_get_value_for_node (pool, node, "escape");
+          if (value != NULL)
+            {
+              its_value_list_set_value (result, "escape", value);
+              return result;
+            }
+        }
 
         /* Recursively check value for the parent node.  */
         if (node->parent != NULL
             && node->parent->type == XML_ELEMENT_NODE)
           {
-            struct its_value_list_ty *values;
-
-            values = its_extension_escape_rule_eval (rule, pool, node->parent);
+            struct its_value_list_ty *values =
+              its_extension_escape_rule_eval (rule, pool, node->parent);
             its_value_list_merge (result, values);
             its_value_list_destroy (values);
             free (values);
@@ -1464,9 +1418,7 @@ static hash_table classes;
 static struct its_rule_ty *
 its_rule_alloc (struct its_rule_class_ty *method_table, xmlNode *node)
 {
-  struct its_rule_ty *rule;
-
-  rule = (struct its_rule_ty *) xcalloc (1, method_table->size);
+  struct its_rule_ty *rule = (struct its_rule_ty *) xcalloc (1, method_table->size);
   rule->methods = method_table;
   if (method_table->constructor)
     method_table->constructor (rule, node);
@@ -1477,25 +1429,27 @@ static struct its_rule_ty *
 its_rule_parse (xmlDoc *doc, xmlNode *node)
 {
   const char *name = (const char *) node->name;
-  void *value;
 
+  void *value;
   if (hash_find_entry (&classes, name, strlen (name), &value) == 0)
     {
-      struct its_rule_ty *result;
-      xmlNs **namespaces;
+      struct its_rule_ty *result =
+        its_rule_alloc ((struct its_rule_class_ty *) value, node);
 
-      result = its_rule_alloc ((struct its_rule_class_ty *) value, node);
-      namespaces = xmlGetNsList (doc, node);
+      xmlNs **namespaces = xmlGetNsList (doc, node);
       if (namespaces)
         {
-          size_t i;
-          for (i = 0; namespaces[i] != NULL; i++)
-            ;
-          result->namespaces = XCALLOC (i + 1, xmlNs *);
-          for (i = 0; namespaces[i] != NULL; i++)
+          {
+            size_t i;
+            for (i = 0; namespaces[i] != NULL; i++)
+              ;
+            result->namespaces = XCALLOC (i + 1, xmlNs *);
+          }
+          for (size_t i = 0; namespaces[i] != NULL; i++)
             result->namespaces[i] = xmlCopyNamespace (namespaces[i]);
         }
       xmlFree (namespaces);
+
       return result;
     }
 
@@ -1540,24 +1494,20 @@ struct its_rule_list_ty
 struct its_rule_list_ty *
 its_rule_list_alloc (void)
 {
-  struct its_rule_list_ty *result;
-
   if (classes.table == NULL)
     {
       hash_init (&classes, 10);
       init_classes ();
     }
 
-  result = XCALLOC (1, struct its_rule_list_ty);
+  struct its_rule_list_ty *result = XCALLOC (1, struct its_rule_list_ty);
   return result;
 }
 
 void
 its_rule_list_free (struct its_rule_list_ty *rules)
 {
-  size_t i;
-
-  for (i = 0; i < rules->nitems; i++)
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       its_rule_destroy (rules->items[i]);
       free (rules->items[i]);
@@ -1570,9 +1520,7 @@ static bool
 its_rule_list_add_from_doc (struct its_rule_list_ty *rules,
                             xmlDoc *doc)
 {
-  xmlNode *root, *node;
-
-  root = xmlDocGetRootElement (doc);
+  xmlNode *root = xmlDocGetRootElement (doc);
   if (!(xmlStrEqual (root->name, BAD_CAST "rules")
         && xmlStrEqual (root->ns->href, BAD_CAST ITS_NS)))
     {
@@ -1583,11 +1531,9 @@ its_rule_list_add_from_doc (struct its_rule_list_ty *rules,
       return false;
     }
 
-  for (node = root->children; node; node = node->next)
+  for (xmlNode *node = root->children; node; node = node->next)
     {
-      struct its_rule_ty *rule;
-
-      rule = its_rule_parse (doc, node);
+      struct its_rule_ty *rule = its_rule_parse (doc, node);
       if (rule != NULL)
         {
           if (rules->nitems == rules->nitems_max)
@@ -1608,14 +1554,11 @@ bool
 its_rule_list_add_from_file (struct its_rule_list_ty *rules,
                              const char *filename)
 {
-  xmlDoc *doc;
-  bool result;
-
-  doc = xmlReadFile (filename, "utf-8",
-                     XML_PARSE_NONET
-                     | XML_PARSE_NOWARNING
-                     | XML_PARSE_NOBLANKS
-                     | XML_PARSE_NOERROR);
+  xmlDoc *doc = xmlReadFile (filename, "utf-8",
+                             XML_PARSE_NONET
+                             | XML_PARSE_NOWARNING
+                             | XML_PARSE_NOBLANKS
+                             | XML_PARSE_NOERROR);
   if (doc == NULL)
     {
       const xmlError *err = xmlGetLastError ();
@@ -1624,6 +1567,7 @@ its_rule_list_add_from_file (struct its_rule_list_ty *rules,
       return false;
     }
 
+  bool result;
   if (setjmp (xml_error_exit) == 0)
     {
       xmlSetStructuredErrorFunc (NULL, structured_error);
@@ -1646,16 +1590,13 @@ bool
 its_rule_list_add_from_string (struct its_rule_list_ty *rules,
                                const char *rule)
 {
-  xmlDoc *doc;
-  bool result;
-
-  doc = xmlReadMemory (rule, strlen (rule),
-                       "(internal)",
-                       NULL,
-                       XML_PARSE_NONET
-                       | XML_PARSE_NOWARNING
-                       | XML_PARSE_NOBLANKS
-                       | XML_PARSE_NOERROR);
+  xmlDoc *doc = xmlReadMemory (rule, strlen (rule),
+                               "(internal)",
+                               NULL,
+                               XML_PARSE_NONET
+                               | XML_PARSE_NOWARNING
+                               | XML_PARSE_NOBLANKS
+                               | XML_PARSE_NOERROR);
   if (doc == NULL)
     {
       const xmlError *err = xmlGetLastError ();
@@ -1664,6 +1605,7 @@ its_rule_list_add_from_string (struct its_rule_list_ty *rules,
       return false;
     }
 
+  bool result;
   if (setjmp (xml_error_exit) == 0)
     {
       xmlSetStructuredErrorFunc (NULL, structured_error);
@@ -1685,9 +1627,7 @@ its_rule_list_add_from_string (struct its_rule_list_ty *rules,
 static void
 its_rule_list_apply (struct its_rule_list_ty *rules, xmlDoc *doc)
 {
-  size_t i;
-
-  for (i = 0; i < rules->nitems; i++)
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       struct its_rule_ty *rule = rules->items[i];
       rule->methods->apply (rule, &rules->pool, doc);
@@ -1697,16 +1637,12 @@ its_rule_list_apply (struct its_rule_list_ty *rules, xmlDoc *doc)
 static struct its_value_list_ty *
 its_rule_list_eval (its_rule_list_ty *rules, xmlNode *node)
 {
-  struct its_value_list_ty *result;
-  size_t i;
+  struct its_value_list_ty *result = XCALLOC (1, struct its_value_list_ty);
 
-  result = XCALLOC (1, struct its_value_list_ty);
-  for (i = 0; i < rules->nitems; i++)
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       struct its_rule_ty *rule = rules->items[i];
-      struct its_value_list_ty *values;
-
-      values = rule->methods->eval (rule, &rules->pool, node);
+      struct its_value_list_ty *values = rule->methods->eval (rule, &rules->pool, node);
       its_value_list_merge (result, values);
       its_value_list_destroy (values);
       free (values);
@@ -1720,29 +1656,27 @@ its_rule_list_is_translatable (its_rule_list_ty *rules,
                                xmlNode *node,
                                int depth)
 {
-  struct its_value_list_ty *values;
-  const char *value;
-  xmlNode *n;
-
   if (node->type != XML_ELEMENT_NODE
       && node->type != XML_ATTRIBUTE_NODE)
     return false;
 
-  values = its_rule_list_eval (rules, node);
+  struct its_value_list_ty *values = its_rule_list_eval (rules, node);
 
   /* Check if NODE has translate="yes".  */
-  value = its_value_list_get_value (values, "translate");
-  if (!(value && strcmp (value, "yes") == 0))
-    {
-      its_value_list_destroy (values);
-      free (values);
-      return false;
-    }
+  {
+    const char *value = its_value_list_get_value (values, "translate");
+    if (!(value && strcmp (value, "yes") == 0))
+      {
+        its_value_list_destroy (values);
+        free (values);
+        return false;
+      }
+  }
 
   /* Check if NODE has withinText="yes", if NODE is not top-level.  */
   if (depth > 0)
     {
-      value = its_value_list_get_value (values, "withinText");
+      const char *value = its_value_list_get_value (values, "withinText");
       if (!(value && strcmp (value, "yes") == 0))
         {
           its_value_list_destroy (values);
@@ -1754,7 +1688,7 @@ its_rule_list_is_translatable (its_rule_list_ty *rules,
   its_value_list_destroy (values);
   free (values);
 
-  for (n = node->children; n; n = n->next)
+  for (xmlNode *n = node->children; n; n = n->next)
     {
       switch (n->type)
         {
@@ -1786,8 +1720,7 @@ its_rule_list_extract_nodes (its_rule_list_ty *rules,
     {
       if (node->properties)
         {
-          xmlAttr *attr;
-          for (attr = node->properties; attr; attr = attr->next)
+          for (xmlAttr *attr = node->properties; attr; attr = attr->next)
             {
               xmlNode *n = (xmlNode *) attr;
               if (its_rule_list_is_translatable (rules, n, 0))
@@ -1799,8 +1732,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)
+          for (xmlNode *n = node->children; n; n = n->next)
             its_rule_list_extract_nodes (rules, nodes, n);
         }
     }
@@ -1812,37 +1744,28 @@ _its_get_content (struct its_rule_list_ty *rules, xmlNode *node,
                   enum its_whitespace_type_ty whitespace,
                   bool do_escape)
 {
-  xmlXPathContext *context;
-  xmlXPathObject *object;
-  char *result = NULL;
-
-  context = xmlXPathNewContext (node->doc);
+  xmlXPathContext *context = xmlXPathNewContext (node->doc);
   if (!context)
     {
       error (0, 0, _("cannot create XPath context"));
       return NULL;
     }
 
-  {
-    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);
-              }
-          }
-      }
-  }
+  for (size_t i = 0; i < rules->nitems; i++)
+    {
+      struct its_rule_ty *rule = rules->items[i];
+      if (rule->namespaces)
+        {
+          for (size_t 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);
+  xmlXPathObject *object = xmlXPathEvalExpression (BAD_CAST pointer, context);
   if (!object)
     {
       xmlXPathFreeContext (context);
@@ -1851,16 +1774,15 @@ _its_get_content (struct its_rule_list_ty *rules, xmlNode *node,
       return NULL;
     }
 
+  char *result = NULL;
   switch (object->type)
     {
     case XPATH_NODESET:
       {
         xmlNodeSet *nodes = object->nodesetval;
         string_list_ty sl;
-        size_t i;
-
         string_list_init (&sl);
-        for (i = 0; i < nodes->nodeNr; i++)
+        for (size_t i = 0; i < nodes->nodeNr; i++)
           {
             char *content = _its_collect_text_content (nodes->nodeTab[i],
                                                        whitespace,
@@ -1928,19 +1850,15 @@ its_rule_list_extract_text (its_rule_list_ty *rules,
   if (node->type == XML_ELEMENT_NODE
       || node->type == XML_ATTRIBUTE_NODE)
     {
-      struct its_value_list_ty *values;
-      const char *value;
-      char *msgid = NULL, *msgctxt = NULL, *comment = NULL;
-      bool do_escape;
-      bool do_escape_during_extract;
-      enum its_whitespace_type_ty whitespace;
-      
-      values = its_rule_list_eval (rules, node);
+      struct its_value_list_ty *values = its_rule_list_eval (rules, node);
 
-      value = its_value_list_get_value (values, "escape");
-      do_escape = value != NULL && strcmp (value, "yes") == 0;
+      bool do_escape;
+      {
+        const char *value = its_value_list_get_value (values, "escape");
+        do_escape = value != NULL && strcmp (value, "yes") == 0;
+      }
 
-      do_escape_during_extract = do_escape;
+      bool do_escape_during_extract = do_escape;
       /* But no, during message extraction (i.e. what xgettext does), we do
          *not* want escaping to be done.  The contents of the POT file is meant
          for translators, and
@@ -1951,35 +1869,36 @@ its_rule_list_extract_text (its_rule_list_ty *rules,
          does) instead.  */
       do_escape_during_extract = false;
 
-      value = its_value_list_get_value (values, "locNote");
-      if (value)
-        comment = xstrdup (value);
-      else
-        {
-          value = its_value_list_get_value (values, "locNotePointer");
-          if (value)
-            comment = _its_get_content (rules, node, value, ITS_WHITESPACE_TRIM,
-                                        do_escape_during_extract);
-        }
+      char *comment = NULL;
+      {
+        const char *value = its_value_list_get_value (values, "locNote");
+        if (value)
+          comment = xstrdup (value);
+        else
+          {
+            value = its_value_list_get_value (values, "locNotePointer");
+            if (value)
+              comment = _its_get_content (rules, node, value, ITS_WHITESPACE_TRIM,
+                                          do_escape_during_extract);
+          }
+      }
 
       if (comment != NULL && *comment != '\0')
         {
           string_list_ty comments;
-          char *tmp;
-
           string_list_init (&comments);
           _its_comment_append (&comments, comment);
-          tmp = string_list_join (&comments, "\n", '\0', false);
+          char *tmp = string_list_join (&comments, "\n", '\0', false);
           free (comment);
           comment = tmp;
         }
       else
         /* Extract comments preceding the node.  */
         {
-          xmlNode *sibling;
           string_list_ty comments;
-
           string_list_init (&comments);
+
+          xmlNode *sibling;
           for (sibling = node->prev; sibling; sibling = sibling->prev)
             if (sibling->type != XML_COMMENT_NODE || sibling->prev == NULL)
               break;
@@ -1999,26 +1918,36 @@ its_rule_list_extract_text (its_rule_list_ty *rules,
               string_list_destroy (&comments);
             }
         }
-      
-      value = its_value_list_get_value (values, "space");
-      if (value && strcmp (value, "preserve") == 0)
-        whitespace = ITS_WHITESPACE_PRESERVE;
-      else if (value && strcmp (value, "trim") == 0)
-        whitespace = ITS_WHITESPACE_TRIM;
-      else if (value && strcmp (value, "paragraph") == 0)
-        whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
-      else
-        whitespace = ITS_WHITESPACE_NORMALIZE;
 
-      value = its_value_list_get_value (values, "contextPointer");
-      if (value)
-        msgctxt = _its_get_content (rules, node, value, ITS_WHITESPACE_PRESERVE,
+      enum its_whitespace_type_ty whitespace;
+      {
+        const char *value = its_value_list_get_value (values, "space");
+        if (value && strcmp (value, "preserve") == 0)
+          whitespace = ITS_WHITESPACE_PRESERVE;
+        else if (value && strcmp (value, "trim") == 0)
+          whitespace = ITS_WHITESPACE_TRIM;
+        else if (value && strcmp (value, "paragraph") == 0)
+          whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
+        else
+          whitespace = ITS_WHITESPACE_NORMALIZE;
+      }
+
+      char *msgctxt = NULL;
+      {
+        const char *value = its_value_list_get_value (values, "contextPointer");
+        if (value)
+          msgctxt = _its_get_content (rules, node, value, ITS_WHITESPACE_PRESERVE,
+                                      do_escape_during_extract);
+      }
+
+      char *msgid = NULL;
+      {
+        const char *value = its_value_list_get_value (values, "textPointer");
+        if (value)
+          msgid = _its_get_content (rules, node, value, ITS_WHITESPACE_PRESERVE,
                                     do_escape_during_extract);
+      }
 
-      value = its_value_list_get_value (values, "textPointer");
-      if (value)
-        msgid = _its_get_content (rules, node, value, ITS_WHITESPACE_PRESERVE,
-                                  do_escape_during_extract);
       its_value_list_destroy (values);
       free (values);
 
@@ -2028,11 +1957,10 @@ its_rule_list_extract_text (its_rule_list_ty *rules,
       if (*msgid != '\0')
         {
           lex_pos_ty pos;
-          char *marker;
-
           pos.file_name = xstrdup (logical_filename);
           pos.line_number = xmlGetLineNo (node);
 
+          char *marker;
           if (node->type == XML_ELEMENT_NODE)
             {
               assert (node->parent);
@@ -2069,13 +1997,11 @@ its_rule_list_extract (its_rule_list_ty *rules,
                        msgdomain_list_ty *mdlp,
                        its_extract_callback_ty callback)
 {
-  xmlDoc *doc;
-
-  doc = xmlReadFd (fileno (fp), logical_filename, NULL,
-                   XML_PARSE_NONET
-                   | XML_PARSE_NOWARNING
-                   | XML_PARSE_NOBLANKS
-                   | XML_PARSE_NOERROR);
+  xmlDoc *doc = xmlReadFd (fileno (fp), logical_filename, NULL,
+                           XML_PARSE_NONET
+                           | XML_PARSE_NOWARNING
+                           | XML_PARSE_NOBLANKS
+                           | XML_PARSE_NOERROR);
   if (doc == NULL)
     {
       const xmlError *err = xmlGetLastError ();
@@ -2097,8 +2023,7 @@ its_rule_list_extract (its_rule_list_ty *rules,
                                    &nodes,
                                    xmlDocGetRootElement (doc));
 
-      size_t i;
-      for (i = 0; i < nodes.nitems; i++)
+      for (size_t i = 0; i < nodes.nitems; i++)
         its_rule_list_extract_text (rules, nodes.items[i],
                                     logical_filename,
                                     mdlp->item[0]->messages,
@@ -2144,8 +2069,7 @@ _its_copy_node_with_attributes (xmlNode *node)
 #else
   copy = xmlNewNode (node->ns, node->name);
 
-  xmlAttr *attributes;
-  for (attributes = node->properties;
+  for (xmlAttr *attributes = node->properties;
        attributes != NULL;
        attributes = attributes->next)
     {
@@ -2245,11 +2169,8 @@ starts_with_character_reference (const char *s, unsigned int *ucs_p)
 static char *
 _its_encode_special_chars_for_merge (const char *content)
 {
-  const char *str;
   size_t amount = 0;
-  char *result, *p;
-
-  for (str = content; *str != '\0'; str++)
+  for (const char *str = content; *str != '\0'; str++)
     {
       if (*str == '&' && starts_with_character_reference (str, NULL))
         amount += sizeof ("&amp;");
@@ -2261,21 +2182,23 @@ _its_encode_special_chars_for_merge (const char *content)
         amount += 1;
     }
 
-  result = XNMALLOC (amount + 1, char);
+  char *result = XNMALLOC (amount + 1, char);
   *result = '\0';
-  p = result;
-  for (str = content; *str != '\0'; str++)
-    {
-      if (*str == '&' && starts_with_character_reference (str, NULL))
-        p = stpcpy (p, "&amp;");
-      else if (*str == '<')
-        p = stpcpy (p, "&lt;");
-      else if (*str == '>')
-        p = stpcpy (p, "&gt;");
-      else
-        *p++ = *str;
-    }
-  *p = '\0';
+  {
+    char *p = result;
+    for (const char *str = content; *str != '\0'; str++)
+      {
+        if (*str == '&' && starts_with_character_reference (str, NULL))
+          p = stpcpy (p, "&amp;");
+        else if (*str == '<')
+          p = stpcpy (p, "&lt;");
+        else if (*str == '>')
+          p = stpcpy (p, "&gt;");
+        else
+          *p++ = *str;
+      }
+    *p = '\0';
+  }
   return result;
 }
 
@@ -2354,12 +2277,11 @@ _its_is_valid_simple_gen_xml (const char *contents,
               xmlAddChild (parent_node, text_node);
             }
 
-          bool slash_before_tag = false;
-          bool slash_after_tag = false;
-
           c = *++p;
           if (c == '\0')
             return false;
+
+          bool slash_before_tag = false;
           if (c == '/')
             {
               slash_before_tag = true;
@@ -2367,6 +2289,7 @@ _its_is_valid_simple_gen_xml (const char *contents,
               if (c == '\0')
                 return false;
             }
+
           /* Parse a name.
              <https://www.w3.org/TR/xml/#NT-Name>  */
           if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
@@ -2383,6 +2306,7 @@ _its_is_valid_simple_gen_xml (const char *contents,
                  || c == '_' || c == ':'
                  || (c >= '0' && c <= '9') || c == '-' || c == '.');
           const char *name_end = p;
+
           xmlNode *current_node = NULL;
           if (add_to_node != NULL && !slash_before_tag)
             {
@@ -2392,8 +2316,7 @@ _its_is_valid_simple_gen_xml (const char *contents,
               if (ignore_case)
                 {
                   /* Convert the name to lower case.  */
-                  char *np;
-                  for (np = name_c; *np != '\0'; np++)
+                  for (char *np = name_c; *np != '\0'; np++)
                     *np = c_tolower (*np);
                 }
               current_node =
@@ -2401,6 +2324,7 @@ _its_is_valid_simple_gen_xml (const char *contents,
                                       NULL);
               xmlAddChild (parent_node, current_node);
             }
+
           /* Skip over whitespace.
              <https://www.w3.org/TR/xml/#sec-common-syn>  */
           while (c == ' ' || c == '\t' || c == '\n' || c == '\r')
@@ -2409,6 +2333,8 @@ _its_is_valid_simple_gen_xml (const char *contents,
               if (c == '\0')
                 return false;
             }
+
+          bool slash_after_tag = false;
           if (!slash_before_tag)
             {
               /* Parse a sequence of attributes.
@@ -2519,6 +2445,7 @@ _its_is_valid_simple_gen_xml (const char *contents,
           if (c != '>')
             return false;
           /* Seen a complete <...> element start/end.  */
+
           /* Verify that the tag is allowed.  */
           string_desc_t tag = sd_new_addr (name_end - name_start, name_start);
           if (!(valid_element == NULL || valid_element (tag)))
@@ -2891,63 +2818,62 @@ its_merge_context_merge_node (struct its_merge_context_ty *context,
 {
   if (node->type == XML_ELEMENT_NODE)
     {
-      struct its_value_list_ty *values;
-      const char *value;
-      char *msgid = NULL, *msgctxt = NULL;
-      bool do_escape;
-      bool do_escape_during_extract;
-      bool do_escape_during_merge;
-      const char *do_unescape_if;
-      enum its_whitespace_type_ty whitespace;
-
-      values = its_rule_list_eval (context->rules, node);
+      struct its_value_list_ty *values = its_rule_list_eval (context->rules, node);
 
-      value = its_value_list_get_value (values, "escape");
-      do_escape = value != NULL && strcmp (value, "yes") == 0;
+      bool do_escape;
+      {
+        const char *value = its_value_list_get_value (values, "escape");
+        do_escape = value != NULL && strcmp (value, "yes") == 0;
+      }
 
-      do_escape_during_extract = do_escape;
+      bool do_escape_during_extract = do_escape;
       /* Like above, in its_rule_list_extract_text.  */
       do_escape_during_extract = false;
 
-      do_escape_during_merge = do_escape;
+      bool do_escape_during_merge = do_escape;
 
-      do_unescape_if = its_value_list_get_value (values, "unescape-if");
+      const char *do_unescape_if = its_value_list_get_value (values, "unescape-if");
 
-      value = its_value_list_get_value (values, "space");
-      if (value && strcmp (value, "preserve") == 0)
-        whitespace = ITS_WHITESPACE_PRESERVE;
-      else if (value && strcmp (value, "trim") == 0)
-        whitespace = ITS_WHITESPACE_TRIM;
-      else if (value && strcmp (value, "paragraph") == 0)
-        whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
-      else
-        whitespace = ITS_WHITESPACE_NORMALIZE;
+      enum its_whitespace_type_ty whitespace;
+      {
+        const char *value = its_value_list_get_value (values, "space");
+        if (value && strcmp (value, "preserve") == 0)
+          whitespace = ITS_WHITESPACE_PRESERVE;
+        else if (value && strcmp (value, "trim") == 0)
+          whitespace = ITS_WHITESPACE_TRIM;
+        else if (value && strcmp (value, "paragraph") == 0)
+          whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
+        else
+          whitespace = ITS_WHITESPACE_NORMALIZE;
+      }
 
-      value = its_value_list_get_value (values, "contextPointer");
-      if (value)
-        msgctxt = _its_get_content (context->rules, node, value,
+      char *msgctxt = NULL;
+      {
+        const char *value = its_value_list_get_value (values, "contextPointer");
+        if (value)
+          msgctxt = _its_get_content (context->rules, node, value,
+                                      ITS_WHITESPACE_PRESERVE,
+                                      do_escape_during_extract);
+      }
+
+      char *msgid = NULL;
+      {
+        const char *value = its_value_list_get_value (values, "textPointer");
+        if (value)
+          msgid = _its_get_content (context->rules, node, value,
                                     ITS_WHITESPACE_PRESERVE,
                                     do_escape_during_extract);
-
-      value = its_value_list_get_value (values, "textPointer");
-      if (value)
-        msgid = _its_get_content (context->rules, node, value,
-                                  ITS_WHITESPACE_PRESERVE,
-                                  do_escape_during_extract);
+      }
 
       if (msgid == NULL)
         msgid = _its_collect_text_content (node, whitespace,
                                            do_escape_during_extract);
       if (*msgid != '\0')
         {
-          message_ty *mp;
-
-          mp = message_list_search (mlp, msgctxt, msgid);
+          message_ty *mp = message_list_search (mlp, msgctxt, msgid);
           if (mp && *mp->msgstr != '\0')
             {
               xmlNode *translated;
-              char language_bcp47[BCP47_MAX];
-
               if (replace_text)
                 {
                   /* Reuse the node.  But first, clear its text content and all
@@ -2966,6 +2892,7 @@ its_merge_context_merge_node (struct its_merge_context_ty *context,
                  <https://www.w3.org/International/questions/qa-when-xmllang.en.html>
                  says: "The value of the xml:lang attribute is a language tag
                  defined by BCP 47."  */
+              char language_bcp47[BCP47_MAX];
               xpg_to_bcp47 (language_bcp47, language);
               xmlSetProp (translated, BAD_CAST "xml:lang", BAD_CAST language_bcp47);
 
@@ -3077,8 +3004,7 @@ its_merge_context_merge (its_merge_context_ty *context,
       xmlSetStructuredErrorFunc (NULL, structured_error);
       xmlSetGenericErrorFunc (NULL, generic_error);
 
-      size_t i;
-      for (i = 0; i < context->nodes.nitems; i++)
+      for (size_t i = 0; i < context->nodes.nitems; i++)
         its_merge_context_merge_node (context, context->nodes.items[i],
                                       language,
                                       mlp,
@@ -3096,14 +3022,11 @@ struct its_merge_context_ty *
 its_merge_context_alloc (its_rule_list_ty *rules,
                          const char *filename)
 {
-  xmlDoc *doc;
-  struct its_merge_context_ty *result;
-
-  doc = xmlReadFile (filename, NULL,
-                     XML_PARSE_NONET
-                     | XML_PARSE_NOWARNING
-                     | XML_PARSE_NOBLANKS
-                     | XML_PARSE_NOERROR);
+  xmlDoc *doc = xmlReadFile (filename, NULL,
+                             XML_PARSE_NONET
+                             | XML_PARSE_NOWARNING
+                             | XML_PARSE_NOBLANKS
+                             | XML_PARSE_NOERROR);
   if (doc == NULL)
     {
       const xmlError *err = xmlGetLastError ();
@@ -3112,6 +3035,7 @@ its_merge_context_alloc (its_rule_list_ty *rules,
       return NULL;
     }
 
+  struct its_merge_context_ty *result;
   if (setjmp (xml_error_exit) == 0)
     {
       xmlSetStructuredErrorFunc (NULL, structured_error);
index 689845395172c1de20d8ec45a471ab3cc5df5a6a..fc9c1debe2ace9bf3ae60112b72dd7601fb14a3e 100644 (file)
@@ -90,17 +90,14 @@ struct locating_rule_list_ty
 static char *
 get_attribute (xmlNode *node, const char *attr)
 {
-  xmlChar *value;
-  char *result;
-
-  value = xmlGetProp (node, BAD_CAST attr);
+  xmlChar *value = xmlGetProp (node, BAD_CAST attr);
   if (!value)
     {
       error (0, 0, _("cannot find attribute %s on %s"), attr, node->name);
       return NULL;
     }
 
-  result = xstrdup ((const char *) value);
+  char *result = xstrdup ((const char *) value);
   xmlFree (value);
 
   return result;
@@ -110,9 +107,7 @@ static const char *
 document_locating_rule_match (struct document_locating_rule_ty *rule,
                               xmlDoc *doc)
 {
-  xmlNode *root;
-
-  root = xmlDocGetRootElement (doc);
+  xmlNode *root = xmlDocGetRootElement (doc);
   if (!root)
     {
       error (0, 0, _("cannot locate root element"));
@@ -149,21 +144,17 @@ locating_rule_match (struct locating_rule_ty *rule,
     }
   else
     {
-      const char *base;
-      char *reduced;
-      int err;
-
-      base = strrchr (filename, '/');
+      const char *base = strrchr (filename, '/');
       if (!base)
         base = filename;
 
-      reduced = xstrdup (base);
+      char *reduced = xstrdup (base);
       /* Remove a trailing ".in" - it's a generic suffix.  */
       while (strlen (reduced) >= 3
              && memcmp (reduced + strlen (reduced) - 3, ".in", 3) == 0)
         reduced[strlen (reduced) - 3] = '\0';
 
-      err = fnmatch (rule->pattern, last_component (reduced), FNM_PATHNAME);
+      int err = fnmatch (rule->pattern, last_component (reduced), FNM_PATHNAME);
       free (reduced);
       if (err != 0)
         return NULL;
@@ -172,15 +163,11 @@ locating_rule_match (struct locating_rule_ty *rule,
   /* Check documentRules.  */
   if (rule->doc_rules.nitems > 0)
     {
-      const char *target;
-      xmlDoc *doc;
-      size_t i;
-
-      doc = xmlReadFile (filename, NULL,
-                         XML_PARSE_NONET
-                         | XML_PARSE_NOWARNING
-                         | XML_PARSE_NOBLANKS
-                         | XML_PARSE_NOERROR);
+      xmlDoc *doc = xmlReadFile (filename, NULL,
+                                 XML_PARSE_NONET
+                                 | XML_PARSE_NOWARNING
+                                 | XML_PARSE_NOBLANKS
+                                 | XML_PARSE_NOERROR);
       if (doc == NULL)
         {
           const xmlError *err = xmlGetLastError ();
@@ -188,7 +175,8 @@ locating_rule_match (struct locating_rule_ty *rule,
           return NULL;
         }
 
-      for (i = 0, target = NULL; i < rule->doc_rules.nitems; i++)
+      const char *target = NULL;
+      for (size_t i = 0; i < rule->doc_rules.nitems; i++)
         {
           target =
             document_locating_rule_match (&rule->doc_rules.items[i], doc);
@@ -211,26 +199,19 @@ locating_rule_list_locate (const struct locating_rule_list_ty *rules,
                            const char *filename,
                            const char *name)
 {
-  size_t i;
-
-  for (i = 0; i < rules->nitems; i++)
+  for (size_t i = 0; i < rules->nitems; i++)
     {
       if (IS_RELATIVE_FILE_NAME (filename))
         {
-          int j;
-
-          for (j = 0; ; ++j)
+          for (int j = 0; ; ++j)
             {
               const char *dir = dir_list_nth (j);
-              char *new_filename;
-              const char *target;
-
               if (dir == NULL)
                 break;
               
-              new_filename = xconcatenated_filename (dir, filename, NULL);
-              target = locating_rule_match (&rules->items[i], new_filename,
-                                            name);
+              char *new_filename = xconcatenated_filename (dir, filename, NULL);
+              const char *target =
+                locating_rule_match (&rules->items[i], new_filename, name);
               free (new_filename);
               if (target != NULL)
                 return target;
@@ -267,16 +248,14 @@ static void
 document_locating_rule_list_add (struct document_locating_rule_list_ty *rules,
                                  xmlNode *node)
 {
-  struct document_locating_rule_ty rule;
-
   if (!xmlHasProp (node, BAD_CAST "target"))
     {
       missing_attribute (node, "target");
       return;
     }
 
+  struct document_locating_rule_ty rule;
   memset (&rule, 0, sizeof (struct document_locating_rule_ty));
-
   if (xmlHasProp (node, BAD_CAST "ns"))
     rule.ns = get_attribute (node, "ns");
   if (xmlHasProp (node, BAD_CAST "localName"))
@@ -298,9 +277,7 @@ document_locating_rule_list_add (struct document_locating_rule_list_ty *rules,
 static void
 locating_rule_destroy (struct locating_rule_ty *rule)
 {
-  size_t i;
-
-  for (i = 0; i < rule->doc_rules.nitems; i++)
+  for (size_t i = 0; i < rule->doc_rules.nitems; i++)
     document_locating_rule_destroy (&rule->doc_rules.items[i]);
   free (rule->doc_rules.items);
 
@@ -313,21 +290,18 @@ static bool
 locating_rule_list_add_from_file (struct locating_rule_list_ty *rules,
                                   const char *rule_file_name)
 {
-  xmlDoc *doc;
-  xmlNode *root, *node;
-
-  doc = xmlReadFile (rule_file_name, "utf-8",
-                     XML_PARSE_NONET
-                     | XML_PARSE_NOWARNING
-                     | XML_PARSE_NOBLANKS
-                     | XML_PARSE_NOERROR);
+  xmlDoc *doc = xmlReadFile (rule_file_name, "utf-8",
+                             XML_PARSE_NONET
+                             | XML_PARSE_NOWARNING
+                             | XML_PARSE_NOBLANKS
+                             | XML_PARSE_NOERROR);
   if (doc == NULL)
     {
       error (0, 0, _("cannot read XML file %s"), rule_file_name);
       return false;
     }
 
-  root = xmlDocGetRootElement (doc);
+  xmlNode *root = xmlDocGetRootElement (doc);
   if (!root)
     {
       error (0, 0, _("cannot locate root element"));
@@ -347,12 +321,10 @@ locating_rule_list_add_from_file (struct locating_rule_list_ty *rules,
       return false;
     }
 
-  for (node = root->children; node; node = node->next)
+  for (xmlNode *node = root->children; node; node = node->next)
     {
       if (xmlStrEqual (node->name, BAD_CAST "locatingRule"))
         {
-          struct locating_rule_ty rule;
-
           if (!xmlHasProp (node, BAD_CAST "pattern"))
             {
               missing_attribute (node, "pattern");
@@ -360,6 +332,7 @@ locating_rule_list_add_from_file (struct locating_rule_list_ty *rules,
             }
           else
             {
+              struct locating_rule_ty rule;
               memset (&rule, 0, sizeof (struct locating_rule_ty));
               rule.pattern = get_attribute (node, "pattern");
               if (xmlHasProp (node, BAD_CAST "name"))
@@ -368,9 +341,7 @@ locating_rule_list_add_from_file (struct locating_rule_list_ty *rules,
                 rule.target = get_attribute (node, "target");
               else
                 {
-                  xmlNode *n;
-
-                  for (n = node->children; n; n = n->next)
+                  for (xmlNode *n = node->children; n; n = n->next)
                     {
                       if (xmlStrEqual (n->name, BAD_CAST "documentRule"))
                         document_locating_rule_list_add (&rule.doc_rules, n);
@@ -397,18 +368,14 @@ bool
 locating_rule_list_add_from_directory (struct locating_rule_list_ty *rules,
                                        const char *directory)
 {
-  DIR *dirp;
-
-  dirp = opendir (directory);
+  DIR *dirp = opendir (directory);
   if (dirp == NULL)
     return false;
 
   for (;;)
     {
-      struct dirent *dp;
-
       errno = 0;
-      dp = readdir (dirp);
+      struct dirent *dp = readdir (dirp);
       if (dp != NULL)
         {
           const char *name = dp->d_name;
@@ -436,11 +403,10 @@ locating_rule_list_add_from_directory (struct locating_rule_list_ty *rules,
 struct locating_rule_list_ty *
 locating_rule_list_alloc (void)
 {
-  struct locating_rule_list_ty *result;
-
   xmlCheckVersion (LIBXML_VERSION);
 
-  result = XCALLOC (1, struct locating_rule_list_ty);
+  struct locating_rule_list_ty *result =
+    XCALLOC (1, struct locating_rule_list_ty);
 
   return result;
 }
index 4e893664b4f05204712e0b66ed997179d0ff0377..48c4b6b9cf8e0349e0a7870728500cfd26654b09 100644 (file)
@@ -185,10 +185,7 @@ message_alloc (const char *msgctxt,
                const char *msgstr, size_t msgstr_len,
                const lex_pos_ty *pp)
 {
-  message_ty *mp;
-  size_t i;
-
-  mp = XMALLOC (message_ty);
+  message_ty *mp = XMALLOC (message_ty);
   mp->msgctxt = msgctxt;
   mp->msgid = msgid;
   mp->msgid_plural = (msgid_plural != NULL ? xstrdup (msgid_plural) : NULL);
@@ -200,18 +197,19 @@ message_alloc (const char *msgctxt,
   mp->filepos_count = 0;
   mp->filepos = NULL;
   mp->is_fuzzy = false;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     mp->is_format[i] = undecided;
   mp->range.min = -1;
   mp->range.max = -1;
   mp->do_wrap = undecided;
-  for (i = 0; i < NSYNTAXCHECKS; i++)
+  for (size_t i = 0; i < NSYNTAXCHECKS; i++)
     mp->do_syntax_check[i] = undecided;
   mp->prev_msgctxt = NULL;
   mp->prev_msgid = NULL;
   mp->prev_msgid_plural = NULL;
   mp->used = 0;
   mp->obsolete = false;
+
   return mp;
 }
 
@@ -219,8 +217,6 @@ message_alloc (const char *msgctxt,
 void
 message_free (message_ty *mp)
 {
-  size_t j;
-
   free ((char *) mp->msgid);
   if (mp->msgid_plural != NULL)
     free ((char *) mp->msgid_plural);
@@ -229,7 +225,7 @@ message_free (message_ty *mp)
     string_list_free (mp->comment);
   if (mp->comment_dot != NULL)
     string_list_free (mp->comment_dot);
-  for (j = 0; j < mp->filepos_count; ++j)
+  for (size_t j = 0; j < mp->filepos_count; ++j)
     free ((char *) mp->filepos[j].file_name);
   if (mp->filepos != NULL)
     free (mp->filepos);
@@ -265,25 +261,21 @@ void
 message_comment_filepos (message_ty *mp,
                          const char *file_name, size_t line_number)
 {
-  size_t j;
-  size_t nbytes;
-  lex_pos_ty *pp;
-
   /* See if we have this position already.  */
-  for (j = 0; j < mp->filepos_count; j++)
+  for (size_t j = 0; j < mp->filepos_count; j++)
     {
-      pp = &mp->filepos[j];
+      lex_pos_ty *pp = &mp->filepos[j];
       if (strcmp (pp->file_name, file_name) == 0
           && pp->line_number == line_number)
         return;
     }
 
   /* Extend the list so that we can add a position to it.  */
-  nbytes = (mp->filepos_count + 1) * sizeof (mp->filepos[0]);
+  size_t nbytes = (mp->filepos_count + 1) * sizeof (mp->filepos[0]);
   mp->filepos = xrealloc (mp->filepos, nbytes);
 
   /* Insert the position at the end.  Don't sort the file positions here.  */
-  pp = &mp->filepos[mp->filepos_count++];
+  lex_pos_ty *pp = &mp->filepos[mp->filepos_count++];
   pp->file_name = xstrdup (file_name);
   pp->line_number = line_number;
 }
@@ -292,31 +284,29 @@ message_comment_filepos (message_ty *mp,
 message_ty *
 message_copy (message_ty *mp)
 {
-  message_ty *result;
-  size_t j, i;
-
-  result = message_alloc (mp->msgctxt != NULL ? xstrdup (mp->msgctxt) : NULL,
-                          xstrdup (mp->msgid), mp->msgid_plural,
-                          mp->msgstr, mp->msgstr_len, &mp->pos);
+  message_ty *result =
+    message_alloc (mp->msgctxt != NULL ? xstrdup (mp->msgctxt) : NULL,
+                   xstrdup (mp->msgid), mp->msgid_plural,
+                   mp->msgstr, mp->msgstr_len, &mp->pos);
 
   if (mp->comment)
     {
-      for (j = 0; j < mp->comment->nitems; ++j)
+      for (size_t j = 0; j < mp->comment->nitems; ++j)
         message_comment_append (result, mp->comment->item[j]);
     }
   if (mp->comment_dot)
     {
-      for (j = 0; j < mp->comment_dot->nitems; ++j)
+      for (size_t j = 0; j < mp->comment_dot->nitems; ++j)
         message_comment_dot_append (result, mp->comment_dot->item[j]);
     }
   result->is_fuzzy = mp->is_fuzzy;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     result->is_format[i] = mp->is_format[i];
   result->range = mp->range;
   result->do_wrap = mp->do_wrap;
-  for (i = 0; i < NSYNTAXCHECKS; i++)
+  for (size_t i = 0; i < NSYNTAXCHECKS; i++)
     result->do_syntax_check[i] = mp->do_syntax_check[i];
-  for (j = 0; j < mp->filepos_count; ++j)
+  for (size_t j = 0; j < mp->filepos_count; ++j)
     {
       lex_pos_ty *pp = &mp->filepos[j];
       message_comment_filepos (result, pp->file_name, pp->line_number);
@@ -334,14 +324,13 @@ message_copy (message_ty *mp)
 message_list_ty *
 message_list_alloc (bool use_hashtable)
 {
-  message_list_ty *mlp;
-
-  mlp = XMALLOC (message_list_ty);
+  message_list_ty *mlp = XMALLOC (message_list_ty);
   mlp->nitems = 0;
   mlp->nitems_max = 0;
   mlp->item = NULL;
   if ((mlp->use_hashtable = use_hashtable))
     hash_init (&mlp->htable, 10);
+
   return mlp;
 }
 
@@ -349,10 +338,8 @@ message_list_alloc (bool use_hashtable)
 void
 message_list_free (message_list_ty *mlp, int keep_messages)
 {
-  size_t j;
-
   if (keep_messages == 0)
-    for (j = 0; j < mlp->nitems; ++j)
+    for (size_t j = 0; j < mlp->nitems; ++j)
       message_free (mlp->item[j]);
   if (mlp->item)
     free (mlp->item);
@@ -368,8 +355,6 @@ message_list_hash_insert_entry (hash_table *htable, message_ty *mp)
   char *alloced_key;
   const char *key;
   size_t keylen;
-  int found;
-
   if (mp->msgctxt != NULL)
     {
       /* Concatenate mp->msgctxt and mp->msgid, to form the hash table key.  */
@@ -389,7 +374,7 @@ message_list_hash_insert_entry (hash_table *htable, message_ty *mp)
       keylen = strlen (mp->msgid) + 1;
     }
 
-  found = (hash_insert_entry (htable, key, keylen, mp) == NULL);
+  int found = (hash_insert_entry (htable, key, keylen, mp) == NULL);
 
   if (mp->msgctxt != NULL)
     freea (alloced_key);
@@ -403,10 +388,8 @@ message_list_append (message_list_ty *mlp, message_ty *mp)
 {
   if (mlp->nitems >= mlp->nitems_max)
     {
-      size_t nbytes;
-
       mlp->nitems_max = mlp->nitems_max * 2 + 4;
-      nbytes = mlp->nitems_max * sizeof (message_ty *);
+      size_t nbytes = mlp->nitems_max * sizeof (message_ty *);
       mlp->item = xrealloc (mlp->item, nbytes);
     }
   mlp->item[mlp->nitems++] = mp;
@@ -422,17 +405,13 @@ message_list_append (message_list_ty *mlp, message_ty *mp)
 void
 message_list_prepend (message_list_ty *mlp, message_ty *mp)
 {
-  size_t j;
-
   if (mlp->nitems >= mlp->nitems_max)
     {
-      size_t nbytes;
-
       mlp->nitems_max = mlp->nitems_max * 2 + 4;
-      nbytes = mlp->nitems_max * sizeof (message_ty *);
+      size_t nbytes = mlp->nitems_max * sizeof (message_ty *);
       mlp->item = xrealloc (mlp->item, nbytes);
     }
-  for (j = mlp->nitems; j > 0; j--)
+  for (size_t j = mlp->nitems; j > 0; j--)
     mlp->item[j] = mlp->item[j - 1];
   mlp->item[0] = mp;
   mlp->nitems++;
@@ -448,19 +427,18 @@ message_list_prepend (message_list_ty *mlp, message_ty *mp)
 void
 message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp)
 {
-  size_t j;
-
   if (mlp->nitems >= mlp->nitems_max)
     {
-      size_t nbytes;
-
       mlp->nitems_max = mlp->nitems_max * 2 + 4;
-      nbytes = mlp->nitems_max * sizeof (message_ty *);
+      size_t nbytes = mlp->nitems_max * sizeof (message_ty *);
       mlp->item = xrealloc (mlp->item, nbytes);
     }
-  for (j = mlp->nitems; j > n; j--)
-    mlp->item[j] = mlp->item[j - 1];
-  mlp->item[j] = mp;
+  {
+    size_t j;
+    for (j = mlp->nitems; j > n; j--)
+      mlp->item[j] = mlp->item[j - 1];
+    mlp->item[j] = mp;
+  }
   mlp->nitems++;
 
   if (mlp->use_hashtable)
@@ -475,12 +453,10 @@ message_list_insert_at (message_list_ty *mlp, size_t n, message_ty *mp)
 void
 message_list_delete_nth (message_list_ty *mlp, size_t n)
 {
-  size_t j;
-
   if (n >= mlp->nitems)
     return;
   message_free (mlp->item[n]);
-  for (j = n + 1; j < mlp->nitems; ++j)
+  for (size_t j = n + 1; j < mlp->nitems; ++j)
     mlp->item[j - 1] = mlp->item[j];
   mlp->nitems--;
 
@@ -498,9 +474,8 @@ void
 message_list_remove_if_not (message_list_ty *mlp,
                             message_predicate_ty *predicate)
 {
-  size_t i, j;
-
-  for (j = 0, i = 0; j < mlp->nitems; j++)
+  size_t i = 0;
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (predicate (mlp->item[j]))
       mlp->item[i++] = mlp->item[j];
   if (mlp->use_hashtable && i < mlp->nitems)
@@ -519,12 +494,11 @@ message_list_msgids_changed (message_list_ty *mlp)
   if (mlp->use_hashtable)
     {
       unsigned long int size = mlp->htable.size;
-      size_t j;
 
       hash_destroy (&mlp->htable);
       hash_init (&mlp->htable, size);
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -546,11 +520,9 @@ message_list_msgids_changed (message_list_ty *mlp)
 message_list_ty *
 message_list_copy (message_list_ty *mlp, int copy_level)
 {
-  message_list_ty *result;
-  size_t j;
+  message_list_ty *result = message_list_alloc (mlp->use_hashtable);
 
-  result = message_list_alloc (mlp->use_hashtable);
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -570,7 +542,6 @@ message_list_search (const message_list_ty *mlp,
       char *alloced_key;
       const char *key;
       size_t keylen;
-
       if (msgctxt != NULL)
         {
           /* Concatenate the msgctxt and msgid, to form the hash table key.  */
@@ -590,28 +561,23 @@ message_list_search (const message_list_ty *mlp,
           keylen = strlen (msgid) + 1;
         }
 
-      {
-        void *htable_value;
-        int found = !hash_find_entry (&mlp->htable, key, keylen, &htable_value);
+      void *htable_value;
+      int found = !hash_find_entry (&mlp->htable, key, keylen, &htable_value);
 
-        if (msgctxt != NULL)
-          freea (alloced_key);
+      if (msgctxt != NULL)
+        freea (alloced_key);
 
-        if (found)
-          return (message_ty *) htable_value;
-        else
-          return NULL;
-      }
+      if (found)
+        return (message_ty *) htable_value;
+      else
+        return NULL;
     }
   else
     {
-      size_t j;
-
-      for (j = 0; j < mlp->nitems; ++j)
+      for (size_t j = 0; j < mlp->nitems; ++j)
         {
-          message_ty *mp;
+          message_ty *mp = mlp->item[j];
 
-          mp = mlp->item[j];
           if ((msgctxt != NULL
                ? mp->msgctxt != NULL && strcmp (msgctxt, mp->msgctxt) == 0
                : mp->msgctxt == NULL)
@@ -643,19 +609,17 @@ fuzzy_search_goal_function (const message_ty *mp,
       lower_bound -= bonus * 1.01;
     }
 
-  {
-    /* The use of 'volatile' guarantees that excess precision bits are dropped
-       before the addition and before the following comparison at the caller's
-       site.  It is necessary on x86 systems where double-floats are not IEEE
-       compliant by default, to avoid that msgmerge results become platform and
-       compiler option dependent.  'volatile' is a portable alternative to
-       gcc's -ffloat-store option.  */
-    volatile double weight = fstrcmp_bounded (msgid, mp->msgid, lower_bound);
+  /* The use of 'volatile' guarantees that excess precision bits are dropped
+     before the addition and before the following comparison at the caller's
+     site.  It is necessary on x86 systems where double-floats are not IEEE
+     compliant by default, to avoid that msgmerge results become platform and
+     compiler option dependent.  'volatile' is a portable alternative to
+     gcc's -ffloat-store option.  */
+  volatile double weight = fstrcmp_bounded (msgid, mp->msgid, lower_bound);
 
-    weight += bonus;
+  weight += bonus;
 
-    return weight;
-  }
+  return weight;
 }
 
 
@@ -664,15 +628,11 @@ message_list_search_fuzzy_inner (message_list_ty *mlp,
                                  const char *msgctxt, const char *msgid,
                                  double *best_weight_p)
 {
-  size_t j;
-  message_ty *best_mp;
+  message_ty *best_mp = NULL;
 
-  best_mp = NULL;
-  for (j = 0; j < mlp->nitems; ++j)
+  for (size_t j = 0; j < mlp->nitems; ++j)
     {
-      message_ty *mp;
-
-      mp = mlp->item[j];
+      message_ty *mp = mlp->item[j];
 
       if (mp->msgstr != NULL && mp->msgstr[0] != '\0')
         {
@@ -685,6 +645,7 @@ message_list_search_fuzzy_inner (message_list_ty *mlp,
             }
         }
     }
+
   return best_mp;
 }
 
@@ -693,9 +654,7 @@ message_ty *
 message_list_search_fuzzy (message_list_ty *mlp,
                            const char *msgctxt, const char *msgid)
 {
-  double best_weight;
-
-  best_weight = FUZZY_THRESHOLD;
+  double best_weight = FUZZY_THRESHOLD;
   return message_list_search_fuzzy_inner (mlp, msgctxt, msgid, &best_weight);
 }
 
@@ -703,12 +662,11 @@ message_list_search_fuzzy (message_list_ty *mlp,
 message_list_list_ty *
 message_list_list_alloc ()
 {
-  message_list_list_ty *mllp;
-
-  mllp = XMALLOC (message_list_list_ty);
+  message_list_list_ty *mllp = XMALLOC (message_list_list_ty);
   mllp->nitems = 0;
   mllp->nitems_max = 0;
   mllp->item = NULL;
+
   return mllp;
 }
 
@@ -716,10 +674,8 @@ message_list_list_alloc ()
 void
 message_list_list_free (message_list_list_ty *mllp, int keep_level)
 {
-  size_t j;
-
   if (keep_level < 2)
-    for (j = 0; j < mllp->nitems; ++j)
+    for (size_t j = 0; j < mllp->nitems; ++j)
       message_list_free (mllp->item[j], keep_level);
   if (mllp->item)
     free (mllp->item);
@@ -732,10 +688,8 @@ message_list_list_append (message_list_list_ty *mllp, message_list_ty *mlp)
 {
   if (mllp->nitems >= mllp->nitems_max)
     {
-      size_t nbytes;
-
       mllp->nitems_max = mllp->nitems_max * 2 + 4;
-      nbytes = mllp->nitems_max * sizeof (message_list_ty *);
+      size_t nbytes = mllp->nitems_max * sizeof (message_list_ty *);
       mllp->item = xrealloc (mllp->item, nbytes);
     }
   mllp->item[mllp->nitems++] = mlp;
@@ -746,9 +700,7 @@ void
 message_list_list_append_list (message_list_list_ty *mllp,
                                message_list_list_ty *mllp2)
 {
-  size_t j;
-
-  for (j = 0; j < mllp2->nitems; ++j)
+  for (size_t j = 0; j < mllp2->nitems; ++j)
     message_list_list_append (mllp, mllp2->item[j]);
 }
 
@@ -757,19 +709,12 @@ message_ty *
 message_list_list_search (message_list_list_ty *mllp,
                           const char *msgctxt, const char *msgid)
 {
-  message_ty *best_mp;
-  int best_weight; /* 0: not found, 1: found without msgstr, 2: translated */
-  size_t j;
-
-  best_mp = NULL;
-  best_weight = 0;
-  for (j = 0; j < mllp->nitems; ++j)
+  message_ty *best_mp = NULL;
+  int best_weight = 0; /* 0: not found, 1: found without msgstr, 2: translated */
+  for (size_t j = 0; j < mllp->nitems; ++j)
     {
-      message_list_ty *mlp;
-      message_ty *mp;
-
-      mlp = mllp->item[j];
-      mp = message_list_search (mlp, msgctxt, msgid);
+      message_list_ty *mlp = mllp->item[j];
+      message_ty *mp = message_list_search (mlp, msgctxt, msgid);
       if (mp)
         {
           int weight = (mp->msgstr_len == 1 && mp->msgstr[0] == '\0' ? 1 : 2);
@@ -789,19 +734,13 @@ message_ty *
 message_list_list_search_fuzzy (message_list_list_ty *mllp,
                                 const char *msgctxt, const char *msgid)
 {
-  size_t j;
-  double best_weight;
-  message_ty *best_mp;
-
-  best_weight = FUZZY_THRESHOLD;
-  best_mp = NULL;
-  for (j = 0; j < mllp->nitems; ++j)
+  double best_weight = FUZZY_THRESHOLD;
+  message_ty *best_mp = NULL;
+  for (size_t j = 0; j < mllp->nitems; ++j)
     {
-      message_list_ty *mlp;
-      message_ty *mp;
-
-      mlp = mllp->item[j];
-      mp = message_list_search_fuzzy_inner (mlp, msgctxt, msgid, &best_weight);
+      message_list_ty *mlp = mllp->item[j];
+      message_ty *mp =
+        message_list_search_fuzzy_inner (mlp, msgctxt, msgid, &best_weight);
       if (mp)
         best_mp = mp;
     }
@@ -813,11 +752,10 @@ message_list_list_search_fuzzy (message_list_list_ty *mllp,
 msgdomain_ty*
 msgdomain_alloc (const char *domain, bool use_hashtable)
 {
-  msgdomain_ty *mdp;
-
-  mdp = XMALLOC (msgdomain_ty);
+  msgdomain_ty *mdp = XMALLOC (msgdomain_ty);
   mdp->domain = domain;
   mdp->messages = message_list_alloc (use_hashtable);
+
   return mdp;
 }
 
@@ -833,9 +771,7 @@ msgdomain_free (msgdomain_ty *mdp)
 msgdomain_list_ty *
 msgdomain_list_alloc (bool use_hashtable)
 {
-  msgdomain_list_ty *mdlp;
-
-  mdlp = XMALLOC (msgdomain_list_ty);
+  msgdomain_list_ty *mdlp = XMALLOC (msgdomain_list_ty);
   /* Put the default domain first, so that when we output it,
      we can omit the 'domain' directive.  */
   mdlp->nitems = 1;
@@ -844,6 +780,7 @@ msgdomain_list_alloc (bool use_hashtable)
   mdlp->item[0] = msgdomain_alloc (MESSAGE_DOMAIN_DEFAULT, use_hashtable);
   mdlp->use_hashtable = use_hashtable;
   mdlp->encoding = NULL;
+
   return mdlp;
 }
 
@@ -851,9 +788,7 @@ msgdomain_list_alloc (bool use_hashtable)
 void
 msgdomain_list_free (msgdomain_list_ty *mdlp)
 {
-  size_t j;
-
-  for (j = 0; j < mdlp->nitems; ++j)
+  for (size_t j = 0; j < mdlp->nitems; ++j)
     msgdomain_free (mdlp->item[j]);
   if (mdlp->item)
     free (mdlp->item);
@@ -866,10 +801,8 @@ msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp)
 {
   if (mdlp->nitems >= mdlp->nitems_max)
     {
-      size_t nbytes;
-
       mdlp->nitems_max = mdlp->nitems_max * 2 + 4;
-      nbytes = mdlp->nitems_max * sizeof (msgdomain_ty *);
+      size_t nbytes = mdlp->nitems_max * sizeof (msgdomain_ty *);
       mdlp->item = xrealloc (mdlp->item, nbytes);
     }
   mdlp->item[mdlp->nitems++] = mdp;
@@ -880,9 +813,7 @@ msgdomain_list_append (msgdomain_list_ty *mdlp, msgdomain_ty *mdp)
 void
 msgdomain_list_append_list (msgdomain_list_ty *mdlp, msgdomain_list_ty *mdlp2)
 {
-  size_t j;
-
-  for (j = 0; j < mdlp2->nitems; ++j)
+  for (size_t j = 0; j < mdlp2->nitems; ++j)
     msgdomain_list_append (mdlp, mdlp2->item[j]);
 }
 #endif
@@ -892,9 +823,7 @@ message_list_ty *
 msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain,
                         bool create)
 {
-  size_t j;
-
-  for (j = 0; j < mdlp->nitems; j++)
+  for (size_t j = 0; j < mdlp->nitems; j++)
     if (strcmp (mdlp->item[j]->domain, domain) == 0)
       return mdlp->item[j]->messages;
 
@@ -915,24 +844,20 @@ msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain,
 msgdomain_list_ty *
 msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level)
 {
-  msgdomain_list_ty *result;
-  size_t j;
-
-  result = XMALLOC (msgdomain_list_ty);
+  msgdomain_list_ty *result = XMALLOC (msgdomain_list_ty);
   result->nitems = 0;
   result->nitems_max = 0;
   result->item = NULL;
   result->use_hashtable = mdlp->use_hashtable;
   result->encoding = mdlp->encoding;
 
-  for (j = 0; j < mdlp->nitems; j++)
+  for (size_t j = 0; j < mdlp->nitems; j++)
     {
       msgdomain_ty *mdp = mdlp->item[j];
 
       if (copy_level < 2)
         {
           msgdomain_ty *result_mdp = XMALLOC (msgdomain_ty);
-
           result_mdp->domain = mdp->domain;
           result_mdp->messages = message_list_copy (mdp->messages, copy_level);
 
@@ -951,15 +876,10 @@ message_ty *
 msgdomain_list_search (msgdomain_list_ty *mdlp,
                        const char *msgctxt, const char *msgid)
 {
-  size_t j;
-
-  for (j = 0; j < mdlp->nitems; ++j)
+  for (size_t j = 0; j < mdlp->nitems; ++j)
     {
-      msgdomain_ty *mdp;
-      message_ty *mp;
-
-      mdp = mdlp->item[j];
-      mp = message_list_search (mdp->messages, msgctxt, msgid);
+      msgdomain_ty *mdp = mdlp->item[j];
+      message_ty *mp = message_list_search (mdp->messages, msgctxt, msgid);
       if (mp)
         return mp;
     }
@@ -973,20 +893,14 @@ message_ty *
 msgdomain_list_search_fuzzy (msgdomain_list_ty *mdlp,
                              const char *msgctxt, const char *msgid)
 {
-  size_t j;
-  double best_weight;
-  message_ty *best_mp;
-
-  best_weight = FUZZY_THRESHOLD;
-  best_mp = NULL;
-  for (j = 0; j < mdlp->nitems; ++j)
+  double best_weight = FUZZY_THRESHOLD;
+  message_ty *best_mp = NULL;
+  for (size_t j = 0; j < mdlp->nitems; ++j)
     {
-      msgdomain_ty *mdp;
-      message_ty *mp;
-
-      mdp = mdlp->item[j];
-      mp = message_list_search_fuzzy_inner (mdp->messages, msgctxt, msgid,
-                                            &best_weight);
+      msgdomain_ty *mdp = mdlp->item[j];
+      message_ty *mp =
+        message_list_search_fuzzy_inner (mdp->messages, msgctxt, msgid,
+                                         &best_weight);
       if (mp)
         best_mp = mp;
     }
index c416b0ded6402ecbb12b942df97ea06c2485960a..ab574af2a27ce29adb23bd690c256d97ea06645e 100644 (file)
@@ -90,20 +90,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp,
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  const char *only_file;
-  const char *ignore_file;
-  msgdomain_list_ty *only_mdlp;
-  msgdomain_list_ty *ignore_mdlp;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_msgid = false;
-  bool sort_by_filepos = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -121,13 +107,17 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
-  only_file = NULL;
-  ignore_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  const char *input_file = NULL;
+  const char *only_file = NULL;
+  const char *ignore_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -175,176 +165,177 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 24: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
-
-      case CHAR_MAX + 1: /* --translated */
-        to_remove |= REMOVE_UNTRANSLATED;
-        break;
-
-      case CHAR_MAX + 2: /* --untranslated */
-        to_remove |= REMOVE_TRANSLATED;
-        break;
-
-      case CHAR_MAX + 3: /* --no-fuzzy */
-        to_remove |= REMOVE_FUZZY;
-        break;
-
-      case CHAR_MAX + 4: /* --only-fuzzy */
-        to_remove |= REMOVE_NONFUZZY;
-        break;
-
-      case CHAR_MAX + 5: /* --no-obsolete */
-        to_remove |= REMOVE_OBSOLETE;
-        break;
-
-      case CHAR_MAX + 6: /* --only-obsolete */
-        to_remove |= REMOVE_NONOBSOLETE;
-        break;
-
-      case CHAR_MAX + 7: /* --set-fuzzy */
-        to_change |= SET_FUZZY;
-        break;
-
-      case CHAR_MAX + 8: /* --clear-fuzzy */
-        to_change |= RESET_FUZZY;
-        break;
-
-      case CHAR_MAX + 9: /* --set-obsolete */
-        to_change |= SET_OBSOLETE;
-        break;
-
-      case CHAR_MAX + 10: /* --clear-obsolete */
-        to_change |= RESET_OBSOLETE;
-        break;
-
-      case CHAR_MAX + 11: /* --fuzzy */
-        to_remove |= REMOVE_NONFUZZY;
-        to_change |= RESET_FUZZY;
-        break;
-
-      case CHAR_MAX + 12: /* --obsolete */
-        to_remove |= REMOVE_NONOBSOLETE;
-        to_change |= RESET_OBSOLETE;
-        break;
-
-      case CHAR_MAX + 13: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 14: /* --only-file */
-        only_file = optarg;
-        break;
-
-      case CHAR_MAX + 15: /* --ignore-file */
-        ignore_file = optarg;
-        break;
-
-      case CHAR_MAX + 16: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 17: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 18: /* --clear-previous */
-        to_change |= REMOVE_PREV;
-        break;
-
-      case CHAR_MAX + 19: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 24: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1: /* --translated */
+          to_remove |= REMOVE_UNTRANSLATED;
+          break;
+
+        case CHAR_MAX + 2: /* --untranslated */
+          to_remove |= REMOVE_TRANSLATED;
+          break;
+
+        case CHAR_MAX + 3: /* --no-fuzzy */
+          to_remove |= REMOVE_FUZZY;
+          break;
+
+        case CHAR_MAX + 4: /* --only-fuzzy */
+          to_remove |= REMOVE_NONFUZZY;
+          break;
+
+        case CHAR_MAX + 5: /* --no-obsolete */
+          to_remove |= REMOVE_OBSOLETE;
+          break;
+
+        case CHAR_MAX + 6: /* --only-obsolete */
+          to_remove |= REMOVE_NONOBSOLETE;
+          break;
+
+        case CHAR_MAX + 7: /* --set-fuzzy */
+          to_change |= SET_FUZZY;
+          break;
+
+        case CHAR_MAX + 8: /* --clear-fuzzy */
+          to_change |= RESET_FUZZY;
+          break;
+
+        case CHAR_MAX + 9: /* --set-obsolete */
+          to_change |= SET_OBSOLETE;
+          break;
+
+        case CHAR_MAX + 10: /* --clear-obsolete */
+          to_change |= RESET_OBSOLETE;
+          break;
+
+        case CHAR_MAX + 11: /* --fuzzy */
+          to_remove |= REMOVE_NONFUZZY;
+          to_change |= RESET_FUZZY;
+          break;
+
+        case CHAR_MAX + 12: /* --obsolete */
+          to_remove |= REMOVE_NONOBSOLETE;
+          to_change |= RESET_OBSOLETE;
+          break;
+
+        case CHAR_MAX + 13: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 14: /* --only-file */
+          only_file = optarg;
+          break;
+
+        case CHAR_MAX + 15: /* --ignore-file */
+          ignore_file = optarg;
+          break;
+
+        case CHAR_MAX + 16: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 17: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 18: /* --clear-previous */
+          to_change |= REMOVE_PREV;
+          break;
+
+        case CHAR_MAX + 19: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 20: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 21: /* --previous */
+          to_change |= ADD_PREV;
+          break;
+
+        case CHAR_MAX + 22: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        case CHAR_MAX + 23: /* --empty */
+          to_change |= REMOVE_TRANSLATION;
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 20: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 21: /* --previous */
-        to_change |= ADD_PREV;
-        break;
-
-      case CHAR_MAX + 22: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      case CHAR_MAX + 23: /* --empty */
-        to_change |= REMOVE_TRANSLATION;
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -383,15 +374,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            "--sort-output", "--sort-by-file");
 
   /* Read input file.  */
-  result = read_catalog_file (input_file, input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (input_file, input_syntax);
 
   /* Read optional files that limit the extent of the attribute changes.  */
-  only_mdlp = (only_file != NULL
-               ? read_catalog_file (only_file, input_syntax)
-               : NULL);
-  ignore_mdlp = (ignore_file != NULL
-                 ? read_catalog_file (ignore_file, input_syntax)
-                 : NULL);
+  msgdomain_list_ty *only_mdlp =
+    (only_file != NULL
+     ? read_catalog_file (only_file, input_syntax)
+     : NULL);
+  msgdomain_list_ty *ignore_mdlp =
+    (ignore_file != NULL
+     ? read_catalog_file (ignore_file, input_syntax)
+     : NULL);
 
   /* Filter the messages and manipulate the attributes.  */
   result = process_msgdomain_list (result, only_mdlp, ignore_mdlp);
@@ -595,9 +588,7 @@ process_message_list (message_list_ty *mlp,
   /* Change the attributes.  */
   if (to_change)
     {
-      size_t j;
-
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -633,14 +624,13 @@ process_message_list (message_list_ty *mlp,
                       && mp->is_fuzzy && !mp->obsolete)
                     {
                       unsigned long int nplurals = 0;
-                      char *msgstr;
-                      size_t pos;
-
-                      for (pos = 0; pos < mp->msgstr_len; ++pos)
+                      for (size_t pos = 0; pos < mp->msgstr_len; ++pos)
                         if (!mp->msgstr[pos])
                           ++nplurals;
+
                       free ((char *) mp->msgstr);
-                      msgstr = XNMALLOC (nplurals, char);
+
+                      char *msgstr = XNMALLOC (nplurals, char);
                       memset (msgstr, '\0', nplurals);
                       mp->msgstr = msgstr;
                       mp->msgstr_len = nplurals;
@@ -669,9 +659,7 @@ process_msgdomain_list (msgdomain_list_ty *mdlp,
                         msgdomain_list_ty *only_mdlp,
                         msgdomain_list_ty *ignore_mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     process_message_list (mdlp->item[k]->messages,
                           only_mdlp
                           ? msgdomain_list_sublist (only_mdlp,
index 9a7dfb447609ed5d105c37a4d29e016251cf5baa..491c53241f2529805ee0ed3a204b82b0aacef81f 100644 (file)
@@ -68,20 +68,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char **argv)
 {
-  int cnt;
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *files_from;
-  string_list_ty *file_list;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_msgid = false;
-  bool sort_by_filepos = false;
-  /* Language (ISO-639 code) and optional territory (ISO-3166 code).  */
-  const char *catalogname = NULL;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -99,14 +85,20 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  files_from = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  const char *files_from = NULL;
   more_than = 0;
   less_than = INT_MAX;
   use_first = false;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
+  /* Language (ISO-639 code) and optional territory (ISO-3166 code).  */
+  const char *catalogname = NULL;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -144,146 +136,145 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case '>':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            more_than = value;
-        }
-        break;
-
-      case '<':
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            less_than = value;
-        }
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'f':
-        files_from = optarg;
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case '>':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              more_than = value;
+          }
+          break;
+
+        case '<':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              less_than = value;
+          }
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'f':
+          files_from = optarg;
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 9: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 't':
+          to_code = optarg;
+          break;
+
+        case 'u':
+          less_than = 2;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1:
+          use_first = true;
+          break;
+
+        case CHAR_MAX + 2: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 3: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 4: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 5: /* --color */
+          if (handle_color_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 6: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 7: /* --lang */
+          catalogname = optarg;
+          break;
+
+        case CHAR_MAX + 8: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 9: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 't':
-        to_code = optarg;
-        break;
-
-      case 'u':
-        less_than = 2;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
+          /* NOTREACHED */
         }
-        break;
-
-      case CHAR_MAX + 1:
-        use_first = true;
-        break;
-
-      case CHAR_MAX + 2: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 3: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 4: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 5: /* --color */
-        if (handle_color_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 6: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 7: /* --lang */
-        catalogname = optarg;
-        break;
-
-      case CHAR_MAX + 8: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -323,16 +314,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            more_than, less_than);
 
   /* Determine list of files we have to process.  */
+  string_list_ty *file_list;
   if (files_from != NULL)
     file_list = read_names_from_file (files_from);
   else
     file_list = string_list_alloc ();
   /* Append names from command line.  */
-  for (cnt = optind; cnt < argc; ++cnt)
+  for (int cnt = optind; cnt < argc; ++cnt)
     string_list_append_unique (file_list, argv[cnt]);
 
   /* Read input files, then filter, convert and merge messages.  */
-  result =
+  msgdomain_list_ty *result =
     catenate_msgdomain_list (file_list, input_syntax,
                              output_syntax->requires_utf8 ? "UTF-8" : to_code);
 
index e20e7a1c480594dd1379add7a3234e54ae5332a9..55b01e752de05dfb359c8d6483e988e5fc83165d 100644 (file)
@@ -74,10 +74,6 @@ static void compare (const char *fn1, const char *fn2,
 int
 main (int argc, char *argv[])
 {
-  bool do_help;
-  bool do_version;
-  catalog_input_format_ty input_syntax = &input_format_po;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -95,8 +91,10 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  do_help = false;
-  do_version = false;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  catalog_input_format_ty input_syntax = &input_format_po;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -114,53 +112,55 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
 
-      case 'D':
-        dir_list_append (optarg);
-        break;
+        case 'D':
+          dir_list_append (optarg);
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'm':
-        multi_domain_mode = true;
-        break;
+        case 'm':
+          multi_domain_mode = true;
+          break;
 
-      case 'N':
-        use_fuzzy_matching = false;
-        break;
+        case 'N':
+          use_fuzzy_matching = false;
+          break;
 
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      case CHAR_MAX + 1:        /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
+        case CHAR_MAX + 1:        /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
 
-      case CHAR_MAX + 2:        /* --use-fuzzy */
-        include_fuzzies = true;
-        break;
+        case CHAR_MAX + 2:        /* --use-fuzzy */
+          include_fuzzies = true;
+          break;
 
-      case CHAR_MAX + 3:        /* --use-untranslated */
-        include_untranslated = true;
-        break;
+        case CHAR_MAX + 3:        /* --use-untranslated */
+          include_untranslated = true;
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -293,9 +293,7 @@ is_message_selected (const message_ty *mp)
 static msgdomain_list_ty *
 remove_obsoletes (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     message_list_remove_if_not (mdlp->item[k]->messages, is_message_selected);
 
   return mdlp;
@@ -309,17 +307,13 @@ match_domain (const char *fn1, const char *fn2,
               message_list_ty *refmlp,
               int *nerrors)
 {
-  size_t j;
-
-  for (j = 0; j < refmlp->nitems; j++)
+  for (size_t j = 0; j < refmlp->nitems; j++)
     {
-      message_ty *refmsg;
-      message_ty *defmsg;
-
-      refmsg = refmlp->item[j];
+      message_ty *refmsg = refmlp->item[j];
 
       /* See if it is in the other file.  */
-      defmsg = message_list_search (defmlp, refmsg->msgctxt, refmsg->msgid);
+      message_ty *defmsg =
+        message_list_search (defmlp, refmsg->msgctxt, refmsg->msgid);
       if (defmsg)
         {
           if (!include_untranslated && defmsg->msgstr[0] == '\0')
@@ -390,29 +384,24 @@ match_domain (const char *fn1, const char *fn2,
 static void
 compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
 {
-  msgdomain_list_ty *def;
-  msgdomain_list_ty *ref;
-  int nerrors;
-  size_t j, k;
-  const char *def_canon_charset;
-  message_list_ty *empty_list;
-
   /* This is the master file, created by a human.  */
-  def = remove_obsoletes (read_catalog_file (fn1, input_syntax));
+  msgdomain_list_ty *def =
+    remove_obsoletes (read_catalog_file (fn1, input_syntax));
 
   /* This is the generated file, created by groping the sources with
      the xgettext program.  */
-  ref = remove_obsoletes (read_catalog_file (fn2, input_syntax));
+  msgdomain_list_ty *ref =
+    remove_obsoletes (read_catalog_file (fn2, input_syntax));
 
   /* The references file can be either in ASCII or in UTF-8.  If it is
      in UTF-8, we have to convert the definitions to UTF-8 as well.  */
   {
     bool was_utf8 = false;
-    for (k = 0; k < ref->nitems; k++)
+    for (size_t k = 0; k < ref->nitems; k++)
       {
         message_list_ty *mlp = ref->item[k]->messages;
 
-        for (j = 0; j < mlp->nitems; j++)
+        for (size_t j = 0; j < mlp->nitems; j++)
           if (is_header (mlp->item[j]) /* && !mlp->item[j]->obsolete */)
             {
               const char *header = mlp->item[j]->msgstr;
@@ -423,10 +412,8 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
 
                   if (charsetstr != NULL)
                     {
-                      size_t len;
-
                       charsetstr += strlen ("charset=");
-                      len = strcspn (charsetstr, " \t\n");
+                      size_t len = strcspn (charsetstr, " \t\n");
                       if (len == strlen ("UTF-8")
                           && c_strncasecmp (charsetstr, "UTF-8", len) == 0)
                         was_utf8 = true;
@@ -441,6 +428,7 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
 
   /* Determine canonicalized encoding name of the definitions now, after
      conversion.  Only used for fuzzy matching.  */
+  const char *def_canon_charset;
   if (use_fuzzy_matching)
     {
       def_canon_charset = def->encoding;
@@ -449,11 +437,11 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
           char *charset = NULL;
 
           /* Get the encoding of the definitions file.  */
-          for (k = 0; k < def->nitems; k++)
+          for (size_t k = 0; k < def->nitems; k++)
             {
               message_list_ty *mlp = def->item[k]->messages;
 
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                   {
                     const char *header = mlp->item[j]->msgstr;
@@ -464,10 +452,8 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
 
                         if (charsetstr != NULL)
                           {
-                            size_t len;
-
                             charsetstr += strlen ("charset=");
-                            len = strcspn (charsetstr, " \t\n");
+                            size_t len = strcspn (charsetstr, " \t\n");
                             charset = (char *) xmalloca (len + 1);
                             memcpy (charset, charsetstr, len);
                             charset[len] = '\0';
@@ -488,24 +474,22 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
   else
     def_canon_charset = NULL;
 
-  empty_list = message_list_alloc (false);
+  message_list_ty *empty_list = message_list_alloc (false);
 
   /* Every entry in the xgettext generated file must be matched by a
      (single) entry in the human created file.  */
-  nerrors = 0;
+  int nerrors = 0;
   if (!multi_domain_mode)
-    for (k = 0; k < ref->nitems; k++)
+    for (size_t k = 0; k < ref->nitems; k++)
       {
         const char *domain = ref->item[k]->domain;
         message_list_ty *refmlp = ref->item[k]->messages;
-        message_list_ty *defmlp;
-        message_fuzzy_index_ty *defmlp_findex;
 
-        defmlp = msgdomain_list_sublist (def, domain, false);
+        message_list_ty *defmlp = msgdomain_list_sublist (def, domain, false);
         if (defmlp == NULL)
           defmlp = empty_list;
 
-        defmlp_findex = NULL;
+        message_fuzzy_index_ty *defmlp_findex = NULL;
 
         match_domain (fn1, fn2, defmlp, &defmlp_findex, def_canon_charset,
                       refmlp, &nerrors);
@@ -519,7 +503,7 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
          the definition domains.  */
       message_list_ty *refmlp = ref->item[0]->messages;
 
-      for (k = 0; k < def->nitems; k++)
+      for (size_t k = 0; k < def->nitems; k++)
         {
           message_list_ty *defmlp = def->item[k]->messages;
 
@@ -540,11 +524,11 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax)
   /* Look for messages in the definition file, which are not present
      in the reference file, indicating messages which defined but not
      used in the program.  */
-  for (k = 0; k < def->nitems; ++k)
+  for (size_t k = 0; k < def->nitems; ++k)
     {
       message_list_ty *defmlp = def->item[k]->messages;
 
-      for (j = 0; j < defmlp->nitems; j++)
+      for (size_t j = 0; j < defmlp->nitems; j++)
         {
           message_ty *defmsg = defmlp->item[j];
 
index 9f709b4818463c51e584b95832d358a764c174eb..4b4a3b731cb317e6e06825cdd6f7580070cd7960 100644 (file)
@@ -69,18 +69,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char *argv[])
 {
-  int cnt;
-  bool do_help = false;
-  bool do_version = false;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_msgid = false;
-  bool sort_by_filepos = false;
-  const char *files_from = NULL;
-  string_list_ty *file_list;
-  char *output_file = NULL;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -98,10 +86,18 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  const char *files_from = NULL;
   more_than = -1;
   less_than = -1;
   use_first = false;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -139,142 +135,141 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case '>':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            more_than = value;
-        }
-        break;
-
-      case '<':
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            less_than = value;
-        }
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'f':
-        files_from = optarg;
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case '>':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              more_than = value;
+          }
+          break;
+
+        case '<':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              less_than = value;
+          }
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'f':
+          files_from = optarg;
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 8: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 't':
+          to_code = optarg;
+          break;
+
+        case 'u':
+          less_than = 2;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1:
+          omit_header = true;
+          break;
+
+        case CHAR_MAX + 2: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 3: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 4: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 5: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 6: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 7: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 8: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 't':
-        to_code = optarg;
-        break;
-
-      case 'u':
-        less_than = 2;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
+          /* NOTREACHED */
         }
-        break;
-
-      case CHAR_MAX + 1:
-        omit_header = true;
-        break;
-
-      case CHAR_MAX + 2: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 3: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 4: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 5: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 6: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 7: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -302,12 +297,13 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            "--sort-output", "--sort-by-file");
 
   /* Determine list of files we have to process.  */
+  string_list_ty *file_list;
   if (files_from != NULL)
     file_list = read_names_from_file (files_from);
   else
     file_list = string_list_alloc ();
   /* Append names from command line.  */
-  for (cnt = optind; cnt < argc; ++cnt)
+  for (int cnt = optind; cnt < argc; ++cnt)
     string_list_append_unique (file_list, argv[cnt]);
 
   /* Test whether sufficient input files were given.  */
@@ -330,7 +326,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Read input files, then filter, convert and merge messages.  */
   allow_duplicates = true;
   msgcomm_mode = true;
-  result = catenate_msgdomain_list (file_list, input_syntax, to_code);
+  msgdomain_list_ty *result =
+    catenate_msgdomain_list (file_list, input_syntax, to_code);
 
   string_list_free (file_list);
 
index 52c1280433fd313d209f55c264b33434c143669b..f853d0e95f2c5409b8d220cebcc698b6c53e4664 100644 (file)
@@ -66,16 +66,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_filepos = false;
-  bool sort_by_msgid = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -93,11 +83,14 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -129,110 +122,111 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 7: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 't':
-        to_code = optarg;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
-
-      case CHAR_MAX + 1: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 2: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 3: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 4: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 7: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 't':
+          to_code = optarg;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 2: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 3: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 4: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 5: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 6: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 5: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 6: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -255,6 +249,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     usage (EXIT_SUCCESS);
 
   /* Test whether we have an .po file name as argument.  */
+  const char *input_file = NULL;
   if (optind == argc)
     input_file = "-";
   else if (optind + 1 == argc)
@@ -275,7 +270,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     to_code = locale_charset ();
 
   /* Read input file.  */
-  result = read_catalog_file (input_file, input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (input_file, input_syntax);
 
   /* Convert if and only if the output syntax supports different encodings.  */
   if (!output_syntax->requires_utf8)
index bf23ecc305958b449a5f6408f6dc26b8bd6abe6c..18fdf7a8e1a9be2322b711409adbc1f1bb294df0 100644 (file)
@@ -67,17 +67,6 @@ static msgdomain_list_ty *fill_header (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_filepos = false;
-  bool sort_by_msgid = false;
-  /* Language (ISO-639 code) and optional territory (ISO-3166 code).  */
-  const char *catalogname = NULL;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -95,10 +84,16 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_filepos = false;
+  bool sort_by_msgid = false;
+  /* Language (ISO-639 code) and optional territory (ISO-3166 code).  */
+  const char *catalogname = NULL;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -130,110 +125,111 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
 
-      case 'D':
-        dir_list_append (optarg);
-        break;
+        case 'D':
+          dir_list_append (optarg);
+          break;
 
-      case 'e':
-        message_print_style_escape (false);
-        break;
+        case 'e':
+          message_print_style_escape (false);
+          break;
 
-      case 'E':
-        message_print_style_escape (true);
-        break;
+        case 'E':
+          message_print_style_escape (true);
+          break;
 
-      case 'F':
-        sort_by_filepos = true;
-        break;
+        case 'F':
+          sort_by_filepos = true;
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'i':
-        message_print_style_indent ();
-        break;
+        case 'i':
+          message_print_style_indent ();
+          break;
 
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
 
-      case 'o':
-        output_file = optarg;
-        break;
+        case 'o':
+          output_file = optarg;
+          break;
 
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
 
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
 
-      case 's':
-        sort_by_msgid = true;
-        break;
+        case 's':
+          sort_by_msgid = true;
+          break;
 
-      case CHAR_MAX + 8: /* --strict */
-        message_print_style_uniforum ();
-        break;
+        case CHAR_MAX + 8: /* --strict */
+          message_print_style_uniforum ();
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
 
-      case CHAR_MAX + 1: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
+        case CHAR_MAX + 1: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
 
-      case CHAR_MAX + 2: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
+        case CHAR_MAX + 2: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
 
-      case CHAR_MAX + 3: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
+        case CHAR_MAX + 3: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
 
-      case CHAR_MAX + 4: /* --lang */
-        catalogname = optarg;
-        break;
+        case CHAR_MAX + 4: /* --lang */
+          catalogname = optarg;
+          break;
 
-      case CHAR_MAX + 5: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
+        case CHAR_MAX + 5: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
 
-      case CHAR_MAX + 6: /* --style */
-        handle_style_option (optarg);
-        break;
+        case CHAR_MAX + 6: /* --style */
+          handle_style_option (optarg);
+          break;
 
-      case CHAR_MAX + 7: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
+        case CHAR_MAX + 7: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -273,7 +269,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            "--sort-output", "--sort-by-file");
 
   /* Read input file.  */
-  result = read_catalog_file (argv[optind], input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (argv[optind], input_syntax);
 
   if (!output_syntax->requires_utf8)
     /* Fill the header entry.  */
@@ -413,14 +409,12 @@ or by email to <%s>.\n"),
 static msgdomain_list_ty *
 fill_header (msgdomain_list_ty *mdlp)
 {
-  size_t k, j;
-
   if (mdlp->encoding == NULL
       && is_ascii_msgdomain_list (mdlp))
     mdlp->encoding = "ASCII";
 
   if (mdlp->encoding != NULL)
-    for (k = 0; k < mdlp->nitems; k++)
+    for (size_t k = 0; k < mdlp->nitems; k++)
       {
         message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -429,7 +423,7 @@ fill_header (msgdomain_list_ty *mdlp)
             message_ty *header_mp = NULL;
 
             /* Search the header entry.  */
-            for (j = 0; j < mlp->nitems; j++)
+            for (size_t j = 0; j < mlp->nitems; j++)
               if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                 {
                   header_mp = mlp->item[j];
index 7e49859b6a02b488db15ba55d71f8d1ce8ed7018..57e61749b116bed7e880dd93b13f7554488cfe43 100644 (file)
@@ -84,13 +84,6 @@ static void process_msgdomain_list (const msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  const char *input_file;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  size_t i;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -108,10 +101,11 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  input_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  const char *input_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -129,50 +123,52 @@ main (int argc, char **argv)
   /* The flag NON_OPTION_TERMINATES_OPTIONS causes option parsing to terminate
      when the first non-option, i.e. the subprogram name, is encountered.  */
   start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        if (input_file != NULL)
-          {
-            error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
-            usage (EXIT_FAILURE);
-          }
-        input_file = optarg;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case CHAR_MAX + 1: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 2: /* --newline */
-        newline = true;
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          if (input_file != NULL)
+            {
+              error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
+              usage (EXIT_FAILURE);
+            }
+          input_file = optarg;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case CHAR_MAX + 1: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 2: /* --newline */
+          newline = true;
+          break;
+
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -202,16 +198,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Build argument list for the program.  */
   sub_argc = argc - optind;
   sub_argv = XNMALLOC (sub_argc + 1, const char *);
-  for (i = 0; i < sub_argc; i++)
-    sub_argv[i] = argv[optind + i];
-  sub_argv[i] = NULL;
+  {
+    size_t i;
+    for (i = 0; i < sub_argc; i++)
+      sub_argv[i] = argv[optind + i];
+    sub_argv[i] = NULL;
+  }
 
   /* By default, input comes from standard input.  */
   if (input_file == NULL)
     input_file = "-";
 
   /* Read input file.  */
-  result = read_catalog_file (input_file, input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (input_file, input_syntax);
 
   if (strcmp (sub_name, "0") != 0)
     {
@@ -224,9 +223,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\
          strings must continue nevertheless.  */
       {
         sigset_t sigpipe_set;
-
         sigemptyset (&sigpipe_set);
         sigaddset (&sigpipe_set, SIGPIPE);
+
         sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL);
       }
 
@@ -360,12 +359,6 @@ process_string (const message_ty *mp, const char *str, size_t len)
   else
     {
       /* General command.  */
-      char *location;
-      pid_t child;
-      int fd[1];
-      void (*orig_sigpipe_handler)(int);
-      int exitstatus;
-      char *newstr;
 
       /* Set environment variables for the subprocess.
          Note: These environment variables, especially MSGEXEC_MSGCTXT and
@@ -388,10 +381,12 @@ process_string (const message_ty *mp, const char *str, size_t len)
         xsetenv ("MSGEXEC_MSGID_PLURAL", mp->msgid_plural, 1);
       else
         unsetenv ("MSGEXEC_MSGID_PLURAL");
-      location = xasprintf ("%s:%ld", mp->pos.file_name,
-                            (long) mp->pos.line_number);
-      xsetenv ("MSGEXEC_LOCATION", location, 1);
-      free (location);
+      {
+        char *location =
+          xasprintf ("%s:%ld", mp->pos.file_name, (long) mp->pos.line_number);
+        xsetenv ("MSGEXEC_LOCATION", location, 1);
+        free (location);
+      }
       if (mp->prev_msgctxt != NULL)
         xsetenv ("MSGEXEC_PREV_MSGCTXT", mp->prev_msgctxt, 1);
       else
@@ -406,29 +401,34 @@ process_string (const message_ty *mp, const char *str, size_t len)
         unsetenv ("MSGEXEC_PREV_MSGID_PLURAL");
 
       /* Open a pipe to a subprocess.  */
-      child = create_pipe_out (sub_name, sub_path, sub_argv, NULL, NULL,
-                               NULL, false, true, true, fd);
+      int fd[1];
+      pid_t child = create_pipe_out (sub_name, sub_path, sub_argv, NULL, NULL,
+                                     NULL, false, true, true, fd);
 
       /* Ignore SIGPIPE here.  We don't care if the subprocesses terminates
          successfully without having read all of the input that we feed it.  */
+      void (*orig_sigpipe_handler)(int);
       orig_sigpipe_handler = signal (SIGPIPE, SIG_IGN);
 
-      if (newline)
-        {
-          newstr = XNMALLOC (len + 1, char);
-          memcpy (newstr, str, len);
-          newstr[len++] = '\n';
-        }
-      else
-        newstr = (char *) str;
+      {
+        char *newstr;
+        if (newline)
+          {
+            newstr = XNMALLOC (len + 1, char);
+            memcpy (newstr, str, len);
+            newstr[len++] = '\n';
+          }
+        else
+          newstr = (char *) str;
 
-      if (full_write (fd[0], newstr, len) < len)
-        if (errno != EPIPE)
-          error (EXIT_FAILURE, errno,
-                 _("write to %s subprocess failed"), sub_name);
+        if (full_write (fd[0], newstr, len) < len)
+          if (errno != EPIPE)
+            error (EXIT_FAILURE, errno,
+                   _("write to %s subprocess failed"), sub_name);
 
-      if (newstr != str)
-        free (newstr);
+        if (newstr != str)
+          free (newstr);
+      }
 
       close (fd[0]);
 
@@ -437,7 +437,7 @@ process_string (const message_ty *mp, const char *str, size_t len)
       /* Remove zombie process from process list, and retrieve exit status.  */
       /* FIXME: Should ignore_sigpipe be set to true here? It depends on the
          semantics of the subprogram...  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, sub_name, false, false, true, true, NULL);
       if (exitcode < exitstatus)
         exitcode = exitstatus;
@@ -450,10 +450,10 @@ process_message (const message_ty *mp)
 {
   const char *msgstr = mp->msgstr;
   size_t msgstr_len = mp->msgstr_len;
-  const char *p;
-  size_t k;
 
   /* Process each NUL delimited substring separately.  */
+  const char *p;
+  size_t k;
   for (p = msgstr, k = 0; p < msgstr + msgstr_len; k++)
     {
       size_t length = strlen (p);
@@ -477,9 +477,7 @@ process_message (const message_ty *mp)
 static void
 process_message_list (const message_list_ty *mlp)
 {
-  size_t j;
-
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     process_message (mlp->item[j]);
 }
 
@@ -487,8 +485,6 @@ process_message_list (const message_list_ty *mlp)
 static void
 process_msgdomain_list (const msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     process_message_list (mdlp->item[k]->messages);
 }
index 3f0880983ada2f045b4d97940f5c1bb532ffc468..426fb5225da17f830b04bf545244379ac91281e1 100644 (file)
@@ -97,17 +97,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_filepos = false;
-  bool sort_by_msgid = false;
-  int i;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -125,11 +114,15 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  const char *input_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_filepos = false;
+  bool sort_by_msgid = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -165,119 +158,120 @@ main (int argc, char **argv)
   /* The flag NON_OPTION_TERMINATES_OPTIONS causes option parsing to terminate
      when the first non-option, i.e. the subprogram name, is encountered.  */
   start_options (argc, argv, options, NON_OPTION_TERMINATES_OPTIONS, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
 
-      case 'D':
-        dir_list_append (optarg);
-        break;
+        case 'D':
+          dir_list_append (optarg);
+          break;
 
-      case 'E':
-        message_print_style_escape (true);
-        break;
+        case 'E':
+          message_print_style_escape (true);
+          break;
 
-      case 'F':
-        sort_by_filepos = true;
-        break;
+        case 'F':
+          sort_by_filepos = true;
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'i':
-        if (input_file != NULL)
-          {
-            error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
-            usage (EXIT_FAILURE);
-          }
-        input_file = optarg;
-        break;
+        case 'i':
+          if (input_file != NULL)
+            {
+              error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
+              usage (EXIT_FAILURE);
+            }
+          input_file = optarg;
+          break;
 
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
 
-      case 'o':
-        output_file = optarg;
-        break;
+        case 'o':
+          output_file = optarg;
+          break;
 
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
 
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
 
-      case 's':
-        sort_by_msgid = true;
-        break;
+        case 's':
+          sort_by_msgid = true;
+          break;
 
-      case CHAR_MAX + 10: /* --strict */
-        message_print_style_uniforum ();
-        break;
+        case CHAR_MAX + 10: /* --strict */
+          message_print_style_uniforum ();
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
 
-      case CHAR_MAX + 1:
-        message_print_style_indent ();
-        break;
+        case CHAR_MAX + 1:
+          message_print_style_indent ();
+          break;
 
-      case CHAR_MAX + 2:
-        message_print_style_escape (false);
-        break;
+        case CHAR_MAX + 2:
+          message_print_style_escape (false);
+          break;
 
-      case CHAR_MAX + 3: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
+        case CHAR_MAX + 3: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
 
-      case CHAR_MAX + 4: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
+        case CHAR_MAX + 4: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
 
-      case CHAR_MAX + 5: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
+        case CHAR_MAX + 5: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
 
-      case CHAR_MAX + 6: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
+        case CHAR_MAX + 6: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
 
-      case CHAR_MAX + 7: /* --style */
-        handle_style_option (optarg);
-        break;
+        case CHAR_MAX + 7: /* --style */
+          handle_style_option (optarg);
+          break;
 
-      case CHAR_MAX + 8: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
+        case CHAR_MAX + 8: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
 
-      case CHAR_MAX + 9: /* --newline */
-        newline = true;
-        break;
+        case CHAR_MAX + 9: /* --newline */
+          newline = true;
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -312,9 +306,12 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Build argument list for the program.  */
   sub_argc = argc - optind;
   sub_argv = XNMALLOC (sub_argc + 1, const char *);
-  for (i = 0; i < sub_argc; i++)
-    sub_argv[i] = argv[optind + i];
-  sub_argv[i] = NULL;
+  {
+    size_t i;
+    for (i = 0; i < sub_argc; i++)
+      sub_argv[i] = argv[optind + i];
+    sub_argv[i] = NULL;
+  }
 
   /* Extra checks for sed scripts.  */
   if (strcmp (sub_name, "sed") == 0)
@@ -324,7 +321,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
                _("at least one sed script must be specified"));
 
       /* Replace GNU sed specific options with portable sed options.  */
-      for (i = 1; i < sub_argc; i++)
+      for (int i = 1; i < sub_argc; i++)
         {
           if (strcmp (sub_argv[i], "--expression") == 0)
             sub_argv[i] = "-e";
@@ -345,7 +342,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     input_file = "-";
 
   /* Read input file.  */
-  result = read_catalog_file (input_file, input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (input_file, input_syntax);
 
   /* Recognize special programs as built-ins.  */
   if (strcmp (sub_name, "recode-sr-latin") == 0 && sub_argc == 1)
@@ -621,7 +618,6 @@ process_string (const char *str, size_t len, char **resultp, size_t *lengthp)
 {
   char *result;
   size_t length;
-
   filter (str, len, &result, &length);
 
   /* Remove NUL bytes from result.  */
@@ -632,9 +628,7 @@ process_string (const char *str, size_t len, char **resultp, size_t *lengthp)
     for (; p < pend; p++)
       if (*p == '\0')
         {
-          char *q;
-
-          q = p;
+          char *q = p;
           for (; p < pend; p++)
             if (*p != '\0')
               *q++ = *p;
@@ -655,14 +649,12 @@ static void
 process_string_with_newline (const char *str, size_t len, char **resultp,
                              size_t *lengthp)
 {
-  char *newstr;
-  char *result;
-  size_t length;
-
-  newstr = XNMALLOC (len + 1, char);
+  char *newstr = XNMALLOC (len + 1, char);
   memcpy (newstr, str, len);
   newstr[len] = '\n';
 
+  char *result;
+  size_t length;
   process_string (newstr, len + 1, &result, &length);
 
   free (newstr);
@@ -680,21 +672,13 @@ process_string_with_newline (const char *str, size_t len, char **resultp,
 static void
 process_message (message_ty *mp)
 {
-  const char *msgstr = mp->msgstr;
-  size_t msgstr_len = mp->msgstr_len;
-  char *location;
-  size_t nsubstrings;
-  char **substrings;
-  size_t total_len;
-  char *total_str;
-  const char *p;
-  char *q;
-  size_t k;
-
   /* Keep the header entry unmodified, if --keep-header was given.  */
   if (is_header (mp) && keep_header)
     return;
 
+  const char *msgstr = mp->msgstr;
+  size_t msgstr_len = mp->msgstr_len;
+
   /* Set environment variables for the subprocess.
      Note: These environment variables, especially MSGFILTER_MSGCTXT and
      MSGFILTER_MSGID, may contain non-ASCII characters.  The subprocess
@@ -716,10 +700,12 @@ process_message (message_ty *mp)
     xsetenv ("MSGFILTER_MSGID_PLURAL", mp->msgid_plural, 1);
   else
     unsetenv ("MSGFILTER_MSGID_PLURAL");
-  location = xasprintf ("%s:%ld", mp->pos.file_name,
-                        (long) mp->pos.line_number);
-  xsetenv ("MSGFILTER_LOCATION", location, 1);
-  free (location);
+  {
+    char *location =
+      xasprintf ("%s:%ld", mp->pos.file_name, (long) mp->pos.line_number);
+    xsetenv ("MSGFILTER_LOCATION", location, 1);
+    free (location);
+  }
   if (mp->prev_msgctxt != NULL)
     xsetenv ("MSGFILTER_PREV_MSGCTXT", mp->prev_msgctxt, 1);
   else
@@ -734,50 +720,61 @@ process_message (message_ty *mp)
     unsetenv ("MSGFILTER_PREV_MSGID_PLURAL");
 
   /* Count NUL delimited substrings.  */
-  for (p = msgstr, nsubstrings = 0;
-       p < msgstr + msgstr_len;
-       p += strlen (p) + 1, nsubstrings++);
+  size_t nsubstrings;
+  {
+    nsubstrings = 0;
+    for (const char *p = msgstr; p < msgstr + msgstr_len; p += strlen (p) + 1)
+      nsubstrings++;
+  }
 
   /* Process each NUL delimited substring separately.  */
-  substrings = XNMALLOC (nsubstrings, char *);
-  for (p = msgstr, k = 0, total_len = 0; k < nsubstrings; k++)
-    {
-      char *result;
-      size_t length;
-
-      if (mp->msgid_plural != NULL)
-        {
-          char *plural_form_string = xasprintf ("%lu", (unsigned long) k);
-
-          xsetenv ("MSGFILTER_PLURAL_FORM", plural_form_string, 1);
-          free (plural_form_string);
-        }
-      else
-        unsetenv ("MSGFILTER_PLURAL_FORM");
-
-      if (newline)
-        process_string_with_newline (p, strlen (p), &result, &length);
-      else
-        process_string (p, strlen (p), &result, &length);
-
-      result = (char *) xrealloc (result, length + 1);
-      result[length] = '\0';
-      substrings[k] = result;
-      total_len += length + 1;
+  char **substrings = XNMALLOC (nsubstrings, char *);
+  size_t total_len;
+  {
+    const char *p;
+    size_t k;
+    for (p = msgstr, k = 0, total_len = 0; k < nsubstrings; k++)
+      {
+        if (mp->msgid_plural != NULL)
+          {
+            char *plural_form_string = xasprintf ("%lu", (unsigned long) k);
 
-      p += strlen (p) + 1;
-    }
+            xsetenv ("MSGFILTER_PLURAL_FORM", plural_form_string, 1);
+            free (plural_form_string);
+          }
+        else
+          unsetenv ("MSGFILTER_PLURAL_FORM");
+
+        char *result;
+        size_t length;
+        if (newline)
+          process_string_with_newline (p, strlen (p), &result, &length);
+        else
+          process_string (p, strlen (p), &result, &length);
+
+        result = (char *) xrealloc (result, length + 1);
+        result[length] = '\0';
+        substrings[k] = result;
+        total_len += length + 1;
+
+        p += strlen (p) + 1;
+      }
+  }
 
   /* Concatenate the results, including the NUL after each.  */
-  total_str = XNMALLOC (total_len, char);
-  for (k = 0, q = total_str; k < nsubstrings; k++)
-    {
-      size_t length = strlen (substrings[k]);
+  char *total_str = XNMALLOC (total_len, char);
+  {
+    size_t k;
+    char *q;
+    for (k = 0, q = total_str; k < nsubstrings; k++)
+      {
+        size_t length = strlen (substrings[k]);
 
-      memcpy (q, substrings[k], length + 1);
-      free (substrings[k]);
-      q += length + 1;
-    }
+        memcpy (q, substrings[k], length + 1);
+        free (substrings[k]);
+        q += length + 1;
+      }
+  }
   free (substrings);
 
   mp->msgstr = total_str;
@@ -788,9 +785,7 @@ process_message (message_ty *mp)
 static void
 process_message_list (message_list_ty *mlp)
 {
-  size_t j;
-
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     process_message (mlp->item[j]);
 }
 
@@ -798,9 +793,7 @@ process_message_list (message_list_ty *mlp)
 static msgdomain_list_ty *
 process_msgdomain_list (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     process_message_list (mdlp->item[k]->messages);
 
   return mdlp;
index ea23dd70009fe4df6a6a9681611eca551dd2a7f6..ddbd3042fa573cc957cb68ded8e8b67e39a261f7 100644 (file)
@@ -197,23 +197,10 @@ static int msgfmt_xml_bulk (const char *directory,
 int
 main (int argc, char *argv[])
 {
-  bool do_help = false;
-  bool do_version = false;
-  bool strict_uniforum = false;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  int arg_i;
-  const char *canon_encoding;
-  struct msg_domain *domain;
-
-  /* Set default value for global variables.  */
-  alignment = DEFAULT_OUTPUT_ALIGNMENT;
-  byteswap = 0 ^ ENDIANNESS;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
   error_one_per_line = 1;
-  exit_status = EXIT_SUCCESS;
   gram_max_allowed_errors = 20;
 
   /* Set locale via LC_ALL.  */
@@ -228,6 +215,14 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  bool strict_uniforum = false;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  alignment = DEFAULT_OUTPUT_ALIGNMENT;
+  byteswap = 0 ^ ENDIANNESS;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -273,178 +268,179 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-      case 'a':
-        if (isdigit ((unsigned char) optarg[0]))
-          {
-            char *endp;
-            size_t new_align = strtoul (optarg, &endp, 0);
-
-            if (endp != optarg)
-              /* Check whether new_align is a power of 2.  */
-              if (new_align > 0 && (new_align & (new_align - 1)) == 0)
-                alignment = new_align;
-          }
-        break;
-      case 'c':
-        check_domain = true;
-        check_format_strings = true;
-        check_header = true;
-        break;
-      case 'C':
-        check_compatibility = true;
-        break;
-      case 'd':
-        java_class_directory = optarg;
-        csharp_base_directory = optarg;
-        tcl_base_directory = optarg;
-        desktop_base_directory = optarg;
-        xml_base_directory = optarg;
-        break;
-      case 'D':
-        dir_list_append (optarg);
-        break;
-      case 'f':
-        include_fuzzies = true;
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'j':
-        java_mode = true;
-        break;
-      case 'k':
-        if (optarg == NULL || *optarg == '\0')
-          desktop_default_keywords = false;
-        else
-          {
-            /* Ensure that desktop_keywords is initialized.  */
-            if (desktop_keywords.table == NULL)
-              hash_init (&desktop_keywords, 100);
-            desktop_add_keyword (&desktop_keywords, optarg, false);
-          }
-        break;
-      case 'l':
-        java_locale_name = optarg;
-        csharp_locale_name = optarg;
-        tcl_locale_name = optarg;
-        desktop_locale_name = optarg;
-        xml_locale_name = optarg;
-        break;
-      case 'L':
-        xml_language = optarg;
-        break;
-      case 'o':
-        output_file_name = optarg;
-        break;
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-      case 'r':
-        java_resource_name = optarg;
-        csharp_resource_name = optarg;
-        break;
-      case CHAR_MAX + 20: /* --strict */
-        strict_uniforum = true;
-        break;
-      case 'v':
-        verbose++;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      case 'x':
-        xml_mode = true;
-        break;
-      case CHAR_MAX + 1: /* --check-accelerators */
-        check_accelerators = true;
-        if (optarg != NULL)
-          {
-            if (optarg[0] != '\0' && ispunct ((unsigned char) optarg[0])
-                && optarg[1] == '\0')
-              accelerator_char = optarg[0];
-            else
-              error (EXIT_FAILURE, 0,
-                     _("the argument to %s should be a single punctuation character"),
-                     "--check-accelerators");
-          }
-        break;
-      case CHAR_MAX + 2: /* --check-domain */
-        check_domain = true;
-        break;
-      case CHAR_MAX + 3: /* --check-format */
-        check_format_strings = true;
-        break;
-      case CHAR_MAX + 4: /* --check-header */
-        check_header = true;
-        break;
-      case CHAR_MAX + 5: /* --java2 */
-        java_mode = true;
-        assume_java2 = true;
-        break;
-      case CHAR_MAX + 6: /* --no-hash */
-        no_hash_table = true;
-        break;
-      case CHAR_MAX + 7: /* --tcl */
-        tcl_mode = true;
-        break;
-      case CHAR_MAX + 8: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-      case CHAR_MAX + 9: /* --qt */
-        qt_mode = true;
-        break;
-      case CHAR_MAX + 10: /* --csharp */
-        csharp_mode = true;
-        break;
-      case CHAR_MAX + 11: /* --csharp-resources */
-        csharp_resources_mode = true;
-        break;
-      case CHAR_MAX + 12: /* --use-untranslated (undocumented) */
-        include_untranslated = true;
-        break;
-      case CHAR_MAX + 13: /* --endianness={big|little} */
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
         {
-          int endianness;
+        case '\0':                /* Long option with key == 0.  */
+          break;
+        case 'a':
+          if (isdigit ((unsigned char) optarg[0]))
+            {
+              char *endp;
+              size_t new_align = strtoul (optarg, &endp, 0);
 
-          if (strcmp (optarg, "big") == 0)
-            endianness = 1;
-          else if (strcmp (optarg, "little") == 0)
-            endianness = 0;
+              if (endp != optarg)
+                /* Check whether new_align is a power of 2.  */
+                if (new_align > 0 && (new_align & (new_align - 1)) == 0)
+                  alignment = new_align;
+            }
+          break;
+        case 'c':
+          check_domain = true;
+          check_format_strings = true;
+          check_header = true;
+          break;
+        case 'C':
+          check_compatibility = true;
+          break;
+        case 'd':
+          java_class_directory = optarg;
+          csharp_base_directory = optarg;
+          tcl_base_directory = optarg;
+          desktop_base_directory = optarg;
+          xml_base_directory = optarg;
+          break;
+        case 'D':
+          dir_list_append (optarg);
+          break;
+        case 'f':
+          include_fuzzies = true;
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'j':
+          java_mode = true;
+          break;
+        case 'k':
+          if (optarg == NULL || *optarg == '\0')
+            desktop_default_keywords = false;
           else
-            error (EXIT_FAILURE, 0, _("invalid endianness: %s"), optarg);
+            {
+              /* Ensure that desktop_keywords is initialized.  */
+              if (desktop_keywords.table == NULL)
+                hash_init (&desktop_keywords, 100);
+              desktop_add_keyword (&desktop_keywords, optarg, false);
+            }
+          break;
+        case 'l':
+          java_locale_name = optarg;
+          csharp_locale_name = optarg;
+          tcl_locale_name = optarg;
+          desktop_locale_name = optarg;
+          xml_locale_name = optarg;
+          break;
+        case 'L':
+          xml_language = optarg;
+          break;
+        case 'o':
+          output_file_name = optarg;
+          break;
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+        case 'r':
+          java_resource_name = optarg;
+          csharp_resource_name = optarg;
+          break;
+        case CHAR_MAX + 20: /* --strict */
+          strict_uniforum = true;
+          break;
+        case 'v':
+          verbose++;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        case 'x':
+          xml_mode = true;
+          break;
+        case CHAR_MAX + 1: /* --check-accelerators */
+          check_accelerators = true;
+          if (optarg != NULL)
+            {
+              if (optarg[0] != '\0' && ispunct ((unsigned char) optarg[0])
+                  && optarg[1] == '\0')
+                accelerator_char = optarg[0];
+              else
+                error (EXIT_FAILURE, 0,
+                       _("the argument to %s should be a single punctuation character"),
+                       "--check-accelerators");
+            }
+          break;
+        case CHAR_MAX + 2: /* --check-domain */
+          check_domain = true;
+          break;
+        case CHAR_MAX + 3: /* --check-format */
+          check_format_strings = true;
+          break;
+        case CHAR_MAX + 4: /* --check-header */
+          check_header = true;
+          break;
+        case CHAR_MAX + 5: /* --java2 */
+          java_mode = true;
+          assume_java2 = true;
+          break;
+        case CHAR_MAX + 6: /* --no-hash */
+          no_hash_table = true;
+          break;
+        case CHAR_MAX + 7: /* --tcl */
+          tcl_mode = true;
+          break;
+        case CHAR_MAX + 8: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+        case CHAR_MAX + 9: /* --qt */
+          qt_mode = true;
+          break;
+        case CHAR_MAX + 10: /* --csharp */
+          csharp_mode = true;
+          break;
+        case CHAR_MAX + 11: /* --csharp-resources */
+          csharp_resources_mode = true;
+          break;
+        case CHAR_MAX + 12: /* --use-untranslated (undocumented) */
+          include_untranslated = true;
+          break;
+        case CHAR_MAX + 13: /* --endianness={big|little} */
+          {
+            int endianness;
+            if (strcmp (optarg, "big") == 0)
+              endianness = 1;
+            else if (strcmp (optarg, "little") == 0)
+              endianness = 0;
+            else
+              error (EXIT_FAILURE, 0, _("invalid endianness: %s"), optarg);
 
-          byteswap = endianness ^ ENDIANNESS;
+            byteswap = endianness ^ ENDIANNESS;
+          }
+          break;
+        case CHAR_MAX + 14: /* --source */
+          java_output_source = true;
+          break;
+        case CHAR_MAX + 15: /* --desktop */
+          desktop_mode = true;
+          break;
+        case CHAR_MAX + 16: /* --template=TEMPLATE */
+          desktop_template_name = optarg;
+          xml_template_name = optarg;
+          break;
+        case CHAR_MAX + 17: /* --no-convert */
+          no_convert_to_utf8 = true;
+          break;
+        case CHAR_MAX + 18: /* --no-redundancy */
+          no_redundancy = true;
+          break;
+        case CHAR_MAX + 19: /* --replace-text */
+          xml_replace_text = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+          break;
         }
-        break;
-      case CHAR_MAX + 14: /* --source */
-        java_output_source = true;
-        break;
-      case CHAR_MAX + 15: /* --desktop */
-        desktop_mode = true;
-        break;
-      case CHAR_MAX + 16: /* --template=TEMPLATE */
-        desktop_template_name = optarg;
-        xml_template_name = optarg;
-        break;
-      case CHAR_MAX + 17: /* --no-convert */
-        no_convert_to_utf8 = true;
-        break;
-      case CHAR_MAX + 18: /* --no-redundancy */
-        no_redundancy = true;
-        break;
-      case CHAR_MAX + 19: /* --replace-text */
-        xml_replace_text = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -502,15 +498,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       {
         const char *first_option;
         const char *second_option;
-        unsigned int i;
-        for (i = 0; ; i++)
-          if (modes & (1 << i))
-            break;
-        first_option = mode_options[i];
-        for (i = i + 1; ; i++)
-          if (modes & (1 << i))
-            break;
-        second_option = mode_options[i];
+        {
+          unsigned int i;
+          for (i = 0; ; i++)
+            if (modes & (1 << i))
+              break;
+          first_option = mode_options[i];
+          for (i = i + 1; ; i++)
+            if (modes & (1 << i))
+              break;
+          second_option = mode_options[i];
+        }
         error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
                first_option, second_option);
       }
@@ -662,6 +660,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\
         }
     }
 
+  exit_status = EXIT_SUCCESS;
+
   if (desktop_mode)
     {
       /* Ensure that desktop_keywords is initialized.  */
@@ -684,35 +684,36 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 
   if (xml_mode)
     {
-      char **its_dirs;
-      char **dirs;
-      locating_rule_list_ty *its_locating_rules;
-      const char *its_basename;
-
-      its_dirs = get_search_path ("its");
-      its_locating_rules = locating_rule_list_alloc ();
-      for (dirs = its_dirs; *dirs != NULL; dirs++)
+      char **its_dirs = get_search_path ("its");
+
+      locating_rule_list_ty *its_locating_rules = locating_rule_list_alloc ();
+      for (char **dirs = its_dirs; *dirs != NULL; dirs++)
         locating_rule_list_add_from_directory (its_locating_rules, *dirs);
 
-      its_basename = locating_rule_list_locate (its_locating_rules,
-                                                xml_template_name,
-                                                xml_language);
+      const char *its_basename =
+        locating_rule_list_locate (its_locating_rules,
+                                   xml_template_name, xml_language);
 
       if (its_basename != NULL)
         {
-          size_t j;
-
           xml_its_rules = its_rule_list_alloc ();
+
+          size_t j;
           for (j = 0; its_dirs[j] != NULL; j++)
             {
               char *its_filename =
                 xconcatenated_filename (its_dirs[j], its_basename, NULL);
-              struct stat statbuf;
+
               bool ok = false;
+              {
+                struct stat statbuf;
+                if (stat (its_filename, &statbuf) == 0)
+                  ok = its_rule_list_add_from_file (xml_its_rules,
+                                                    its_filename);
+              }
 
-              if (stat (its_filename, &statbuf) == 0)
-                ok = its_rule_list_add_from_file (xml_its_rules, its_filename);
               free (its_filename);
+
               if (ok)
                 break;
             }
@@ -722,9 +723,10 @@ There is NO WARRANTY, to the extent permitted by law.\n\
               xml_its_rules = NULL;
             }
         }
+
       locating_rule_list_free (its_locating_rules);
 
-      for (dirs = its_dirs; *dirs != NULL; dirs++)
+      for (char **dirs = its_dirs; *dirs != NULL; dirs++)
         free (*dirs);
       free (its_dirs);
 
@@ -754,7 +756,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
                   : output_file_name);
 
   /* Process all given .po files.  */
-  for (arg_i = optind; arg_i < argc; arg_i++)
+  for (int arg_i = optind; arg_i < argc; arg_i++)
     {
       /* Remember that we currently have not specified any domain.  This
          is of course not true when we saw the -o option.  */
@@ -767,18 +769,23 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 
   /* We know a priori that some input_syntax->parse() functions convert
      strings to UTF-8.  */
-  canon_encoding = (input_syntax->produces_utf8 ? po_charset_utf8 : NULL);
+  const char *canon_encoding =
+    (input_syntax->produces_utf8 ? po_charset_utf8 : NULL);
 
   /* Remove obsolete messages.  They were only needed for duplicate
      checking.  */
-  for (domain = domain_list; domain != NULL; domain = domain->next)
+  for (struct msg_domain *domain = domain_list;
+       domain != NULL;
+       domain = domain->next)
     message_list_remove_if_not (domain->mlp, is_nonobsolete);
 
   /* Perform all kinds of checks: plural expressions, format strings, ...  */
   {
     int nerrors = 0;
 
-    for (domain = domain_list; domain != NULL; domain = domain->next)
+    for (struct msg_domain *domain = domain_list;
+         domain != NULL;
+         domain = domain->next)
       nerrors +=
         check_message_list (domain->mlp,
                             /* Untranslated and fuzzy messages have already
@@ -806,17 +813,20 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   char *all_input_file_names;
   {
     string_list_ty input_file_names;
-
     string_list_init (&input_file_names);;
-    for (arg_i = optind; arg_i < argc; arg_i++)
+    for (int arg_i = optind; arg_i < argc; arg_i++)
       string_list_append (&input_file_names, argv[arg_i]);
+
     all_input_file_names =
       string_list_join (&input_file_names, ", ", '\0', false);
+
     string_list_destroy (&input_file_names);
   }
 
   /* Now write out all domains.  */
-  for (domain = domain_list; domain != NULL; domain = domain->next)
+  for (struct msg_domain *domain = domain_list;
+       domain != NULL;
+       domain = domain->next)
     {
       if (java_mode)
         {
@@ -1121,15 +1131,12 @@ or by email to <%s>.\n"),
 static const char *
 add_mo_suffix (const char *fname)
 {
-  size_t len;
-  char *result;
-
-  len = strlen (fname);
+  size_t len = strlen (fname);
   if (len > 3 && memcmp (fname + len - 3, ".mo", 3) == 0)
     return fname;
   if (len > 4 && memcmp (fname + len - 4, ".gmo", 4) == 0)
     return fname;
-  result = XNMALLOC (len + 4, char);
+  char *result = XNMALLOC (len + 4, char);
   stpcpy (stpcpy (result, fname), ".mo");
   return result;
 }
@@ -1146,12 +1153,12 @@ new_domain (const char *name, const char *file_name)
   if (*p_dom == NULL)
     {
       struct msg_domain *domain;
-
       domain = XMALLOC (struct msg_domain);
       domain->mlp = message_list_alloc (true);
       domain->domain_name = name;
       domain->file_name = file_name;
       domain->next = NULL;
+
       *p_dom = domain;
     }
 
@@ -1234,9 +1241,7 @@ msgfmt_set_domain (default_catalog_reader_ty *dcatr,
   if (!java_mode && !csharp_mode && !csharp_resources_mode && !tcl_mode
       && !qt_mode && !desktop_mode && !xml_mode && output_file_name == NULL)
     {
-      size_t correct;
-
-      correct = strcspn (name, INVALID_PATH_CHAR);
+      size_t correct = strcspn (name, INVALID_PATH_CHAR);
       if (name[correct] != '\0')
         {
           exit_status = EXIT_FAILURE;
@@ -1413,8 +1418,8 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax)
 {
   char *real_filename;
   FILE *fp = open_catalog_file (filename, &real_filename, true);
-  default_catalog_reader_ty *dcatr;
 
+  default_catalog_reader_ty *dcatr;
   dcatr = default_catalog_reader_alloc (&msgfmt_methods,
                                         textmode_xerror_handler);
   dcatr->pass_obsolete_entries = true;
@@ -1431,8 +1436,10 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax)
       dcatr->domain = current_domain->domain_name;
       dcatr->mlp = current_domain->mlp;
     }
+
   catalog_reader_parse ((abstract_catalog_reader_ty *) dcatr, fp, real_filename,
                         filename, false, input_syntax);
+
   catalog_reader_free ((abstract_catalog_reader_ty *) dcatr);
 
   if (fp != stdin)
@@ -1443,18 +1450,14 @@ static void
 add_languages (string_list_ty *languages, string_list_ty *desired_languages,
                const char *line, size_t length)
 {
-  const char *start;
-
   /* Split the line by whitespace and build the languages list.  */
-  for (start = line; start - line < length; )
+  for (const char *start = line; start - line < length; )
     {
-      const char *p;
-
       /* Skip whitespace before the string.  */
       while (*start == ' ' || *start == '\t')
         start++;
 
-      p = start;
+      const char *p = start;
       while (*p != '\0' && *p != ' ' && *p != '\t')
         p++;
 
@@ -1470,33 +1473,37 @@ add_languages (string_list_ty *languages, string_list_ty *desired_languages,
 static void
 get_languages (string_list_ty *languages, const char *directory)
 {
-  char *envval;
-  string_list_ty real_desired_languages, *desired_languages = NULL;
-  char *linguas_file_name = NULL;
-  struct stat statbuf;
-  FILE *fp;
-  size_t line_len = 0;
-  char *line_buf = NULL;
-
-  envval = getenv ("LINGUAS");
-  if (envval)
-    {
-      string_list_init (&real_desired_languages);
-      add_languages (&real_desired_languages, NULL, envval, strlen (envval));
-      desired_languages = &real_desired_languages;
-    }
+  string_list_ty real_desired_languages;
+  string_list_ty *desired_languages = NULL;
+
+  {
+    char *envval = getenv ("LINGUAS");
+    if (envval)
+      {
+        string_list_init (&real_desired_languages);
+        add_languages (&real_desired_languages, NULL, envval, strlen (envval));
+        desired_languages = &real_desired_languages;
+      }
+  }
 
-  linguas_file_name = xconcatenated_filename (directory, "LINGUAS", NULL);
-  if (stat (linguas_file_name, &statbuf) < 0)
+  char *linguas_file_name = xconcatenated_filename (directory, "LINGUAS", NULL);
+  bool linguas_file_exists;
+  {
+    struct stat statbuf;
+    linguas_file_exists = (stat (linguas_file_name, &statbuf) >= 0);
+  }
+  if (!linguas_file_exists)
     error (EXIT_SUCCESS, 0, _("%s does not exist"), linguas_file_name);
   else
     {
-      fp = fopen (linguas_file_name, "r");
+      FILE *fp = fopen (linguas_file_name, "r");
       if (fp == NULL)
         error (EXIT_SUCCESS, 0, _("%s exists but cannot read"),
                linguas_file_name);
       else
         {
+          size_t line_len = 0;
+          char *line_buf = NULL;
           while (!feof (fp))
             {
               /* Read next line from file.  */
@@ -1542,9 +1549,7 @@ msgfmt_operand_list_init (msgfmt_operand_list_ty *operands)
 static void
 msgfmt_operand_list_destroy (msgfmt_operand_list_ty *operands)
 {
-  size_t i;
-
-  for (i = 0; i < operands->nitems; i++)
+  for (size_t i = 0; i < operands->nitems; i++)
     {
       free (operands->items[i].language);
       message_list_free (operands->items[i].mlp, 0);
@@ -1557,8 +1562,6 @@ msgfmt_operand_list_append (msgfmt_operand_list_ty *operands,
                             const char *language,
                             message_list_ty *messages)
 {
-  msgfmt_operand_ty *operand;
-
   if (operands->nitems == operands->nitems_max)
     {
       operands->nitems_max = operands->nitems_max * 2 + 1;
@@ -1567,7 +1570,7 @@ msgfmt_operand_list_append (msgfmt_operand_list_ty *operands,
                                   * operands->nitems_max);
     }
 
-  operand = &operands->items[operands->nitems++];
+  msgfmt_operand_ty *operand = &operands->items[operands->nitems++];
   operand->language = xstrdup (language);
   operand->mlp = messages;
 }
@@ -1577,10 +1580,6 @@ msgfmt_operand_list_add_from_directory (msgfmt_operand_list_ty *operands,
                                         const char *directory)
 {
   string_list_ty languages;
-  void *saved_dir_list;
-  int retval = 0;
-  size_t i;
-
   string_list_init (&languages);
   get_languages (&languages, directory);
 
@@ -1589,28 +1588,29 @@ msgfmt_operand_list_add_from_directory (msgfmt_operand_list_ty *operands,
 
   /* Reset the directory search list so only .po files under DIRECTORY
      will be read.  */
-  saved_dir_list = dir_list_save_reset ();
+  void *saved_dir_list = dir_list_save_reset ();
   dir_list_append (directory);
 
+  int retval = 0;
+
   /* Read all .po files.  */
-  for (i = 0; i < languages.nitems; i++)
+  for (size_t i = 0; i < languages.nitems; i++)
     {
       const char *language = languages.item[i];
-      message_list_ty *mlp;
-      char *input_file_name;
-      int nerrors;
 
       current_domain = new_domain (MESSAGE_DOMAIN_DEFAULT,
                                    add_mo_suffix (MESSAGE_DOMAIN_DEFAULT));
 
-      input_file_name = xconcatenated_filename ("", language, ".po");
-      read_catalog_file_msgfmt (input_file_name, &input_format_po);
-      free (input_file_name);
+      {
+        char *input_file_name = xconcatenated_filename ("", language, ".po");
+        read_catalog_file_msgfmt (input_file_name, &input_format_po);
+        free (input_file_name);
+      }
 
       /* The domain directive is not supported in the bulk execution mode.
          Thus, domain_list should always contain a single domain.  */
       assert (current_domain == domain_list && domain_list->next == NULL);
-      mlp = current_domain->mlp;
+      message_list_ty *mlp = current_domain->mlp;
       free (current_domain);
       current_domain = domain_list = NULL;
 
@@ -1620,7 +1620,7 @@ msgfmt_operand_list_add_from_directory (msgfmt_operand_list_ty *operands,
 
       /* Perform all kinds of checks: plural expressions, format
          strings, ...  */
-      nerrors =
+      int nerrors =
         check_message_list (mlp,
                             /* Untranslated and fuzzy messages have already
                                been dealt with during parsing, see below in
@@ -1666,12 +1666,11 @@ msgfmt_desktop_bulk (const char *directory,
                      const char *file_name)
 {
   msgfmt_operand_list_ty operands;
-  int nerrors, status;
-
   msgfmt_operand_list_init (&operands);
 
   /* Read all .po files.  */
-  nerrors = msgfmt_operand_list_add_from_directory (&operands, directory);
+  int nerrors = msgfmt_operand_list_add_from_directory (&operands, directory);
+  int status;
   if (nerrors > 0)
     status = 1;
   else
@@ -1697,12 +1696,10 @@ msgfmt_xml_bulk (const char *directory,
                  const char *file_name)
 {
   msgfmt_operand_list_ty operands;
-  int nerrors, status;
-
   msgfmt_operand_list_init (&operands);
 
   /* Read all .po files.  */
-  nerrors = msgfmt_operand_list_add_from_directory (&operands, directory);
+  int nerrors = msgfmt_operand_list_add_from_directory (&operands, directory);
   if (nerrors > 0)
     {
       msgfmt_operand_list_destroy (&operands);
@@ -1710,11 +1707,11 @@ msgfmt_xml_bulk (const char *directory,
     }
 
   /* Write the messages into .xml file.  */
-  status = msgdomain_write_xml_bulk (&operands,
-                                     template_file_name,
-                                     its_rules,
-                                     false,
-                                     file_name);
+  int status = msgdomain_write_xml_bulk (&operands,
+                                         template_file_name,
+                                         its_rules,
+                                         false,
+                                         file_name);
 
   msgfmt_operand_list_destroy (&operands);
 
index c127d8582f45f51ba7903ccc7ca3a622d759a543..b435b321bbf54a8ec260d70a1db338b4c74f03a7 100644 (file)
@@ -105,18 +105,6 @@ static msgdomain_list_ty *process_msgdomain_list (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  int grep_pass;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_filepos = false;
-  bool sort_by_msgid = false;
-  size_t i;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -134,27 +122,27 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
-  grep_pass = -1;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
   location_files = string_list_alloc ();
   domain_names = string_list_alloc ();
   workflow_flags = string_list_alloc ();
   sticky_flags = string_list_alloc ();
-
-  for (i = 0; i < 5; i++)
+  for (size_t i = 0; i < 5; i++)
     {
       struct grep_task *gt = &grep_task[i];
-
       gt->matcher = &matcher_grep;
       gt->pattern_count = 0;
       gt->patterns = NULL;
       gt->patterns_size = 0;
       gt->case_insensitive = false;
     }
+  bool sort_by_filepos = false;
+  bool sort_by_msgid = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -200,228 +188,230 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'C':
-        grep_pass = 3;
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        if (grep_pass < 0)
-          no_pass (opt);
-        {
-          struct grep_task *gt = &grep_task[grep_pass];
-          /* Append optarg and a newline to gt->patterns.  */
-          size_t len = strlen (optarg);
-          gt->patterns =
-            (char *) xrealloc (gt->patterns, gt->patterns_size + len + 1);
-          memcpy (gt->patterns + gt->patterns_size, optarg, len);
-          gt->patterns_size += len;
-          *(gt->patterns + gt->patterns_size) = '\n';
-          gt->patterns_size += 1;
-          gt->pattern_count++;
-        }
-        break;
-
-      case 'E':
-        if (grep_pass < 0)
-          no_pass (opt);
-        grep_task[grep_pass].matcher = &matcher_egrep;
-        break;
-
-      case 'f':
-        if (grep_pass < 0)
-          no_pass (opt);
+  {
+    int grep_pass = -1;
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
         {
-          struct grep_task *gt = &grep_task[grep_pass];
-          /* Append the contents of the specified file to gt->patterns.  */
-          FILE *fp = fopen (optarg, "r");
-
-          if (fp == NULL)
-            error (EXIT_FAILURE, errno,
-                   _("error while opening \"%s\" for reading"), optarg);
-
-          while (!feof (fp))
-            {
-              char buf[4096];
-              size_t count = fread (buf, 1, sizeof buf, fp);
-
-              if (count == 0)
-                {
-                  if (ferror (fp))
-                    error (EXIT_FAILURE, errno,
-                           _("error while reading \"%s\""), optarg);
-                  /* EOF reached.  */
-                  break;
-                }
-
-              gt->patterns =
-                (char *) xrealloc (gt->patterns, gt->patterns_size + count);
-              memcpy (gt->patterns + gt->patterns_size, buf, count);
-              gt->patterns_size += count;
-            }
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'C':
+          grep_pass = 3;
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          if (grep_pass < 0)
+            no_pass (opt);
+          {
+            struct grep_task *gt = &grep_task[grep_pass];
+            /* Append optarg and a newline to gt->patterns.  */
+            size_t len = strlen (optarg);
+            gt->patterns =
+              (char *) xrealloc (gt->patterns, gt->patterns_size + len + 1);
+            memcpy (gt->patterns + gt->patterns_size, optarg, len);
+            gt->patterns_size += len;
+            *(gt->patterns + gt->patterns_size) = '\n';
+            gt->patterns_size += 1;
+            gt->pattern_count++;
+          }
+          break;
+
+        case 'E':
+          if (grep_pass < 0)
+            no_pass (opt);
+          grep_task[grep_pass].matcher = &matcher_egrep;
+          break;
+
+        case 'f':
+          if (grep_pass < 0)
+            no_pass (opt);
+          {
+            struct grep_task *gt = &grep_task[grep_pass];
+
+            /* Append the contents of the specified file to gt->patterns.  */
+            FILE *fp = fopen (optarg, "r");
+            if (fp == NULL)
+              error (EXIT_FAILURE, errno,
+                     _("error while opening \"%s\" for reading"), optarg);
+
+            while (!feof (fp))
+              {
+                char buf[4096];
+                size_t count = fread (buf, 1, sizeof buf, fp);
+
+                if (count == 0)
+                  {
+                    if (ferror (fp))
+                      error (EXIT_FAILURE, errno,
+                             _("error while reading \"%s\""), optarg);
+                    /* EOF reached.  */
+                    break;
+                  }
+
+                gt->patterns =
+                  (char *) xrealloc (gt->patterns, gt->patterns_size + count);
+                memcpy (gt->patterns + gt->patterns_size, buf, count);
+                gt->patterns_size += count;
+              }
 
-          /* Append a final newline if file ended in a non-newline.  */
-          if (gt->patterns_size > 0
-              && *(gt->patterns + gt->patterns_size - 1) != '\n')
-            {
-              gt->patterns =
-                (char *) xrealloc (gt->patterns, gt->patterns_size + 1);
-              *(gt->patterns + gt->patterns_size) = '\n';
-              gt->patterns_size += 1;
-            }
+            /* Append a final newline if file ended in a non-newline.  */
+            if (gt->patterns_size > 0
+                && *(gt->patterns + gt->patterns_size - 1) != '\n')
+              {
+                gt->patterns =
+                  (char *) xrealloc (gt->patterns, gt->patterns_size + 1);
+                *(gt->patterns + gt->patterns_size) = '\n';
+                gt->patterns_size += 1;
+              }
 
-          fclose (fp);
-          gt->pattern_count++;
-        }
-        break;
-
-      case 'F':
-        if (grep_pass < 0)
-          no_pass (opt);
-        grep_task[grep_pass].matcher = &matcher_fgrep;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        if (grep_pass < 0)
-          no_pass (opt);
-        grep_task[grep_pass].case_insensitive = true;
-        break;
-
-      case 'J':
-        grep_pass = 0;
-        break;
-
-      case 'K':
-        grep_pass = 1;
-        break;
-
-      case 'M':
-        string_list_append (domain_names, optarg);
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
+            fclose (fp);
+            gt->pattern_count++;
+          }
+          break;
+
+        case 'F':
+          if (grep_pass < 0)
+            no_pass (opt);
+          grep_task[grep_pass].matcher = &matcher_fgrep;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          if (grep_pass < 0)
+            no_pass (opt);
+          grep_task[grep_pass].case_insensitive = true;
+          break;
+
+        case 'J':
+          grep_pass = 0;
+          break;
+
+        case 'K':
+          grep_pass = 1;
+          break;
+
+        case 'M':
+          string_list_append (domain_names, optarg);
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'N':
+          string_list_append (location_files, optarg);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case CHAR_MAX + 12: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 'S':
+          string_list_append (sticky_flags, optarg);
+          break;
+
+        case 'T':
+          grep_pass = 2;
+          break;
+
+        case 'v':
+          invert_match = true;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case 'W':
+          string_list_append (workflow_flags, optarg);
+          break;
+
+        case 'X':
+          grep_pass = 4;
+          break;
+
+        case CHAR_MAX + 1:
+          message_print_style_escape (true);
+          break;
+
+        case CHAR_MAX + 2:
+          message_print_style_indent ();
+          break;
+
+        case CHAR_MAX + 3:
+          message_print_style_escape (false);
+          break;
+
+        case CHAR_MAX + 4:
+          sort_by_filepos = true;
+          break;
+
+        case CHAR_MAX + 5:
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 6: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 7: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 8: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 9: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 10: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 11: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case 'N':
-        string_list_append (location_files, optarg);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case CHAR_MAX + 12: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 'S':
-        string_list_append (sticky_flags, optarg);
-        break;
-
-      case 'T':
-        grep_pass = 2;
-        break;
-
-      case 'v':
-        invert_match = true;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
+          break;
         }
-        break;
-
-      case 'W':
-        string_list_append (workflow_flags, optarg);
-        break;
-
-      case 'X':
-        grep_pass = 4;
-        break;
-
-      case CHAR_MAX + 1:
-        message_print_style_escape (true);
-        break;
-
-      case CHAR_MAX + 2:
-        message_print_style_indent ();
-        break;
-
-      case CHAR_MAX + 3:
-        message_print_style_escape (false);
-        break;
-
-      case CHAR_MAX + 4:
-        sort_by_filepos = true;
-        break;
-
-      case CHAR_MAX + 5:
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 6: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 7: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 8: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 9: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 10: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 11: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -444,6 +434,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     usage (EXIT_SUCCESS);
 
   /* Test whether we have an .po file name as argument.  */
+  const char *input_file = NULL;
   if (optind == argc)
     input_file = "-";
   else if (optind + 1 == argc)
@@ -460,7 +451,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            "--sort-output", "--sort-by-file");
 
   /* Compile the patterns.  */
-  for (grep_pass = 0; grep_pass < 5; grep_pass++)
+  for (int grep_pass = 0; grep_pass < 5; grep_pass++)
     {
       struct grep_task *gt = &grep_task[grep_pass];
 
@@ -479,7 +470,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
 
   /* Read input file.  */
-  result = read_catalog_file (input_file, input_syntax);
+  msgdomain_list_ty *result = read_catalog_file (input_file, input_syntax);
 
   if (grep_task[0].pattern_count > 0
       || grep_task[1].pattern_count > 0
@@ -672,9 +663,7 @@ or by email to <%s>.\n"),
 static bool
 filename_list_match (const string_list_ty *slp, const char *filename)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (fnmatch (slp->item[j], filename, FNM_PATHNAME) == 0)
       return true;
   return false;
@@ -691,9 +680,7 @@ is_string_selected (int grep_pass, const char *str, size_t len)
   if (gt->pattern_count > 0)
     {
       size_t match_size;
-      size_t match_offset;
-
-      match_offset =
+      size_t match_offset =
         gt->matcher->execute (gt->compiled_patterns, str, len,
                               &match_size, false);
       return (match_offset != (size_t) -1);
@@ -708,13 +695,8 @@ is_string_selected (int grep_pass, const char *str, size_t len)
 static bool
 is_message_selected_no_invert (const message_ty *mp)
 {
-  size_t i;
-  const char *msgstr;
-  size_t msgstr_len;
-  const char *p;
-
   /* Test whether one of mp->filepos[] is selected.  */
-  for (i = 0; i < mp->filepos_count; i++)
+  for (size_t i = 0; i < mp->filepos_count; i++)
     if (filename_list_match (location_files, mp->filepos[i].file_name))
       return true;
 
@@ -728,7 +710,7 @@ is_message_selected_no_invert (const message_ty *mp)
       || (mp->do_wrap == no && string_list_member (sticky_flags, "no-wrap")))
     return true;
   /* Recognize flag "[no-]<language>-format".  */
-  for (i = 0; i < sticky_flags->nitems; i++)
+  for (size_t i = 0; i < sticky_flags->nitems; i++)
     {
       const char *flag = sticky_flags->item[i];
       size_t flag_len = strlen (flag);
@@ -741,8 +723,7 @@ is_message_selected_no_invert (const message_ty *mp)
               flag += 3;
               flag_len -= 3;
             }
-          size_t j;
-          for (j = 0; j < NFORMATS; j++)
+          for (size_t j = 0; j < NFORMATS; j++)
             if (strlen (format_language[j]) == flag_len
                 && memcmp (format_language[j], flag, flag_len) == 0)
               {
@@ -766,47 +747,48 @@ is_message_selected_no_invert (const message_ty *mp)
     return true;
 
   /* Test msgstr using the --msgstr arguments.  */
-  msgstr = mp->msgstr;
-  msgstr_len = mp->msgstr_len;
-  /* Process each NUL delimited substring separately.  */
-  for (p = msgstr; p < msgstr + msgstr_len; )
-    {
-      size_t length = strlen (p);
+  {
+    const char *msgstr = mp->msgstr;
+    size_t msgstr_len = mp->msgstr_len;
+    /* Process each NUL delimited substring separately.  */
+    for (const char *p = msgstr; p < msgstr + msgstr_len; )
+      {
+        size_t length = strlen (p);
 
-      if (is_string_selected (2, p, length))
-        return true;
+        if (is_string_selected (2, p, length))
+          return true;
 
-      p += length + 1;
-    }
+        p += length + 1;
+      }
+  }
 
   /* Test translator comments using the --comment arguments.  */
   if (grep_task[3].pattern_count > 0
       && mp->comment != NULL && mp->comment->nitems > 0)
     {
       size_t length;
-      char *total_comment;
-      char *q;
-      size_t j;
-      bool selected;
-
-      length = 0;
-      for (j = 0; j < mp->comment->nitems; j++)
-        length += strlen (mp->comment->item[j]) + 1;
-      total_comment = (char *) xmalloca (length);
-
-      q = total_comment;
-      for (j = 0; j < mp->comment->nitems; j++)
-        {
-          size_t l = strlen (mp->comment->item[j]);
+      {
+        length = 0;
+        for (size_t j = 0; j < mp->comment->nitems; j++)
+          length += strlen (mp->comment->item[j]) + 1;
+      }
+      char *total_comment = (char *) xmalloca (length);
 
-          memcpy (q, mp->comment->item[j], l);
-          q += l;
-          *q++ = '\n';
-        }
-      if (q != total_comment + length)
-        abort ();
+      {
+        char *q = total_comment;
+        for (size_t j = 0; j < mp->comment->nitems; j++)
+          {
+            size_t l = strlen (mp->comment->item[j]);
+
+            memcpy (q, mp->comment->item[j], l);
+            q += l;
+            *q++ = '\n';
+          }
+        if (q != total_comment + length)
+          abort ();
+      }
 
-      selected = is_string_selected (3, total_comment, length);
+      bool selected = is_string_selected (3, total_comment, length);
 
       freea (total_comment);
 
@@ -819,29 +801,28 @@ is_message_selected_no_invert (const message_ty *mp)
       && mp->comment_dot != NULL && mp->comment_dot->nitems > 0)
     {
       size_t length;
-      char *total_comment;
-      char *q;
-      size_t j;
-      bool selected;
-
-      length = 0;
-      for (j = 0; j < mp->comment_dot->nitems; j++)
-        length += strlen (mp->comment_dot->item[j]) + 1;
-      total_comment = (char *) xmalloca (length);
-
-      q = total_comment;
-      for (j = 0; j < mp->comment_dot->nitems; j++)
-        {
-          size_t l = strlen (mp->comment_dot->item[j]);
+      {
+        length = 0;
+        for (size_t j = 0; j < mp->comment_dot->nitems; j++)
+          length += strlen (mp->comment_dot->item[j]) + 1;
+      }
+      char *total_comment = (char *) xmalloca (length);
 
-          memcpy (q, mp->comment_dot->item[j], l);
-          q += l;
-          *q++ = '\n';
-        }
-      if (q != total_comment + length)
-        abort ();
+      {
+        char *q = total_comment;
+        for (size_t j = 0; j < mp->comment_dot->nitems; j++)
+          {
+            size_t l = strlen (mp->comment_dot->item[j]);
+
+            memcpy (q, mp->comment_dot->item[j], l);
+            q += l;
+            *q++ = '\n';
+          }
+        if (q != total_comment + length)
+          abort ();
+      }
 
-      selected = is_string_selected (4, total_comment, length);
+      bool selected = is_string_selected (4, total_comment, length);
 
       freea (total_comment);
 
@@ -857,13 +838,11 @@ is_message_selected_no_invert (const message_ty *mp)
 static bool
 is_message_selected (const message_ty *mp)
 {
-  bool result;
-
   /* Always keep the header entry.  */
   if (is_header (mp))
     return true;
 
-  result = is_message_selected_no_invert (mp);
+  bool result = is_message_selected_no_invert (mp);
 
   if (invert_match)
     return !result;
@@ -887,9 +866,7 @@ process_message_list (const char *domain, message_list_ty *mlp)
 static msgdomain_list_ty *
 process_msgdomain_list (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     process_message_list (mdlp->item[k]->domain, mdlp->item[k]->messages);
 
   return mdlp;
index 278b41bb4aa9e2c7a7e6ba31369f0aba8a75908d..d9f0e90c59d7e3ffd56b6acec01bec1c792407bf 100644 (file)
@@ -120,14 +120,6 @@ static msgdomain_list_ty *update_msgstr_plurals (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -145,11 +137,13 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
+  const char *input_file = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
   locale = NULL;
 
   /* Parse command line options.  */
@@ -173,85 +167,86 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'i':
-        if (input_file != NULL)
-          {
-            error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
-            usage (EXIT_FAILURE);
-          }
-        input_file = optarg;
-        break;
+        case 'i':
+          if (input_file != NULL)
+            {
+              error (EXIT_SUCCESS, 0, _("at most one input file allowed"));
+              usage (EXIT_FAILURE);
+            }
+          input_file = optarg;
+          break;
 
-      case 'l':
-        locale = optarg;
-        break;
+        case 'l':
+          locale = optarg;
+          break;
 
-      case 'o':
-        output_file = optarg;
-        break;
+        case 'o':
+          output_file = optarg;
+          break;
 
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
 
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
 
-      case CHAR_MAX + 1:
-        no_translator = true;
-        break;
+        case CHAR_MAX + 1:
+          no_translator = true;
+          break;
 
-      case CHAR_MAX + 2: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
+        case CHAR_MAX + 2: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
 
-      case CHAR_MAX + 3: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
+        case CHAR_MAX + 3: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
 
-      case CHAR_MAX + 4: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
+        case CHAR_MAX + 4: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
 
-      case CHAR_MAX + 5: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
+        case CHAR_MAX + 5: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
 
-      case CHAR_MAX + 6: /* --style */
-        handle_style_option (optarg);
-        break;
+        case CHAR_MAX + 6: /* --style */
+          handle_style_option (optarg);
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -311,6 +306,7 @@ This is necessary so you can test your translations.\n"),
   if (output_file == NULL)
     output_file = xasprintf ("%s.po", catalogname);
 
+  msgdomain_list_ty *result;
   if (strcmp (output_file, "-") != 0
       && access (output_file, F_OK) == 0)
     {
@@ -468,18 +464,15 @@ or by email to <%s>.\n"),
 static const char *
 find_pot ()
 {
-  DIR *dirp;
-  char *found = NULL;
-
-  dirp = opendir (".");
+  DIR *dirp = opendir (".");
   if (dirp != NULL)
     {
+      char *found = NULL;
+
       for (;;)
         {
-          struct dirent *dp;
-
           errno = 0;
-          dp = readdir (dirp);
+          struct dirent *dp = readdir (dirp);
           if (dp != NULL)
             {
               const char *name = dp->d_name;
@@ -738,40 +731,33 @@ catalogname_for_locale (const char *locale)
     "yao_MW",   /* Yao          Malawi */
     "zap_MX"    /* Zapotec      Mexico */
   };
-  const char *dot;
-  size_t i;
 
   /* Remove the ".codeset" part from the locale.  */
-  dot = strchr (locale, '.');
-  if (dot != NULL)
-    {
-      const char *codeset_end;
-      char *shorter_locale;
-
-      codeset_end = strpbrk (dot + 1, "_@");
-      if (codeset_end == NULL)
-        codeset_end = dot + strlen (dot);
+  {
+    const char *dot = strchr (locale, '.');
+    if (dot != NULL)
+      {
+        const char *codeset_end = strpbrk (dot + 1, "_@");
+        if (codeset_end == NULL)
+          codeset_end = dot + strlen (dot);
 
-      shorter_locale = XNMALLOC (strlen (locale), char);
-      memcpy (shorter_locale, locale, dot - locale);
-      strcpy (shorter_locale + (dot - locale), codeset_end);
-      locale = shorter_locale;
-    }
+        char *shorter_locale = XNMALLOC (strlen (locale), char);
+        memcpy (shorter_locale, locale, dot - locale);
+        strcpy (shorter_locale + (dot - locale), codeset_end);
+        locale = shorter_locale;
+      }
+  }
 
   /* If the territory is the language's principal territory, drop it.  */
-  for (i = 0; i < SIZEOF (locales_with_principal_territory); i++)
+  for (size_t i = 0; i < SIZEOF (locales_with_principal_territory); i++)
     if (strcmp (locale, locales_with_principal_territory[i]) == 0)
       {
-        const char *language_end;
-        size_t len;
-        char *shorter_locale;
-
-        language_end = strchr (locale, '_');
+        const char *language_end = strchr (locale, '_');
         if (language_end == NULL)
           abort ();
 
-        len = language_end - locale;
-        shorter_locale = XNMALLOC (len + 1, char);
+        size_t len = language_end - locale;
+        char *shorter_locale = XNMALLOC (len + 1, char);
         memcpy (shorter_locale, locale, len);
         shorter_locale[len] = '\0';
         locale = shorter_locale;
@@ -786,16 +772,11 @@ catalogname_for_locale (const char *locale)
 static const char *
 language_of_locale (const char *locale)
 {
-  const char *language_end;
-
-  language_end = strpbrk (locale, "_.@");
+  const char *language_end = strpbrk (locale, "_.@");
   if (language_end != NULL)
     {
-      size_t len;
-      char *result;
-
-      len = language_end - locale;
-      result = XNMALLOC (len + 1, char);
+      size_t len = language_end - locale;
+      char *result = XNMALLOC (len + 1, char);
       memcpy (result, locale, len);
       result[len] = '\0';
 
@@ -813,17 +794,16 @@ language_of_locale (const char *locale)
 static const char *
 canonical_locale_charset ()
 {
-  const char *tmp;
-  char *old_LC_ALL;
-  const char *charset;
-
   /* Save LC_ALL environment variable.  */
-
-  tmp = getenv ("LC_ALL");
-  old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
+  char *old_LC_ALL;
+  {
+    const char *tmp = getenv ("LC_ALL");
+    old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
+  }
 
   xsetenv ("LC_ALL", locale, 1);
 
+  const char *charset;
   if (setlocale (LC_ALL, "") == NULL)
     /* Nonexistent locale.  Use anything.  */
     charset = "";
@@ -858,9 +838,7 @@ static const char *output_charset;
 static const char *
 englishname_of_language ()
 {
-  size_t i;
-
-  for (i = 0; i < language_table_size; i++)
+  for (size_t i = 0; i < language_table_size; i++)
     if (strcmp (language_table[i].code, language) == 0)
       return language_table[i].english;
 
@@ -872,76 +850,67 @@ englishname_of_language ()
 static const char *
 project_id (const char *header)
 {
-  const char *old_field;
-
   /* Return the first part of the Project-Id-Version field if present, assuming
      it was already filled in by xgettext.  */
-  old_field = get_field (header, "Project-Id-Version");
-  if (old_field != NULL && strcmp (old_field, "PACKAGE VERSION") != 0)
-    {
-      /* Remove the last word from old_field.  */
-      const char *last_space;
-
-      last_space = strrchr (old_field, ' ');
-      if (last_space != NULL)
-        {
-          while (last_space > old_field && last_space[-1] == ' ')
-            last_space--;
-          if (last_space > old_field)
-            {
-              size_t package_len = last_space - old_field;
-              char *package = XNMALLOC (package_len + 1, char);
-              memcpy (package, old_field, package_len);
-              package[package_len] = '\0';
+  {
+    const char *old_field = get_field (header, "Project-Id-Version");
+    if (old_field != NULL && strcmp (old_field, "PACKAGE VERSION") != 0)
+      {
+        /* Remove the last word from old_field.  */
+        const char *last_space = strrchr (old_field, ' ');
+        if (last_space != NULL)
+          {
+            while (last_space > old_field && last_space[-1] == ' ')
+              last_space--;
+            if (last_space > old_field)
+              {
+                size_t package_len = last_space - old_field;
+                char *package = XNMALLOC (package_len + 1, char);
+                memcpy (package, old_field, package_len);
+                package[package_len] = '\0';
 
-              return package;
-            }
-        }
-      /* It contains no version, just a package name.  */
-      return old_field;
-    }
+                return package;
+              }
+          }
+        /* It contains no version, just a package name.  */
+        return old_field;
+      }
+  }
 
   /* On native Windows, a Bourne shell is generally not available.
      Avoid error messages such as
      "msginit.exe: subprocess ... failed: No such file or directory"  */
 #if !(defined _WIN32 && ! defined __CYGWIN__)
   {
-    const char *gettextlibdir;
-    char *prog;
-    const char *argv[3];
-    pid_t child;
-    int fd[1];
-    FILE *fp;
-    char *line;
-    size_t linesize;
-    size_t linelen;
-    int exitstatus;
-
-    gettextlibdir = getenv ("GETTEXTLIBEXECDIR_SRCDIR");
+    const char *gettextlibdir = getenv ("GETTEXTLIBEXECDIR_SRCDIR");
     if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
       gettextlibdir = relocate (LIBEXECDIR "/gettext");
 
-    prog = xconcatenated_filename (gettextlibdir, "project-id", NULL);
+    char *prog = xconcatenated_filename (gettextlibdir, "project-id", NULL);
 
     /* Call the project-id shell script.  */
+    const char *argv[3];
     argv[0] = BOURNE_SHELL;
     argv[1] = prog;
     argv[2] = NULL;
-    child = create_pipe_in (prog, BOURNE_SHELL, argv, NULL, NULL,
-                            DEV_NULL, false, true, false, fd);
+
+    int fd[1];
+    pid_t child = create_pipe_in (prog, BOURNE_SHELL, argv, NULL, NULL,
+                                  DEV_NULL, false, true, false, fd);
     if (child == -1)
       goto failed;
 
     /* Retrieve its result.  */
-    fp = fdopen (fd[0], "r");
+    FILE *fp = fdopen (fd[0], "r");
     if (fp == NULL)
       {
         error (0, errno, _("fdopen() failed"));
         goto failed;
       }
 
-    line = NULL; linesize = 0;
-    linelen = getline (&line, &linesize, fp);
+    char *line = NULL;
+    size_t linesize = 0;
+    size_t linelen = getline (&line, &linesize, fp);
     if (linelen == (size_t)(-1))
       {
         error (0, 0, _("%s subprocess I/O error"), prog);
@@ -954,7 +923,8 @@ project_id (const char *header)
     fclose (fp);
 
     /* Remove zombie process from process list, and retrieve exit status.  */
-    exitstatus = wait_subprocess (child, prog, false, false, true, false, NULL);
+    int exitstatus =
+      wait_subprocess (child, prog, false, false, true, false, NULL);
     if (exitstatus != 0)
       {
         error (0, 0, _("%s subprocess failed with exit code %d"),
@@ -975,56 +945,49 @@ failed:
 static const char *
 project_id_version (const char *header)
 {
-  const char *old_field;
-
   /* Return the old value if present, assuming it was already filled in by
      xgettext.  */
-  old_field = get_field (header, "Project-Id-Version");
-  if (old_field != NULL && strcmp (old_field, "PACKAGE VERSION") != 0)
-    return old_field;
+  {
+    const char *old_field = get_field (header, "Project-Id-Version");
+    if (old_field != NULL && strcmp (old_field, "PACKAGE VERSION") != 0)
+      return old_field;
+  }
 
   /* On native Windows, a Bourne shell is generally not available.
      Avoid error messages such as
      "msginit.exe: subprocess ... failed: No such file or directory"  */
 #if !(defined _WIN32 && ! defined __CYGWIN__)
   {
-    const char *gettextlibdir;
-    char *prog;
-    const char *argv[4];
-    pid_t child;
-    int fd[1];
-    FILE *fp;
-    char *line;
-    size_t linesize;
-    size_t linelen;
-    int exitstatus;
-
-    gettextlibdir = getenv ("GETTEXTLIBEXECDIR_SRCDIR");
+    const char *gettextlibdir = getenv ("GETTEXTLIBEXECDIR_SRCDIR");
     if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
       gettextlibdir = relocate (LIBEXECDIR "/gettext");
 
-    prog = xconcatenated_filename (gettextlibdir, "project-id", NULL);
+    char *prog = xconcatenated_filename (gettextlibdir, "project-id", NULL);
 
     /* Call the project-id shell script.  */
+    const char *argv[4];
     argv[0] = BOURNE_SHELL;
     argv[1] = prog;
     argv[2] = "yes";
     argv[3] = NULL;
-    child = create_pipe_in (prog, BOURNE_SHELL, argv, NULL, NULL,
-                            DEV_NULL, false, true, false, fd);
+
+    int fd[1];
+    pid_t child = create_pipe_in (prog, BOURNE_SHELL, argv, NULL, NULL,
+                                  DEV_NULL, false, true, false, fd);
     if (child == -1)
       goto failed;
 
     /* Retrieve its result.  */
-    fp = fdopen (fd[0], "r");
+    FILE *fp = fdopen (fd[0], "r");
     if (fp == NULL)
       {
         error (0, errno, _("fdopen() failed"));
         goto failed;
       }
 
-    line = NULL; linesize = 0;
-    linelen = getline (&line, &linesize, fp);
+    char *line = NULL;
+    size_t linesize = 0;
+    size_t linelen = getline (&line, &linesize, fp);
     if (linelen == (size_t)(-1))
       {
         error (0, 0, _("%s subprocess I/O error"), prog);
@@ -1037,7 +1000,8 @@ project_id_version (const char *header)
     fclose (fp);
 
     /* Remove zombie process from process list, and retrieve exit status.  */
-    exitstatus = wait_subprocess (child, prog, false, false, true, false, NULL);
+    int exitstatus =
+      wait_subprocess (child, prog, false, false, true, false, NULL);
     if (exitstatus != 0)
       {
         error (0, 0, _("%s subprocess failed with exit code %d"),
@@ -1066,8 +1030,8 @@ po_revision_date (const char *header)
     {
       /* Assume the translator will modify the PO file now.  */
       time_t now;
-
       time (&now);
+
       return po_strftime (&now);
     }
 }
@@ -1079,36 +1043,37 @@ po_revision_date (const char *header)
 static struct passwd *
 get_user_pwd ()
 {
-  const char *username;
-  struct passwd *userpasswd;
-
   /* 1. attempt: getpwnam(getenv("USER"))  */
-  username = getenv ("USER");
-  if (username != NULL)
-    {
-      errno = 0;
-      userpasswd = getpwnam (username);
-      if (userpasswd != NULL)
-        return userpasswd;
-      if (errno != 0)
-        error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username);
-    }
+  {
+    const char *username = getenv ("USER");
+    if (username != NULL)
+      {
+        errno = 0;
+        struct passwd *userpasswd = getpwnam (username);
+        if (userpasswd != NULL)
+          return userpasswd;
+        if (errno != 0)
+          error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username);
+      }
+  }
 
   /* 2. attempt: getpwnam(getlogin())  */
-  username = getlogin ();
-  if (username != NULL)
-    {
-      errno = 0;
-      userpasswd = getpwnam (username);
-      if (userpasswd != NULL)
-        return userpasswd;
-      if (errno != 0)
-        error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username);
-    }
+  {
+    const char *username = getlogin ();
+    if (username != NULL)
+      {
+        errno = 0;
+        struct passwd *userpasswd = getpwnam (username);
+        if (userpasswd != NULL)
+          return userpasswd;
+        if (errno != 0)
+          error (EXIT_FAILURE, errno, "getpwnam(\"%s\")", username);
+      }
+  }
 
   /* 3. attempt: getpwuid(getuid())  */
   errno = 0;
-  userpasswd = getpwuid (getuid ());
+  struct passwd *userpasswd = getpwuid (getuid ());
   if (userpasswd != NULL)
     return userpasswd;
   if (errno != 0)
@@ -1125,22 +1090,16 @@ static const char *
 get_user_fullname ()
 {
 #if HAVE_PWD_H
-  struct passwd *pwd;
-
-  pwd = get_user_pwd ();
+  struct passwd *pwd = get_user_pwd ();
   if (pwd != NULL)
     {
-      const char *fullname;
-      const char *fullname_end;
-      char *result;
-
       /* Return the pw_gecos field, up to the first comma (if any).  */
-      fullname = pwd->pw_gecos;
-      fullname_end = strchr (fullname, ',');
+      const char *fullname = pwd->pw_gecos;
+      const char *fullname_end = strchr (fullname, ',');
       if (fullname_end == NULL)
         fullname_end = fullname + strlen (fullname);
 
-      result = XNMALLOC (fullname_end - fullname + 1, char);
+      char *result = XNMALLOC (fullname_end - fullname + 1, char);
       memcpy (result, fullname, fullname_end - fullname);
       result[fullname_end - fullname] = '\0';
 
@@ -1162,25 +1121,18 @@ get_user_email ()
 #if !(defined _WIN32 && ! defined __CYGWIN__)
   {
     const char *prog = relocate (LIBEXECDIR "/gettext/user-email");
-    const char *dll_dirs[2];
-    const char *argv[4];
-    pid_t child;
-    int fd[1];
-    FILE *fp;
-    char *line;
-    size_t linesize;
-    size_t linelen;
-    int exitstatus;
 
     /* The program 'hostname', that 'user-email' may invoke, is installed in
        gettextlibdir and depends on libintl and libgettextlib.  On Windows,
        in installations with shared libraries, these DLLs are installed in
        ${bindir}.  Make sure that the program can find them, even if
        ${bindir} is not in $PATH.  */
+    const char *dll_dirs[2];
     dll_dirs[0] = relocate (BINDIR);
     dll_dirs[1] = NULL;
 
     /* Ask the user for his email address.  */
+    const char *argv[4];
     argv[0] = BOURNE_SHELL;
     argv[1] = prog;
     argv[2] = _("\
@@ -1188,21 +1140,24 @@ The new message catalog should contain your email address, so that users can\n\
 give you feedback about the translations, and so that maintainers can contact\n\
 you in case of unexpected technical problems.\n");
     argv[3] = NULL;
-    child = create_pipe_in (prog, BOURNE_SHELL, argv, dll_dirs, NULL,
-                            DEV_NULL, false, true, false, fd);
+
+    int fd[1];
+    pid_t child = create_pipe_in (prog, BOURNE_SHELL, argv, dll_dirs, NULL,
+                                  DEV_NULL, false, true, false, fd);
     if (child == -1)
       goto failed;
 
     /* Retrieve his answer.  */
-    fp = fdopen (fd[0], "r");
+    FILE *fp = fdopen (fd[0], "r");
     if (fp == NULL)
       {
         error (0, errno, _("fdopen() failed"));
         goto failed;
       }
 
-    line = NULL; linesize = 0;
-    linelen = getline (&line, &linesize, fp);
+    char *line = NULL;
+    size_t linesize = 0;
+    size_t linelen = getline (&line, &linesize, fp);
     if (linelen == (size_t)(-1))
       {
         error (0, 0, _("%s subprocess I/O error"), prog);
@@ -1215,7 +1170,8 @@ you in case of unexpected technical problems.\n");
     fclose (fp);
 
     /* Remove zombie process from process list, and retrieve exit status.  */
-    exitstatus = wait_subprocess (child, prog, false, false, true, false, NULL);
+    int exitstatus =
+      wait_subprocess (child, prog, false, false, true, false, NULL);
     if (exitstatus != 0)
       {
         error (0, 0, _("%s subprocess failed with exit code %d"),
@@ -1255,10 +1211,8 @@ last_translator ()
 static const char *
 language_team_englishname ()
 {
-  size_t i;
-
   /* Search for a name depending on the catalogname.  */
-  for (i = 0; i < language_variant_table_size; i++)
+  for (size_t i = 0; i < language_variant_table_size; i++)
     if (strcmp (language_variant_table[i].code, catalogname) == 0)
       return language_variant_table[i].english;
 
@@ -1277,26 +1231,18 @@ language_team_address ()
 #if !(defined _WIN32 && ! defined __CYGWIN__)
   {
     const char *prog = relocate (PROJECTSDIR "/team-address");
-    const char *dll_dirs[2];
-    const char *argv[7];
-    pid_t child;
-    int fd[1];
-    FILE *fp;
-    char *line;
-    size_t linesize;
-    size_t linelen;
-    const char *result;
-    int exitstatus;
 
     /* The program 'urlget', that 'team-address' may invoke, is installed in
        gettextlibdir and depends on libintl and libgettextlib.  On Windows,
        in installations with shared libraries, these DLLs are installed in
        ${bindir}.  Make sure that the program can find them, even if
        ${bindir} is not in $PATH.  */
+    const char *dll_dirs[2];
     dll_dirs[0] = relocate (BINDIR);
     dll_dirs[1] = NULL;
 
     /* Call the team-address shell script.  */
+    const char *argv[7];
     argv[0] = BOURNE_SHELL;
     argv[1] = prog;
     argv[2] = relocate (PROJECTSDIR);
@@ -1304,21 +1250,25 @@ language_team_address ()
     argv[4] = catalogname;
     argv[5] = language;
     argv[6] = NULL;
-    child = create_pipe_in (prog, BOURNE_SHELL, argv, dll_dirs, NULL,
-                            DEV_NULL, false, true, false, fd);
+
+    int fd[1];
+    pid_t child = create_pipe_in (prog, BOURNE_SHELL, argv, dll_dirs, NULL,
+                                  DEV_NULL, false, true, false, fd);
     if (child == -1)
       goto failed;
 
     /* Retrieve its result.  */
-    fp = fdopen (fd[0], "r");
+    FILE *fp = fdopen (fd[0], "r");
     if (fp == NULL)
       {
         error (0, errno, _("fdopen() failed"));
         goto failed;
       }
 
-    line = NULL; linesize = 0;
-    linelen = getline (&line, &linesize, fp);
+    char *line = NULL;
+    size_t linesize = 0;
+    size_t linelen = getline (&line, &linesize, fp);
+    const char *result;
     if (linelen == (size_t)(-1))
       result = "";
     else
@@ -1331,7 +1281,8 @@ language_team_address ()
     fclose (fp);
 
     /* Remove zombie process from process list, and retrieve exit status.  */
-    exitstatus = wait_subprocess (child, prog, false, false, true, false, NULL);
+    int exitstatus =
+      wait_subprocess (child, prog, false, false, true, false, NULL);
     if (exitstatus != 0)
       {
         error (0, 0, _("%s subprocess failed with exit code %d"),
@@ -1403,58 +1354,47 @@ content_transfer_encoding ()
 static const char *
 plural_forms ()
 {
-  const char *gettextcldrdir;
-  char *prog = NULL;
-  size_t i;
-
   /* Search for a formula depending on the catalogname.  */
-  for (i = 0; i < plural_table_size; i++)
+  for (size_t i = 0; i < plural_table_size; i++)
     if (strcmp (plural_table[i].lang, catalogname) == 0)
       return plural_table[i].value;
 
   /* Search for a formula depending on the language only.  */
-  for (i = 0; i < plural_table_size; i++)
+  for (size_t i = 0; i < plural_table_size; i++)
     if (strcmp (plural_table[i].lang, language) == 0)
       return plural_table[i].value;
 
-  gettextcldrdir = getenv ("GETTEXTCLDRDIR");
+  const char *gettextcldrdir = getenv ("GETTEXTCLDRDIR");
   if (gettextcldrdir != NULL && gettextcldrdir[0] != '\0')
     {
-      const char *gettextlibdir;
-      const char *dirs[3];
-      char *last_dir;
-      const char *dll_dirs[2];
-      const char *argv[4];
-      pid_t child;
-      int fd[1];
-      FILE *fp;
-      char *line;
-      size_t linesize;
-      size_t linelen;
-      int exitstatus;
-
-      gettextlibdir = getenv ("GETTEXTLIBEXECDIR_BUILDDIR");
+      const char *gettextlibdir = getenv ("GETTEXTLIBEXECDIR_BUILDDIR");
       if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
         gettextlibdir = relocate (LIBEXECDIR "/gettext");
 
-      prog = xconcatenated_filename (gettextlibdir, "cldr-plurals", EXEEXT);
+      char *prog =
+        xconcatenated_filename (gettextlibdir, "cldr-plurals", EXEEXT);
 
-      last_dir = xstrdup (gettextcldrdir);
-      dirs[0] = "common";
-      dirs[1] = "supplemental";
-      dirs[2] = "plurals.xml";
-      for (i = 0; i < SIZEOF (dirs); i++)
-        {
-          char *dir = xconcatenated_filename (last_dir, dirs[i], NULL);
-          free (last_dir);
-          last_dir = dir;
-        }
+      char *last_dir;
+      {
+        last_dir = xstrdup (gettextcldrdir);
+        const char *dirs[3];
+        dirs[0] = "common";
+        dirs[1] = "supplemental";
+        dirs[2] = "plurals.xml";
+        for (size_t i = 0; i < SIZEOF (dirs); i++)
+          {
+            char *dir = xconcatenated_filename (last_dir, dirs[i], NULL);
+            free (last_dir);
+            last_dir = dir;
+          }
+      }
 
       /* The program 'cldr-plurals', that we invoke here, is installed in
          gettextlibdir and depends on libintl and libgettextlib.  On Windows,
          in installations with shared libraries, these DLLs are installed in
          ${bindir}.  Make sure that the program can find them, even if
          ${bindir} is not in $PATH.  */
+      const char *dll_dirs[2];
       dll_dirs[0] = relocate (BINDIR);
       dll_dirs[1] = NULL;
 
@@ -1462,26 +1402,30 @@ plural_forms ()
          argv[0] must be prog, not just the base name "cldr-plurals",
          because on Cygwin in a build with --enable-shared, the libtool
          wrapper of cldr-plurals.exe apparently needs this.  */
+      const char *argv[4];
       argv[0] = prog;
       argv[1] = language;
       argv[2] = last_dir;
       argv[3] = NULL;
-      child = create_pipe_in (prog, prog, argv, dll_dirs, NULL,
-                              DEV_NULL, false, true, false, fd);
+
+      int fd[1];
+      pid_t child = create_pipe_in (prog, prog, argv, dll_dirs, NULL,
+                                    DEV_NULL, false, true, false, fd);
       free (last_dir);
       if (child == -1)
         goto failed;
 
       /* Retrieve its result.  */
-      fp = fdopen (fd[0], "r");
+      FILE *fp = fdopen (fd[0], "r");
       if (fp == NULL)
         {
           error (0, errno, _("fdopen() failed"));
           goto failed;
         }
 
-      line = NULL; linesize = 0;
-      linelen = getline (&line, &linesize, fp);
+      char *line = NULL;
+      size_t linesize = 0;
+      size_t linelen = getline (&line, &linesize, fp);
       if (linelen == (size_t)(-1))
         {
           error (0, 0, _("%s subprocess I/O error"), prog);
@@ -1500,8 +1444,8 @@ plural_forms ()
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus = wait_subprocess (child, prog, false, false, true, false,
-                                    NULL);
+      int exitstatus =
+        wait_subprocess (child, prog, false, false, true, false, NULL);
       if (exitstatus != 0)
         {
           error (0, 0, _("%s subprocess failed with exit code %d"),
@@ -1510,10 +1454,10 @@ plural_forms ()
         }
 
       return line;
-    }
 
- failed:
-  free (prog);
+     failed:
+      free (prog);
+    }
   return NULL;
 }
 
@@ -1551,24 +1495,20 @@ static char *
 get_field (const char *header, const char *field)
 {
   size_t len = strlen (field);
-  const char *line;
 
-  for (line = header;;)
+  for (const char *line = header;;)
     {
       if (strncmp (line, field, len) == 0 && line[len] == ':')
         {
-          const char *value_start;
-          const char *value_end;
-          char *value;
-
-          value_start = line + len + 1;
+          const char *value_start = line + len + 1;
           if (*value_start == ' ')
             value_start++;
-          value_end = strchr (value_start, '\n');
+
+          const char *value_end = strchr (value_start, '\n');
           if (value_end == NULL)
             value_end = value_start + strlen (value_start);
 
-          value = XNMALLOC (value_end - value_start + 1, char);
+          char *value = XNMALLOC (value_end - value_start + 1, char);
           memcpy (value, value_start, value_end - value_start);
           value[value_end - value_start] = '\0';
 
@@ -1590,38 +1530,35 @@ static char *
 put_field (const char *old_header, const char *field, const char *value)
 {
   size_t len = strlen (field);
-  const char *line;
-  char *new_header;
-  char *p;
 
-  for (line = old_header;;)
+  for (const char *line = old_header;;)
     {
       if (strncmp (line, field, len) == 0 && line[len] == ':')
         {
-          const char *value_start;
-          const char *value_end;
-
-          value_start = line + len + 1;
+          const char *value_start = line + len + 1;
           if (*value_start == ' ')
             value_start++;
-          value_end = strchr (value_start, '\n');
+
+          const char *value_end = strchr (value_start, '\n');
           if (value_end == NULL)
             value_end = value_start + strlen (value_start);
 
-          new_header = XNMALLOC (strlen (old_header)
-                                 - (value_end - value_start)
-                                 + strlen (value)
-                                 + (*value_end != '\n' ? 1 : 0)
-                                 + 1,
-                                 char);
-          p = new_header;
-          memcpy (p, old_header, value_start - old_header);
-          p += value_start - old_header;
-          memcpy (p, value, strlen (value));
-          p += strlen (value);
-          if (*value_end != '\n')
-            *p++ = '\n';
-          strcpy (p, value_end);
+          char *new_header = XNMALLOC (strlen (old_header)
+                                       - (value_end - value_start)
+                                       + strlen (value)
+                                       + (*value_end != '\n' ? 1 : 0)
+                                       + 1,
+                                       char);
+          {
+            char *p = new_header;
+            memcpy (p, old_header, value_start - old_header);
+            p += value_start - old_header;
+            memcpy (p, value, strlen (value));
+            p += strlen (value);
+            if (*value_end != '\n')
+              *p++ = '\n';
+            strcpy (p, value_end);
+          }
 
           return new_header;
         }
@@ -1633,23 +1570,25 @@ put_field (const char *old_header, const char *field, const char *value)
         break;
     }
 
-  new_header = XNMALLOC (strlen (old_header) + 1
-                         + len + 2 + strlen (value) + 1
-                         + 1,
-                         char);
-  p = new_header;
-  memcpy (p, old_header, strlen (old_header));
-  p += strlen (old_header);
-  if (p > new_header && p[-1] != '\n')
+  char *new_header = XNMALLOC (strlen (old_header) + 1
+                               + len + 2 + strlen (value) + 1
+                               + 1,
+                               char);
+  {
+    char *p = new_header;
+    memcpy (p, old_header, strlen (old_header));
+    p += strlen (old_header);
+    if (p > new_header && p[-1] != '\n')
+      *p++ = '\n';
+    memcpy (p, field, len);
+    p += len;
+    *p++ = ':';
+    *p++ = ' ';
+    memcpy (p, value, strlen (value));
+    p += strlen (value);
     *p++ = '\n';
-  memcpy (p, field, len);
-  p += len;
-  *p++ = ':';
-  *p++ = ' ';
-  memcpy (p, value, strlen (value));
-  p += strlen (value);
-  *p++ = '\n';
-  *p = '\0';
+    *p = '\0';
+  }
 
   return new_header;
 }
@@ -1665,28 +1604,27 @@ get_title ()
      We could avoid the use of xstr_iconv() by using a separate message catalog
      and bind_textdomain_codeset(), but that doesn't seem worth the trouble
      for one single message.  */
-  const char *tmp;
-  char *old_LC_ALL;
-  char *old_LANGUAGE;
-  const char *msgid;
-  const char *english;
-  const char *result;
 
   /* First, the English title.  */
-  english = xasprintf ("%s translations for %%s package",
-                       englishname_of_language ());
+  const char *english = xasprintf ("%s translations for %%s package",
+                                   englishname_of_language ());
 
   /* Save LC_ALL, LANGUAGE environment variables.  */
-
-  tmp = getenv ("LC_ALL");
-  old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
-
-  tmp = getenv ("LANGUAGE");
-  old_LANGUAGE = (tmp != NULL ? xstrdup (tmp) : NULL);
+  char *old_LC_ALL;
+  {
+    const char *tmp = getenv ("LC_ALL");
+    old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
+  }
+  char *old_LANGUAGE;
+  {
+    const char *tmp = getenv ("LANGUAGE");
+    old_LANGUAGE = (tmp != NULL ? xstrdup (tmp) : NULL);
+  }
 
   xsetenv ("LC_ALL", locale, 1);
   unsetenv ("LANGUAGE");
 
+  const char *result;
   if (setlocale (LC_ALL, "") == NULL)
     /* Nonexistent locale.  Use the English title.  */
     result = english;
@@ -1696,7 +1634,7 @@ get_title ()
       /* TRANSLATORS: "English" needs to be replaced by your language.
          For example in it.po write "Traduzioni italiani ...",
          *not* "Traduzioni inglesi ...".  */
-      msgid = N_("English translations for %s package");
+      const char *msgid = N_("English translations for %s package");
       result = gettext (msgid);
       if (result != msgid && strcmp (result, msgid) != 0)
         /* Use the English and the foreign title.  */
@@ -1735,23 +1673,21 @@ subst_string (const char *str,
 {
   if (nsubst > 0)
     {
-      char *malloced = NULL;
-      size_t *substlen;
-      size_t i;
-      unsigned int j;
-
-      substlen = (size_t *) xmalloca (nsubst * sizeof (size_t));
-      for (j = 0; j < nsubst; j++)
+      size_t *substlen = (size_t *) xmalloca (nsubst * sizeof (size_t));
+      for (unsigned int j = 0; j < nsubst; j++)
         {
           substlen[j] = strlen (subst[j][0]);
           if (substlen[j] == 0)
             abort ();
         }
 
-      for (i = 0;;)
+      char *malloced = NULL;
+
+      for (size_t i = 0;;)
         {
           if (str[i] == '\0')
             break;
+          unsigned int j;
           for (j = 0; j < nsubst; j++)
             if (*(str + i) == *subst[j][0]
                 && strncmp (str + i, subst[j][0], substlen[j]) == 0)
@@ -1786,9 +1722,7 @@ static void
 subst_string_list (string_list_ty *slp,
                    unsigned int nsubst, const char *(*subst)[2])
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; j++)
+  for (size_t j = 0; j < slp->nitems; j++)
     slp->item[j] = subst_string (slp->item[j], nsubst, subst);
 }
 
@@ -1802,11 +1736,8 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
      contains non-ASCII characters, and we keep the UTF-8 encoding.
      Otherwise, when the POT file is plain ASCII, we use the locale's
      encoding.  */
-  bool was_utf8;
-  size_t k, j;
-
-  was_utf8 = false;
-  for (k = 0; k < mdlp->nitems; k++)
+  bool was_utf8 = false;
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -1815,7 +1746,7 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
           message_ty *header_mp = NULL;
 
           /* Search the header entry.  */
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
               {
                 header_mp = mlp->item[j];
@@ -1860,23 +1791,21 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
       nfields = SIZEOF (update_fields);
       field_last_translator = UPDATE_FIELDS_LAST_TRANSLATOR;
     }
-  const char **field_value = XNMALLOC (nfields, const char *);
-  size_t i;
 
-  for (i = 0; i < nfields; i++)
+  const char **field_value = XNMALLOC (nfields, const char *);
+  for (size_t i = 0; i < nfields; i++)
     field_value[i] = NULL;
 
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
       if (mlp->nitems > 0)
         {
           message_ty *header_mp = NULL;
-          char *header;
 
           /* Search the header entry.  */
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
               {
                 header_mp = mlp->item[j];
@@ -1892,10 +1821,10 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
               message_list_prepend (mlp, header_mp);
             }
 
-          header = xstrdup (header_mp->msgstr);
+          char *header = xstrdup (header_mp->msgstr);
 
           /* Fill in the fields.  */
-          for (i = 0; i < nfields; i++)
+          for (size_t i = 0; i < nfields; i++)
             {
               if (field_value[i] == NULL)
                 field_value[i] =
@@ -1918,11 +1847,9 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
           /* Update the comments in the header entry.  */
           if (header_mp->comment != NULL)
             {
-              const char *subst[4][2];
-              const char *id;
-              time_t now;
+              const char *id = project_id (header);
 
-              id = project_id (header);
+              const char *subst[4][2];
               subst[0][0] = "SOME DESCRIPTIVE TITLE";
               subst[0][1] = xasprintf (get_title (), id, id);
               subst[1][0] = "PACKAGE";
@@ -1930,9 +1857,13 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
               subst[2][0] = "FIRST AUTHOR <EMAIL@ADDRESS>";
               subst[2][1] = field_value[field_last_translator];
               subst[3][0] = "YEAR";
-              subst[3][1] =
-                xasprintf ("%d",
-                           (time (&now), (localtime (&now))->tm_year + 1900));
+              {
+                time_t now;
+                subst[3][1] =
+                  xasprintf ("%d",
+                             (time (&now), (localtime (&now))->tm_year + 1900));
+              }
+
               subst_string_list (header_mp->comment, SIZEOF (subst), subst);
             }
 
@@ -1953,38 +1884,36 @@ fill_header (msgdomain_list_ty *mdlp, bool fresh)
 static msgdomain_list_ty *
 update_msgstr_plurals (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
-      message_ty *header_entry;
-      unsigned long int nplurals;
-      char *untranslated_plural_msgstr;
-      size_t j;
-
-      header_entry = message_list_search (mlp, NULL, "");
-      nplurals = get_plural_count (header_entry ? header_entry->msgstr : NULL);
-      untranslated_plural_msgstr = XNMALLOC (nplurals, char);
+
+      message_ty *header_entry = message_list_search (mlp, NULL, "");
+
+      unsigned long int nplurals =
+        get_plural_count (header_entry ? header_entry->msgstr : NULL);
+
+      char *untranslated_plural_msgstr = XNMALLOC (nplurals, char);
       memset (untranslated_plural_msgstr, '\0', nplurals);
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
-          bool is_untranslated;
-          const char *p;
-          const char *pend;
 
           if (mp->msgid_plural != NULL)
             {
               /* 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;
-                  }
+              bool is_untranslated = true;
+              {
+                const char *p = mp->msgstr;
+                const char *pend = p + mp->msgstr_len;
+                for (; p < pend; p++)
+                  if (*p != '\0')
+                    {
+                      is_untranslated = false;
+                      break;
+                    }
+              }
               if (is_untranslated)
                 {
                   /* Change mp->msgstr_len consecutive empty strings into
index 3a769d362f61e39e83b0804f64598859208b8e39..d36cb157773c33ebb71b30392bd37ba0cbd4c4d3 100644 (file)
@@ -40,8 +40,7 @@ bool
 is_ascii_string_desc (string_desc_t string)
 {
   size_t len = sd_length (string);
-  size_t i;
-  for (i = 0; i < len; i++)
+  for (size_t i = 0; i < len; i++)
     if (!c_isascii ((unsigned char) sd_char_at (string, i)))
       return false;
   return true;
@@ -50,10 +49,8 @@ is_ascii_string_desc (string_desc_t string)
 bool
 is_ascii_string_list (const string_list_ty *slp)
 {
-  size_t i;
-
   if (slp != NULL)
-    for (i = 0; i < slp->nitems; i++)
+    for (size_t i = 0; i < slp->nitems; i++)
       if (!is_ascii_string (slp->item[i]))
         return false;
   return true;
@@ -62,12 +59,14 @@ is_ascii_string_list (const string_list_ty *slp)
 bool
 is_ascii_message (const message_ty *mp)
 {
-  const char *p = mp->msgstr;
-  const char *p_end = p + mp->msgstr_len;
+  {
+    const char *p = mp->msgstr;
+    const char *p_end = p + mp->msgstr_len;
 
-  for (; p < p_end; p++)
-    if (!c_isascii ((unsigned char) *p))
-      return false;
+    for (; p < p_end; p++)
+      if (!c_isascii ((unsigned char) *p))
+        return false;
+  }
 
   if (!is_ascii_string_list (mp->comment))
     return false;
@@ -99,9 +98,7 @@ is_ascii_message (const message_ty *mp)
 bool
 is_ascii_message_list (const message_list_ty *mlp)
 {
-  size_t j;
-
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (!is_ascii_message (mlp->item[j]))
       return false;
 
@@ -111,9 +108,7 @@ is_ascii_message_list (const message_list_ty *mlp)
 bool
 is_ascii_msgdomain_list (const msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     if (!is_ascii_message_list (mdlp->item[k]->messages))
       return false;
 
index 7f9c903dffbe0b6ea5e760cde63ab44b67dc0df6..c80ea21dc70b31de3c2c5925da1b84f9b8cd68f3 100644 (file)
@@ -110,34 +110,27 @@ catenate_msgdomain_list (string_list_ty *file_list,
 {
   const char * const *files = file_list->item;
   size_t nfiles = file_list->nitems;
-  msgdomain_list_ty **mdlps;
-  const char ***canon_charsets;
-  const char ***identifications;
-  msgdomain_list_ty *total_mdlp;
-  const char *canon_to_code;
-  size_t n, j;
 
   /* Read input files.  */
-  mdlps = XNMALLOC (nfiles, msgdomain_list_ty *);
-  for (n = 0; n < nfiles; n++)
+  msgdomain_list_ty **mdlps = XNMALLOC (nfiles, msgdomain_list_ty *);
+  for (size_t n = 0; n < nfiles; n++)
     mdlps[n] = read_catalog_file (files[n], input_syntax);
 
   /* Determine the canonical name of each input file's encoding.  */
-  canon_charsets = XNMALLOC (nfiles, const char **);
-  for (n = 0; n < nfiles; n++)
+  const char ***canon_charsets = XNMALLOC (nfiles, const char **);
+  for (size_t n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
-      size_t k;
 
       canon_charsets[n] = XNMALLOC (mdlp->nitems, const char *);
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           message_list_ty *mlp = mdlp->item[k]->messages;
           const char *canon_from_code = NULL;
 
           if (mlp->nitems > 0)
             {
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                   {
                     const char *header = mlp->item[j]->msgstr;
@@ -148,17 +141,14 @@ catenate_msgdomain_list (string_list_ty *file_list,
 
                         if (charsetstr != NULL)
                           {
-                            size_t len;
-                            char *charset;
-                            const char *canon_charset;
-
                             charsetstr += strlen ("charset=");
-                            len = strcspn (charsetstr, " \t\n");
-                            charset = (char *) xmalloca (len + 1);
+                            size_t len = strcspn (charsetstr, " \t\n");
+
+                            char *charset = (char *) xmalloca (len + 1);
                             memcpy (charset, charsetstr, len);
                             charset[len] = '\0';
 
-                            canon_charset = po_charset_canonicalize (charset);
+                            const char *canon_charset = po_charset_canonicalize (charset);
                             if (canon_charset == NULL)
                               {
                                 /* Don't give an error for POT files, because
@@ -216,21 +206,20 @@ catenate_msgdomain_list (string_list_ty *file_list,
     }
 
   /* Determine textual identifications of each file/domain combination.  */
-  identifications = XNMALLOC (nfiles, const char **);
-  for (n = 0; n < nfiles; n++)
+  const char ***identifications = XNMALLOC (nfiles, const char **);
+  for (size_t n = 0; n < nfiles; n++)
     {
       const char *filename = last_component (files[n]);
       msgdomain_list_ty *mdlp = mdlps[n];
-      size_t k;
 
       identifications[n] = XNMALLOC (mdlp->nitems, const char *);
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           const char *domain = mdlp->item[k]->domain;
           message_list_ty *mlp = mdlp->item[k]->messages;
           char *project_id = NULL;
 
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
               {
                 const char *header = mlp->item[j]->msgstr;
@@ -241,11 +230,9 @@ catenate_msgdomain_list (string_list_ty *file_list,
 
                     if (cp != NULL)
                       {
-                        const char *endp;
-
                         cp += sizeof ("Project-Id-Version:") - 1;
 
-                        endp = strchr (cp, '\n');
+                        const char *endp = strchr (cp, '\n');
                         if (endp == NULL)
                           endp = cp + strlen (cp);
 
@@ -255,6 +242,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
                         if (cp < endp)
                           {
                             size_t len = endp - cp;
+
                             project_id = XNMALLOC (len + 1, char);
                             memcpy (project_id, cp, len);
                             project_id[len] = '\0';
@@ -278,27 +266,22 @@ catenate_msgdomain_list (string_list_ty *file_list,
      If for a message, there is at least one non-fuzzy, non-empty translation,
      use only the non-fuzzy, non-empty translations.  Otherwise use the
      fuzzy or empty translations as well.  */
-  total_mdlp = msgdomain_list_alloc (true);
-  for (n = 0; n < nfiles; n++)
+  msgdomain_list_ty *total_mdlp = msgdomain_list_alloc (true);
+  for (size_t n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
-      size_t k;
 
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           const char *domain = mdlp->item[k]->domain;
           message_list_ty *mlp = mdlp->item[k]->messages;
-          message_list_ty *total_mlp;
+          message_list_ty *total_mlp = msgdomain_list_sublist (total_mdlp, domain, true);
 
-          total_mlp = msgdomain_list_sublist (total_mdlp, domain, true);
-
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             {
               message_ty *mp = mlp->item[j];
-              message_ty *tmp;
-              size_t i;
 
-              tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid);
+              message_ty *tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid);
               if (tmp != NULL)
                 {
                   if ((tmp->msgid_plural != NULL) != (mp->msgid_plural != NULL))
@@ -315,7 +298,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
                   tmp = message_alloc (mp->msgctxt, mp->msgid, mp->msgid_plural,
                                        NULL, 0, &mp->pos);
                   tmp->is_fuzzy = true; /* may be set to false later */
-                  for (i = 0; i < NFORMATS; i++)
+                  for (size_t i = 0; i < NFORMATS; i++)
                     tmp->is_format[i] = undecided; /* may be set to yes/no later */
                   tmp->range.min = - INT_MAX;
                   tmp->range.max = - INT_MAX;
@@ -347,12 +330,11 @@ catenate_msgdomain_list (string_list_ty *file_list,
     }
 
   /* Remove messages that are not used and need not be converted.  */
-  for (n = 0; n < nfiles; n++)
+  for (size_t n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
-      size_t k;
 
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -366,23 +348,18 @@ catenate_msgdomain_list (string_list_ty *file_list,
             canon_charsets[n][k] = NULL;
         }
     }
-  {
-    size_t k;
-
-    for (k = 0; k < total_mdlp->nitems; k++)
-      {
-        message_list_ty *mlp = total_mdlp->item[k]->messages;
+  for (size_t k = 0; k < total_mdlp->nitems; k++)
+    {
+      message_list_ty *mlp = total_mdlp->item[k]->messages;
 
-        message_list_remove_if_not (mlp, is_message_selected);
-      }
-  }
+      message_list_remove_if_not (mlp, is_message_selected);
+    }
 
   /* Determine the common known a-priori encoding, if any.  */
   if (nfiles > 0)
     {
       bool all_same_encoding = true;
-
-      for (n = 1; n < nfiles; n++)
+      for (size_t n = 1; n < nfiles; n++)
         if (mdlps[n]->encoding != mdlps[0]->encoding)
           {
             all_same_encoding = false;
@@ -396,7 +373,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
   /* Determine whether we need a target encoding that contains the control
      characters needed for escaping file names with spaces.  */
   bool has_filenames_with_spaces = false;
-  for (n = 0; n < nfiles; n++)
+  for (size_t n = 0; n < nfiles; n++)
     {
       has_filenames_with_spaces =
         has_filenames_with_spaces
@@ -404,6 +381,7 @@ catenate_msgdomain_list (string_list_ty *file_list,
     }
 
   /* Determine the target encoding for the remaining messages.  */
+  const char *canon_to_code;
   if (to_code != NULL)
     {
       /* Canonicalize target encoding.  */
@@ -432,12 +410,11 @@ catenate_msgdomain_list (string_list_ty *file_list,
       bool with_UTF8 = false;
       bool all_ASCII_compatible = true;
 
-      for (n = 0; n < nfiles; n++)
+      for (size_t n = 0; n < nfiles; n++)
         {
           msgdomain_list_ty *mdlp = mdlps[n];
-          size_t k;
 
-          for (k = 0; k < mdlp->nitems; k++)
+          for (size_t k = 0; k < mdlp->nitems; k++)
             if (canon_charsets[n][k] != NULL)
               {
                 if (canon_charsets[n][k] == po_charset_ascii)
@@ -516,12 +493,11 @@ Converting the output to %s.\n\
 
   /* Now convert the remaining messages to canon_to_code.  */
   if (canon_to_code != NULL)
-    for (n = 0; n < nfiles; n++)
+    for (size_t n = 0; n < nfiles; n++)
       {
         msgdomain_list_ty *mdlp = mdlps[n];
-        size_t k;
 
-        for (k = 0; k < mdlp->nitems; k++)
+        for (size_t k = 0; k < mdlp->nitems; k++)
           if (canon_charsets[n][k] != NULL)
             /* If the user hasn't given a to_code, don't bother doing a noop
                conversion that would only replace the charset name in the
@@ -544,20 +520,18 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
       }
 
   /* Fill the resulting messages.  */
-  for (n = 0; n < nfiles; n++)
+  for (size_t n = 0; n < nfiles; n++)
     {
       msgdomain_list_ty *mdlp = mdlps[n];
-      size_t k;
 
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           message_list_ty *mlp = mdlp->item[k]->messages;
 
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             {
               message_ty *mp = mlp->item[j];
               message_ty *tmp = mp->tmp;
-              size_t i;
 
               /* No need to discard unneeded weak translations here;
                  they have already been filtered out above.  */
@@ -568,17 +542,17 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
                   tmp->msgstr_len = mp->msgstr_len;
                   tmp->pos = mp->pos;
                   if (mp->comment)
-                    for (i = 0; i < mp->comment->nitems; i++)
+                    for (size_t i = 0; i < mp->comment->nitems; i++)
                       message_comment_append (tmp, mp->comment->item[i]);
                   if (mp->comment_dot)
-                    for (i = 0; i < mp->comment_dot->nitems; i++)
+                    for (size_t i = 0; i < mp->comment_dot->nitems; i++)
                       message_comment_dot_append (tmp,
                                                   mp->comment_dot->item[i]);
-                  for (i = 0; i < mp->filepos_count; i++)
+                  for (size_t i = 0; i < mp->filepos_count; i++)
                     message_comment_filepos (tmp, mp->filepos[i].file_name,
                                              mp->filepos[i].line_number);
                   tmp->is_fuzzy = mp->is_fuzzy;
-                  for (i = 0; i < NFORMATS; i++)
+                  for (size_t i = 0; i < NFORMATS; i++)
                     tmp->is_format[i] = mp->is_format[i];
                   tmp->range = mp->range;
                   tmp->do_wrap = mp->do_wrap;
@@ -601,16 +575,16 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
                       tmp->prev_msgid_plural = mp->prev_msgid_plural;
                     }
                   if (mp->comment && tmp->comment == NULL)
-                    for (i = 0; i < mp->comment->nitems; i++)
+                    for (size_t i = 0; i < mp->comment->nitems; i++)
                       message_comment_append (tmp, mp->comment->item[i]);
                   if (mp->comment_dot && tmp->comment_dot == NULL)
-                    for (i = 0; i < mp->comment_dot->nitems; i++)
+                    for (size_t i = 0; i < mp->comment_dot->nitems; i++)
                       message_comment_dot_append (tmp,
                                                   mp->comment_dot->item[i]);
-                  for (i = 0; i < mp->filepos_count; i++)
+                  for (size_t i = 0; i < mp->filepos_count; i++)
                     message_comment_filepos (tmp, mp->filepos[i].file_name,
                                              mp->filepos[i].line_number);
-                  for (i = 0; i < NFORMATS; i++)
+                  for (size_t i = 0; i < NFORMATS; i++)
                     if (tmp->is_format[i] == undecided)
                       tmp->is_format[i] = mp->is_format[i];
                   if (tmp->range.min == - INT_MAX
@@ -637,29 +611,30 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
                   /* Copy mp, among others, into tmp.  */
                   char *id = xasprintf ("#-#-#-#-#  %s  #-#-#-#-#",
                                         identifications[n][k]);
-                  size_t nbytes;
 
                   if (tmp->alternative_count == 0)
                     tmp->pos = mp->pos;
 
-                  i = tmp->alternative_count;
-                  nbytes = (i + 1) * sizeof (struct altstr);
-                  tmp->alternative = xrealloc (tmp->alternative, nbytes);
-                  tmp->alternative[i].msgstr = mp->msgstr;
-                  tmp->alternative[i].msgstr_len = mp->msgstr_len;
-                  tmp->alternative[i].msgstr_end =
-                    tmp->alternative[i].msgstr + tmp->alternative[i].msgstr_len;
-                  tmp->alternative[i].comment = mp->comment;
-                  tmp->alternative[i].comment_dot = mp->comment_dot;
-                  tmp->alternative[i].id = id;
-                  tmp->alternative_count = i + 1;
-
-                  for (i = 0; i < mp->filepos_count; i++)
+                  {
+                    size_t i = tmp->alternative_count;
+                    size_t nbytes = (i + 1) * sizeof (struct altstr);
+                    tmp->alternative = xrealloc (tmp->alternative, nbytes);
+                    tmp->alternative[i].msgstr = mp->msgstr;
+                    tmp->alternative[i].msgstr_len = mp->msgstr_len;
+                    tmp->alternative[i].msgstr_end =
+                      tmp->alternative[i].msgstr + tmp->alternative[i].msgstr_len;
+                    tmp->alternative[i].comment = mp->comment;
+                    tmp->alternative[i].comment_dot = mp->comment_dot;
+                    tmp->alternative[i].id = id;
+                    tmp->alternative_count = i + 1;
+                  }
+
+                  for (size_t i = 0; i < mp->filepos_count; i++)
                     message_comment_filepos (tmp, mp->filepos[i].file_name,
                                              mp->filepos[i].line_number);
                   if (!mp->is_fuzzy)
                     tmp->is_fuzzy = false;
-                  for (i = 0; i < NFORMATS; i++)
+                  for (size_t i = 0; i < NFORMATS; i++)
                     if (mp->is_format[i] == yes)
                       tmp->is_format[i] = yes;
                     else if (mp->is_format[i] == no
@@ -689,158 +664,170 @@ UTF-8 encoded from the beginning, i.e. already in your source code files.\n"),
             }
         }
     }
-  {
-    size_t k;
-
-    for (k = 0; k < total_mdlp->nitems; k++)
-      {
-        message_list_ty *mlp = total_mdlp->item[k]->messages;
-
-        for (j = 0; j < mlp->nitems; j++)
-          {
-            message_ty *tmp = mlp->item[j];
+  for (size_t k = 0; k < total_mdlp->nitems; k++)
+    {
+      message_list_ty *mlp = total_mdlp->item[k]->messages;
 
-            if (tmp->alternative_count > 0)
-              {
-                /* Test whether all alternative translations are equal.  */
-                struct altstr *first = &tmp->alternative[0];
-                size_t i;
-
-                for (i = 0; i < tmp->alternative_count; i++)
-                  if (!(tmp->alternative[i].msgstr_len == first->msgstr_len
-                        && memcmp (tmp->alternative[i].msgstr, first->msgstr,
-                                   first->msgstr_len) == 0))
-                    break;
+      for (size_t j = 0; j < mlp->nitems; j++)
+        {
+          message_ty *tmp = mlp->item[j];
 
-                if (i == tmp->alternative_count)
+          if (tmp->alternative_count > 0)
+            {
+              /* Test whether all alternative translations are equal.  */
+              struct altstr *first = &tmp->alternative[0];
+
+              bool all_equal = true;
+              for (size_t i = 0; i < tmp->alternative_count; i++)
+                if (!(tmp->alternative[i].msgstr_len == first->msgstr_len
+                      && memcmp (tmp->alternative[i].msgstr, first->msgstr,
+                                 first->msgstr_len) == 0))
                   {
-                    /* All alternatives are equal.  */
-                    tmp->msgstr = first->msgstr;
-                    tmp->msgstr_len = first->msgstr_len;
+                    all_equal = false;
+                    break;
                   }
-                else
+
+              if (all_equal)
+                {
+                  /* All alternatives are equal.  */
+                  tmp->msgstr = first->msgstr;
+                  tmp->msgstr_len = first->msgstr_len;
+                }
+              else
+                {
+                  /* Concatenate the alternative msgstrs into a single one,
+                     separated by markers.  */
+                  char *new_msgstr;
                   {
-                    /* Concatenate the alternative msgstrs into a single one,
-                       separated by markers.  */
-                    size_t len;
-                    const char *p;
-                    const char *p_end;
-                    char *new_msgstr;
-                    char *np;
-
-                    len = 0;
-                    for (i = 0; i < tmp->alternative_count; i++)
+                    size_t len = 0;
+                    for (size_t i = 0; i < tmp->alternative_count; i++)
                       {
                         size_t id_len = strlen (tmp->alternative[i].id);
 
                         len += tmp->alternative[i].msgstr_len;
 
-                        p = tmp->alternative[i].msgstr;
-                        p_end = tmp->alternative[i].msgstr_end;
+                        const char *p = tmp->alternative[i].msgstr;
+                        const char *p_end = tmp->alternative[i].msgstr_end;
                         for (; p < p_end; p += strlen (p) + 1)
                           len += id_len + 2;
                       }
-
                     new_msgstr = XNMALLOC (len, char);
-                    np = new_msgstr;
-                    for (;;)
-                      {
-                        /* Test whether there's one more plural form to
-                           process.  */
-                        for (i = 0; i < tmp->alternative_count; i++)
-                          if (tmp->alternative[i].msgstr
-                              < tmp->alternative[i].msgstr_end)
+                  }
+                  char *np = new_msgstr;
+                  for (;;)
+                    {
+                      /* Test whether there's one more plural form to
+                         process.  */
+                      bool all_plural_forms_processed = true;
+                      for (size_t i = 0; i < tmp->alternative_count; i++)
+                        if (tmp->alternative[i].msgstr
+                            < tmp->alternative[i].msgstr_end)
+                          {
+                            all_plural_forms_processed = false;
                             break;
-                        if (i == tmp->alternative_count)
-                          break;
+                          }
 
-                        /* Process next plural form.  */
-                        for (i = 0; i < tmp->alternative_count; i++)
-                          if (tmp->alternative[i].msgstr
-                              < tmp->alternative[i].msgstr_end)
-                            {
-                              if (np > new_msgstr && np[-1] != '\0'
-                                  && np[-1] != '\n')
-                                *np++ = '\n';
+                      if (all_plural_forms_processed)
+                        break;
 
-                              len = strlen (tmp->alternative[i].id);
+                      /* Process next plural form.  */
+                      for (size_t i = 0; i < tmp->alternative_count; i++)
+                        if (tmp->alternative[i].msgstr
+                            < tmp->alternative[i].msgstr_end)
+                          {
+                            if (np > new_msgstr && np[-1] != '\0'
+                                && np[-1] != '\n')
+                              *np++ = '\n';
+
+                            {
+                              size_t len = strlen (tmp->alternative[i].id);
                               memcpy (np, tmp->alternative[i].id, len);
                               np += len;
                               *np++ = '\n';
+                            }
 
-                              len = strlen (tmp->alternative[i].msgstr);
+                            {
+                              size_t len = strlen (tmp->alternative[i].msgstr);
                               memcpy (np, tmp->alternative[i].msgstr, len);
                               np += len;
                               tmp->alternative[i].msgstr += len + 1;
                             }
+                          }
 
-                        /* Plural forms are separated by NUL bytes.  */
-                        *np++ = '\0';
-                      }
-                    tmp->msgstr = new_msgstr;
-                    tmp->msgstr_len = np - new_msgstr;
+                      /* Plural forms are separated by NUL bytes.  */
+                      *np++ = '\0';
+                    }
+                  tmp->msgstr = new_msgstr;
+                  tmp->msgstr_len = np - new_msgstr;
 
-                    tmp->is_fuzzy = true;
-                  }
+                  tmp->is_fuzzy = true;
+                }
 
+              {
                 /* Test whether all alternative comments are equal.  */
-                for (i = 0; i < tmp->alternative_count; i++)
+                bool all_comments_equal = true;
+                for (size_t i = 0; i < tmp->alternative_count; i++)
                   if (tmp->alternative[i].comment == NULL
                       || !string_list_equal (tmp->alternative[i].comment,
                                              first->comment))
-                    break;
+                    {
+                      all_comments_equal = false;
+                      break;
+                    }
 
-                if (i == tmp->alternative_count)
+                if (all_comments_equal)
                   /* All alternatives are equal.  */
                   tmp->comment = first->comment;
                 else
                   /* Concatenate the alternative comments into a single one,
                      separated by markers.  */
-                  for (i = 0; i < tmp->alternative_count; i++)
+                  for (size_t i = 0; i < tmp->alternative_count; i++)
                     {
                       string_list_ty *slp = tmp->alternative[i].comment;
 
                       if (slp != NULL)
                         {
-                          size_t l;
-
                           message_comment_append (tmp, tmp->alternative[i].id);
-                          for (l = 0; l < slp->nitems; l++)
+                          for (size_t l = 0; l < slp->nitems; l++)
                             message_comment_append (tmp, slp->item[l]);
                         }
                     }
+              }
 
+              {
                 /* Test whether all alternative dot comments are equal.  */
-                for (i = 0; i < tmp->alternative_count; i++)
+                bool all_comments_equal = true;
+                for (size_t i = 0; i < tmp->alternative_count; i++)
                   if (tmp->alternative[i].comment_dot == NULL
                       || !string_list_equal (tmp->alternative[i].comment_dot,
                                              first->comment_dot))
-                    break;
+                    {
+                      all_comments_equal = false;
+                      break;
+                    }
 
-                if (i == tmp->alternative_count)
+                if (all_comments_equal)
                   /* All alternatives are equal.  */
                   tmp->comment_dot = first->comment_dot;
                 else
                   /* Concatenate the alternative dot comments into a single one,
                      separated by markers.  */
-                  for (i = 0; i < tmp->alternative_count; i++)
+                  for (size_t i = 0; i < tmp->alternative_count; i++)
                     {
                       string_list_ty *slp = tmp->alternative[i].comment_dot;
 
                       if (slp != NULL)
                         {
-                          size_t l;
-
                           message_comment_dot_append (tmp,
                                                       tmp->alternative[i].id);
-                          for (l = 0; l < slp->nitems; l++)
+                          for (size_t l = 0; l < slp->nitems; l++)
                             message_comment_dot_append (tmp, slp->item[l]);
                         }
                     }
               }
-          }
-      }
-  }
+            }
+        }
+    }
 
   return total_mdlp;
 }
index 070edee7a566b5d25b85b77a40f851fda86760a8..00cbcf3b98eddab4fc31ddc41444b9011e85afbf 100644 (file)
 void
 check_pot_charset (const msgdomain_list_ty *mdlp, const char *filename)
 {
-  size_t j, k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       const message_list_ty *mlp = mdlp->item[k]->messages;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
           {
             const char *header = mlp->item[j]->msgstr;
@@ -69,12 +67,10 @@ check_pot_charset (const msgdomain_list_ty *mdlp, const char *filename)
 
                 if (charsetstr != NULL)
                   {
-                    size_t len;
-                    char *charset;
-
                     charsetstr += strlen ("charset=");
-                    len = strcspn (charsetstr, " \t\n");
-                    charset = (char *) xmalloca (len + 1);
+                    size_t len = strcspn (charsetstr, " \t\n");
+
+                    char *charset = (char *) xmalloca (len + 1);
                     memcpy (charset, charsetstr, len);
                     charset[len] = '\0';
 
@@ -103,21 +99,16 @@ check_pot_charset (const msgdomain_list_ty *mdlp, const char *filename)
 void
 compare_po_locale_charsets (const msgdomain_list_ty *mdlp)
 {
-  const char *locale_code;
-  const char *canon_locale_code;
-  bool warned;
-  size_t j, k;
-
   /* Check whether the locale encoding and the PO file's encoding are the
      same.  Otherwise emit a warning.  */
-  locale_code = locale_charset ();
-  canon_locale_code = po_charset_canonicalize (locale_code);
-  warned = false;
-  for (k = 0; k < mdlp->nitems; k++)
+  const char *locale_code = locale_charset ();
+  const char *canon_locale_code = po_charset_canonicalize (locale_code);
+  bool warned = false;
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       const message_list_ty *mlp = mdlp->item[k]->messages;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
           {
             const char *header = mlp->item[j]->msgstr;
@@ -128,22 +119,21 @@ compare_po_locale_charsets (const msgdomain_list_ty *mdlp)
 
                 if (charsetstr != NULL)
                   {
-                    size_t len;
-                    char *charset;
-                    const char *canon_charset;
-
                     charsetstr += strlen ("charset=");
-                    len = strcspn (charsetstr, " \t\n");
-                    charset = (char *) xmalloca (len + 1);
+                    size_t len = strcspn (charsetstr, " \t\n");
+
+                    char *charset = (char *) xmalloca (len + 1);
                     memcpy (charset, charsetstr, len);
                     charset[len] = '\0';
 
-                    canon_charset = po_charset_canonicalize (charset);
+                    const char *canon_charset = po_charset_canonicalize (charset);
                     if (canon_charset == NULL)
                       error (EXIT_FAILURE, 0,
                              _("present charset \"%s\" is not a portable encoding name"),
                              charset);
+
                     freea (charset);
+
                     if (canon_locale_code != canon_charset)
                       {
                         size_t prefix_width =
index fc743eee1ccc3c035dc2bdd9ca8ddc5443702977..412a0f9650d8ad13dcd82acc60f6ee5f90d82da8 100644 (file)
@@ -58,11 +58,9 @@ plural_expression_histogram (const struct plural_distribution *self,
   if (min <= max)
     {
       const struct expression *expr = self->expr;
-      unsigned long n;
-      unsigned int count;
 
-      count = 0;
-      for (n = min; n <= max; n++)
+      unsigned int count = 0;
+      for (unsigned long n = min; n <= max; n++)
         {
           struct eval_result res = plural_eval (expr, n);
 
@@ -101,9 +99,7 @@ check_plural_eval (const struct expression *plural_expr,
     /* nplurals_value is nonsense.  Don't risk an out-of-memory.  */
     array = NULL;
 
-  unsigned long n;
-
-  for (n = 0; n <= 1000; n++)
+  for (unsigned long n = 0; n <= 1000; n++)
     {
       struct eval_result res = plural_eval (plural_expr, n);
       if (res.status != PE_OK)
@@ -152,9 +148,7 @@ check_plural_eval (const struct expression *plural_expr,
   /* Normalize the array[val] statistics.  */
   if (array != NULL)
     {
-      unsigned long val;
-
-      for (val = 0; val < nplurals_value; val++)
+      for (unsigned long val = 0; val < nplurals_value; val++)
         array[val] = (array[val] == OFTEN ? 1 : 0);
     }
 
@@ -176,20 +170,15 @@ plural_help (const char *nullentry)
   struct plural_table_entry *ptentry = NULL;
 
   {
-    const char *language;
-
-    language = c_strstr (nullentry, "Language: ");
+    const char *language = c_strstr (nullentry, "Language: ");
     if (language != NULL)
       {
-        size_t len;
-
         language += 10;
-        len = strcspn (language, " \t\n");
+
+        size_t len = strcspn (language, " \t\n");
         if (len > 0)
           {
-            size_t j;
-
-            for (j = 0; j < plural_table_size; j++)
+            for (size_t j = 0; j < plural_table_size; j++)
               if (len == strlen (plural_table[j].lang)
                   && strncmp (language, plural_table[j].lang, len) == 0)
                 {
@@ -202,15 +191,12 @@ plural_help (const char *nullentry)
 
   if (ptentry == NULL)
     {
-      const char *language;
-
-      language = c_strstr (nullentry, "Language-Team: ");
+      const char *language = c_strstr (nullentry, "Language-Team: ");
       if (language != NULL)
         {
-          size_t j;
-
           language += 15;
-          for (j = 0; j < plural_table_size; j++)
+
+          for (size_t j = 0; j < plural_table_size; j++)
             if (str_startswith (language, plural_table[j].language))
               {
                 ptentry = &plural_table[j];
@@ -246,26 +232,14 @@ check_plural (const message_list_ty *mlp,
               xerror_handler_ty xeh)
 {
   int seen_errors = 0;
-  const message_ty *has_plural;
-  unsigned long min_nplurals;
-  const message_ty *min_pos;
-  unsigned long max_nplurals;
-  const message_ty *max_pos;
-  struct plural_distribution distribution;
-  size_t j;
-  message_ty *header;
 
   /* Determine whether mlp has plural entries.  */
-  has_plural = NULL;
-  min_nplurals = ULONG_MAX;
-  min_pos = NULL;
-  max_nplurals = 0;
-  max_pos = NULL;
-  distribution.expr = NULL;
-  distribution.often = NULL;
-  distribution.often_length = 0;
-  distribution.histogram = NULL;
-  for (j = 0; j < mlp->nitems; j++)
+  const message_ty *has_plural = NULL;
+  unsigned long min_nplurals = ULONG_MAX;
+  const message_ty *min_pos = NULL;
+  unsigned long max_nplurals = 0;
+  const message_ty *max_pos = NULL;
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -274,18 +248,20 @@ check_plural (const message_list_ty *mlp,
           && !(ignore_fuzzy_messages && (mp->is_fuzzy && !is_header (mp)))
           && mp->msgid_plural != NULL)
         {
-          const char *p;
-          const char *p_end;
-          unsigned long n;
-
           if (has_plural == NULL)
             has_plural = mp;
 
-          n = 0;
-          for (p = mp->msgstr, p_end = p + mp->msgstr_len;
-               p < p_end;
-               p += strlen (p) + 1)
-            n++;
+          unsigned long n;
+          {
+            n = 0;
+            const char *p;
+            const char *p_end;
+            for (p = mp->msgstr, p_end = p + mp->msgstr_len;
+                 p < p_end;
+                 p += strlen (p) + 1)
+              n++;
+          }
+
           if (min_nplurals > n)
             {
               min_nplurals = n;
@@ -299,19 +275,21 @@ check_plural (const message_list_ty *mlp,
         }
     }
 
+  struct plural_distribution distribution;
+  distribution.expr = NULL;
+  distribution.often = NULL;
+  distribution.often_length = 0;
+  distribution.histogram = NULL;
+
   /* Look at the plural entry for this domain.
-     Cf, function extract_plural_expression.  */
-  header = message_list_search (mlp, NULL, "");
+     Cf. function extract_plural_expression.  */
+  message_ty *header = message_list_search (mlp, NULL, "");
   if (header != NULL && !header->obsolete)
     {
-      const char *nullentry;
-      const char *plural;
-      const char *nplurals;
+      const char *nullentry = header->msgstr;
 
-      nullentry = header->msgstr;
-
-      plural = c_strstr (nullentry, "plural=");
-      nplurals = c_strstr (nullentry, "nplurals=");
+      const char *plural = c_strstr (nullentry, "plural=");
+      const char *nplurals = c_strstr (nullentry, "nplurals=");
       if (plural == NULL && has_plural != NULL)
         {
           const char *msg1 =
@@ -362,62 +340,64 @@ check_plural (const message_list_ty *mlp,
         }
       if (plural != NULL && nplurals != NULL)
         {
-          const char *endp;
-          unsigned long int nplurals_value;
-          struct parse_args args;
-          const struct expression *plural_expr;
-
           /* First check the number.  */
           nplurals += 9;
-          while (*nplurals != '\0' && c_isspace ((unsigned char) *nplurals))
-            ++nplurals;
-          endp = nplurals;
-          nplurals_value = 0;
-          if (*nplurals >= '0' && *nplurals <= '9')
-            nplurals_value = strtoul (nplurals, (char **) &endp, 10);
-          if (nplurals == endp)
-            {
-              const char *msg = _("invalid nplurals value");
-              char *help = plural_help (nullentry);
-
-              if (help != NULL)
-                {
-                  char *msgext = xasprintf ("%s\n%s", msg, help);
-                  xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
-                               msgext);
-                  free (msgext);
-                  free (help);
-                }
-              else
-                xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
-                             msg);
+          unsigned long int nplurals_value;
+          {
+            while (*nplurals != '\0' && c_isspace ((unsigned char) *nplurals))
+              ++nplurals;
+            const char *endp = nplurals;
+            nplurals_value = 0;
+            if (*nplurals >= '0' && *nplurals <= '9')
+              nplurals_value = strtoul (nplurals, (char **) &endp, 10);
+            if (nplurals == endp)
+              {
+                const char *msg = _("invalid nplurals value");
+                char *help = plural_help (nullentry);
+
+                if (help != NULL)
+                  {
+                    char *msgext = xasprintf ("%s\n%s", msg, help);
+                    xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
+                                 msgext);
+                    free (msgext);
+                    free (help);
+                  }
+                else
+                  xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+                               msg);
 
-              seen_errors++;
-            }
+                seen_errors++;
+              }
+          }
 
           /* Then check the expression.  */
           plural += 7;
-          args.cp = plural;
-          if (parse_plural_expression (&args) != 0)
-            {
-              const char *msg = _("invalid plural expression");
-              char *help = plural_help (nullentry);
-
-              if (help != NULL)
-                {
-                  char *msgext = xasprintf ("%s\n%s", msg, help);
-                  xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
-                               msgext);
-                  free (msgext);
-                  free (help);
-                }
-              else
-                xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
-                             msg);
+          const struct expression *plural_expr;
+          {
+            struct parse_args args;
+            args.cp = plural;
+            if (parse_plural_expression (&args) != 0)
+              {
+                const char *msg = _("invalid plural expression");
+                char *help = plural_help (nullentry);
+
+                if (help != NULL)
+                  {
+                    char *msgext = xasprintf ("%s\n%s", msg, help);
+                    xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
+                                 msgext);
+                    free (msgext);
+                    free (help);
+                  }
+                else
+                  xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+                               msg);
 
-              seen_errors++;
-            }
-          plural_expr = args.res;
+                seen_errors++;
+              }
+            plural_expr = args.res;
+          }
 
           /* See whether nplurals and plural fit together.  */
           if (!seen_errors)
@@ -520,12 +500,13 @@ formatstring_error_logger (void *data, const char *format, ...)
   struct formatstring_error_logger_locals *l =
     (struct formatstring_error_logger_locals *) data;
   va_list args;
-  char *msg;
-
   va_start (args, format);
+
+  char *msg;
   if (vasprintf (&msg, format, args) < 0)
     l->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
                     _("memory exhausted"));
+
   va_end (args);
   l->xeh->xerror (CAT_SEVERITY_ERROR,
                   l->curr_mp,
@@ -555,100 +536,100 @@ check_pair (const message_ty *mp,
             int check_accelerators, char accelerator_char,
             xerror_handler_ty xeh)
 {
-  int seen_errors;
-  int has_newline;
-  unsigned int j;
-
   /* If the msgid string is empty we have the special entry reserved for
      information about the translation.  */
   if (msgid[0] == '\0')
     return 0;
 
-  seen_errors = 0;
+  int seen_errors = 0;
 
   if (check_newlines)
     {
       /* Test 1: check whether all or none of the strings begin with a '\n'.  */
-      has_newline = (msgid[0] == '\n');
-#define TEST_NEWLINE(p) (p[0] == '\n')
-      if (msgid_plural != NULL)
-        {
-          const char *p;
-
-          if (TEST_NEWLINE(msgid_plural) != has_newline)
-            {
-              xeh->xerror (CAT_SEVERITY_ERROR,
-                           mp, msgid_pos->file_name, msgid_pos->line_number,
-                           (size_t)(-1), false,
-                           _("'msgid' and 'msgid_plural' entries do not both begin with '\\n'"));
-              seen_errors++;
-            }
-          for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
-            if (TEST_NEWLINE(p) != has_newline)
+      {
+        int has_newline = (msgid[0] == '\n');
+        #define TEST_NEWLINE(p) (p[0] == '\n')
+        if (msgid_plural != NULL)
+          {
+            if (TEST_NEWLINE(msgid_plural) != has_newline)
               {
-                char *msg =
-                  xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both begin with '\\n'"),
-                             j);
                 xeh->xerror (CAT_SEVERITY_ERROR,
                              mp, msgid_pos->file_name, msgid_pos->line_number,
-                             (size_t)(-1), false, msg);
-                free (msg);
+                             (size_t)(-1), false,
+                             _("'msgid' and 'msgid_plural' entries do not both begin with '\\n'"));
                 seen_errors++;
               }
-        }
-      else
-        {
-          if (TEST_NEWLINE(msgstr) != has_newline)
-            {
-              xeh->xerror (CAT_SEVERITY_ERROR,
-                           mp, msgid_pos->file_name, msgid_pos->line_number,
-                           (size_t)(-1), false,
-                           _("'msgid' and 'msgstr' entries do not both begin with '\\n'"));
-              seen_errors++;
-            }
-        }
-#undef TEST_NEWLINE
+            const char *p;
+            unsigned int j;
+            for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
+              if (TEST_NEWLINE(p) != has_newline)
+                {
+                  char *msg =
+                    xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both begin with '\\n'"),
+                               j);
+                  xeh->xerror (CAT_SEVERITY_ERROR,
+                               mp, msgid_pos->file_name, msgid_pos->line_number,
+                               (size_t)(-1), false, msg);
+                  free (msg);
+                  seen_errors++;
+                }
+          }
+        else
+          {
+            if (TEST_NEWLINE(msgstr) != has_newline)
+              {
+                xeh->xerror (CAT_SEVERITY_ERROR,
+                             mp, msgid_pos->file_name, msgid_pos->line_number,
+                             (size_t)(-1), false,
+                             _("'msgid' and 'msgstr' entries do not both begin with '\\n'"));
+                seen_errors++;
+              }
+          }
+        #undef TEST_NEWLINE
+      }
 
       /* Test 2: check whether all or none of the strings end with a '\n'.  */
-      has_newline = (msgid[strlen (msgid) - 1] == '\n');
-#define TEST_NEWLINE(p) (p[0] != '\0' && p[strlen (p) - 1] == '\n')
-      if (msgid_plural != NULL)
-        {
-          const char *p;
-
-          if (TEST_NEWLINE(msgid_plural) != has_newline)
-            {
-              xeh->xerror (CAT_SEVERITY_ERROR,
-                           mp, msgid_pos->file_name, msgid_pos->line_number,
-                           (size_t)(-1), false,
-                           _("'msgid' and 'msgid_plural' entries do not both end with '\\n'"));
-              seen_errors++;
-            }
-          for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
-            if (TEST_NEWLINE(p) != has_newline)
+      {
+        int has_newline = (msgid[strlen (msgid) - 1] == '\n');
+        #define TEST_NEWLINE(p) (p[0] != '\0' && p[strlen (p) - 1] == '\n')
+        if (msgid_plural != NULL)
+          {
+            if (TEST_NEWLINE(msgid_plural) != has_newline)
               {
-                char *msg =
-                  xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both end with '\\n'"),
-                             j);
                 xeh->xerror (CAT_SEVERITY_ERROR,
                              mp, msgid_pos->file_name, msgid_pos->line_number,
-                             (size_t)(-1), false, msg);
-                free (msg);
+                             (size_t)(-1), false,
+                             _("'msgid' and 'msgid_plural' entries do not both end with '\\n'"));
                 seen_errors++;
               }
-        }
-      else
-        {
-          if (TEST_NEWLINE(msgstr) != has_newline)
-            {
-              xeh->xerror (CAT_SEVERITY_ERROR,
-                           mp, msgid_pos->file_name, msgid_pos->line_number,
-                           (size_t)(-1), false,
-                           _("'msgid' and 'msgstr' entries do not both end with '\\n'"));
-              seen_errors++;
-            }
-        }
-#undef TEST_NEWLINE
+            const char *p;
+            unsigned int j;
+            for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
+              if (TEST_NEWLINE(p) != has_newline)
+                {
+                  char *msg =
+                    xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both end with '\\n'"),
+                               j);
+                  xeh->xerror (CAT_SEVERITY_ERROR,
+                               mp, msgid_pos->file_name, msgid_pos->line_number,
+                               (size_t)(-1), false, msg);
+                  free (msg);
+                  seen_errors++;
+                }
+          }
+        else
+          {
+            if (TEST_NEWLINE(msgstr) != has_newline)
+              {
+                xeh->xerror (CAT_SEVERITY_ERROR,
+                             mp, msgid_pos->file_name, msgid_pos->line_number,
+                             (size_t)(-1), false,
+                             _("'msgid' and 'msgstr' entries do not both end with '\\n'"));
+                seen_errors++;
+              }
+          }
+        #undef TEST_NEWLINE
+      }
     }
 
   if (check_compatibility && msgid_plural != NULL)
@@ -681,15 +662,12 @@ check_pair (const message_ty *mp,
        two accelerators collide, only whether the translator has bothered
        thinking about them.  */
     {
-      const char *p;
-
       /* We are only interested in msgids that contain exactly one '&'.  */
-      p = strchr (msgid, accelerator_char);
+      const char *p = strchr (msgid, accelerator_char);
       if (p != NULL && strchr (p + 1, accelerator_char) == NULL)
         {
           /* Count the number of '&' in msgstr, but ignore '&&'.  */
           unsigned int count = 0;
-
           for (p = msgstr; (p = strchr (p, accelerator_char)) != NULL; p++)
             if (p[1] == accelerator_char)
               p++;
@@ -752,9 +730,8 @@ check_header_entry (const message_ty *mp, const char *msgstr_string,
   const size_t nrequiredfields = nfields - 1;
 #endif
   int seen_errors = 0;
-  int cnt;
 
-  for (cnt = 0; cnt < nfields; ++cnt)
+  for (int cnt = 0; cnt < nfields; ++cnt)
     {
 #if 0
       int severity =
@@ -765,8 +742,8 @@ check_header_entry (const message_ty *mp, const char *msgstr_string,
 #endif
       const char *field = required_fields[cnt];
       size_t len = strlen (field);
-      const char *line;
 
+      const char *line;
       for (line = msgstr_string; *line != '\0'; )
         {
           if (strncmp (line, field, len) == 0 && line[len] == ':')
@@ -859,9 +836,8 @@ check_message_list (const message_list_ty *mlp,
                     xerror_handler_ty xeh)
 {
   int seen_errors = 0;
-  struct plural_distribution distribution;
-  size_t j;
 
+  struct plural_distribution distribution;
   distribution.expr = NULL;
   distribution.often = NULL;
   distribution.often_length = 0;
@@ -871,7 +847,7 @@ check_message_list (const message_list_ty *mlp,
     seen_errors += check_plural (mlp, ignore_untranslated_messages,
                                  ignore_fuzzy_messages, &distribution, xeh);
 
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
index f7a8c6228f2d0bad68212708d1d6d9aaed1fce7c..fb5433559948225b6260d341e39755e39c02604f 100644 (file)
 msgdomain_list_ty *
 msgdomain_list_english (msgdomain_list_ty *mdlp)
 {
-  size_t j, k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -54,9 +52,11 @@ msgdomain_list_english (msgdomain_list_ty *mdlp)
                 {
                   size_t len0 = strlen (mp->msgid) + 1;
                   size_t len1 = strlen (mp->msgid_plural) + 1;
+
                   char *cp = XNMALLOC (len0 + len1, char);
                   memcpy (cp, mp->msgid, len0);
                   memcpy (cp + len0, mp->msgid_plural, len1);
+
                   mp->msgstr = cp;
                   mp->msgstr_len = len0 + len1;
                 }
index 1b9ac8d472c803d43d5d925c0252888811d260e3..e18ff8986e4ea348367895a78dd944130f10f739 100644 (file)
@@ -39,12 +39,11 @@ msgstr_equal_ignoring_potcdate (const char *msgstr1, size_t msgstr1_len,
 {
   const char *msgstr1_end = msgstr1 + msgstr1_len;
   const char *msgstr2_end = msgstr2 + msgstr2_len;
-  const char *ptr1;
-  const char *ptr2;
   const char *const field = "POT-Creation-Date:";
   const ptrdiff_t fieldlen = sizeof ("POT-Creation-Date:") - 1;
 
   /* Search for the occurrence of field in msgstr1.  */
+  const char *ptr1;
   for (ptr1 = msgstr1;;)
     {
       if (msgstr1_end - ptr1 < fieldlen)
@@ -61,6 +60,7 @@ msgstr_equal_ignoring_potcdate (const char *msgstr1, size_t msgstr1_len,
     }
 
   /* Search for the occurrence of field in msgstr2.  */
+  const char *ptr2;
   for (ptr2 = msgstr2;;)
     {
       if (msgstr2_end - ptr2 < fieldlen)
@@ -115,13 +115,11 @@ pos_equal (const lex_pos_ty *pos1, const lex_pos_ty *pos2)
 bool
 string_list_equal (const string_list_ty *slp1, const string_list_ty *slp2)
 {
-  size_t i, i1, i2;
-
-  i1 = (slp1 != NULL ? slp1->nitems : 0);
-  i2 = (slp2 != NULL ? slp2->nitems : 0);
+  size_t i1 = (slp1 != NULL ? slp1->nitems : 0);
+  size_t i2 = (slp2 != NULL ? slp2->nitems : 0);
   if (i1 != i2)
     return false;
-  for (i = 0; i < i1; i++)
+  for (size_t i = 0; i < i1; i++)
     if (strcmp (slp1->item[i], slp2->item[i]) != 0)
       return false;
   return true;
@@ -131,8 +129,6 @@ bool
 message_equal (const message_ty *mp1, const message_ty *mp2,
                bool ignore_potcdate)
 {
-  size_t i, i1, i2;
-
   if (!(mp1->msgctxt != NULL
         ? mp2->msgctxt != NULL && strcmp (mp1->msgctxt, mp2->msgctxt) == 0
         : mp2->msgctxt == NULL))
@@ -163,18 +159,18 @@ message_equal (const message_ty *mp1, const message_ty *mp2,
   if (!string_list_equal (mp1->comment_dot, mp2->comment_dot))
     return false;
 
-  i1 = mp1->filepos_count;
-  i2 = mp2->filepos_count;
+  size_t i1 = mp1->filepos_count;
+  size_t i2 = mp2->filepos_count;
   if (i1 != i2)
     return false;
-  for (i = 0; i < i1; i++)
+  for (size_t i = 0; i < i1; i++)
     if (!pos_equal (&mp1->filepos[i], &mp2->filepos[i]))
       return false;
 
   if (mp1->is_fuzzy != mp2->is_fuzzy)
     return false;
 
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     if (mp1->is_format[i] != mp2->is_format[i])
       return false;
 
@@ -209,13 +205,11 @@ bool
 message_list_equal (const message_list_ty *mlp1, const message_list_ty *mlp2,
                     bool ignore_potcdate)
 {
-  size_t i, i1, i2;
-
-  i1 = mlp1->nitems;
-  i2 = mlp2->nitems;
+  size_t i1 = mlp1->nitems;
+  size_t i2 = mlp2->nitems;
   if (i1 != i2)
     return false;
-  for (i = 0; i < i1; i++)
+  for (size_t i = 0; i < i1; i++)
     if (!message_equal (mlp1->item[i], mlp2->item[i], ignore_potcdate))
       return false;
   return true;
@@ -235,13 +229,11 @@ msgdomain_list_equal (const msgdomain_list_ty *mdlp1,
                       const msgdomain_list_ty *mdlp2,
                       bool ignore_potcdate)
 {
-  size_t i, i1, i2;
-
-  i1 = mdlp1->nitems;
-  i2 = mdlp2->nitems;
+  size_t i1 = mdlp1->nitems;
+  size_t i2 = mdlp2->nitems;
   if (i1 != i2)
     return false;
-  for (i = 0; i < i1; i++)
+  for (size_t i = 0; i < i1; i++)
     if (!msgdomain_equal (mdlp1->item[i], mdlp2->item[i], ignore_potcdate))
       return false;
   return true;
index f36a43b204d8bdddaf553028a39d73ed73e1bbeb..0c9e16abb0976e1c9e9d962108ec64468cef7557 100644 (file)
@@ -105,7 +105,6 @@ new_index (index_ty idx)
 static inline index_list_ty
 addlast_index (index_list_ty list, index_ty idx)
 {
-  index_list_ty result;
   size_t length = list[IL_LENGTH];
 
   /* Look whether it should be inserted.  */
@@ -113,7 +112,7 @@ addlast_index (index_list_ty list, index_ty idx)
     return NULL;
 
   /* Now make room for one more list element.  */
-  result = NULL;
+  index_list_ty result = NULL;
   if (length == list[IL_ALLOCATED])
     {
       size_t new_allocated = 2 * length - (length >> 6);
@@ -132,7 +131,6 @@ addlast_index (index_list_ty list, index_ty idx)
 MAYBE_UNUSED static inline index_list_ty
 add_index (index_list_ty list, index_ty idx)
 {
-  index_list_ty result;
   size_t length = list[IL_LENGTH];
 
   /* Look where it should be inserted.  */
@@ -152,7 +150,7 @@ add_index (index_list_ty list, index_ty idx)
     }
 
   /* Now make room for one more list element.  */
-  result = NULL;
+  index_list_ty result = NULL;
   if (length == list[IL_ALLOCATED])
     {
       size_t new_allocated = 2 * length - (length >> 6);
@@ -207,16 +205,14 @@ message_fuzzy_index_alloc (const message_list_ty *mlp,
                            const char *canon_charset)
 {
   message_fuzzy_index_ty *findex = XMALLOC (message_fuzzy_index_ty);
-  size_t count = mlp->nitems;
-  size_t j;
-  size_t l;
-
   findex->messages = mlp->item;
   findex->iterator = po_charset_character_iterator (canon_charset);
 
+  size_t count = mlp->nitems;
+
   /* Setup hash table.  */
   hash_init (&findex->gram4, 10 * count);
-  for (j = 0; j < count; j++)
+  for (size_t j = 0; j < count; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -245,7 +241,6 @@ message_fuzzy_index_alloc (const message_list_ty *mlp,
                                  it to the index j, or extend the existing
                                  hash table entry accordingly.  */
                               void *found;
-
                               if (hash_find_entry (&findex->gram4, p0, p4 - p0,
                                                    &found) == 0)
                                 {
@@ -277,12 +272,10 @@ message_fuzzy_index_alloc (const message_list_ty *mlp,
 
   /* Shrink memory used by the hash table.  */
   {
-    void *iter;
+    void *iter = NULL;
     const void *key;
     size_t keylen;
     void **valuep;
-
-    iter = NULL;
     while (hash_iterate_modify (&findex->gram4, &iter, &key, &keylen, &valuep)
            == 0)
       {
@@ -303,9 +296,9 @@ message_fuzzy_index_alloc (const message_list_ty *mlp,
 
   /* Setup lists of short messages.  */
   findex->short_messages = XNMALLOC (SHORT_MSG_MAX + 1, message_list_ty *);
-  for (l = 0; l <= SHORT_MSG_MAX; l++)
+  for (size_t l = 0; l <= SHORT_MSG_MAX; l++)
     findex->short_messages[l] = message_list_alloc (false);
-  for (j = 0; j < count; j++)
+  for (size_t j = 0; j < count; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -320,7 +313,7 @@ message_fuzzy_index_alloc (const message_list_ty *mlp,
     }
 
   /* Shrink memory used by the lists of short messages.  */
-  for (l = 0; l <= SHORT_MSG_MAX; l++)
+  for (size_t l = 0; l <= SHORT_MSG_MAX; l++)
     {
       message_list_ty *smlp = findex->short_messages[l];
 
@@ -373,17 +366,14 @@ mult_index_list_accumulate (struct mult_index_list *accu, index_list_ty list)
   size_t len1 = accu->nitems;
   size_t len2 = list[IL_LENGTH];
   size_t need = len1 + len2;
-  index_ty *ptr2;
-  index_ty *ptr2_end;
-  struct mult_index *destptr;
 
   /* Make the work area large enough.  */
   if (accu->nitems2_max < need)
     {
       size_t new_max = 2 * accu->nitems2_max + 1;
-
       if (new_max < need)
         new_max = need;
+
       if (accu->item2 != NULL)
         free (accu->item2);
       accu->item2 = XNMALLOC (new_max, struct mult_index);
@@ -391,16 +381,13 @@ mult_index_list_accumulate (struct mult_index_list *accu, index_list_ty list)
     }
 
   /* Make a linear pass through accu and list simultaneously.  */
-  ptr2 = list + 2;
-  ptr2_end = ptr2 + len2;
-  destptr = accu->item2;
+  index_ty *ptr2 = list + 2;
+  index_ty *ptr2_end = ptr2 + len2;
+  struct mult_index *destptr = accu->item2;
   if (len1 > 0)
     {
-      struct mult_index *ptr1;
-      struct mult_index *ptr1_end;
-
-      ptr1 = accu->item;
-      ptr1_end = ptr1 + len1;
+      struct mult_index *ptr1 = accu->item;
+      struct mult_index *ptr1_end = ptr1 + len1;
       while (ptr1 < ptr1_end && ptr2 < ptr2_end)
         {
           if (ptr1->index < *ptr2)
@@ -533,7 +520,6 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
                          characters.  Get the hash table entry containing
                          a list of indices, and add it to the accu.  */
                       void *found;
-
                       if (hash_find_entry (&findex->gram4, p0, p4 - p0,
                                            &found) == 0)
                         {
@@ -565,20 +551,16 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
                      to the best_weight which will be quite high already after
                      the first few messages.  */
                   {
-                    size_t count;
-                    struct mult_index *ptr;
-                    message_ty *best_mp;
-                    double best_weight;
-
-                    count = accu.nitems;
+                    size_t count = accu.nitems;
                     if (heuristic)
                       {
                         if (count > findex->firstfew)
                           count = findex->firstfew;
                       }
 
-                    best_weight = lower_bound;
-                    best_mp = NULL;
+                    double best_weight = lower_bound;
+                    message_ty *best_mp = NULL;
+                    struct mult_index *ptr;
                     for (ptr = accu.item; count > 0; ptr++, count--)
                       {
                         message_ty *mp = findex->messages[ptr->index];
@@ -603,11 +585,10 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
     }
 
   /* The string had less than 4 characters.  */
+  size_t lmin;
+  size_t lmax;
   {
     size_t l = strlen (str);
-    size_t lmin, lmax;
-    message_ty *best_mp;
-    double best_weight;
 
     if (!(l <= SHORT_STRING_MAX_BYTES))
       abort ();
@@ -618,51 +599,49 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
     lmax = (int) (l * (2 / FUZZY_THRESHOLD - 1));
     if (!(lmax <= SHORT_MSG_MAX))
       abort ();
+  }
 
-    best_weight = lower_bound;
-    best_mp = NULL;
-    for (l = lmin; l <= lmax; l++)
-      {
-        message_list_ty *mlp = findex->short_messages[l];
-        size_t j;
+  double best_weight = lower_bound;
+  message_ty *best_mp = NULL;
+  for (size_t l = lmin; l <= lmax; l++)
+    {
+      message_list_ty *mlp = findex->short_messages[l];
 
-        for (j = 0; j < mlp->nitems; j++)
-          {
-            message_ty *mp = mlp->item[j];
-            double weight =
-              fuzzy_search_goal_function (mp, msgctxt, msgid, best_weight);
-
-            if (weight > best_weight)
-              {
-                best_weight = weight;
-                best_mp = mp;
-              }
-          }
-      }
+      for (size_t j = 0; j < mlp->nitems; j++)
+        {
+          message_ty *mp = mlp->item[j];
+          double weight =
+            fuzzy_search_goal_function (mp, msgctxt, msgid, best_weight);
 
-    return best_mp;
-  }
+          if (weight > best_weight)
+            {
+              best_weight = weight;
+              best_mp = mp;
+            }
+        }
+    }
+
+  return best_mp;
 }
 
 /* Free a fuzzy index.  */
 void
 message_fuzzy_index_free (message_fuzzy_index_ty *findex)
 {
-  size_t l;
-  void *iter;
-  const void *key;
-  size_t keylen;
-  void *data;
-
   /* Free the short lists.  */
-  for (l = 0; l <= SHORT_MSG_MAX; l++)
+  for (size_t l = 0; l <= SHORT_MSG_MAX; l++)
     message_list_free (findex->short_messages[l], 1);
   free (findex->short_messages);
 
   /* Free the index lists occurring as values in the hash tables.  */
-  iter = NULL;
-  while (hash_iterate (&findex->gram4, &iter, &key, &keylen, &data) == 0)
-    free ((index_list_ty *) data);
+  {
+    void *iter = NULL;
+    const void *key;
+    size_t keylen;
+    void *data;
+    while (hash_iterate (&findex->gram4, &iter, &key, &keylen, &data) == 0)
+      free ((index_list_ty *) data);
+  }
   /* Free the hash table itself.  */
   hash_destroy (&findex->gram4);
 
index 8240c8d32bad02f57f5533e17a028d14bd9f0a84..6ddd6447dd4574714bfc031ba6c27a271a2af267 100644 (file)
@@ -33,18 +33,18 @@ header_set_charset (message_ty *header_mp, const char *charsetstr,
                     const char *value)
 {
   const char *msgstr = header_mp->msgstr;
-  size_t len, len1, len2, len3;
-  char *new_msgstr;
 
-  len = strcspn (charsetstr, " \t\n");
+  size_t len = strcspn (charsetstr, " \t\n");
 
-  len1 = charsetstr - msgstr;
-  len2 = strlen (value);
-  len3 = (msgstr + strlen (msgstr)) - (charsetstr + len);
-  new_msgstr = XNMALLOC (len1 + len2 + len3 + 1, char);
+  size_t len1 = charsetstr - msgstr;
+  size_t len2 = strlen (value);
+  size_t len3 = (msgstr + strlen (msgstr)) - (charsetstr + len);
+
+  char *new_msgstr = XNMALLOC (len1 + len2 + len3 + 1, char);
   memcpy (new_msgstr, msgstr, len1);
   memcpy (new_msgstr + len1, value, len2);
   memcpy (new_msgstr + len1 + len2, charsetstr + len, len3 + 1);
+
   header_mp->msgstr = new_msgstr;
   header_mp->msgstr_len = len1 + len2 + len3 + 1;
 }
@@ -75,28 +75,23 @@ void
 msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
                                  const char *field, const char *value)
 {
-  size_t field_len;
-  int field_index;
-  size_t k, i;
-
-  field_len = strlen (field);
+  size_t field_len = strlen (field);
 
   /* Search the field in known_fields[].  */
-  field_index = -1;
-  for (k = 0; k < SIZEOF (known_fields); k++)
+  int field_index = -1;
+  for (size_t k = 0; k < SIZEOF (known_fields); k++)
     if (strcmp (known_fields[k].name, field) == 0)
       {
         field_index = k;
         break;
       }
 
-  for (i = 0; i < mdlp->nitems; i++)
+  for (size_t i = 0; i < mdlp->nitems; i++)
     {
       message_list_ty *mlp = mdlp->item[i]->messages;
-      size_t j;
 
       /* Search the header entry.  */
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
           {
             message_ty *mp = mlp->item[j];
@@ -152,6 +147,7 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
                   {
                     /* Test whether h starts with a field name whose index is
                        > field_index.  */
+                    size_t k;
                     for (k = field_index + 1; k < SIZEOF (known_fields); k++)
                       if (strncmp (h, known_fields[k].name, known_fields[k].len)
                           == 0)
@@ -197,10 +193,9 @@ message_list_delete_header_field (message_list_ty *mlp,
                                   const char *field)
 {
   size_t field_len = strlen (field);
-  size_t j;
 
   /* Search the header entry.  */
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
       {
         message_ty *mp = mlp->item[j];
index 3175e776ee66b4fa961c1a7cf551a70c424294d1..91cfe26b51b50413d6a96cf20b023d70ffee4378 100644 (file)
@@ -135,10 +135,8 @@ convert_string_list (const iconveh_t *cd, string_list_ty *slp,
                      const struct conversion_context* context,
                      xerror_handler_ty xeh)
 {
-  size_t i;
-
   if (slp != NULL)
-    for (i = 0; i < slp->nitems; i++)
+    for (size_t i = 0; i < slp->nitems; i++)
       slp->item[i] = convert_string (cd, slp->item[i], context, xeh);
 }
 
@@ -173,29 +171,39 @@ convert_msgstr (const iconveh_t *cd, message_ty *mp,
                 const struct conversion_context* context,
                 xerror_handler_ty xeh)
 {
-  char *result = NULL;
-  size_t resultlen = 0;
-
   if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0'))
     abort ();
 
+  char *result = NULL;
+  size_t resultlen = 0;
+
   if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL,
                        &result, &resultlen) == 0)
     /* Verify the result has a NUL byte at the end.  */
     if (resultlen > 0 && result[resultlen - 1] == '\0')
       /* Verify the result has the same number of NUL bytes.  */
       {
-        const char *p;
-        const char *pend;
         int nulcount1;
-        int nulcount2;
+        {
+          nulcount1 = 0;
+          const char *p;
+          const char *pend;
+          for (p = mp->msgstr, pend = p + mp->msgstr_len;
+               p < pend;
+               p += strlen (p) + 1)
+            nulcount1++;
+        }
 
-        for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0;
-             p < pend;
-             p += strlen (p) + 1, nulcount1++);
-        for (p = result, pend = p + resultlen, nulcount2 = 0;
-             p < pend;
-             p += strlen (p) + 1, nulcount2++);
+        int nulcount2;
+        {
+          nulcount2 = 0;
+          const char *p;
+          const char *pend;
+          for (p = result, pend = p + resultlen;
+               p < pend;
+               p += strlen (p) + 1)
+            nulcount2++;
+        }
 
         if (nulcount1 == nulcount2)
           {
@@ -219,16 +227,14 @@ iconv_message_list_internal (message_list_ty *mlp,
                              const char *from_filename,
                              xerror_handler_ty xeh)
 {
-  bool canon_from_code_overridden = (canon_from_code != NULL);
-  bool msgids_changed;
-  size_t j;
-
   /* If the list is empty, nothing to do.  */
   if (mlp->nitems == 0)
     return false;
 
+  bool canon_from_code_overridden = (canon_from_code != NULL);
+
   /* Search the header entry, and extract and replace the charset name.  */
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
       {
         const char *header = mlp->item[j]->msgstr;
@@ -301,26 +307,25 @@ iconv_message_list_internal (message_list_ty *mlp,
                      _("input file doesn't contain a header entry with a charset specification"));
     }
 
-  msgids_changed = false;
+  bool msgids_changed = false;
 
   /* If the two encodings are the same, nothing to do.  */
   if (canon_from_code != canon_to_code)
     {
 #if HAVE_ICONV
       iconveh_t cd;
-      struct conversion_context context;
-
       if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0)
         xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
                      xasprintf (_("Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), and iconv() does not support this conversion."),
                                 canon_from_code, canon_to_code,
                                 last_component (program_name)));
 
+      struct conversion_context context;
       context.from_code = canon_from_code;
       context.to_code = canon_to_code;
       context.from_filename = from_filename;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -370,11 +375,8 @@ iconv_msgdomain_list (msgdomain_list_ty *mdlp,
                       const char *from_filename,
                       xerror_handler_ty xeh)
 {
-  const char *canon_to_code;
-  size_t k;
-
   /* Canonicalize target encoding.  */
-  canon_to_code = po_charset_canonicalize (to_code);
+  const char *canon_to_code = po_charset_canonicalize (to_code);
   if (canon_to_code == NULL)
     xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
                  xasprintf (_("target charset \"%s\" is not a portable encoding name."),
@@ -389,7 +391,7 @@ iconv_msgdomain_list (msgdomain_list_ty *mdlp,
                  xasprintf (_("Cannot write the control characters that protect file names with spaces in the %s encoding"),
                             canon_to_code));
 
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     iconv_message_list_internal (mdlp->item[k]->messages,
                                  mdlp->encoding, canon_to_code, update_header,
                                  from_filename, xeh);
@@ -422,10 +424,8 @@ iconvable_string (const iconveh_t *cd, const char *string)
 static bool
 iconvable_string_list (const iconveh_t *cd, string_list_ty *slp)
 {
-  size_t i;
-
   if (slp != NULL)
-    for (i = 0; i < slp->nitems; i++)
+    for (size_t i = 0; i < slp->nitems; i++)
       if (!iconvable_string (cd, slp->item[i]))
         return false;
   return true;
@@ -463,12 +463,12 @@ iconvable_msgid (const iconveh_t *cd, message_ty *mp)
 static bool
 iconvable_msgstr (const iconveh_t *cd, message_ty *mp)
 {
-  char *result = NULL;
-  size_t resultlen = 0;
-
   if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0'))
     abort ();
 
+  char *result = NULL;
+  size_t resultlen = 0;
+
   if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL,
                        &result, &resultlen) == 0)
     {
@@ -478,17 +478,27 @@ iconvable_msgstr (const iconveh_t *cd, message_ty *mp)
       if (resultlen > 0 && result[resultlen - 1] == '\0')
         /* Test if the result has the same number of NUL bytes.  */
         {
-          const char *p;
-          const char *pend;
           int nulcount1;
-          int nulcount2;
+          {
+            nulcount1 = 0;
+            const char *p;
+            const char *pend;
+            for (p = mp->msgstr, pend = p + mp->msgstr_len;
+                 p < pend;
+                 p += strlen (p) + 1)
+              nulcount1++;
+          }
 
-          for (p = mp->msgstr, pend = p + mp->msgstr_len, nulcount1 = 0;
-               p < pend;
-               p += strlen (p) + 1, nulcount1++);
-          for (p = result, pend = p + resultlen, nulcount2 = 0;
-               p < pend;
-               p += strlen (p) + 1, nulcount2++);
+          int nulcount2;
+          {
+            nulcount2 = 0;
+            const char *p;
+            const char *pend;
+            for (p = result, pend = p + resultlen;
+                 p < pend;
+                 p += strlen (p) + 1)
+              nulcount2++;
+          }
 
           if (nulcount1 == nulcount2)
             ok = true;
@@ -507,15 +517,14 @@ is_message_list_iconvable (message_list_ty *mlp,
                            const char *canon_from_code,
                            const char *canon_to_code)
 {
-  bool canon_from_code_overridden = (canon_from_code != NULL);
-  size_t j;
-
   /* If the list is empty, nothing to check.  */
   if (mlp->nitems == 0)
     return true;
 
+  bool canon_from_code_overridden = (canon_from_code != NULL);
+
   /* Search the header entry, and extract the charset name.  */
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
       {
         const char *header = mlp->item[j]->msgstr;
@@ -526,17 +535,14 @@ is_message_list_iconvable (message_list_ty *mlp,
 
             if (charsetstr != NULL)
               {
-                size_t len;
-                char *charset;
-                const char *canon_charset;
-
                 charsetstr += strlen ("charset=");
-                len = strcspn (charsetstr, " \t\n");
-                charset = (char *) xmalloca (len + 1);
+                size_t len = strcspn (charsetstr, " \t\n");
+
+                char *charset = (char *) xmalloca (len + 1);
                 memcpy (charset, charsetstr, len);
                 charset[len] = '\0';
 
-                canon_charset = po_charset_canonicalize (charset);
+                const char *canon_charset = po_charset_canonicalize (charset);
                 if (canon_charset == NULL)
                   {
                     if (!canon_from_code_overridden)
@@ -582,12 +588,11 @@ is_message_list_iconvable (message_list_ty *mlp,
     {
 #if HAVE_ICONV
       iconveh_t cd;
-
       if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0)
         /* iconv() doesn't support this conversion.  */
         return false;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
index 73ea54daf73f54f39d49f2bec04c1452b02607a3..02f7b702054c74bdc5c7cf240fecab0d3082b1b1 100644 (file)
@@ -187,16 +187,12 @@ definitions_init_comp_findex (definitions_ty *definitions)
     {
       /* Combine all the compendium message lists into a single one.  Don't
          bother checking for duplicates.  */
-      message_list_ty *all_compendium;
-      size_t i;
-
-      all_compendium = message_list_alloc (false);
-      for (i = 0; i < compendiums->nitems; i++)
+      message_list_ty *all_compendium = message_list_alloc (false);
+      for (size_t i = 0; i < compendiums->nitems; i++)
         {
           message_list_ty *mlp = compendiums->item[i];
-          size_t j;
 
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             message_list_append (all_compendium, mlp->item[j]);
         }
 
@@ -222,7 +218,6 @@ definitions_search_fuzzy (definitions_ty *definitions,
                           const char *msgctxt, const char *msgid)
 {
   message_ty *mp1;
-
   if (false)
     {
       /* Old, slow code.  */
@@ -244,10 +239,7 @@ definitions_search_fuzzy (definitions_ty *definitions,
 
   if (compendiums != NULL)
     {
-      double lower_bound_for_mp2;
-      message_ty *mp2;
-
-      lower_bound_for_mp2 =
+      double lower_bound_for_mp2 =
         (mp1 != NULL
          ? fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0)
          : FUZZY_THRESHOLD);
@@ -259,9 +251,10 @@ definitions_search_fuzzy (definitions_ty *definitions,
       if (definitions->comp_findex == NULL)
         definitions_init_comp_findex (definitions);
 
-      mp2 = message_fuzzy_index_search (definitions->comp_findex,
-                                        msgctxt, msgid,
-                                        lower_bound_for_mp2, true);
+      message_ty *mp2 =
+        message_fuzzy_index_search (definitions->comp_findex,
+                                    msgctxt, msgid,
+                                    lower_bound_for_mp2, true);
 
       /* Choose the best among mp1, mp2.  */
       if (mp1 == NULL
@@ -328,8 +321,6 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
   const char *prev_msgctxt;
   const char *prev_msgid;
   const char *prev_msgid_plural;
-  message_ty *result;
-  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 -
@@ -376,33 +367,29 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
         const char *string;
         size_t len;
       } header_fields[UNKNOWN + 1];
-      struct obstack pool;
-      const char *cp;
-      char *newp;
 
       /* Clear all fields.  */
       memset (header_fields, '\0', sizeof (header_fields));
 
       /* Prepare a temporary memory pool.  */
+      struct obstack pool;
       obstack_init (&pool);
 
-      cp = def->msgstr;
+      const char *cp = def->msgstr;
       while (*cp != '\0')
         {
           const char *endp = strchr (cp, '\n');
           int terminated = endp != NULL;
           size_t len;
-          size_t cnt;
 
           if (!terminated)
             {
               /* Add a trailing newline.  */
-              char *copy;
               endp = strchr (cp, '\0');
 
               len = endp - cp + 1;
 
-              copy = (char *) obstack_alloc (&pool, len + 1);
+              char *copy = (char *) obstack_alloc (&pool, len + 1);
               stpcpy (stpcpy (copy, cp), "\n");
               cp = copy;
             }
@@ -413,6 +400,7 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
             }
 
           /* Compare with any of the known fields.  */
+          size_t cnt;
           for (cnt = 0;
                cnt < sizeof (known_fields) / sizeof (known_fields[0]);
                ++cnt)
@@ -507,33 +495,25 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
 
               /* The rest of the Language-Team field should be the english name
                  of the language.  Convert to ISO 639 and ISO 3166 syntax.  */
-              {
-                size_t i;
-
-                for (i = 0; i < language_variant_table_size; i++)
-                  if (strlen (language_variant_table[i].english)
-                      == language_team_len
-                      && memcmp (language_variant_table[i].english,
+              for (size_t i = 0; i < language_variant_table_size; i++)
+                if (strlen (language_variant_table[i].english)
+                    == language_team_len
+                    && memcmp (language_variant_table[i].english,
+                               language_team_ptr, language_team_len) == 0)
+                  {
+                    header_fields[LANGUAGE].string =
+                      language_variant_table[i].code;
+                    break;
+                  }
+              if (header_fields[LANGUAGE].string == NULL)
+                for (size_t i = 0; i < language_table_size; i++)
+                  if (strlen (language_table[i].english) == language_team_len
+                      && memcmp (language_table[i].english,
                                  language_team_ptr, language_team_len) == 0)
                     {
-                      header_fields[LANGUAGE].string =
-                        language_variant_table[i].code;
+                      header_fields[LANGUAGE].string = language_table[i].code;
                       break;
                     }
-              }
-              if (header_fields[LANGUAGE].string == NULL)
-                {
-                  size_t i;
-
-                  for (i = 0; i < language_table_size; i++)
-                    if (strlen (language_table[i].english) == language_team_len
-                        && memcmp (language_table[i].english,
-                                   language_team_ptr, language_team_len) == 0)
-                      {
-                        header_fields[LANGUAGE].string = language_table[i].code;
-                        break;
-                      }
-                }
               if (header_fields[LANGUAGE].string != NULL)
                 {
                   /* Prepend a space and append a newline.  */
@@ -551,24 +531,20 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
         }
 
       {
-        const char *msgid_bugs_ptr;
-
-        msgid_bugs_ptr = c_strstr (ref->msgstr, "Report-Msgid-Bugs-To:");
+        const char *msgid_bugs_ptr =
+          c_strstr (ref->msgstr, "Report-Msgid-Bugs-To:");
         if (msgid_bugs_ptr != NULL)
           {
-            size_t msgid_bugs_len;
-            const char *endp;
-
             msgid_bugs_ptr += sizeof ("Report-Msgid-Bugs-To:") - 1;
 
-            endp = strchr (msgid_bugs_ptr, '\n');
+            const char *endp = strchr (msgid_bugs_ptr, '\n');
+            size_t msgid_bugs_len;
             if (endp == NULL)
               {
                 /* Add a trailing newline.  */
-                char *extended;
                 endp = strchr (msgid_bugs_ptr, '\0');
                 msgid_bugs_len = (endp - msgid_bugs_ptr) + 1;
-                extended = (char *) obstack_alloc (&pool, msgid_bugs_len + 1);
+                char *extended = (char *) obstack_alloc (&pool, msgid_bugs_len + 1);
                 stpcpy (stpcpy (extended, msgid_bugs_ptr), "\n");
                 msgid_bugs_ptr = extended;
               }
@@ -581,24 +557,19 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
       }
 
       {
-        const char *pot_date_ptr;
-
-        pot_date_ptr = c_strstr (ref->msgstr, "POT-Creation-Date:");
+        const char *pot_date_ptr = c_strstr (ref->msgstr, "POT-Creation-Date:");
         if (pot_date_ptr != NULL)
           {
-            size_t pot_date_len;
-            const char *endp;
-
             pot_date_ptr += sizeof ("POT-Creation-Date:") - 1;
 
-            endp = strchr (pot_date_ptr, '\n');
+            const char *endp = strchr (pot_date_ptr, '\n');
+            size_t pot_date_len;
             if (endp == NULL)
               {
                 /* Add a trailing newline.  */
-                char *extended;
                 endp = strchr (pot_date_ptr, '\0');
                 pot_date_len = (endp - pot_date_ptr) + 1;
-                extended = (char *) obstack_alloc (&pool, pot_date_len + 1);
+                char *extended = (char *) obstack_alloc (&pool, pot_date_len + 1);
                 stpcpy (stpcpy (extended, pot_date_ptr), "\n");
                 pot_date_ptr = extended;
               }
@@ -613,37 +584,37 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
       /* Concatenate all the various fields.  */
       {
         size_t len;
-        size_t cnt;
-
-        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);
+        {
+          len = 0;
+          for (size_t 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;
+        }
+        char *newp = XNMALLOC (len + 1, char);
+        cp = newp;
         newp[len] = '\0';
-      }
 
 #define IF_FILLED(idx)                                                        \
-      if (header_fields[idx].string)                                          \
-        newp = stpncpy (stpcpy (newp, known_fields[idx].name),                \
-                        header_fields[idx].string, header_fields[idx].len)
-
-      IF_FILLED (PROJECT_ID);
-      IF_FILLED (REPORT_MSGID_BUGS_TO);
-      IF_FILLED (POT_CREATION_DATE);
-      IF_FILLED (PO_REVISION_DATE);
-      IF_FILLED (LAST_TRANSLATOR);
-      IF_FILLED (LANGUAGE_TEAM);
-      IF_FILLED (LANGUAGE);
-      IF_FILLED (MIME_VERSION);
-      IF_FILLED (CONTENT_TYPE);
-      IF_FILLED (CONTENT_TRANSFER);
-      if (header_fields[UNKNOWN].string != NULL)
-        stpcpy (newp, header_fields[UNKNOWN].string);
+        if (header_fields[idx].string)                                        \
+          newp = stpncpy (stpcpy (newp, known_fields[idx].name),              \
+                          header_fields[idx].string, header_fields[idx].len)
+
+        IF_FILLED (PROJECT_ID);
+        IF_FILLED (REPORT_MSGID_BUGS_TO);
+        IF_FILLED (POT_CREATION_DATE);
+        IF_FILLED (PO_REVISION_DATE);
+        IF_FILLED (LAST_TRANSLATOR);
+        IF_FILLED (LANGUAGE_TEAM);
+        IF_FILLED (LANGUAGE);
+        IF_FILLED (MIME_VERSION);
+        IF_FILLED (CONTENT_TYPE);
+        IF_FILLED (CONTENT_TRANSFER);
+        if (header_fields[UNKNOWN].string != NULL)
+          stpcpy (newp, header_fields[UNKNOWN].string);
 
 #undef IF_FILLED
+      }
 
       /* Free the temporary memory pool.  */
       obstack_free (&pool, NULL);
@@ -674,21 +645,22 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
         }
     }
 
-  result = message_alloc (ref->msgctxt != NULL ? xstrdup (ref->msgctxt) : NULL,
-                          xstrdup (ref->msgid), ref->msgid_plural,
-                          msgstr, msgstr_len, &def->pos);
+  message_ty *result =
+    message_alloc (ref->msgctxt != NULL ? xstrdup (ref->msgctxt) : NULL,
+                   xstrdup (ref->msgid), ref->msgid_plural,
+                   msgstr, msgstr_len, &def->pos);
 
   /* Take the comments from the definition file.  There will be none at
      all in the reference file, as it was generated by xgettext.  */
   if (def->comment)
-    for (j = 0; j < def->comment->nitems; ++j)
+    for (size_t j = 0; j < def->comment->nitems; ++j)
       message_comment_append (result, def->comment->item[j]);
 
   /* Take the dot comments from the reference file, as they are
      generated by xgettext.  Any in the definition file are old ones
      collected by previous runs of xgettext and msgmerge.  */
   if (ref->comment_dot)
-    for (j = 0; j < ref->comment_dot->nitems; ++j)
+    for (size_t j = 0; j < ref->comment_dot->nitems; ++j)
       message_comment_dot_append (result, ref->comment_dot->item[j]);
 
   /* The flags are mixed in a special way.  Some informations come
@@ -705,31 +677,27 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
           : def->msgid_plural != NULL))
     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, NULL)
-               > 0)
-          result->is_fuzzy = true;
-      }
-  }
+  for (size_t 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, NULL)
+             > 0)
+        result->is_fuzzy = true;
+    }
 
   result->range = ref->range;
   /* If the definition message was assuming a certain range, but the reference
@@ -773,7 +741,7 @@ message_merge (message_ty *def, message_ty *ref, bool force_fuzzy,
   /* Take the file position comments from the reference file, as they
      are generated by xgettext.  Any in the definition file are old ones
      collected by previous runs of xgettext and msgmerge.  */
-  for (j = 0; j < ref->filepos_count; ++j)
+  for (size_t j = 0; j < ref->filepos_count; ++j)
     {
       lex_pos_ty *pp = &ref->filepos[j];
       message_comment_filepos (result, pp->file_name, pp->line_number);
@@ -810,15 +778,11 @@ match_domain (const char *definitions_file_name,
     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;
 
     {
-      message_ty *header_entry;
-      const struct expression *plural_expr;
-
-      header_entry =
+      message_ty *header_entry =
         message_list_search (definitions_current_list (definitions), NULL, "");
+      const struct expression *plural_expr;
       extract_plural_expression (header_entry ? header_entry->msgstr : NULL,
                                  &plural_expr, &nplurals);
       untranslated_plural_msgstr = XNMALLOC (nplurals, char);
@@ -849,10 +813,10 @@ match_domain (const char *definitions_file_name,
     /* 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);
+    struct search_result { message_ty *found; bool fuzzy; } *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
@@ -863,7 +827,7 @@ match_domain (const char *definitions_file_name,
       #ifdef _OPENMP
        #pragma omp parallel for schedule(dynamic)
       #endif
-      for (jj = 0; jj < nn; jj++)
+      for (long int jj = 0; jj < nn; jj++)
         {
           message_ty *refmsg = refmlp->item[jj];
           message_ty *defmsg;
@@ -903,7 +867,7 @@ match_domain (const char *definitions_file_name,
         }
     }
 
-    for (j = 0; j < refmlp->nitems; j++)
+    for (size_t j = 0; j < refmlp->nitems; j++)
       {
         message_ty *refmsg = refmlp->item[j];
 
@@ -943,7 +907,6 @@ match_domain (const char *definitions_file_name,
             if (search_results[j].found != NULL && search_results[j].fuzzy)
               {
                 message_ty *defmsg = search_results[j].found;
-                message_ty *mp;
 
                 if (verbosity_level > 1)
                   po_xerror2 (PO_SEVERITY_ERROR,
@@ -956,7 +919,8 @@ match_domain (const char *definitions_file_name,
                    #: 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);
+                message_ty *mp =
+                  message_merge (defmsg, refmsg, true, &distribution);
 
                 message_list_append (resultmlp, mp);
 
@@ -971,27 +935,26 @@ match_domain (const char *definitions_file_name,
               }
             else
               {
-                message_ty *mp;
-                bool is_untranslated;
-                const char *p;
-                const char *pend;
-
                 if (verbosity_level > 1)
                   po_xerror (PO_SEVERITY_ERROR, refmsg, NULL, 0, 0, false,
                              xasprintf (
                                _("this message is used but not defined in %s"),
                                definitions_file_name));
 
-                mp = message_copy (refmsg);
+                message_ty *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;
-                    }
+                bool is_untranslated = true;
+                {
+                  const char *p;
+                  const char *pend;
+                  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)
                   {
@@ -1023,9 +986,8 @@ match_domain (const char *definitions_file_name,
     /* 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++)
+    for (size_t j = 0; j < resultmlp->nitems; j++)
       problematic |= resultmlp->item[j]->used;
 
     if (problematic)
@@ -1043,7 +1005,7 @@ match_domain (const char *definitions_file_name,
                                          : NULL);
           }
 
-        for (j = 0; j < resultmlp->nitems; j++)
+        for (size_t j = 0; j < resultmlp->nitems; j++)
           {
             message_ty *mp = resultmlp->item[j];
 
@@ -1051,22 +1013,21 @@ match_domain (const char *definitions_file_name,
               {
                 /* ref->msgid_plural != NULL but def->msgid_plural == NULL.
                    Use a copy of def->msgstr for each possible plural form.  */
-                size_t new_msgstr_len;
-                char *new_msgstr;
-                char *p;
-                unsigned long i;
-
                 if (verbosity_level > 1)
                   po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
                              _("this message should define plural forms"));
 
-                new_msgstr_len = nplurals * mp->msgstr_len;
-                new_msgstr = XNMALLOC (new_msgstr_len, char);
-                for (i = 0, p = new_msgstr; i < nplurals; i++)
-                  {
-                    memcpy (p, mp->msgstr, mp->msgstr_len);
-                    p += mp->msgstr_len;
-                  }
+                size_t new_msgstr_len = nplurals * mp->msgstr_len;
+                char *new_msgstr = XNMALLOC (new_msgstr_len, char);
+                {
+                  char *p;
+                  unsigned long i;
+                  for (i = 0, p = new_msgstr; i < nplurals; i++)
+                    {
+                      memcpy (p, mp->msgstr, mp->msgstr_len);
+                      p += mp->msgstr_len;
+                    }
+                }
                 mp->msgstr = new_msgstr;
                 mp->msgstr_len = new_msgstr_len;
                 mp->is_fuzzy = true;
@@ -1094,21 +1055,17 @@ match_domain (const char *definitions_file_name,
   /* 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.  */
-  {
-    size_t j;
-
-    for (j = 0; j < resultmlp->nitems; j++)
-      {
-        message_ty *mp = resultmlp->item[j];
+  for (size_t 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;
-          }
-      }
-  }
+      if (!mp->is_fuzzy || mp->msgstr[0] == '\0')
+        {
+          mp->prev_msgctxt = NULL;
+          mp->prev_msgid = NULL;
+          mp->prev_msgid_plural = NULL;
+        }
+    }
 }
 
 msgdomain_list_ty *
@@ -1116,27 +1073,18 @@ merge (const char *definitions_file_name, const char *references_file_name,
        catalog_input_format_ty input_syntax,
        msgdomain_list_ty **defp)
 {
-  msgdomain_list_ty *def;
-  msgdomain_list_ty *ref;
-  size_t j, k;
-  unsigned int processed;
   struct statistics stats;
-  msgdomain_list_ty *result;
-  const char *def_canon_charset;
-  definitions_ty definitions;
-  message_list_ty *empty_list;
-
   stats.merged = stats.fuzzied = stats.missing = stats.obsolete = 0;
 
   /* This is the definitions file, created by a human.  */
-  def = read_catalog_file (definitions_file_name, input_syntax);
+  msgdomain_list_ty *def = read_catalog_file (definitions_file_name, input_syntax);
 
   /* This is the references file, created by groping the sources with
      the xgettext program.  */
-  ref = read_catalog_file (references_file_name, input_syntax);
+  msgdomain_list_ty *ref = read_catalog_file (references_file_name, input_syntax);
   check_pot_charset (ref, references_file_name);
   /* Add a dummy header entry, if the references file contains none.  */
-  for (k = 0; k < ref->nitems; k++)
+  for (size_t k = 0; k < ref->nitems; k++)
     if (message_list_search (ref->item[k]->messages, NULL, "") == NULL)
       {
         static lex_pos_ty pos = { __FILE__, __LINE__ };
@@ -1150,11 +1098,11 @@ merge (const char *definitions_file_name, const char *references_file_name,
      UTF-8 as well.  */
   {
     bool was_utf8 = false;
-    for (k = 0; k < ref->nitems; k++)
+    for (size_t k = 0; k < ref->nitems; k++)
       {
         message_list_ty *mlp = ref->item[k]->messages;
 
-        for (j = 0; j < mlp->nitems; j++)
+        for (size_t j = 0; j < mlp->nitems; j++)
           if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
             {
               const char *header = mlp->item[j]->msgstr;
@@ -1165,10 +1113,8 @@ merge (const char *definitions_file_name, const char *references_file_name,
 
                   if (charsetstr != NULL)
                     {
-                      size_t len;
-
                       charsetstr += strlen ("charset=");
-                      len = strcspn (charsetstr, " \t\n");
+                      size_t len = strcspn (charsetstr, " \t\n");
                       if (len == strlen ("UTF-8")
                           && c_strncasecmp (charsetstr, "UTF-8", len) == 0)
                         was_utf8 = true;
@@ -1182,7 +1128,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                                     definitions_file_name,
                                     textmode_xerror_handler);
         if (compendiums != NULL)
-          for (k = 0; k < compendiums->nitems; k++)
+          for (size_t k = 0; k < compendiums->nitems; k++)
             iconv_message_list (compendiums->item[k], NULL, po_charset_utf8,
                                 compendium_filenames->item[k],
                                 textmode_xerror_handler);
@@ -1199,11 +1145,11 @@ merge (const char *definitions_file_name, const char *references_file_name,
           char *charset = NULL;
 
           /* Get the encoding of the definitions file.  */
-          for (k = 0; k < def->nitems; k++)
+          for (size_t k = 0; k < def->nitems; k++)
             {
               message_list_ty *mlp = def->item[k]->messages;
 
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                   {
                     const char *header = mlp->item[j]->msgstr;
@@ -1214,10 +1160,8 @@ merge (const char *definitions_file_name, const char *references_file_name,
 
                         if (charsetstr != NULL)
                           {
-                            size_t len;
-
                             charsetstr += strlen ("charset=");
-                            len = strcspn (charsetstr, " \t\n");
+                            size_t len = strcspn (charsetstr, " \t\n");
                             charset = (char *) xmalloca (len + 1);
                             memcpy (charset, charsetstr, len);
                             charset[len] = '\0';
@@ -1237,7 +1181,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                   bool all_compendiums_iconvable = true;
 
                   if (compendiums != NULL)
-                    for (k = 0; k < compendiums->nitems; k++)
+                    for (size_t k = 0; k < compendiums->nitems; k++)
                       if (!is_message_list_iconvable (compendiums->item[k],
                                                       NULL, canon_charset))
                         {
@@ -1249,7 +1193,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                     {
                       /* Convert the compendiums to def's encoding.  */
                       if (compendiums != NULL)
-                        for (k = 0; k < compendiums->nitems; k++)
+                        for (size_t k = 0; k < compendiums->nitems; k++)
                           iconv_message_list (compendiums->item[k],
                                               NULL, canon_charset,
                                               compendium_filenames->item[k],
@@ -1269,13 +1213,13 @@ merge (const char *definitions_file_name, const char *references_file_name,
                    Compare the encodings of the compendiums.  */
                 const char *common_canon_charset = NULL;
 
-                for (k = 0; k < compendiums->nitems; k++)
+                for (size_t k = 0; k < compendiums->nitems; k++)
                   {
                     message_list_ty *mlp = compendiums->item[k];
                     char *charset = NULL;
                     const char *canon_charset = NULL;
 
-                    for (j = 0; j < mlp->nitems; j++)
+                    for (size_t j = 0; j < mlp->nitems; j++)
                       if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                         {
                           const char *header = mlp->item[j]->msgstr;
@@ -1287,10 +1231,8 @@ merge (const char *definitions_file_name, const char *references_file_name,
 
                               if (charsetstr != NULL)
                                 {
-                                  size_t len;
-
                                   charsetstr += strlen ("charset=");
-                                  len = strcspn (charsetstr, " \t\n");
+                                  size_t len = strcspn (charsetstr, " \t\n");
                                   charset = (char *) xmalloca (len + 1);
                                   memcpy (charset, charsetstr, len);
                                   charset[len] = '\0';
@@ -1330,7 +1272,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                                             definitions_file_name,
                                             textmode_xerror_handler);
                 if (compendiums != NULL)
-                  for (k = 0; k < compendiums->nitems; k++)
+                  for (size_t k = 0; k < compendiums->nitems; k++)
                     iconv_message_list (compendiums->item[k],
                                         NULL, po_charset_utf8,
                                         compendium_filenames->item[k],
@@ -1342,6 +1284,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
 
   /* Determine canonicalized encoding name of the definitions now, after
      conversion.  Only used for fuzzy matching.  */
+  const char *def_canon_charset;
   if (use_fuzzy_matching)
     {
       def_canon_charset = def->encoding;
@@ -1350,11 +1293,11 @@ merge (const char *definitions_file_name, const char *references_file_name,
           char *charset = NULL;
 
           /* Get the encoding of the definitions file.  */
-          for (k = 0; k < def->nitems; k++)
+          for (size_t k = 0; k < def->nitems; k++)
             {
               message_list_ty *mlp = def->item[k]->messages;
 
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
                   {
                     const char *header = mlp->item[j]->msgstr;
@@ -1365,10 +1308,8 @@ merge (const char *definitions_file_name, const char *references_file_name,
 
                         if (charsetstr != NULL)
                           {
-                            size_t len;
-
                             charsetstr += strlen ("charset=");
-                            len = strcspn (charsetstr, " \t\n");
+                            size_t len = strcspn (charsetstr, " \t\n");
                             charset = (char *) xmalloca (len + 1);
                             memcpy (charset, charsetstr, len);
                             charset[len] = '\0';
@@ -1390,23 +1331,23 @@ merge (const char *definitions_file_name, const char *references_file_name,
     def_canon_charset = NULL;
 
   /* Initialize and preprocess the total set of message definitions.  */
+  definitions_ty definitions;
   definitions_init (&definitions, def_canon_charset);
-  empty_list = message_list_alloc (false);
+  message_list_ty *empty_list = message_list_alloc (false);
 
-  result = msgdomain_list_alloc (false);
-  processed = 0;
+  msgdomain_list_ty *result = msgdomain_list_alloc (false);
+  unsigned int processed = 0;
 
   /* Every reference must be matched with its definition. */
   if (!multi_domain_mode)
-    for (k = 0; k < ref->nitems; k++)
+    for (size_t k = 0; k < ref->nitems; k++)
       {
         const char *domain = ref->item[k]->domain;
         message_list_ty *refmlp = ref->item[k]->messages;
         message_list_ty *resultmlp =
           msgdomain_list_sublist (result, domain, true);
-        message_list_ty *defmlp;
 
-        defmlp = msgdomain_list_sublist (def, domain, false);
+        message_list_ty *defmlp = msgdomain_list_sublist (def, domain, false);
         if (defmlp == NULL)
           defmlp = empty_list;
         definitions_set_current_list (&definitions, defmlp);
@@ -1421,7 +1362,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
          the definition domains.  */
       message_list_ty *refmlp = ref->item[0]->messages;
 
-      for (k = 0; k < def->nitems; k++)
+      for (size_t k = 0; k < def->nitems; k++)
         {
           const char *domain = def->item[k]->domain;
           message_list_ty *defmlp = def->item[k]->messages;
@@ -1448,12 +1389,12 @@ merge (const char *definitions_file_name, const char *references_file_name,
       /* Look for messages in the definition file, which are not present
          in the reference file, indicating messages which defined but not
          used in the program.  Don't scan the compendium(s).  */
-      for (k = 0; k < def->nitems; ++k)
+      for (size_t k = 0; k < def->nitems; ++k)
         {
           const char *domain = def->item[k]->domain;
           message_list_ty *defmlp = def->item[k]->messages;
 
-          for (j = 0; j < defmlp->nitems; j++)
+          for (size_t j = 0; j < defmlp->nitems; j++)
             {
               message_ty *defmsg = defmlp->item[j];
 
@@ -1461,9 +1402,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                 {
                   /* Remember the old translation although it is not used anymore.
                      But we mark it as obsolete.  */
-                  message_ty *mp;
-
-                  mp = message_copy (defmsg);
+                  message_ty *mp = message_copy (defmsg);
                   /* Clear the extracted comments.  */
                   if (mp->comment_dot != NULL)
                     {
@@ -1473,9 +1412,7 @@ merge (const char *definitions_file_name, const char *references_file_name,
                   /* Clear the file position comments.  */
                   if (mp->filepos != NULL)
                     {
-                      size_t i;
-
-                      for (i = 0; i < mp->filepos_count; i++)
+                      for (size_t i = 0; i < mp->filepos_count; i++)
                         free ((char *) mp->filepos[i].file_name);
                       mp->filepos_count = 0;
                       free (mp->filepos);
index c23bf66a0b7cec88e15dae68ba9f75245bcb502a..f2c099210f6fa497620695e7b0a1225b5a8df03c 100644 (file)
@@ -29,9 +29,8 @@ bool
 message_has_filenames_with_spaces (const message_ty *mp)
 {
   size_t n = mp->filepos_count;
-  size_t i;
 
-  for (i = 0; i < n; i++)
+  for (size_t i = 0; i < n; i++)
     if (pos_filename_has_spaces (&mp->filepos[i]))
       return true;
 
@@ -41,9 +40,7 @@ message_has_filenames_with_spaces (const message_ty *mp)
 bool
 message_list_has_filenames_with_spaces (const message_list_ty *mlp)
 {
-  size_t j;
-
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (message_has_filenames_with_spaces (mlp->item[j]))
       return true;
 
@@ -53,9 +50,7 @@ message_list_has_filenames_with_spaces (const message_list_ty *mlp)
 bool
 msgdomain_list_has_filenames_with_spaces (const msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     if (message_list_has_filenames_with_spaces (mdlp->item[k]->messages))
       return true;
 
index 37dc06eda34ca11fd5e63554ce33db313e59506b..efff142e3aa7288633502a16f91a4bd98d10b16c 100644 (file)
@@ -77,22 +77,9 @@ static void msgdomain_list_stablesort_by_obsolete (msgdomain_list_ty *mdlp);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  char *color;
-  msgdomain_list_ty *def;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_filepos = false;
-  bool sort_by_msgid = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
-  verbosity_level = 0;
-  quiet = false;
   gram_max_allowed_errors = UINT_MAX;
 
   /* Set locale via LC_ALL.  */
@@ -107,11 +94,17 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  color = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  verbosity_level = 0;
+  quiet = false;
+  char *output_file = NULL;
+  char *color = NULL;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_filepos = false;
+  bool sort_by_msgid = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -154,151 +147,152 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'C':
-        compendium (optarg);
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'm':
-        multi_domain_mode = true;
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
-
-      case 'N':
-        use_fuzzy_matching = false;
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 'q':
-        quiet = true;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case 'U':
-        update_mode = true;
-        break;
-
-      case 'v':
-        ++verbosity_level;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
-
-      case CHAR_MAX + 1: /* --backup */
-        version_control_string = optarg;
-        break;
-
-      case CHAR_MAX + 2: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case CHAR_MAX + 3: /* --suffix */
-        backup_suffix_string = optarg;
-        break;
-
-      case CHAR_MAX + 4: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 5: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 6: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 7: /* --previous */
-        keep_previous = true;
-        break;
-
-      case CHAR_MAX + 8: /* --lang */
-        catalogname = optarg;
-        break;
-
-      case CHAR_MAX + 9: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'C':
+          compendium (optarg);
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'm':
+          multi_domain_mode = true;
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'N':
+          use_fuzzy_matching = false;
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 'q':
+          quiet = true;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case 'U':
+          update_mode = true;
+          break;
+
+        case 'v':
+          ++verbosity_level;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1: /* --backup */
+          version_control_string = optarg;
+          break;
+
+        case CHAR_MAX + 2: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case CHAR_MAX + 3: /* --suffix */
+          backup_suffix_string = optarg;
+          break;
+
+        case CHAR_MAX + 4: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 5: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 6: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 7: /* --previous */
+          keep_previous = true;
+          break;
+
+        case CHAR_MAX + 8: /* --lang */
+          catalogname = optarg;
+          break;
+
+        case CHAR_MAX + 9: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          color = optarg;
+          break;
+
+        case CHAR_MAX + 10: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 11: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        case CHAR_MAX + 12: /* --for-msgfmt */
+          for_msgfmt = true;
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        color = optarg;
-        break;
-
-      case CHAR_MAX + 10: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 11: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      case CHAR_MAX + 12: /* --for-msgfmt */
-        for_msgfmt = true;
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -410,7 +404,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   #endif
 
   /* Merge the two files.  */
-  result = merge (argv[optind], argv[optind + 1], input_syntax, &def);
+  msgdomain_list_ty *def;
+  msgdomain_list_ty *result =
+    merge (argv[optind], argv[optind + 1], input_syntax, &def);
 
   /* Sort the results.  */
   if (sort_by_filepos)
@@ -431,12 +427,9 @@ There is NO WARRANTY, to the extent permitted by law.\n\
          which don't put the .pot file under CVS.  */
       if (!msgdomain_list_equal (def, result, true))
         {
-          /* Back up def.po.  */
-          enum backup_type backup_type;
-          char *backup_file;
-
           output_file = argv[optind];
 
+          /* Back up def.po.  */
           if (backup_suffix_string == NULL)
             {
               backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
@@ -447,10 +440,12 @@ There is NO WARRANTY, to the extent permitted by law.\n\
           if (backup_suffix_string != NULL)
             simple_backup_suffix = backup_suffix_string;
 
-          backup_type = xget_version (_("backup type"), version_control_string);
+          enum backup_type backup_type =
+            xget_version (_("backup type"), version_control_string);
           if (backup_type != none)
             {
-              backup_file = find_backup_file_name (output_file, backup_type);
+              char *backup_file =
+                find_backup_file_name (output_file, backup_type);
               xcopy_file_preserving (output_file, backup_file);
             }
 
@@ -634,16 +629,13 @@ or by email to <%s>.\n"),
 static void
 compendium (const char *filename)
 {
-  msgdomain_list_ty *mdlp;
-  size_t k;
-
-  mdlp = read_catalog_file (filename, &input_format_po);
+  msgdomain_list_ty *mdlp = read_catalog_file (filename, &input_format_po);
   if (compendiums == NULL)
     {
       compendiums = message_list_list_alloc ();
       compendium_filenames = string_list_alloc ();
     }
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_list_append (compendiums, mdlp->item[k]->messages);
       string_list_append (compendium_filenames, filename);
@@ -655,9 +647,7 @@ compendium (const char *filename)
 static void
 msgdomain_list_stablesort_by_obsolete (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -665,16 +655,13 @@ msgdomain_list_stablesort_by_obsolete (msgdomain_list_ty *mdlp)
       if (mlp->nitems > 0)
         {
           message_ty **l1 = XNMALLOC (mlp->nitems, message_ty *);
-          size_t n1;
           message_ty **l2 = XNMALLOC (mlp->nitems, message_ty *);
-          size_t n2;
-          size_t j;
 
           /* Sort the non-obsolete messages into l1 and the obsolete messages
              into l2.  */
-          n1 = 0;
-          n2 = 0;
-          for (j = 0; j < mlp->nitems; j++)
+          size_t n1 = 0;
+          size_t n2 = 0;
+          for (size_t j = 0; j < mlp->nitems; j++)
             {
               message_ty *mp = mlp->item[j];
 
index 093e855890f4a409f728aaff6346a29705fd968f..fcf1590e380158f95a69159eaae9ce9f0b09861d 100644 (file)
@@ -85,13 +85,6 @@ static void read_one_file (message_list_ty *mlp, const char *filename);
 int
 main (int argc, char **argv)
 {
-  bool do_help = false;
-  bool do_version = false;
-  const char *output_file = "-";
-  msgdomain_list_ty *result;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_msgid = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -108,6 +101,13 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  const char *output_file = "-";
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -138,116 +138,117 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'd':
-        csharp_base_directory = optarg;
-        tcl_base_directory = optarg;
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'j':
-        java_mode = true;
-        break;
-
-      case 'l':
-        java_locale_name = optarg;
-        csharp_locale_name = optarg;
-        tcl_locale_name = optarg;
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'r':
-        java_resource_name = optarg;
-        csharp_resource_name = optarg;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 8: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 'v':
-        verbose = true;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
-
-      case CHAR_MAX + 1: /* --tcl */
-        tcl_mode = true;
-        break;
-
-      case CHAR_MAX + 2: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 3: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 4: /* --csharp */
-        csharp_mode = true;
-        break;
-
-      case CHAR_MAX + 5: /* --csharp-resources */
-        csharp_resources_mode = true;
-        break;
-
-      case CHAR_MAX + 6: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'd':
+          csharp_base_directory = optarg;
+          tcl_base_directory = optarg;
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'j':
+          java_mode = true;
+          break;
+
+        case 'l':
+          java_locale_name = optarg;
+          csharp_locale_name = optarg;
+          tcl_locale_name = optarg;
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'r':
+          java_resource_name = optarg;
+          csharp_resource_name = optarg;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 8: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 'v':
+          verbose = true;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1: /* --tcl */
+          tcl_mode = true;
+          break;
+
+        case CHAR_MAX + 2: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 3: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 4: /* --csharp */
+          csharp_mode = true;
+          break;
+
+        case CHAR_MAX + 5: /* --csharp-resources */
+          csharp_resources_mode = true;
+          break;
+
+        case CHAR_MAX + 6: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 7: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 7: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        break;
-      }
+          break;
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -283,15 +284,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
       {
         const char *first_option;
         const char *second_option;
-        unsigned int i;
-        for (i = 0; ; i++)
-          if (modes & (1 << i))
-            break;
-        first_option = mode_options[i];
-        for (i = i + 1; ; i++)
-          if (modes & (1 << i))
-            break;
-        second_option = mode_options[i];
+        {
+          unsigned int i;
+          for (i = 0; ; i++)
+            if (modes & (1 << i))
+              break;
+          first_option = mode_options[i];
+          for (i = i + 1; ; i++)
+            if (modes & (1 << i))
+              break;
+          second_option = mode_options[i];
+        }
         error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
                first_option, second_option);
       }
@@ -368,6 +371,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
 
   /* Read the given .mo file. */
+  msgdomain_list_ty *result;
   if (java_mode)
     {
       result = msgdomain_read_java (java_resource_name, java_locale_name);
@@ -383,9 +387,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     }
   else
     {
-      message_list_ty *mlp;
-
-      mlp = message_list_alloc (false);
+      message_list_ty *mlp = message_list_alloc (false);
       if (optind < argc)
         {
           do
index 6c01075d80bad5740abe60b1de3f65fb2561eb7e..efc9f0fc2070a4250f11f65a98ba66c8227299ca 100644 (file)
@@ -66,17 +66,6 @@ _GL_NORETURN_FUNC static void usage (int status);
 int
 main (int argc, char **argv)
 {
-  bool do_help;
-  bool do_version;
-  char *output_file;
-  const char *input_file;
-  string_list_ty *file_list;
-  msgdomain_list_ty *result;
-  catalog_input_format_ty input_syntax = &input_format_po;
-  catalog_output_format_ty output_syntax = &output_format_po;
-  bool sort_by_msgid = false;
-  bool sort_by_filepos = false;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -94,14 +83,17 @@ main (int argc, char **argv)
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
-  output_file = NULL;
-  input_file = NULL;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  char *output_file = NULL;
   more_than = 0;
   less_than = INT_MAX;
   use_first = false;
+  catalog_input_format_ty input_syntax = &input_format_po;
+  catalog_output_format_ty output_syntax = &output_format_po;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -136,124 +128,125 @@ main (int argc, char **argv)
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
-
-      case 'd':
-        more_than = 1;
-        less_than = INT_MAX;
-        break;
-
-      case 'D':
-        dir_list_append (optarg);
-        break;
-
-      case 'e':
-        message_print_style_escape (false);
-        break;
-
-      case 'E':
-        message_print_style_escape (true);
-        break;
-
-      case 'F':
-        sort_by_filepos = true;
-        break;
-
-      case 'h':
-        do_help = true;
-        break;
-
-      case 'i':
-        message_print_style_indent ();
-        break;
-
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
-
-      case 'o':
-        output_file = optarg;
-        break;
-
-      case 'p':
-        output_syntax = &output_format_properties;
-        break;
-
-      case 'P':
-        input_syntax = &input_format_properties;
-        break;
-
-      case 's':
-        sort_by_msgid = true;
-        break;
-
-      case CHAR_MAX + 8: /* --strict */
-        message_print_style_uniforum ();
-        break;
-
-      case 't':
-        to_code = optarg;
-        break;
-
-      case 'u':
-        more_than = 0;
-        less_than = 2;
-        break;
-
-      case 'V':
-        do_version = true;
-        break;
-
-      case 'w':
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
         {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
-
-      case CHAR_MAX + 1:
-        use_first = true;
-        break;
-
-      case CHAR_MAX + 2: /* --no-wrap */
-        message_page_width_ignore ();
-        break;
-
-      case CHAR_MAX + 3: /* --stringtable-input */
-        input_syntax = &input_format_stringtable;
-        break;
-
-      case CHAR_MAX + 4: /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
-
-      case CHAR_MAX + 5: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
+        case '\0':                /* Long option with key == 0.  */
+          break;
+
+        case 'd':
+          more_than = 1;
+          less_than = INT_MAX;
+          break;
+
+        case 'D':
+          dir_list_append (optarg);
+          break;
+
+        case 'e':
+          message_print_style_escape (false);
+          break;
+
+        case 'E':
+          message_print_style_escape (true);
+          break;
+
+        case 'F':
+          sort_by_filepos = true;
+          break;
+
+        case 'h':
+          do_help = true;
+          break;
+
+        case 'i':
+          message_print_style_indent ();
+          break;
+
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
+
+        case 'o':
+          output_file = optarg;
+          break;
+
+        case 'p':
+          output_syntax = &output_format_properties;
+          break;
+
+        case 'P':
+          input_syntax = &input_format_properties;
+          break;
+
+        case 's':
+          sort_by_msgid = true;
+          break;
+
+        case CHAR_MAX + 8: /* --strict */
+          message_print_style_uniforum ();
+          break;
+
+        case 't':
+          to_code = optarg;
+          break;
+
+        case 'u':
+          more_than = 0;
+          less_than = 2;
+          break;
+
+        case 'V':
+          do_version = true;
+          break;
+
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
+
+        case CHAR_MAX + 1:
+          use_first = true;
+          break;
+
+        case CHAR_MAX + 2: /* --no-wrap */
+          message_page_width_ignore ();
+          break;
+
+        case CHAR_MAX + 3: /* --stringtable-input */
+          input_syntax = &input_format_stringtable;
+          break;
+
+        case CHAR_MAX + 4: /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
+
+        case CHAR_MAX + 5: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
+
+        case CHAR_MAX + 6: /* --style */
+          handle_style_option (optarg);
+          break;
+
+        case CHAR_MAX + 7: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
+
+        default:
           usage (EXIT_FAILURE);
-        break;
-
-      case CHAR_MAX + 6: /* --style */
-        handle_style_option (optarg);
-        break;
-
-      case CHAR_MAX + 7: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
-
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -276,6 +269,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
     usage (EXIT_SUCCESS);
 
   /* Test whether we have an .po file name as argument.  */
+  const char *input_file = NULL;
   if (optind == argc)
     input_file = "-";
   else if (optind + 1 == argc)
@@ -292,12 +286,13 @@ There is NO WARRANTY, to the extent permitted by law.\n\
            "--sort-output", "--sort-by-file");
 
   /* Determine list of files we have to process: a single file.  */
-  file_list = string_list_alloc ();
+  string_list_ty *file_list = string_list_alloc ();
   string_list_append (file_list, input_file);
 
   /* Read input files, then filter, convert and merge messages.  */
   allow_duplicates = true;
-  result = catenate_msgdomain_list (file_list, input_syntax, to_code);
+  msgdomain_list_ty *result =
+    catenate_msgdomain_list (file_list, input_syntax, to_code);
 
   string_list_free (file_list);
 
index b9055835554f26d2c0cee97752e124670befffa0..4bba0ec73b27745c125bfded69a2c6f4551b79e1 100644 (file)
 static FILE *
 try_open_catalog_file (const char *input_name, char **real_file_name_p)
 {
-  static const char *extension[] = { "", ".po", ".pot", };
-  char *file_name;
-  FILE *ret_val;
-  int j;
-  size_t k;
-  const char *dir;
-
   if (strcmp (input_name, "-") == 0 || strcmp (input_name, "/dev/stdin") == 0)
     {
       *real_file_name_p = xstrdup (_("<stdin>"));
       return stdin;
     }
 
+  static const char *extension[] = { "", ".po", ".pot", };
+
   /* We have a real name for the input file.  */
   if (IS_RELATIVE_FILE_NAME (input_name))
     {
       /* For relative file names, look through the directory search list,
          trying the various extensions.  If no directory search list is
          specified, the current directory is used.  */
-      for (j = 0; (dir = dir_list_nth (j)) != NULL; ++j)
-        for (k = 0; k < SIZEOF (extension); ++k)
+      const char *dir;
+      for (int j = 0; (dir = dir_list_nth (j)) != NULL; ++j)
+        for (size_t k = 0; k < SIZEOF (extension); ++k)
           {
-            file_name = xconcatenated_filename (dir, input_name, extension[k]);
+            char *file_name =
+              xconcatenated_filename (dir, input_name, extension[k]);
 
-            ret_val = fopen (file_name, "r");
-            if (ret_val != NULL || errno != ENOENT)
+            FILE *fp = fopen (file_name, "r");
+            if (fp != NULL || errno != ENOENT)
               {
                 /* We found the file.  */
                 *real_file_name_p = file_name;
-                return ret_val;
+                return fp;
               }
 
             free (file_name);
@@ -81,16 +78,17 @@ try_open_catalog_file (const char *input_name, char **real_file_name_p)
     {
       /* The name is not relative.  Try the various extensions, but ignore the
          directory search list.  */
-      for (k = 0; k < SIZEOF (extension); ++k)
+      for (size_t k = 0; k < SIZEOF (extension); ++k)
         {
-          file_name = xconcatenated_filename ("", input_name, extension[k]);
+          char *file_name =
+            xconcatenated_filename ("", input_name, extension[k]);
 
-          ret_val = fopen (file_name, "r");
-          if (ret_val != NULL || errno != ENOENT)
+          FILE *fp = fopen (file_name, "r");
+          if (fp != NULL || errno != ENOENT)
             {
               /* We found the file.  */
               *real_file_name_p = file_name;
-              return ret_val;
+              return fp;
             }
 
           free (file_name);
index 8058f96050ab0a693f7e3b060d59d0108593b7dc..63248189de806374a9063d86787093e1d8a545b2 100644 (file)
@@ -29,7 +29,6 @@ get_plural_count (const char *header)
 {
   const struct expression *plural;
   unsigned long int nplurals;
-
   extract_plural_expression (header, &plural, &nplurals);
 
   return nplurals;
index 1a0dad88386a4274ffcf8bde9a63e48eef92d51f..e52222eed0017cb6b74ff876f58b275c88132705 100644 (file)
@@ -94,9 +94,8 @@ po_charset_canonicalize (const char *charset)
     "GEORGIAN-PS",
     utf8
   };
-  size_t i;
 
-  for (i = 0; i < SIZEOF (standard_charsets); i++)
+  for (size_t i = 0; i < SIZEOF (standard_charsets); i++)
     if (c_strcasecmp (charset, standard_charsets[i]) == 0)
       return standard_charsets[i < 3 ? 0 : i < 27 ? ((i - 3) & ~1) + 3 : i];
   return NULL;
@@ -128,9 +127,8 @@ bool po_is_charset_weird (const char *canon_charset)
     "SHIFT_JIS",
     "JOHAB"
   };
-  size_t i;
 
-  for (i = 0; i < SIZEOF (weird_charsets); i++)
+  for (size_t i = 0; i < SIZEOF (weird_charsets); i++)
     if (strcmp (canon_charset, weird_charsets[i]) == 0)
       return true;
   return false;
@@ -151,9 +149,8 @@ bool po_is_charset_weird_cjk (const char *canon_charset)
     "SHIFT_JIS",        /* 0x{00..7F},    0x{81..F9}{40..FC} */
     "JOHAB"             /* 0x{00..7F},    0x{84..F9}{31..FE} */
   };
-  size_t i;
 
-  for (i = 0; i < SIZEOF (weird_cjk_charsets); i++)
+  for (size_t i = 0; i < SIZEOF (weird_cjk_charsets); i++)
     if (strcmp (canon_charset, weird_cjk_charsets[i]) == 0)
       return true;
   return false;
index a3dfd5b334806ed49ba7441e7fd8d7eab523b783..872a32698f3f4d46090389669179056057bef5de 100644 (file)
@@ -51,18 +51,17 @@ difftm (const struct tm *a, const struct tm *b)
 char *
 po_strftime (const time_t *tp)
 {
-  struct tm local_time;
-  char tz_sign;
-  long tz_min;
+  struct tm local_time = *localtime (tp);
 
-  local_time = *localtime (tp);
-  tz_sign = '+';
-  tz_min = difftm (&local_time, gmtime (tp)) / 60;
+  long tz_min = difftm (&local_time, gmtime (tp)) / 60;
+
+  char tz_sign = '+';
   if (tz_min < 0)
     {
       tz_min = -tz_min;
       tz_sign = '-';
     }
+
   return xasprintf ("%d-%02d-%02d %02d:%02d%c%02ld%02ld",
                     local_time.tm_year + TM_YEAR_ORIGIN,
                     local_time.tm_mon + 1,
index f0c6dce5a48cfce7ef102c501979e0f769486f9a..d9492cfef3f1a7bc2477281ee142730ed2fa78ee 100644 (file)
@@ -42,9 +42,8 @@ abstract_catalog_reader_ty *
 catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table,
                       xerror_handler_ty xerror_handler)
 {
-  abstract_catalog_reader_ty *catr;
-
-  catr = (abstract_catalog_reader_ty *) xmalloc (method_table->size);
+  abstract_catalog_reader_ty *catr =
+    (abstract_catalog_reader_ty *) xmalloc (method_table->size);
   catr->methods = method_table;
   catr->xeh = xerror_handler;
   catr->pass_comments = false;
@@ -264,8 +263,8 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
             s += strlen (catr->po_lex_isolate_start);
 
           const char *filename_start = s;
-          const char *filename_end;
 
+          const char *filename_end;
           if (isolated_filename)
             {
               for (;; s++)
@@ -322,8 +321,8 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
                       {
                         /* Parsed a GNU style file comment with spaces.  */
                         size_t filename_length = filename_end - filename_start;
-                        char *filename = XNMALLOC (filename_length + 1, char);
 
+                        char *filename = XNMALLOC (filename_length + 1, char);
                         memcpy (filename, filename_start, filename_length);
                         filename[filename_length] = '\0';
 
@@ -364,8 +363,8 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
                       /* Parsed a GNU style file comment with spaces.  */
                       filename_end = s - 1;
                       size_t filename_length = filename_end - filename_start;
-                      char *filename = XNMALLOC (filename_length + 1, char);
 
+                      char *filename = XNMALLOC (filename_length + 1, char);
                       memcpy (filename, filename_start, filename_length);
                       filename[filename_length] = '\0';
 
@@ -418,8 +417,8 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
                   {
                     filename_end = string_end;
                     size_t filename_length = filename_end - filename_start;
-                    char *filename = XNMALLOC (filename_length + 1, char);
 
+                    char *filename = XNMALLOC (filename_length + 1, char);
                     memcpy (filename, filename_start, filename_length);
                     filename[filename_length] = '\0';
 
@@ -436,8 +435,8 @@ parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
           /* Parsed a file comment without line number.  */
           {
             size_t filename_length = filename_end - filename_start;
-            char *filename = XNMALLOC (filename_length + 1, char);
 
+            char *filename = XNMALLOC (filename_length + 1, char);
             memcpy (filename, filename_start, filename_length);
             filename[filename_length] = '\0';
 
@@ -472,7 +471,6 @@ parse_comment_solaris_filepos (abstract_catalog_reader_ty *catr, const char *s)
       && s[5] == ':')
     {
       const char *string_start;
-      const char *string_end;
 
       {
         const char *p = s + 6;
@@ -482,7 +480,7 @@ parse_comment_solaris_filepos (abstract_catalog_reader_ty *catr, const char *s)
         string_start = p;
       }
 
-      for (string_end = string_start; *string_end != '\0'; string_end++)
+      for (const char *string_end = string_start; *string_end != '\0'; string_end++)
         {
           const char *p = string_end;
 
@@ -534,9 +532,9 @@ parse_comment_solaris_filepos (abstract_catalog_reader_ty *catr, const char *s)
                             {
                               /* Parsed a Sun style file comment.  */
                               size_t string_length = string_end - string_start;
+
                               char *string =
                                 XNMALLOC (string_length + 1, char);
-
                               memcpy (string, string_start, string_length);
                               string[string_length] = '\0';
 
index ba9c25876a3da05b0e21427064735714da3dc7bf..e6eca5ae6438a7b85e3f426a909bc567c0f197d2 100644 (file)
@@ -29,10 +29,10 @@ read_catalog_file (const char *filename, catalog_input_format_ty input_syntax)
 {
   char *real_filename;
   FILE *fp = open_catalog_file (filename, &real_filename, true);
-  msgdomain_list_ty *result;
 
-  result = read_catalog_stream (fp, real_filename, filename, input_syntax,
-                                textmode_xerror_handler);
+  msgdomain_list_ty *result =
+    read_catalog_stream (fp, real_filename, filename, input_syntax,
+                         textmode_xerror_handler);
 
   if (fp != stdin)
     fclose (fp);
index 91d19fba0d8b17123d38e0856cede11ac76a4a19..d9b01cc162932d086a3cf0edffd365ebceb2591a 100644 (file)
@@ -34,30 +34,26 @@ parse_comment_special (const char *s,
                        struct argument_range *rangep, enum is_wrap *wrapp,
                        enum is_syntax_check *scp)
 {
-  size_t i;
-
   *fuzzyp = false;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     formatp[i] = undecided;
   rangep->min = -1;
   rangep->max = -1;
   *wrapp = undecided;
   if (scp != NULL)
     {
-      for (i = 0; i < NSYNTAXCHECKS; i++)
+      for (size_t i = 0; i < NSYNTAXCHECKS; i++)
         scp[i] = undecided;
     }
 
   while (*s != '\0')
     {
-      const char *t;
-
       /* Skip whitespace.  */
       while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL)
         s++;
 
       /* Collect a token.  */
-      t = s;
+      const char *t = s;
       while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL)
         s++;
       if (s != t)
@@ -74,13 +70,10 @@ parse_comment_special (const char *s,
           /* Accept format description.  */
           if (len >= 7 && memcmp (t + len - 7, "-format", 7) == 0)
             {
-              const char *p;
-              size_t n;
-              enum is_format value;
-
-              p = t;
-              n = len - 7;
+              const char *p = t;
+              size_t n = len - 7;
 
+              enum is_format value;
               if (n >= 3 && memcmp (p, "no-", 3) == 0)
                 {
                   p += 3;
@@ -102,6 +95,7 @@ parse_comment_special (const char *s,
               else
                 value = yes;
 
+              size_t i;
               for (i = 0; i < NFORMATS; i++)
                 if (strlen (format_language[i]) == n
                     && memcmp (format_language[i], p, n) == 0)
@@ -120,20 +114,20 @@ parse_comment_special (const char *s,
               while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL)
                 s++;
 
-              /* Collect a token.  */
-              t = s;
+              /* Collect an interval token.  */
+              const char *it = s;
               while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL)
                 s++;
               /* Parse it.  */
-              if (*t >= '0' && *t <= '9')
+              if (*it >= '0' && *it <= '9')
                 {
                   unsigned int min = 0;
 
-                  for (; *t >= '0' && *t <= '9'; t++)
+                  for (; *it >= '0' && *it <= '9'; it++)
                     {
                       if (min <= INT_MAX / 10)
                         {
-                          min = 10 * min + (*t - '0');
+                          min = 10 * min + (*it - '0');
                           if (min > INT_MAX)
                             min = INT_MAX;
                         }
@@ -141,16 +135,16 @@ parse_comment_special (const char *s,
                         /* Avoid integer overflow.  */
                         min = INT_MAX;
                     }
-                  if (*t++ == '.')
-                    if (*t++ == '.')
-                      if (*t >= '0' && *t <= '9')
+                  if (*it++ == '.')
+                    if (*it++ == '.')
+                      if (*it >= '0' && *it <= '9')
                         {
                           unsigned int max = 0;
-                          for (; *t >= '0' && *t <= '9'; t++)
+                          for (; *it >= '0' && *it <= '9'; it++)
                             {
                               if (max <= INT_MAX / 10)
                                 {
-                                  max = 10 * max + (*t - '0');
+                                  max = 10 * max + (*it - '0');
                                   if (max > INT_MAX)
                                     max = INT_MAX;
                                 }
@@ -183,13 +177,10 @@ parse_comment_special (const char *s,
           /* Accept syntax check description.  */
           if (scp != NULL && len >= 6 && memcmp (t + len - 6, "-check", 6) == 0)
             {
-              const char *p;
-              size_t n;
-              enum is_syntax_check value;
-
-              p = t;
-              n = len - 6;
+              const char *p = t;
+              size_t n = len - 6;
 
+              enum is_syntax_check value;
               if (n >= 3 && memcmp (p, "no-", 3) == 0)
                 {
                   p += 3;
@@ -199,6 +190,7 @@ parse_comment_special (const char *s,
               else
                 value = yes;
 
+              size_t i;
               for (i = 0; i < NSYNTAXCHECKS; i++)
                 if (strlen (syntax_check_name[i]) == n
                     && memcmp (syntax_check_name[i], p, n) == 0)
index d71cae93b98ebea67209f9389c2a90f3772e19e9..186585cb2122aa3db3d86f5b72ac1b8cef0e121e 100644 (file)
@@ -92,7 +92,6 @@ void
 default_constructor (abstract_catalog_reader_ty *catr)
 {
   default_catalog_reader_ty *dcatr = (default_catalog_reader_ty *) catr;
-  size_t i;
 
   dcatr->domain = MESSAGE_DOMAIN_DEFAULT;
   dcatr->comment = NULL;
@@ -100,7 +99,7 @@ default_constructor (abstract_catalog_reader_ty *catr)
   dcatr->filepos_count = 0;
   dcatr->filepos = NULL;
   dcatr->is_fuzzy = false;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     dcatr->is_format[i] = undecided;
   dcatr->range.min = -1;
   dcatr->range.max = -1;
@@ -112,7 +111,6 @@ void
 default_destructor (abstract_catalog_reader_ty *catr)
 {
   default_catalog_reader_ty *dcatr = (default_catalog_reader_ty *) catr;
-  size_t j;
 
   /* Do not free dcatr->mdlp and dcatr->mlp.  */
   if (dcatr->handle_comments)
@@ -123,7 +121,7 @@ default_destructor (abstract_catalog_reader_ty *catr)
         string_list_free (dcatr->comment_dot);
     }
 
-  for (j = 0; j < dcatr->filepos_count; ++j)
+  for (size_t j = 0; j < dcatr->filepos_count; ++j)
     free ((char *) dcatr->filepos[j].file_name);
   if (dcatr->filepos != NULL)
     free (dcatr->filepos);
@@ -149,26 +147,23 @@ default_parse_debrief (abstract_catalog_reader_ty *catr)
 static void
 default_copy_comment_state (default_catalog_reader_ty *dcatr, message_ty *mp)
 {
-  size_t j, i;
-
   if (dcatr->handle_comments)
     {
       if (dcatr->comment != NULL)
-        for (j = 0; j < dcatr->comment->nitems; ++j)
+        for (size_t j = 0; j < dcatr->comment->nitems; ++j)
           message_comment_append (mp, dcatr->comment->item[j]);
       if (dcatr->comment_dot != NULL)
-        for (j = 0; j < dcatr->comment_dot->nitems; ++j)
+        for (size_t j = 0; j < dcatr->comment_dot->nitems; ++j)
           message_comment_dot_append (mp, dcatr->comment_dot->item[j]);
     }
-  for (j = 0; j < dcatr->filepos_count; ++j)
+  for (size_t j = 0; j < dcatr->filepos_count; ++j)
     {
-      lex_pos_ty *pp;
+      lex_pos_ty *pp = &dcatr->filepos[j];
 
-      pp = &dcatr->filepos[j];
       message_comment_filepos (mp, pp->file_name, pp->line_number);
     }
   mp->is_fuzzy = dcatr->is_fuzzy;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     mp->is_format[i] = dcatr->is_format[i];
   mp->range = dcatr->range;
   mp->do_wrap = dcatr->do_wrap;
@@ -178,8 +173,6 @@ default_copy_comment_state (default_catalog_reader_ty *dcatr, message_ty *mp)
 static void
 default_reset_comment_state (default_catalog_reader_ty *dcatr)
 {
-  size_t j, i;
-
   if (dcatr->handle_comments)
     {
       if (dcatr->comment != NULL)
@@ -193,14 +186,14 @@ default_reset_comment_state (default_catalog_reader_ty *dcatr)
           dcatr->comment_dot = NULL;
         }
     }
-  for (j = 0; j < dcatr->filepos_count; ++j)
+  for (size_t j = 0; j < dcatr->filepos_count; ++j)
     free ((char *) dcatr->filepos[j].file_name);
   if (dcatr->filepos != NULL)
     free (dcatr->filepos);
   dcatr->filepos_count = 0;
   dcatr->filepos = NULL;
   dcatr->is_fuzzy = false;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     dcatr->is_format[i] = undecided;
   dcatr->range.min = -1;
   dcatr->range.max = -1;
@@ -282,12 +275,11 @@ default_comment_filepos (abstract_catalog_reader_ty *catr,
                          const char *file_name, size_t line_number)
 {
   default_catalog_reader_ty *dcatr = (default_catalog_reader_ty *) catr;
-  size_t nbytes;
-  lex_pos_ty *pp;
 
-  nbytes = (dcatr->filepos_count + 1) * sizeof (dcatr->filepos[0]);
+  size_t nbytes = (dcatr->filepos_count + 1) * sizeof (dcatr->filepos[0]);
   dcatr->filepos = xrealloc (dcatr->filepos, nbytes);
-  pp = &dcatr->filepos[dcatr->filepos_count++];
+
+  lex_pos_ty *pp = &dcatr->filepos[dcatr->filepos_count++];
   pp->file_name = xstrdup (file_name);
   pp->line_number = line_number;
 }
@@ -298,18 +290,17 @@ void
 default_comment_special (abstract_catalog_reader_ty *catr, const char *s)
 {
   default_catalog_reader_ty *dcatr = (default_catalog_reader_ty *) catr;
+
   bool tmp_fuzzy;
   enum is_format tmp_format[NFORMATS];
   struct argument_range tmp_range;
   enum is_wrap tmp_wrap;
-  size_t i;
-
   parse_comment_special (s, &tmp_fuzzy, tmp_format, &tmp_range, &tmp_wrap,
                          NULL);
 
   if (tmp_fuzzy)
     dcatr->is_fuzzy = true;
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     if (tmp_format[i] != undecided)
       dcatr->is_format[i] = tmp_format[i];
   if (has_range_p (tmp_range))
@@ -364,12 +355,11 @@ default_add_message (default_catalog_reader_ty *dcatr,
                      char *prev_msgid_plural,
                      bool force_fuzzy, bool obsolete)
 {
-  message_ty *mp;
-
   if (dcatr->mdlp != NULL)
     /* Select the appropriate sublist of dcatr->mdlp.  */
     dcatr->mlp = msgdomain_list_sublist (dcatr->mdlp, dcatr->domain, true);
 
+  message_ty *mp;
   if (dcatr->allow_duplicates && msgid[0] != '\0')
     /* Doesn't matter if this message ID has been seen before.  */
     mp = NULL;
@@ -493,10 +483,8 @@ read_catalog_stream (FILE *fp, const char *real_filename,
                      catalog_input_format_ty input_syntax,
                      xerror_handler_ty xerror_handler)
 {
-  default_catalog_reader_ty *dcatr;
-  msgdomain_list_ty *mdlp;
-
-  dcatr = default_catalog_reader_alloc (&default_methods, xerror_handler);
+  default_catalog_reader_ty *dcatr =
+    default_catalog_reader_alloc (&default_methods, xerror_handler);
   dcatr->pass_obsolete_entries = true;
   dcatr->handle_comments = true;
   dcatr->allow_domain_directives = true;
@@ -508,9 +496,11 @@ read_catalog_stream (FILE *fp, const char *real_filename,
   if (input_syntax->produces_utf8)
     /* We know a priori that input_syntax->parse convert strings to UTF-8.  */
     dcatr->mdlp->encoding = po_charset_utf8;
+
   catalog_reader_parse ((abstract_catalog_reader_ty *) dcatr, fp, real_filename,
                         logical_filename, false, input_syntax);
-  mdlp = dcatr->mdlp;
+
+  msgdomain_list_ty *mdlp = dcatr->mdlp;
   catalog_reader_free ((abstract_catalog_reader_ty *) dcatr);
   return mdlp;
 }
index bfd6fa62f39bf89e7f468a0a5f60af2e29a448c7..ead8f4f77b86496a6de38390d2f02e4da06e776a 100644 (file)
@@ -59,16 +59,13 @@ execute_and_read_po_output (const char *progname,
                             void *private_data)
 {
   struct locals *l = (struct locals *) private_data;
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  int exitstatus;
 
   /* Open a pipe to the C# execution engine.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, true, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, true, fd);
 
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
@@ -79,7 +76,7 @@ execute_and_read_po_output (const char *progname,
   fclose (fp);
 
   /* Remove zombie process from process list, and retrieve exit status.  */
-  exitstatus =
+  int exitstatus =
     wait_subprocess (child, progname, false, false, true, true, NULL);
   if (exitstatus != 0)
     error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
@@ -93,31 +90,21 @@ msgdomain_list_ty *
 msgdomain_read_csharp (const char *resource_name, const char *locale_name,
                        const char *directory)
 {
-  char *directory_converted;
-  char *culture_name;
-  const char *args[4];
-  const char *gettextexedir;
-  const char *gettextlibdir;
-  char *assembly_path;
-  const char *libdirs[1];
-  struct locals locals;
-
   /* Assign a default value to the resource name.  */
   if (resource_name == NULL)
     resource_name = "Messages";
 
-  directory_converted = cygpath_w (directory);
+  char *directory_converted = cygpath_w (directory);
 
   /* Convert the locale name to a .NET specific culture name.  */
-  culture_name = xstrdup (locale_name);
+  char *culture_name = xstrdup (locale_name);
   {
-    char *p;
-    for (p = culture_name; *p != '\0'; p++)
+    for (char *p = culture_name; *p != '\0'; p++)
       if (*p == '_')
         *p = '-';
     if (str_startswith (culture_name, "sr-CS"))
       memcpy (culture_name, "sr-SP", 5);
-    p = strchr (culture_name, '@');
+    char *p = strchr (culture_name, '@');
     if (p != NULL)
       {
         if (strcmp (p, "@latin") == 0)
@@ -138,6 +125,7 @@ msgdomain_read_csharp (const char *resource_name, const char *locale_name,
   }
 
   /* Prepare arguments.  */
+  const char *args[4];
   args[0] = directory_converted;
   args[1] = resource_name;
   args[2] = culture_name;
@@ -145,20 +133,22 @@ msgdomain_read_csharp (const char *resource_name, const char *locale_name,
 
   /* Make it possible to override the .exe location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
+  const char *gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
   if (gettextexedir == NULL || gettextexedir[0] == '\0')
     gettextexedir = relocate (LIBDIR "/gettext");
 
   /* Make it possible to override the .dll location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
+  const char *gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
   if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
     gettextlibdir = relocate (LIBDIR);
 
   /* Dump the resource and retrieve the resulting output.  */
-  assembly_path =
+  char *assembly_path =
     xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe");
+  const char *libdirs[1];
   libdirs[0] = gettextlibdir;
+  struct locals locals;
   if (execute_csharp_program (assembly_path, libdirs, 1,
                               args,
                               verbose, false,
index 161db07a2a85deb37610ab2488575802a49dc443..36018b9bffd104c89b214659d64cecb44c9a235a 100644 (file)
@@ -44,9 +44,7 @@
 desktop_reader_ty *
 desktop_reader_alloc (desktop_reader_class_ty *method_table)
 {
-  desktop_reader_ty *reader;
-
-  reader = (desktop_reader_ty *) xmalloc (method_table->size);
+  desktop_reader_ty *reader = (desktop_reader_ty *) xmalloc (method_table->size);
   reader->methods = method_table;
   if (method_table->constructor)
     method_table->constructor (reader);
@@ -106,9 +104,7 @@ static FILE *fp;
 static int
 phase1_getc ()
 {
-  int c;
-
-  c = getc (fp);
+  int c = getc (fp);
 
   if (c == EOF)
     {
@@ -230,9 +226,6 @@ desktop_lex (token_ty *tp)
 
         case '[':
           {
-            bool non_blank = false;
-            size_t non_blank_lineno = 0;
-
             for (;;)
               {
                 c = phase2_getc ();
@@ -252,6 +245,8 @@ desktop_lex (token_ty *tp)
                 APPEND (c);
               }
             /* Skip until newline.  */
+            bool non_blank = false;
+            size_t non_blank_lineno = 0;
             while (c != '\n' && c != EOF)
               {
                 c = phase2_getc ();
@@ -305,7 +300,6 @@ desktop_lex (token_ty *tp)
           {
             size_t locale_start;
             bool found_locale = false;
-            size_t value_start;
             for (;;)
               {
                 APPEND (c);
@@ -405,7 +399,7 @@ desktop_lex (token_ty *tp)
               }
 
             size_t before_value_lineno = pos.line_number;
-            value_start = sd_length (sb_contents (&buffer));
+            size_t value_start = sd_length (sb_contents (&buffer));
             for (;;)
               {
                 c = phase2_getc ();
@@ -476,6 +470,7 @@ desktop_parse (desktop_reader_ty *reader, FILE *file,
     {
       struct token_ty token;
       desktop_lex (&token);
+
       switch (token.type)
         {
         case token_type_eof:
@@ -514,52 +509,53 @@ desktop_parse (desktop_reader_ty *reader, FILE *file,
 char *
 desktop_escape_string (const char *s, bool is_list)
 {
-  char *buffer, *p;
-
-  p = buffer = XNMALLOC (strlen (s) * 2 + 1, char);
-
-  /* The first character must not be a whitespace.  */
-  if (*s == ' ')
-    {
-      p = stpcpy (p, "\\s");
-      s++;
-    }
-  else if (*s == '\t')
-    {
-      p = stpcpy (p, "\\t");
-      s++;
-    }
-
-  for (;; s++)
-    {
-      if (*s == '\0')
-        {
-          *p = '\0';
-          break;
-        }
+  char *buffer = XNMALLOC (strlen (s) * 2 + 1, char);
+  {
+    char *p = buffer;
+
+    /* The first character must not be a whitespace.  */
+    if (*s == ' ')
+      {
+        p = stpcpy (p, "\\s");
+        s++;
+      }
+    else if (*s == '\t')
+      {
+        p = stpcpy (p, "\\t");
+        s++;
+      }
+
+    for (;; s++)
+      {
+        if (*s == '\0')
+          {
+            *p = '\0';
+            break;
+          }
 
-      switch (*s)
-        {
-        case '\n':
-          p = stpcpy (p, "\\n");
-          break;
-        case '\r':
-          p = stpcpy (p, "\\r");
-          break;
-        case '\\':
-          if (is_list && *(s + 1) == ';')
-            {
-              p = stpcpy (p, "\\;");
-              s++;
-            }
-          else
-            p = stpcpy (p, "\\\\");
-          break;
-        default:
-          *p++ = *s;
-          break;
-        }
-    }
+        switch (*s)
+          {
+          case '\n':
+            p = stpcpy (p, "\\n");
+            break;
+          case '\r':
+            p = stpcpy (p, "\\r");
+            break;
+          case '\\':
+            if (is_list && *(s + 1) == ';')
+              {
+                p = stpcpy (p, "\\;");
+                s++;
+              }
+            else
+              p = stpcpy (p, "\\\\");
+            break;
+          default:
+            *p++ = *s;
+            break;
+          }
+      }
+  }
 
   return buffer;
 }
@@ -567,52 +563,54 @@ desktop_escape_string (const char *s, bool is_list)
 char *
 desktop_unescape_string (const char *s, bool is_list)
 {
-  char *buffer, *p;
+  char *buffer = XNMALLOC (strlen (s) + 1, char);
+  {
+    char *p = buffer;
+    for (;; s++)
+      {
+        if (*s == '\0')
+          {
+            *p = '\0';
+            break;
+          }
 
-  p = buffer = XNMALLOC (strlen (s) + 1, char);
-  for (;; s++)
-    {
-      if (*s == '\0')
-        {
-          *p = '\0';
-          break;
-        }
+        if (*s == '\\')
+          {
+            s++;
+
+            if (*s == '\0')
+              {
+                *p = '\0';
+                break;
+              }
+
+            switch (*s)
+              {
+              case 's':
+                *p++ = ' ';
+                break;
+              case 'n':
+                *p++ = '\n';
+                break;
+              case 't':
+                *p++ = '\t';
+                break;
+              case 'r':
+                *p++ = '\r';
+                break;
+              case ';':
+                p = stpcpy (p, "\\;");
+                break;
+              default:
+                *p++ = *s;
+                break;
+              }
+          }
+        else
+          *p++ = *s;
+      }
+  }
 
-      if (*s == '\\')
-        {
-          s++;
-
-          if (*s == '\0')
-            {
-              *p = '\0';
-              break;
-            }
-
-          switch (*s)
-            {
-            case 's':
-              *p++ = ' ';
-              break;
-            case 'n':
-              *p++ = '\n';
-              break;
-            case 't':
-              *p++ = '\t';
-              break;
-            case 'r':
-              *p++ = '\r';
-              break;
-            case ';':
-              p = stpcpy (p, "\\;");
-              break;
-            default:
-              *p++ = *s;
-              break;
-            }
-        }
-      else
-        *p++ = *s;
-    }
   return buffer;
 }
 
index d8b25d8cb7f98ddbd9952ecaa5a2467843875746..02ae3491ff4ab69480fc1e973e57f2352724ec3a 100644 (file)
@@ -56,16 +56,13 @@ execute_and_read_po_output (const char *progname,
                             void *private_data)
 {
   struct locals *l = (struct locals *) private_data;
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  int exitstatus;
 
   /* Open a pipe to the JVM.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          DEV_NULL, false, true, true, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                DEV_NULL, false, true, true, fd);
 
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
@@ -76,7 +73,7 @@ execute_and_read_po_output (const char *progname,
   fclose (fp);
 
   /* Remove zombie process from process list, and retrieve exit status.  */
-  exitstatus =
+  int exitstatus =
     wait_subprocess (child, progname, false, false, true, true, NULL);
   if (exitstatus != 0)
     error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
@@ -90,13 +87,10 @@ msgdomain_list_ty *
 msgdomain_read_java (const char *resource_name, const char *locale_name)
 {
   const char *class_name = "gnu.gettext.DumpResource";
-  const char *gettextjar;
-  const char *args[3];
-  struct locals locals;
 
   /* Make it possible to override the gettext.jar location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextjar = getenv ("GETTEXTJAR");
+  const char *gettextjar = getenv ("GETTEXTJAR");
   if (gettextjar == NULL || gettextjar[0] == '\0')
     gettextjar = relocate (GETTEXTJAR);
 
@@ -105,6 +99,7 @@ msgdomain_read_java (const char *resource_name, const char *locale_name)
     resource_name = "Messages";
 
   /* Prepare arguments.  */
+  const char *args[3];
   args[0] = resource_name;
   if (locale_name != NULL)
     {
@@ -117,6 +112,7 @@ msgdomain_read_java (const char *resource_name, const char *locale_name)
   /* Dump the resource and retrieve the resulting output.
      Here we use the user's CLASSPATH, not a minimal one, so that the
      resource can be found.  */
+  struct locals locals;
   if (execute_java_class (class_name, &gettextjar, 1, false, NULL,
                           args,
                           verbose, false,
index bcad4170eec5f85157015cb0cd07d7b78ca602a9..fe4348c2e1068b2cc19b01e67e9dc54aaf99d9d8 100644 (file)
@@ -67,8 +67,6 @@ read_binary_mo_file (struct binary_mo_file *bfp,
   char *buf = NULL;
   size_t alloc = 0;
   size_t size = 0;
-  size_t count;
-
   while (!feof (fp))
     {
       const size_t increment = 4096;
@@ -79,7 +77,7 @@ read_binary_mo_file (struct binary_mo_file *bfp,
             alloc = size + increment;
           buf = (char *) xrealloc (buf, alloc);
         }
-      count = fread (buf + size, 1, increment, fp);
+      size_t count = fread (buf + size, 1, increment, fp);
       if (count == 0)
         {
           if (ferror (fp))
@@ -90,6 +88,7 @@ read_binary_mo_file (struct binary_mo_file *bfp,
         size += count;
     }
   buf = (char *) xrealloc (buf, size);
+
   bfp->filename = filename;
   bfp->data = buf;
   bfp->size = size;
@@ -99,16 +98,14 @@ read_binary_mo_file (struct binary_mo_file *bfp,
 static nls_uint32
 get_uint32 (const struct binary_mo_file *bfp, size_t offset)
 {
-  nls_uint32 b0, b1, b2, b3;
   size_t end = xsum (offset, 4);
-
   if (size_overflow_p (end) || end > bfp->size)
     error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
 
-  b0 = *(unsigned char *) (bfp->data + offset + 0);
-  b1 = *(unsigned char *) (bfp->data + offset + 1);
-  b2 = *(unsigned char *) (bfp->data + offset + 2);
-  b3 = *(unsigned char *) (bfp->data + offset + 3);
+  nls_uint32 b0 = *(unsigned char *) (bfp->data + offset + 0);
+  nls_uint32 b1 = *(unsigned char *) (bfp->data + offset + 1);
+  nls_uint32 b2 = *(unsigned char *) (bfp->data + offset + 2);
+  nls_uint32 b3 = *(unsigned char *) (bfp->data + offset + 3);
   if (bfp->endian == MO_LITTLE_ENDIAN)
     return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24);
   else
@@ -122,10 +119,11 @@ get_string (const struct binary_mo_file *bfp, size_t offset, size_t *lengthp)
   /* See 'struct string_desc'.  */
   nls_uint32 s_length = get_uint32 (bfp, offset);
   nls_uint32 s_offset = get_uint32 (bfp, offset + 4);
-  size_t s_end = xsum3 (s_offset, s_length, 1);
 
+  size_t s_end = xsum3 (s_offset, s_length, 1);
   if (size_overflow_p (s_end) || s_end > bfp->size)
     error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
+
   if (bfp->data[s_offset + s_length] != '\0')
     error (EXIT_FAILURE, 0,
            _("file \"%s\" contains a not NUL terminated string"),
@@ -141,27 +139,16 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset,
                    const struct mo_file_header *header, size_t *lengthp)
 {
   /* See 'struct sysdep_string'.  */
-  size_t length;
-  char *string;
-  size_t i;
-  char *p;
-  nls_uint32 s_offset;
 
   /* Compute the length.  */
-  s_offset = get_uint32 (bfp, offset);
-  length = 0;
-  for (i = 4; ; i += 8)
+  nls_uint32 s_offset = get_uint32 (bfp, offset);
+  size_t length = 0;
+  for (size_t i = 4; ; i += 8)
     {
       nls_uint32 segsize = get_uint32 (bfp, offset + i);
       nls_uint32 sysdepref = get_uint32 (bfp, offset + i + 4);
-      nls_uint32 sysdep_segment_offset;
-      nls_uint32 ss_length;
-      nls_uint32 ss_offset;
-      size_t ss_end;
-      size_t s_end;
-      size_t n;
-
-      s_end = xsum (s_offset, segsize);
+
+      size_t s_end = xsum (s_offset, segsize);
       if (size_overflow_p (s_end) || s_end > bfp->size)
         error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
       length += segsize;
@@ -182,10 +169,10 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset,
         error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format"),
                bfp->filename);
       /* See 'struct sysdep_segment'.  */
-      sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8;
-      ss_length = get_uint32 (bfp, sysdep_segment_offset);
-      ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4);
-      ss_end = xsum (ss_offset, ss_length);
+      nls_uint32 sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8;
+      nls_uint32 ss_length = get_uint32 (bfp, sysdep_segment_offset);
+      nls_uint32 ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4);
+      size_t ss_end = xsum (ss_offset, ss_length);
       if (size_overflow_p (ss_end) || ss_end > bfp->size)
         error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
       if (!(ss_length > 0 && bfp->data[ss_end - 1] == '\0'))
@@ -196,50 +183,48 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset,
                  _("file \"%s\" contains a not NUL terminated string, at %s"),
                  bfp->filename, location);
         }
-      n = strlen (bfp->data + ss_offset);
+      size_t n = strlen (bfp->data + ss_offset);
       length += (n > 1 ? 1 + n + 1 : n);
     }
 
   /* Allocate and fill the string.  */
-  string = XNMALLOC (length, char);
-  p = string;
-  s_offset = get_uint32 (bfp, offset);
-  for (i = 4; ; i += 8)
-    {
-      nls_uint32 segsize = get_uint32 (bfp, offset + i);
-      nls_uint32 sysdepref = get_uint32 (bfp, offset + i + 4);
-      nls_uint32 sysdep_segment_offset;
-      nls_uint32 ss_length;
-      nls_uint32 ss_offset;
-      size_t n;
+  char *string = XNMALLOC (length, char);
+  {
+    char *p = string;
+    s_offset = get_uint32 (bfp, offset);
+    for (size_t i = 4; ; i += 8)
+      {
+        nls_uint32 segsize = get_uint32 (bfp, offset + i);
+        nls_uint32 sysdepref = get_uint32 (bfp, offset + i + 4);
 
-      memcpy (p, bfp->data + s_offset, segsize);
-      p += segsize;
-      s_offset += segsize;
+        memcpy (p, bfp->data + s_offset, segsize);
+        p += segsize;
+        s_offset += segsize;
 
-      if (sysdepref == SEGMENTS_END)
-        break;
-      if (sysdepref >= header->n_sysdep_segments)
-        abort ();
-      /* See 'struct sysdep_segment'.  */
-      sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8;
-      ss_length = get_uint32 (bfp, sysdep_segment_offset);
-      ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4);
-      if (ss_offset + ss_length > bfp->size)
-        abort ();
-      if (!(ss_length > 0 && bfp->data[ss_offset + ss_length - 1] == '\0'))
-        abort ();
-      n = strlen (bfp->data + ss_offset);
-      if (n > 1)
-        *p++ = '<';
-      memcpy (p, bfp->data + ss_offset, n);
-      p += n;
-      if (n > 1)
-        *p++ = '>';
-    }
+        if (sysdepref == SEGMENTS_END)
+          break;
+        if (sysdepref >= header->n_sysdep_segments)
+          abort ();
+        /* See 'struct sysdep_segment'.  */
+        nls_uint32 sysdep_segment_offset = header->sysdep_segments_offset + sysdepref * 8;
+        nls_uint32 ss_length = get_uint32 (bfp, sysdep_segment_offset);
+        nls_uint32 ss_offset = get_uint32 (bfp, sysdep_segment_offset + 4);
+        if (ss_offset + ss_length > bfp->size)
+          abort ();
+        if (!(ss_length > 0 && bfp->data[ss_offset + ss_length - 1] == '\0'))
+          abort ();
+        size_t n = strlen (bfp->data + ss_offset);
+        if (n > 1)
+          *p++ = '<';
+        memcpy (p, bfp->data + ss_offset, n);
+        p += n;
+        if (n > 1)
+          *p++ = '>';
+      }
 
-  if (p != string + length)
-    abort ();
+    if (p != string + length)
+      abort ();
+  }
 
   *lengthp = length;
   return string;
@@ -249,12 +234,9 @@ get_sysdep_string (const struct binary_mo_file *bfp, size_t offset,
 void
 read_mo_file (message_list_ty *mlp, const char *filename)
 {
-  FILE *fp;
-  struct binary_mo_file bf;
-  struct mo_file_header header;
-  unsigned int i;
   static lex_pos_ty pos = { __FILE__, __LINE__ };
 
+  FILE *fp;
   if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
     {
       fp = stdin;
@@ -269,12 +251,15 @@ read_mo_file (message_list_ty *mlp, const char *filename)
     }
 
   /* Read the file contents into memory.  */
+  struct binary_mo_file bf;
   read_binary_mo_file (&bf, fp, filename);
 
   /* Get a 32-bit number from the file header.  */
 # define GET_HEADER_FIELD(field) \
     get_uint32 (&bf, offsetof (struct mo_file_header, field))
 
+  struct mo_file_header header;
+
   /* We must grope the file to determine which endian it is.
      Perversity of the universe tends towards maximum, so it will
      probably not match the currently executing architecture.  */
@@ -313,13 +298,11 @@ read_mo_file (message_list_ty *mlp, const char *filename)
       {
         char *prev_msgid = NULL;
 
-        for (i = 0; i < header.nstrings; i++)
+        for (unsigned int i = 0; i < header.nstrings; i++)
           {
-            char *msgid;
             size_t msgid_len;
-
-            msgid = get_string (&bf, header.orig_tab_offset + i * 8,
-                                &msgid_len);
+            char *msgid = get_string (&bf, header.orig_tab_offset + i * 8,
+                                      &msgid_len);
             if (i == 0)
               prev_msgid = msgid;
             else
@@ -335,9 +318,6 @@ read_mo_file (message_list_ty *mlp, const char *filename)
       /* Verify the hash table.  */
       if (header.hash_tab_size > 0)
         {
-          char *seen;
-          unsigned int j;
-
           /* Verify the hash table's size.  */
           if (!(header.hash_tab_size > 2))
             error (EXIT_FAILURE, 0,
@@ -346,15 +326,15 @@ read_mo_file (message_list_ty *mlp, const char *filename)
 
           /* Verify that the non-empty hash table entries contain the values
              1, ..., nstrings, each exactly once.  */
-          seen = (char *) xcalloc (header.nstrings, 1);
-          for (j = 0; j < header.hash_tab_size; j++)
+          char *seen = (char *) xcalloc (header.nstrings, 1);
+          for (unsigned int j = 0; j < header.hash_tab_size; j++)
             {
               nls_uint32 entry =
                 get_uint32 (&bf, header.hash_tab_offset + j * 4);
 
               if (entry != 0)
                 {
-                  i = entry - 1;
+                  unsigned int i = entry - 1;
                   if (!(i < header.nstrings && seen[i] == 0))
                     error (EXIT_FAILURE, 0,
                            _("file \"%s\" is not in GNU .mo format: The hash table contains invalid entries."),
@@ -362,7 +342,7 @@ read_mo_file (message_list_ty *mlp, const char *filename)
                   seen[i] = 1;
                 }
             }
-          for (i = 0; i < header.nstrings; i++)
+          for (unsigned int i = 0; i < header.nstrings; i++)
             if (seen[i] == 0)
               error (EXIT_FAILURE, 0, _("file \"%s\" is not in GNU .mo format: Some messages are not present in the hash table."),
                      filename);
@@ -370,7 +350,7 @@ read_mo_file (message_list_ty *mlp, const char *filename)
 
           /* Verify that the hash table lookup algorithm finds the entry for
              each message.  */
-          for (i = 0; i < header.nstrings; i++)
+          for (unsigned int i = 0; i < header.nstrings; i++)
             {
               size_t msgid_len;
               char *msgid = get_string (&bf, header.orig_tab_offset + i * 8,
@@ -398,43 +378,40 @@ read_mo_file (message_list_ty *mlp, const char *filename)
             }
         }
 
-      for (i = 0; i < header.nstrings; i++)
+      for (unsigned int i = 0; i < header.nstrings; i++)
         {
-          message_ty *mp;
-          char *msgctxt;
-          char *msgid;
-          size_t msgid_len;
-          char *separator;
-          char *msgstr;
-          size_t msgstr_len;
-
           /* Read the msgctxt and msgid.  */
-          msgid = get_string (&bf, header.orig_tab_offset + i * 8,
-                              &msgid_len);
+          size_t msgid_len;
+          char *msgid = get_string (&bf, header.orig_tab_offset + i * 8,
+                                    &msgid_len);
           /* Split into msgctxt and msgid.  */
-          separator = strchr (msgid, MSGCTXT_SEPARATOR);
-          if (separator != NULL)
-            {
-              /* The part before the MSGCTXT_SEPARATOR is the msgctxt.  */
-              *separator = '\0';
-              msgctxt = msgid;
-              msgid = separator + 1;
-              msgid_len -= msgid - msgctxt;
-            }
-          else
-            msgctxt = NULL;
+          char *msgctxt;
+          {
+            char *separator = strchr (msgid, MSGCTXT_SEPARATOR);
+            if (separator != NULL)
+              {
+                /* The part before the MSGCTXT_SEPARATOR is the msgctxt.  */
+                *separator = '\0';
+                msgctxt = msgid;
+                msgid = separator + 1;
+                msgid_len -= msgid - msgctxt;
+              }
+            else
+              msgctxt = NULL;
+          }
 
           /* Read the msgstr.  */
-          msgstr = get_string (&bf, header.trans_tab_offset + i * 8,
-                               &msgstr_len);
-
-          mp = message_alloc (msgctxt,
-                              msgid,
-                              (strlen (msgid) + 1 < msgid_len
-                               ? msgid + strlen (msgid) + 1
-                               : NULL),
-                              msgstr, msgstr_len,
-                              &pos);
+          size_t msgstr_len;
+          char *msgstr = get_string (&bf, header.trans_tab_offset + i * 8,
+                                     &msgstr_len);
+
+          message_ty *mp = message_alloc (msgctxt,
+                                          msgid,
+                                          (strlen (msgid) + 1 < msgid_len
+                                           ? msgid + strlen (msgid) + 1
+                                           : NULL),
+                                          msgstr, msgstr_len,
+                                          &pos);
           message_list_append (mlp, mp);
         }
 
@@ -454,78 +431,80 @@ read_mo_file (message_list_ty *mlp, const char *filename)
           header.trans_sysdep_tab_offset =
             GET_HEADER_FIELD (trans_sysdep_tab_offset);
 
-          for (i = 0; i < header.n_sysdep_strings; i++)
+          for (unsigned int i = 0; i < header.n_sysdep_strings; i++)
             {
-              message_ty *mp;
-              char *msgctxt;
+              /* Read the msgctxt and msgid.  */
               char *msgid;
               size_t msgid_len;
-              char *separator;
-              char *msgstr;
-              size_t msgstr_len;
-              nls_uint32 offset;
-              size_t f;
-
-              /* Read the msgctxt and msgid.  */
-              offset = get_uint32 (&bf, header.orig_sysdep_tab_offset + i * 4);
-              msgid = get_sysdep_string (&bf, offset, &header, &msgid_len);
+              {
+                nls_uint32 offset = get_uint32 (&bf, header.orig_sysdep_tab_offset + i * 4);
+                msgid = get_sysdep_string (&bf, offset, &header, &msgid_len);
+              }
               /* Split into msgctxt and msgid.  */
-              separator = strchr (msgid, MSGCTXT_SEPARATOR);
-              if (separator != NULL)
-                {
-                  /* The part before the MSGCTXT_SEPARATOR is the msgctxt.  */
-                  *separator = '\0';
-                  msgctxt = msgid;
-                  msgid = separator + 1;
-                  msgid_len -= msgid - msgctxt;
-                }
-              else
-                msgctxt = NULL;
+              char *msgctxt;
+              {
+                char *separator = strchr (msgid, MSGCTXT_SEPARATOR);
+                if (separator != NULL)
+                  {
+                    /* The part before the MSGCTXT_SEPARATOR is the msgctxt.  */
+                    *separator = '\0';
+                    msgctxt = msgid;
+                    msgid = separator + 1;
+                    msgid_len -= msgid - msgctxt;
+                  }
+                else
+                  msgctxt = NULL;
+              }
 
               /* Read the msgstr.  */
-              offset = get_uint32 (&bf, header.trans_sysdep_tab_offset + i * 4);
-              msgstr = get_sysdep_string (&bf, offset, &header, &msgstr_len);
+              char *msgstr;
+              size_t msgstr_len;
+              {
+                nls_uint32 offset = get_uint32 (&bf, header.trans_sysdep_tab_offset + i * 4);
+                msgstr = get_sysdep_string (&bf, offset, &header, &msgstr_len);
+              }
 
-              mp = message_alloc (msgctxt,
-                                  msgid,
-                                  (strlen (msgid) + 1 < msgid_len
-                                   ? msgid + strlen (msgid) + 1
-                                   : NULL),
-                                  msgstr, msgstr_len,
-                                  &pos);
+              message_ty *mp = message_alloc (msgctxt,
+                                              msgid,
+                                              (strlen (msgid) + 1 < msgid_len
+                                               ? msgid + strlen (msgid) + 1
+                                               : NULL),
+                                              msgstr, msgstr_len,
+                                              &pos);
 
               /* Only messages with c-format or objc-format annotation are
                  recognized as having system-dependent strings by msgfmt.
                  Which one of the two, we don't know.  We have to guess,
                  assuming that c-format is more probable than objc-format and
                  that the .mo was likely produced by "msgfmt -c".  */
-              for (f = format_c; ; f = format_objc)
+              for (size_t f = format_c; ; f = format_objc)
                 {
-                  bool valid = true;
                   struct formatstring_parser *parser = formatstring_parsers[f];
-                  const char *str_end;
-                  const char *str;
 
-                  str_end = msgid + msgid_len;
-                  for (str = msgid; str < str_end; str += strlen (str) + 1)
-                    {
-                      char *invalid_reason = NULL;
-                      void *descr =
-                        parser->parse (str, false, NULL, &invalid_reason);
+                  bool valid = true;
+                  {
+                    const char *str_end = msgid + msgid_len;
+                    for (const char *str = msgid; str < str_end; str += strlen (str) + 1)
+                      {
+                        char *invalid_reason = NULL;
+                        void *descr =
+                          parser->parse (str, false, NULL, &invalid_reason);
+
+                        if (descr != NULL)
+                          parser->free (descr);
+                        else
+                          {
+                            free (invalid_reason);
+                            valid = false;
+                            break;
+                          }
+                      }
+                  }
 
-                      if (descr != NULL)
-                        parser->free (descr);
-                      else
-                        {
-                          free (invalid_reason);
-                          valid = false;
-                          break;
-                        }
-                    }
                   if (valid)
                     {
-                      str_end = msgstr + msgstr_len;
-                      for (str = msgstr; str < str_end; str += strlen (str) + 1)
+                      const char *str_end = msgstr + msgstr_len;
+                      for (const char *str = msgstr; str < str_end; str += strlen (str) + 1)
                         {
                           char *invalid_reason = NULL;
                           void *descr =
index 79f433d65d18991d3f82698aeb125e38b422c0c5..7723779d50f422026cf239eac99d84e19ee03b95 100644 (file)
@@ -73,9 +73,8 @@ void
 po_gram_error (struct po_parser_state *ps, const char *fmt, ...)
 {
   va_list ap;
-  char *buffer;
-
   va_start (ap, fmt);
+  char *buffer;
   if (vasprintf (&buffer, fmt, ap) < 0)
     ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
                            _("memory exhausted"));
@@ -95,9 +94,8 @@ po_gram_error_at_line (abstract_catalog_reader_ty *catr, const lex_pos_ty *pp,
                        const char *fmt, ...)
 {
   va_list ap;
-  char *buffer;
-
   va_start (ap, fmt);
+  char *buffer;
   if (vasprintf (&buffer, fmt, ap) < 0)
     catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
                        _("memory exhausted"));
@@ -144,17 +142,14 @@ po_lex_charset_set (struct po_parser_state *ps,
 
   if (charsetstr != NULL)
     {
-      size_t len;
-      char *charset;
-      const char *canon_charset;
-
       charsetstr += strlen ("charset=");
-      len = strcspn (charsetstr, " \t\n");
-      charset = (char *) xmalloca (len + 1);
+      size_t len = strcspn (charsetstr, " \t\n");
+
+      char *charset = (char *) xmalloca (len + 1);
       memcpy (charset, charsetstr, len);
       charset[len] = '\0';
 
-      canon_charset = po_charset_canonicalize (charset);
+      const char *canon_charset = po_charset_canonicalize (charset);
       if (canon_charset == NULL)
         {
           /* Don't warn for POT files, because POT files usually contain
@@ -179,8 +174,6 @@ Message conversion to user's charset might not work.\n"),
         }
       else
         {
-          const char *envval;
-
           ps->po_lex_charset = canon_charset;
 
           if (strcmp (canon_charset, "UTF-8") == 0)
@@ -211,7 +204,7 @@ Message conversion to user's charset might not work.\n"),
              0x5C.  Some programs, like vim, distribute PO files in this
              broken format.  GNU msgfmt must continue to support this old
              PO file format when the Makefile requests it.  */
-          envval = getenv ("OLD_PO_FILE_INPUT");
+          const char *envval = getenv ("OLD_PO_FILE_INPUT");
           if (envval != NULL && *envval != '\0')
             {
               /* Assume the PO file is in old format, with extraneous
@@ -229,23 +222,19 @@ Message conversion to user's charset might not work.\n"),
               if (ps->po_lex_iconv == (iconv_t)(-1))
                 {
                   const char *progname;
-                  char *warning_message;
-                  const char *recommendation;
-                  const char *note;
-                  char *whole_message;
-
 # if IN_LIBGETTEXTPO
                   progname = "libgettextpo";
 # else
                   progname = last_component (program_name);
 # endif
 
-                  warning_message =
+                  char *warning_message =
                     xasprintf (_("\
 Charset \"%s\" is not supported. %s relies on iconv(),\n\
 and iconv() does not support \"%s\".\n"),
                                ps->po_lex_charset, progname, ps->po_lex_charset);
 
+                  const char *recommendation;
 # if !defined _LIBICONV_VERSION || (_LIBICONV_VERSION == 0x10b && defined __APPLE__)
                   recommendation = _("\
 Installing GNU libiconv and then reinstalling GNU gettext\n\
@@ -259,13 +248,14 @@ would fix this problem.\n");
                      is likely to be confused if it can't see the character
                      boundaries.  */
                   ps->po_lex_weird_cjk = po_is_charset_weird_cjk (ps->po_lex_charset);
+                  const char *note;
                   if (po_is_charset_weird (ps->po_lex_charset)
                       && !ps->po_lex_weird_cjk)
                     note = _("Continuing anyway, expect parse errors.");
                   else
                     note = _("Continuing anyway.");
 
-                  whole_message =
+                  char *whole_message =
                     xasprintf ("%s%s%s\n",
                                warning_message, recommendation, note);
 
@@ -285,30 +275,25 @@ would fix this problem.\n");
               if (po_is_charset_weird (ps->po_lex_charset) && !ps->po_lex_weird_cjk)
                 {
                   const char *progname;
-                  char *warning_message;
-                  const char *recommendation;
-                  const char *note;
-                  char *whole_message;
-
 # if IN_LIBGETTEXTPO
                   progname = "libgettextpo";
 # else
                   progname = last_component (program_name);
 # endif
 
-                  warning_message =
+                  char *warning_message =
                     xasprintf (_("\
 Charset \"%s\" is not supported. %s relies on iconv().\n\
 This version was built without iconv().\n"),
                                ps->po_lex_charset, progname);
 
-                  recommendation = _("\
+                  const char *recommendation = _("\
 Installing GNU libiconv and then reinstalling GNU gettext\n\
 would fix this problem.\n");
 
-                  note = _("Continuing anyway, expect parse errors.");
+                  const char *note = _("Continuing anyway, expect parse errors.");
 
-                  whole_message =
+                  char *whole_message =
                     xasprintf ("%s%s%s\n",
                                warning_message, recommendation, note);
 
@@ -578,8 +563,6 @@ mbfile_init (mbfile_t mbf, FILE *stream)
 static void
 mbfile_getc (struct po_parser_state *ps, mbchar_t mbc, mbfile_t mbf)
 {
-  size_t bytes;
-
   /* Return character pushed back, if there is one.  */
   if (mbf->pushback_count > 0)
     {
@@ -606,6 +589,8 @@ mbfile_getc (struct po_parser_state *ps, mbchar_t mbc, mbfile_t mbf)
       mbf->bufcount++;
     }
 
+  size_t bytes;
+
 #if HAVE_ICONV
   if (ps->po_lex_iconv != (iconv_t)(-1))
     {
@@ -838,8 +823,8 @@ mbfile_getc_normalized (struct po_parser_state *ps, mbchar_t mbc, mbfile_t mbf)
   if (!mb_iseof (mbc) && mb_iseq (mbc, '\r'))
     {
       mbchar_t mbc2;
-
       mbfile_getc (ps, mbc2, ps->mbf);
+
       if (!mb_iseof (mbc2))
         {
           if (mb_iseq (mbc2, '\n'))
@@ -893,7 +878,6 @@ lex_getc (struct po_parser_state *ps, mbchar_t mbc)
       if (mb_iseq (mbc, '\\'))
         {
           mbchar_t mbc2;
-
           mbfile_getc_normalized (ps, mbc2, ps->mbf);
 
           if (mb_iseof (mbc2))
@@ -971,10 +955,8 @@ static int
 control_sequence (struct po_parser_state *ps)
 {
   mbchar_t mbc;
-  int val;
-  int max;
-
   lex_getc (ps, mbc);
+
   if (mb_len (mbc) == 1)
     switch (mb_ptr (mbc) [0])
       {
@@ -1005,69 +987,73 @@ control_sequence (struct po_parser_state *ps)
 
       case '0': case '1': case '2': case '3':
       case '4': case '5': case '6': case '7':
-        val = 0;
-        max = 0;
-        for (;;)
-          {
-            char c = mb_ptr (mbc) [0];
-            /* Warning: not portable, can't depend on '0'..'7' ordering.  */
-            val = val * 8 + (c - '0');
-            if (++max == 3)
-              break;
-            lex_getc (ps, mbc);
-            if (mb_len (mbc) == 1)
-              switch (mb_ptr (mbc) [0])
-                {
-                case '0': case '1': case '2': case '3':
-                case '4': case '5': case '6': case '7':
-                  continue;
+        {
+          int val = 0;
+          int max = 0;
+          for (;;)
+            {
+              char c = mb_ptr (mbc) [0];
+              /* Warning: not portable, can't depend on '0'..'7' ordering.  */
+              val = val * 8 + (c - '0');
+              if (++max == 3)
+                break;
+              lex_getc (ps, mbc);
+              if (mb_len (mbc) == 1)
+                switch (mb_ptr (mbc) [0])
+                  {
+                  case '0': case '1': case '2': case '3':
+                  case '4': case '5': case '6': case '7':
+                    continue;
 
-                default:
-                  break;
-                }
-            lex_ungetc (ps, mbc);
-            break;
-          }
-        return val;
+                  default:
+                    break;
+                  }
+              lex_ungetc (ps, mbc);
+              break;
+            }
+          return val;
+        }
 
       case 'x':
-        lex_getc (ps, mbc);
-        if (mb_iseof (mbc) || mb_len (mbc) != 1
-            || !c_isxdigit (mb_ptr (mbc) [0]))
-          break;
+        {
+          lex_getc (ps, mbc);
+          if (mb_iseof (mbc) || mb_len (mbc) != 1
+              || !c_isxdigit (mb_ptr (mbc) [0]))
+            break;
 
-        val = 0;
-        for (;;)
-          {
-            char c = mb_ptr (mbc) [0];
-            val *= 16;
-            if (c_isdigit (c))
-              /* Warning: not portable, can't depend on '0'..'9' ordering */
-              val += c - '0';
-            else if (c_isupper (c))
-              /* Warning: not portable, can't depend on 'A'..'F' ordering */
-              val += c - 'A' + 10;
-            else
-              /* Warning: not portable, can't depend on 'a'..'f' ordering */
-              val += c - 'a' + 10;
+          int val = 0;
+          for (;;)
+            {
+              char c = mb_ptr (mbc) [0];
+              val *= 16;
+              if (c_isdigit (c))
+                /* Warning: not portable, can't depend on '0'..'9' ordering */
+                val += c - '0';
+              else if (c_isupper (c))
+                /* Warning: not portable, can't depend on 'A'..'F' ordering */
+                val += c - 'A' + 10;
+              else
+                /* Warning: not portable, can't depend on 'a'..'f' ordering */
+                val += c - 'a' + 10;
 
-            lex_getc (ps, mbc);
-            if (mb_len (mbc) == 1)
-              switch (mb_ptr (mbc) [0])
-                {
-                case '0': case '1': case '2': case '3': case '4':
-                case '5': case '6': case '7': case '8': case '9':
-                case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
-                case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
-                  continue;
+              lex_getc (ps, mbc);
+              if (mb_len (mbc) == 1)
+                switch (mb_ptr (mbc) [0])
+                  {
+                  case '0': case '1': case '2': case '3': case '4':
+                  case '5': case '6': case '7': case '8': case '9':
+                  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+                  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+                    continue;
 
-                default:
-                  break;
-                }
-            lex_ungetc (ps, mbc);
-            break;
-          }
-        return val;
+                  default:
+                    break;
+                  }
+              lex_ungetc (ps, mbc);
+              break;
+            }
+          return val;
+        }
 
       /* FIXME: \u and \U are not handled.  */
       }
@@ -1086,11 +1072,9 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
   char *buf = ps->buf;
   size_t bufmax = ps->bufmax;
 
-  mbchar_t mbc;
-  size_t bufpos;
-
   for (;;)
     {
+      mbchar_t mbc;
       lex_getc (ps, mbc);
 
       if (mb_iseof (mbc))
@@ -1150,25 +1134,27 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
             ps->signal_eilseq = false;
             if (ps->catr->pass_comments)
               {
-                bufpos = 0;
-                for (;;)
-                  {
-                    while (bufpos + mb_len (mbc) >= bufmax)
-                      {
-                        bufmax += 100;
-                        buf = xrealloc (buf, bufmax);
-                        ps->bufmax = bufmax;
-                        ps->buf = buf;
-                      }
-                    if (mb_iseof (mbc) || mb_iseq (mbc, '\n'))
-                      break;
-
-                    memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc));
-                    bufpos += mb_len (mbc);
-
-                    lex_getc (ps, mbc);
-                  }
-                buf[bufpos] = '\0';
+                {
+                  size_t bufpos = 0;
+                  for (;;)
+                    {
+                      while (bufpos + mb_len (mbc) >= bufmax)
+                        {
+                          bufmax += 100;
+                          buf = xrealloc (buf, bufmax);
+                          ps->bufmax = bufmax;
+                          ps->buf = buf;
+                        }
+                      if (mb_iseof (mbc) || mb_iseq (mbc, '\n'))
+                        break;
+
+                      memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc));
+                      bufpos += mb_len (mbc);
+
+                      lex_getc (ps, mbc);
+                    }
+                  buf[bufpos] = '\0';
+                }
 
                 lval->string.string = buf;
                 lval->string.pos = ps->gram_pos;
@@ -1191,41 +1177,43 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
 
           case '"':
             /* Accumulate a string.  */
-            bufpos = 0;
-            for (;;)
-              {
-                lex_getc (ps, mbc);
-                while (bufpos + mb_len (mbc) >= bufmax)
-                  {
-                    bufmax += 100;
-                    buf = xrealloc (buf, bufmax);
-                    ps->bufmax = bufmax;
-                    ps->buf = buf;
-                  }
-                if (mb_iseof (mbc))
-                  {
-                    po_gram_error_at_line (ps->catr, &ps->gram_pos,
-                                           _("end-of-file within string"));
-                    break;
-                  }
-                if (mb_iseq (mbc, '\n'))
-                  {
-                    po_gram_error_at_line (ps->catr, &ps->gram_pos,
-                                           _("end-of-line within string"));
+            {
+              size_t bufpos = 0;
+              for (;;)
+                {
+                  lex_getc (ps, mbc);
+                  while (bufpos + mb_len (mbc) >= bufmax)
+                    {
+                      bufmax += 100;
+                      buf = xrealloc (buf, bufmax);
+                      ps->bufmax = bufmax;
+                      ps->buf = buf;
+                    }
+                  if (mb_iseof (mbc))
+                    {
+                      po_gram_error_at_line (ps->catr, &ps->gram_pos,
+                                             _("end-of-file within string"));
+                      break;
+                    }
+                  if (mb_iseq (mbc, '\n'))
+                    {
+                      po_gram_error_at_line (ps->catr, &ps->gram_pos,
+                                             _("end-of-line within string"));
+                      break;
+                    }
+                  if (mb_iseq (mbc, '"'))
                     break;
-                  }
-                if (mb_iseq (mbc, '"'))
-                  break;
-                if (mb_iseq (mbc, '\\'))
-                  buf[bufpos++] = control_sequence (ps);
-                else
-                  {
-                    /* Add mbc to the accumulator.  */
-                    memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc));
-                    bufpos += mb_len (mbc);
-                  }
-              }
-            buf[bufpos] = '\0';
+                  if (mb_iseq (mbc, '\\'))
+                    buf[bufpos++] = control_sequence (ps);
+                  else
+                    {
+                      /* Add mbc to the accumulator.  */
+                      memcpy_small (&buf[bufpos], mb_ptr (mbc), mb_len (mbc));
+                      bufpos += mb_len (mbc);
+                    }
+                }
+              buf[bufpos] = '\0';
+            }
 
             /* Strings cannot contain the msgctxt separator, because it cannot
                be faithfully represented in the msgid of a .mo file.  */
@@ -1250,47 +1238,48 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
           case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
           case 'Y': case 'Z':
           case '_': case '$':
-            bufpos = 0;
-            for (;;)
-              {
-                char c = mb_ptr (mbc) [0];
-                if (bufpos + 1 >= bufmax)
-                  {
-                    bufmax += 100;
-                    buf = xrealloc (buf, bufmax);
-                    ps->bufmax = bufmax;
-                    ps->buf = buf;
-                  }
-                buf[bufpos++] = c;
-                lex_getc (ps, mbc);
-                if (mb_len (mbc) == 1)
-                  switch (mb_ptr (mbc) [0])
+            {
+              size_t bufpos = 0;
+              for (;;)
+                {
+                  char c = mb_ptr (mbc) [0];
+                  if (bufpos + 1 >= bufmax)
                     {
-                    default:
-                      break;
-                    case 'a': case 'b': case 'c': case 'd': case 'e':
-                    case 'f': case 'g': case 'h': case 'i': case 'j':
-                    case 'k': case 'l': case 'm': case 'n': case 'o':
-                    case 'p': case 'q': case 'r': case 's': case 't':
-                    case 'u': case 'v': case 'w': case 'x': case 'y':
-                    case 'z':
-                    case 'A': case 'B': case 'C': case 'D': case 'E':
-                    case 'F': case 'G': case 'H': case 'I': case 'J':
-                    case 'K': case 'L': case 'M': case 'N': case 'O':
-                    case 'P': case 'Q': case 'R': case 'S': case 'T':
-                    case 'U': case 'V': case 'W': case 'X': case 'Y':
-                    case 'Z':
-                    case '_': case '$':
-                    case '0': case '1': case '2': case '3': case '4':
-                    case '5': case '6': case '7': case '8': case '9':
-                      continue;
+                      bufmax += 100;
+                      buf = xrealloc (buf, bufmax);
+                      ps->bufmax = bufmax;
+                      ps->buf = buf;
                     }
-                break;
-              }
-            lex_ungetc (ps, mbc);
-
-            buf[bufpos] = '\0';
+                  buf[bufpos++] = c;
+                  lex_getc (ps, mbc);
+                  if (mb_len (mbc) == 1)
+                    switch (mb_ptr (mbc) [0])
+                      {
+                      default:
+                        break;
+                      case 'a': case 'b': case 'c': case 'd': case 'e':
+                      case 'f': case 'g': case 'h': case 'i': case 'j':
+                      case 'k': case 'l': case 'm': case 'n': case 'o':
+                      case 'p': case 'q': case 'r': case 's': case 't':
+                      case 'u': case 'v': case 'w': case 'x': case 'y':
+                      case 'z':
+                      case 'A': case 'B': case 'C': case 'D': case 'E':
+                      case 'F': case 'G': case 'H': case 'I': case 'J':
+                      case 'K': case 'L': case 'M': case 'N': case 'O':
+                      case 'P': case 'Q': case 'R': case 'S': case 'T':
+                      case 'U': case 'V': case 'W': case 'X': case 'Y':
+                      case 'Z':
+                      case '_': case '$':
+                      case '0': case '1': case '2': case '3': case '4':
+                      case '5': case '6': case '7': case '8': case '9':
+                        continue;
+                      }
+                  break;
+                }
+              lex_ungetc (ps, mbc);
 
+              buf[bufpos] = '\0';
+            }
             {
               int k = keyword_p (ps, buf);
               if (k == NAME)
@@ -1309,34 +1298,36 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps)
 
           case '0': case '1': case '2': case '3': case '4':
           case '5': case '6': case '7': case '8': case '9':
-            bufpos = 0;
-            for (;;)
-              {
-                char c = mb_ptr (mbc) [0];
-                if (bufpos + 1 >= bufmax)
-                  {
-                    bufmax += 100;
-                    buf = xrealloc (buf, bufmax + 1);
-                    ps->bufmax = bufmax;
-                    ps->buf = buf;
-                  }
-                buf[bufpos++] = c;
-                lex_getc (ps, mbc);
-                if (mb_len (mbc) == 1)
-                  switch (mb_ptr (mbc) [0])
+            {
+              size_t bufpos = 0;
+              for (;;)
+                {
+                  char c = mb_ptr (mbc) [0];
+                  if (bufpos + 1 >= bufmax)
                     {
-                    default:
-                      break;
-
-                    case '0': case '1': case '2': case '3': case '4':
-                    case '5': case '6': case '7': case '8': case '9':
-                      continue;
+                      bufmax += 100;
+                      buf = xrealloc (buf, bufmax + 1);
+                      ps->bufmax = bufmax;
+                      ps->buf = buf;
                     }
-                break;
-              }
-            lex_ungetc (ps, mbc);
+                  buf[bufpos++] = c;
+                  lex_getc (ps, mbc);
+                  if (mb_len (mbc) == 1)
+                    switch (mb_ptr (mbc) [0])
+                      {
+                      default:
+                        break;
+
+                      case '0': case '1': case '2': case '3': case '4':
+                      case '5': case '6': case '7': case '8': case '9':
+                        continue;
+                      }
+                  break;
+                }
+              lex_ungetc (ps, mbc);
 
-            buf[bufpos] = '\0';
+              buf[bufpos] = '\0';
+            }
 
             lval->number.number = atol (buf);
             lval->number.pos = ps->gram_pos;
index b8c7fc150b663ce429923cd1770d512cbe50cc32..d7e4bf419496b7f269656dc78dc81185a7e3a167 100644 (file)
@@ -188,19 +188,20 @@ conv_from_iso_8859_1 (char *string)
       size_t length = strlen (string);
       /* Each ISO-8859-1 character needs 2 bytes at worst.  */
       unsigned char *utf8_string = XNMALLOC (2 * length + 1, unsigned char);
-      unsigned char *q = utf8_string;
-      const char *str = string;
-      const char *str_limit = str + length;
-
-      while (str < str_limit)
-        {
-          unsigned int uc = (unsigned char) *str++;
-          int n = u8_uctomb (q, uc, 6);
-          assert (n > 0);
-          q += n;
-        }
-      *q = '\0';
-      assert (q - utf8_string <= 2 * length);
+      {
+        unsigned char *q = utf8_string;
+        const char *str = string;
+        const char *str_limit = str + length;
+        while (str < str_limit)
+          {
+            unsigned int uc = (unsigned char) *str++;
+            int n = u8_uctomb (q, uc, 6);
+            assert (n > 0);
+            q += n;
+          }
+        *q = '\0';
+        assert (q - utf8_string <= 2 * length);
+      }
 
       return (char *) utf8_string;
     }
@@ -247,10 +248,11 @@ conv_from_java (char *string)
                   if (p[6] == '\\' && p[7] == 'u')
                     {
                       unsigned int m = 0;
+                      int i2;
 
-                      for (i = 0; i < 4; i++)
+                      for (i2 = 0; i2 < 4; i2++)
                         {
-                          int c1 = (unsigned char) p[8 + i];
+                          int c1 = (unsigned char) p[8 + i2];
 
                           if (c1 >= '0' && c1 <= '9')
                             m = (m << 4) + (c1 - '0');
@@ -262,7 +264,7 @@ conv_from_java (char *string)
                             goto just_one_byte;
                         }
 
-                      if (i == 4 && (m >= 0xdc00 && m < 0xe000))
+                      if (i2 == 4 && (m >= 0xdc00 && m < 0xe000))
                         {
                           /* Combine two UTF-16 words to a character.  */
                           uc = 0x10000 + ((n - 0xd800) << 10) + (m - 0xdc00);
@@ -332,9 +334,8 @@ phase4_getuc (abstract_catalog_reader_ty *catr)
       if (c2 == 'u')
         {
           unsigned int n = 0;
-          int i;
 
-          for (i = 0; i < 4; i++)
+          for (int i = 0; i < 4; i++)
             {
               int c1 = phase3_getc ();
 
@@ -476,16 +477,15 @@ read_escaped_string (abstract_catalog_reader_ty *catr, bool in_key)
               && (c >= UNICODE (0xdc00) && c < UNICODE (0xe000)))
             {
               unsigned short utf16buf[2];
-              ucs4_t uc;
-              int len;
-
               utf16buf[0] = utf16_surr;
               utf16buf[1] = UTF16_VALUE (c);
+
+              ucs4_t uc;
               if (u16_mbtouc (&uc, utf16buf, 2) != 2)
                 abort ();
 
               utf8_buffer_ensure_available (6);
-              len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 6);
+              int len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 6);
               if (len < 0)
                 catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL,
                                    real_file_name, pos.line_number, (size_t)(-1),
@@ -514,10 +514,9 @@ read_escaped_string (abstract_catalog_reader_ty *catr, bool in_key)
               else
                 {
                   ucs4_t uc = UTF16_VALUE (c);
-                  int len;
 
                   utf8_buffer_ensure_available (3);
-                  len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 3);
+                  int len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 3);
                   if (len < 0)
                     catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL,
                                        real_file_name, pos.line_number, (size_t)(-1),
@@ -547,10 +546,9 @@ read_escaped_string (abstract_catalog_reader_ty *catr, bool in_key)
             {
               /* Convert the byte from ISO-8859-1 to UTF-8 on the fly.  */
               ucs4_t uc = c;
-              int len;
 
               utf8_buffer_ensure_available (2);
-              len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 2);
+              int len = u8_uctomb (utf8_buffer + utf8_buflen, uc, 2);
               if (len < 0)
                 abort ();
               utf8_buflen += len;
@@ -612,16 +610,14 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file,
   for (;;)
     {
       int c;
-      bool comment;
-      bool hidden;
 
       c = phase2_getc ();
 
       if (c == EOF)
         break;
 
-      comment = false;
-      hidden = false;
+      bool comment = false;
+      bool hidden = false;
       if (c == '#')
         comment = true;
       else if (c == '!')
@@ -642,7 +638,6 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file,
         {
           /* A comment line.  */
           struct string_buffer buffer;
-
           sb_init (&buffer);
           for (;;)
             {
@@ -662,28 +657,21 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file,
       else
         {
           /* A key/value pair.  */
-          char *msgid;
-          lex_pos_ty msgid_pos;
-
-          msgid_pos = pos;
-          msgid = read_escaped_string (catr, true);
+          lex_pos_ty msgid_pos = pos;
+          char *msgid = read_escaped_string (catr, true);
           if (msgid == NULL)
             /* Skip blank line.  */
             ;
           else
             {
-              char *msgstr;
-              lex_pos_ty msgstr_pos;
-              bool force_fuzzy;
-
-              msgstr_pos = pos;
-              msgstr = read_escaped_string (catr, false);
+              lex_pos_ty msgstr_pos = pos;
+              char *msgstr = read_escaped_string (catr, false);
               if (msgstr == NULL)
                 msgstr = xstrdup ("");
 
               /* Be sure to make the message fuzzy if it was commented out
                  and if it is not already header/fuzzy/untranslated.  */
-              force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
+              bool force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
 
               catalog_reader_seen_message (catr,
                                            NULL, msgid, &msgid_pos, NULL,
index 7bb9889e11cc04a2e3e4bd68ef1e2b8bf41cbe97..cff2f7b318f1a939d3088de513460fa7b5f4a027 100644 (file)
@@ -60,16 +60,13 @@ execute_and_read_po_output (const char *progname,
                             void *private_data)
 {
   struct locals *l = (struct locals *) private_data;
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  int exitstatus;
 
   /* Open a pipe to the C# execution engine.  */
-  child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
-                          NULL, false, true, true, fd);
+  int fd[1];
+  pid_t child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL,
+                                NULL, false, true, true, fd);
 
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
@@ -80,7 +77,7 @@ execute_and_read_po_output (const char *progname,
   fclose (fp);
 
   /* Remove zombie process from process list, and retrieve exit status.  */
-  exitstatus =
+  int exitstatus =
     wait_subprocess (child, progname, false, false, true, true, NULL);
   if (exitstatus != 0)
     error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
@@ -93,36 +90,31 @@ execute_and_read_po_output (const char *progname,
 void
 read_resources_file (message_list_ty *mlp, const char *filename)
 {
-  char *filename_converted;
-  const char *args[2];
-  const char *gettextexedir;
-  const char *gettextlibdir;
-  char *assembly_path;
-  const char *libdirs[1];
-  struct locals locals;
-
-  filename_converted = cygpath_w (filename);
+  char *filename_converted = cygpath_w (filename);
 
   /* Prepare arguments.  */
+  const char *args[2];
   args[0] = filename_converted;
   args[1] = NULL;
 
   /* Make it possible to override the .exe location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
+  const char *gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
   if (gettextexedir == NULL || gettextexedir[0] == '\0')
     gettextexedir = relocate (LIBDIR "/gettext");
 
   /* Make it possible to override the .dll location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
+  const char *gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
   if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
     gettextlibdir = relocate (LIBDIR);
 
   /* Dump the resource and retrieve the resulting output.  */
-  assembly_path =
+  char *assembly_path =
     xconcatenated_filename (gettextexedir, "msgunfmt.net", ".exe");
+  const char *libdirs[1];
   libdirs[0] = gettextlibdir;
+  struct locals locals;
   if (execute_csharp_program (assembly_path, libdirs, 1,
                               args,
                               verbose, false,
@@ -133,9 +125,8 @@ read_resources_file (message_list_ty *mlp, const char *filename)
   /* Add the output to mlp.  */
   {
     message_list_ty *read_mlp = locals.mdlp->item[0]->messages;
-    size_t j;
 
-    for (j = 0; j < read_mlp->nitems; j++)
+    for (size_t j = 0; j < read_mlp->nitems; j++)
       message_list_append (mlp, read_mlp->item[j]);
   }
 
index 5394ef1ca7cd94e447a4afa4aabf39b8b1bfff67..c9a8473982bbab4a1d3a4f69ee04b5878ba896a5 100644 (file)
@@ -81,12 +81,10 @@ static int phase1_pushback_length;
 static int
 phase1_getc (abstract_catalog_reader_ty *catr)
 {
-  int c;
-
   if (phase1_pushback_length)
     return phase1_pushback[--phase1_pushback_length];
 
-  c = getc (fp);
+  int c = getc (fp);
 
   if (c == EOF)
     {
@@ -144,12 +142,10 @@ phase2_getc (abstract_catalog_reader_ty *catr)
   if (encoding == enc_undetermined)
     {
       /* Determine the input file's encoding.  */
-      int c0, c1;
-
-      c0 = phase1_getc (catr);
+      int c0 = phase1_getc (catr);
       if (c0 == EOF)
         return UEOF;
-      c1 = phase1_getc (catr);
+      int c1 = phase1_getc (catr);
       if (c1 == EOF)
         {
           phase1_ungetc (c0);
@@ -161,9 +157,7 @@ phase2_getc (abstract_catalog_reader_ty *catr)
         encoding = enc_ucs2le;
       else
         {
-          int c2;
-
-          c2 = phase1_getc (catr);
+          int c2 = phase1_getc (catr);
           if (c2 == EOF)
             {
               phase1_ungetc (c1);
@@ -187,12 +181,10 @@ phase2_getc (abstract_catalog_reader_ty *catr)
     case enc_ucs2be:
       /* Read an UCS-2BE encoded character.  */
       {
-        int c0, c1;
-
-        c0 = phase1_getc (catr);
+        int c0 = phase1_getc (catr);
         if (c0 == EOF)
           return UEOF;
-        c1 = phase1_getc (catr);
+        int c1 = phase1_getc (catr);
         if (c1 == EOF)
           return UEOF;
         return (c0 << 8) + c1;
@@ -201,12 +193,10 @@ phase2_getc (abstract_catalog_reader_ty *catr)
     case enc_ucs2le:
       /* Read an UCS-2LE encoded character.  */
       {
-        int c0, c1;
-
-        c0 = phase1_getc (catr);
+        int c0 = phase1_getc (catr);
         if (c0 == EOF)
           return UEOF;
-        c1 = phase1_getc (catr);
+        int c1 = phase1_getc (catr);
         if (c1 == EOF)
           return UEOF;
         return c0 + (c1 << 8);
@@ -217,8 +207,8 @@ phase2_getc (abstract_catalog_reader_ty *catr)
       {
         unsigned char buf[6];
         unsigned int count;
+
         int c;
-        ucs4_t uc;
 
         c = phase1_getc (catr);
         if (c == EOF)
@@ -275,7 +265,9 @@ phase2_getc (abstract_catalog_reader_ty *catr)
               }
           }
 
+        ucs4_t uc;
         u8_mbtouc (&uc, buf, count);
+
         return uc;
       }
 
@@ -283,7 +275,6 @@ phase2_getc (abstract_catalog_reader_ty *catr)
       /* Read an ISO-8859-1 encoded character.  */
       {
         int c = phase1_getc (catr);
-
         if (c == EOF)
           return UEOF;
         return c;
@@ -328,25 +319,21 @@ phase3_ungetc (int c)
 static char *
 conv_from_ucs4 (const int *buffer, size_t buflen)
 {
-  unsigned char *utf8_string;
-  size_t i;
-  unsigned char *q;
 
   /* Each UCS-4 word needs 6 bytes at worst.  */
-  utf8_string = XNMALLOC (6 * buflen + 1, unsigned char);
-
-  for (i = 0, q = utf8_string; i < buflen; )
-    {
-      unsigned int uc;
-      int n;
-
-      uc = buffer[i++];
-      n = u8_uctomb (q, uc, 6);
-      assert (n > 0);
-      q += n;
-    }
-  *q = '\0';
-  assert (q - utf8_string <= 6 * buflen);
+  unsigned char *utf8_string = XNMALLOC (6 * buflen + 1, unsigned char);
+  {
+    unsigned char *q = utf8_string;
+    for (size_t i = 0; i < buflen; )
+      {
+        unsigned int uc = buffer[i++];
+        int n = u8_uctomb (q, uc, 6);
+        assert (n > 0);
+        q += n;
+      }
+    *q = '\0';
+    assert (q - utf8_string <= 6 * buflen);
+  }
 
   return (char *) utf8_string;
 }
@@ -358,14 +345,17 @@ conv_from_ucs4 (const int *buffer, size_t buflen)
 static char *
 parse_escaped_string (const int *string, size_t length)
 {
+  const int *string_limit = string + length;
+
+  if (string == string_limit)
+    return NULL;
+
   static int *buffer;
   static size_t bufmax;
   static size_t buflen;
-  const int *string_limit = string + length;
+
   int c;
 
-  if (string == string_limit)
-    return NULL;
   c = *string++;
   if (c != '"')
     return NULL;
@@ -385,8 +375,7 @@ parse_escaped_string (const int *string, size_t length)
           if (c >= '0' && c <= '7')
             {
               unsigned int n = 0;
-              int j = 0;
-              for (;;)
+              for (int j = 0;;)
                 {
                   n = n * 8 + (c - '0');
                   if (++j == 3)
@@ -403,8 +392,7 @@ parse_escaped_string (const int *string, size_t length)
           else if (c == 'u' || c == 'U')
             {
               unsigned int n = 0;
-              int j;
-              for (j = 0; j < 4; j++)
+              for (int j = 0; j < 4; j++)
                 {
                   if (string == string_limit)
                     break;
@@ -515,8 +503,6 @@ static void
 comment_line_end (abstract_catalog_reader_ty *catr,
                   size_t chars_to_remove, bool test_for_fuzzy_msgstr)
 {
-  char *line;
-
   buflen -= chars_to_remove;
   /* Drop trailing white space, but not EOLs.  */
   while (buflen >= 1
@@ -534,7 +520,7 @@ comment_line_end (abstract_catalog_reader_ty *catr,
                                 buflen - (buffer[buflen - 1] == ';') - 2)))
     return;
 
-  line = conv_from_ucs4 (buffer, buflen);
+  char *line = conv_from_ucs4 (buffer, buflen);
 
   if (strcmp (line, "Flag: untranslated") == 0)
     {
@@ -590,14 +576,10 @@ phase4_getc (abstract_catalog_reader_ty *catr)
     case '*':
       /* C style comment.  */
       {
-        bool last_was_star;
-        size_t trailing_stars;
-        bool seen_newline;
-
         comment_start ();
-        last_was_star = false;
-        trailing_stars = 0;
-        seen_newline = false;
+        bool last_was_star = false;
+        size_t trailing_stars = 0;
+        bool seen_newline = false;
         /* Drop additional stars at the beginning of the comment.  */
         for (;;)
           {
@@ -712,6 +694,7 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos)
   static int *buffer;
   static size_t bufmax;
   static size_t buflen;
+
   int c;
 
   /* Skip whitespace before the string.  */
@@ -741,8 +724,7 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos)
               if (c >= '0' && c <= '7')
                 {
                   unsigned int n = 0;
-                  int j = 0;
-                  for (;;)
+                  for (int j = 0;;)
                     {
                       n = n * 8 + (c - '0');
                       if (++j == 3)
@@ -759,8 +741,7 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos)
               else if (c == 'u' || c == 'U')
                 {
                   unsigned int n = 0;
-                  int j;
-                  for (j = 0; j < 4; j++)
+                  for (int j = 0; j < 4; j++)
                     {
                       c = phase3_getc (catr);
                       if (c >= '0' && c <= '9')
@@ -840,12 +821,6 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
 
   for (;;)
     {
-      char *msgid;
-      lex_pos_ty msgid_pos;
-      char *msgstr;
-      lex_pos_ty msgstr_pos;
-      int c;
-
       /* Prepare for next msgid/msgstr pair.  */
       special_comment_reset ();
       next_is_obsolete = false;
@@ -853,12 +828,15 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
       fuzzy_msgstr = NULL;
 
       /* Read the key and all the comments preceding it.  */
-      msgid = read_string (catr, &msgid_pos);
+      lex_pos_ty msgid_pos;
+      char *msgid = read_string (catr, &msgid_pos);
       if (msgid == NULL)
         break;
 
       special_comment_finish (catr);
 
+      int c;
+
       /* Skip whitespace.  */
       do
         c = phase4_getc (catr);
@@ -877,8 +855,8 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
         {
           /* "key"; is an abbreviation for "key"=""; and does not
              necessarily designate an untranslated entry.  */
-          msgstr = xstrdup ("");
-          msgstr_pos = msgid_pos;
+          char *msgstr = xstrdup ("");
+          lex_pos_ty msgstr_pos = msgid_pos;
           catalog_reader_seen_message (catr,
                                        NULL, msgid, &msgid_pos, NULL,
                                        msgstr, strlen (msgstr) + 1, &msgstr_pos,
@@ -888,7 +866,8 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file,
       else if (c == '=')
         {
           /* Read the value.  */
-          msgstr = read_string (catr, &msgstr_pos);
+          lex_pos_ty msgstr_pos;
+          char *msgstr = read_string (catr, &msgstr_pos);
           if (msgstr == NULL)
             {
               catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL,
index 3322797273cdd60fd505ae399002e1887aebc982..829ef866ffa9d8d8ad31945d627a0ed6a083d841 100644 (file)
 msgdomain_list_ty *
 msgdomain_read_tcl (const char *locale_name, const char *directory)
 {
-  const char *gettextdatadir;
-  char *tclscript;
-  size_t len;
-  char *frobbed_locale_name;
-  char *p;
-  char *file_name;
-  const char *argv[4];
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  msgdomain_list_ty *mdlp;
-  int exitstatus;
-  size_t k;
-
   /* Make it possible to override the msgunfmt.tcl location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextdatadir = getenv ("GETTEXTTCLDIR");
+  const char *gettextdatadir = getenv ("GETTEXTTCLDIR");
   if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
     gettextdatadir = relocate (GETTEXTDATADIR);
 
-  tclscript = xconcatenated_filename (gettextdatadir, "msgunfmt.tcl", NULL);
+  char *tclscript = xconcatenated_filename (gettextdatadir, "msgunfmt.tcl", NULL);
 
   /* Convert the locale name to lowercase and remove any encoding.  */
-  len = strlen (locale_name);
-  frobbed_locale_name = (char *) xmalloca (len + 1);
-  memcpy (frobbed_locale_name, locale_name, len + 1);
-  for (p = frobbed_locale_name; *p != '\0'; p++)
-    if (*p >= 'A' && *p <= 'Z')
-      *p = *p - 'A' + 'a';
-    else if (*p == '.')
-      {
-        *p = '\0';
-        break;
-      }
-
-  file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg");
+  size_t len = strlen (locale_name);
+  char *frobbed_locale_name = (char *) xmalloca (len + 1);
+  {
+    memcpy (frobbed_locale_name, locale_name, len + 1);
+    for (char *p = frobbed_locale_name; *p != '\0'; p++)
+      if (*p >= 'A' && *p <= 'Z')
+        *p = *p - 'A' + 'a';
+      else if (*p == '.')
+        {
+          *p = '\0';
+          break;
+        }
+  }
+
+  char *file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg");
 
   freea (frobbed_locale_name);
 
   /* Prepare arguments.  */
+  const char *argv[4];
   argv[0] = "tclsh";
   argv[1] = tclscript;
   argv[2] = file_name;
@@ -101,21 +90,23 @@ msgdomain_read_tcl (const char *locale_name, const char *directory)
     }
 
   /* Open a pipe to the Tcl interpreter.  */
-  child = create_pipe_in ("tclsh", "tclsh", argv, NULL, NULL,
-                          DEV_NULL, false, true, true, fd);
+  int fd[1];
+  pid_t child = create_pipe_in ("tclsh", "tclsh", argv, NULL, NULL,
+                                DEV_NULL, false, true, true, fd);
 
-  fp = fdopen (fd[0], "r");
+  FILE *fp = fdopen (fd[0], "r");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
   /* Read the message list.  */
-  mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po,
-                              textmode_xerror_handler);
+  msgdomain_list_ty *mdlp =
+    read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po,
+                         textmode_xerror_handler);
 
   fclose (fp);
 
   /* Remove zombie process from process list, and retrieve exit status.  */
-  exitstatus =
+  int exitstatus =
     wait_subprocess (child, "tclsh", false, false, true, true, NULL);
   if (exitstatus != 0)
     {
@@ -131,21 +122,19 @@ msgdomain_read_tcl (const char *locale_name, const char *directory)
   free (tclscript);
 
   /* Move the header entry to the beginning.  */
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
-      size_t j;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         if (is_header (mlp->item[j]))
           {
             /* Found the header entry.  */
             if (j > 0)
               {
                 message_ty *header = mlp->item[j];
-                size_t i;
 
-                for (i = j; i > 0; i--)
+                for (size_t i = j; i > 0; i--)
                   mlp->item[i] = mlp->item[i - 1];
                 mlp->item[0] = header;
               }
index 7d105801f9ac8c3b8961ea62d9a7925ee7cf32a4..8520801444afbd3cf8797a6bfd85104a84a03db7 100644 (file)
@@ -52,10 +52,6 @@ static void process (FILE *stream);
 int
 main (int argc, char *argv[])
 {
-  /* Default values for command line options.  */
-  bool do_help = false;
-  bool do_version = false;
-
   /* Set program name for message texts.  */
   set_program_name (argv[0]);
 
@@ -70,6 +66,10 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
   static const struct program_option options[] =
@@ -79,21 +79,23 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int opt;
-  while ((opt = get_next_option ()) != -1)
-    switch (opt)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'h':
-        do_help = true;
-        break;
-      case 'V':
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-      }
+  {
+    int opt;
+    while ((opt = get_next_option ()) != -1)
+      switch (opt)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'h':
+          do_help = true;
+          break;
+        case 'V':
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+        }
+  }
 
   /* Version information is requested.  */
   if (do_version)
@@ -256,6 +258,8 @@ static void
 process (FILE *stream)
 {
   struct linebuffer lb;
+  init_linebuffer (&lb);
+
   const char *locale_code = locale_charset ();
   bool need_code_conversion = (c_strcasecmp (locale_code, "UTF-8") != 0);
 #if HAVE_ICONV
@@ -267,8 +271,6 @@ process (FILE *stream)
   size_t last_backconv_line_len;
 #endif
 
-  init_linebuffer (&lb);
-
   /* Initialize the conversion descriptors.  */
   if (need_code_conversion)
     {
@@ -301,16 +303,11 @@ process (FILE *stream)
      in a whole chunk would take an excessive amount of memory.  */
   for (;;)
     {
-      char *line;
-      size_t line_len;
-      char *filtered_line;
-      size_t filtered_line_len;
-
       /* Read a line.  */
       if (read_linebuffer (&lb, stream) == NULL)
         break;
-      line = lb.buffer;
-      line_len = lb.length;
+      char *line = lb.buffer;
+      size_t line_len = lb.length;
       /* read_linebuffer always returns a non-void result.  */
       if (line_len == 0)
         abort ();
@@ -341,6 +338,8 @@ process (FILE *stream)
 #endif
 
       /* Apply the filter.  */
+      char *filtered_line;
+      size_t filtered_line_len;
       serbian_to_latin (line, line_len, &filtered_line, &filtered_line_len);
 
 #if HAVE_ICONV
index 1e062025f0bb8919a634d79758c10d173972f460..f0271970de0528646e460d5b4b1a1cb75abce503 100644 (file)
@@ -86,10 +86,10 @@ static void
 fill (const char *dir, size_t len, void *data)
 {
   struct path_array_ty *array = data;
-  char *base;
-  char *name;
 
-  base = xmemdup0 (dir, len);
+  char *base = xmemdup0 (dir, len);
+
+  char *name;
   if (array->sub == NULL)
     name = base;
   else
@@ -121,29 +121,25 @@ fill (const char *dir, size_t len, void *data)
 char **
 get_search_path (const char *sub)
 {
-  const char *gettextdatadir;
-  const char *gettextdatadirs;
-  const char *xdgdatadirs;
-  struct path_array_ty array;
-
   /* Count how many array elements are needed.  */
   size_t count = 2;
 
-  gettextdatadirs = getenv ("GETTEXTDATADIRS");
+  const char *gettextdatadirs = getenv ("GETTEXTDATADIRS");
   if (gettextdatadirs != NULL)
     foreach_elements (gettextdatadirs, increment, &count);
 
-  xdgdatadirs = getenv ("XDG_DATA_DIRS");
+  const char *xdgdatadirs = getenv ("XDG_DATA_DIRS");
   if (xdgdatadirs != NULL)
     foreach_elements (xdgdatadirs, increment, &count);
 
   /* Allocate the array.  */
+  struct path_array_ty array;
   array.ptr = XNMALLOC (count + 1, char *);
   array.len = 0;
 
   /* Fill the array.  */
   {
-    gettextdatadir = getenv ("GETTEXTDATADIR");
+    const char *gettextdatadir = getenv ("GETTEXTDATADIR");
     if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
       /* Make it possible to override the locator file location.  This
          is necessary for running the testsuite before "make
index 910f0a9009d35a31e16f5665147cf6a4b94c4479..349627a9e18371615b6ec41a741a609ed4da1c38 100644 (file)
@@ -42,9 +42,7 @@ string_list_init (string_list_ty *slp)
 string_list_ty *
 string_list_alloc ()
 {
-  string_list_ty *slp;
-
-  slp = XMALLOC (string_list_ty);
+  string_list_ty *slp = XMALLOC (string_list_ty);
   slp->item = NULL;
   slp->nitems = 0;
   slp->nitems_max = 0;
@@ -60,10 +58,8 @@ string_list_append (string_list_ty *slp, const char *s)
   /* Grow the list.  */
   if (slp->nitems >= slp->nitems_max)
     {
-      size_t nbytes;
-
       slp->nitems_max = slp->nitems_max * 2 + 4;
-      nbytes = slp->nitems_max * sizeof (slp->item[0]);
+      size_t nbytes = slp->nitems_max * sizeof (slp->item[0]);
       slp->item = (const char **) xrealloc (slp->item, nbytes);
     }
 
@@ -80,10 +76,8 @@ string_list_append_move (string_list_ty *slp, char *s)
   /* Grow the list.  */
   if (slp->nitems >= slp->nitems_max)
     {
-      size_t nbytes;
-
       slp->nitems_max = slp->nitems_max * 2 + 4;
-      nbytes = slp->nitems_max * sizeof (slp->item[0]);
+      size_t nbytes = slp->nitems_max * sizeof (slp->item[0]);
       slp->item = (const char **) xrealloc (slp->item, nbytes);
     }
 
@@ -97,10 +91,8 @@ string_list_append_move (string_list_ty *slp, char *s)
 void
 string_list_append_unique (string_list_ty *slp, const char *s)
 {
-  size_t j;
-
   /* Do nothing if the string is already in the list.  */
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strcmp (slp->item[j], s) == 0)
       return;
 
@@ -122,10 +114,8 @@ void
 string_list_append_unique_desc (string_list_ty *slp,
                                 const char *s, size_t s_len)
 {
-  size_t j;
-
   /* Do nothing if the string is already in the list.  */
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strlen (slp->item[j]) == s_len && memcmp (slp->item[j], s, s_len) == 0)
       return;
 
@@ -153,9 +143,7 @@ string_list_append_unique_desc (string_list_ty *slp,
 void
 string_list_destroy (string_list_ty *slp)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     free ((char *) slp->item[j]);
   if (slp->item != NULL)
     free (slp->item);
@@ -166,9 +154,7 @@ string_list_destroy (string_list_ty *slp)
 void
 string_list_free (string_list_ty *slp)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     free ((char *) slp->item[j]);
   if (slp->item != NULL)
     free (slp->item);
@@ -181,23 +167,23 @@ string_list_free (string_list_ty *slp)
 char *
 string_list_concat (const string_list_ty *slp)
 {
-  size_t len;
-  size_t j;
   char *result;
-  size_t pos;
-
-  len = 1;
-  for (j = 0; j < slp->nitems; ++j)
-    len += strlen (slp->item[j]);
-  result = XNMALLOC (len, char);
-  pos = 0;
-  for (j = 0; j < slp->nitems; ++j)
-    {
-      len = strlen (slp->item[j]);
-      memcpy (result + pos, slp->item[j], len);
-      pos += len;
-    }
-  result[pos] = '\0';
+  {
+    size_t len = 1;
+    for (size_t j = 0; j < slp->nitems; ++j)
+      len += strlen (slp->item[j]);
+    result = XNMALLOC (len, char);
+  }
+  {
+    size_t pos = 0;
+    for (size_t j = 0; j < slp->nitems; ++j)
+      {
+        size_t len = strlen (slp->item[j]);
+        memcpy (result + pos, slp->item[j], len);
+        pos += len;
+      }
+    result[pos] = '\0';
+  }
   return result;
 }
 
@@ -234,40 +220,44 @@ string_list_join (const string_list_ty *slp, const char *separator,
                   char terminator, bool drop_redundant_terminator)
 {
   size_t separator_len = strlen (separator);
-  size_t len;
-  size_t j;
-  char *result;
-  size_t pos;
 
-  len = 1;
-  for (j = 0; j < slp->nitems; ++j)
-    {
-      if (j > 0)
-        len += separator_len;
-      len += strlen (slp->item[j]);
-    }
-  if (terminator)
-    ++len;
-  result = XNMALLOC (len, char);
-  pos = 0;
-  for (j = 0; j < slp->nitems; ++j)
+  char *result;
+  {
+    size_t len = 1;
+    for (size_t j = 0; j < slp->nitems; ++j)
+      {
+        if (j > 0)
+          len += separator_len;
+        len += strlen (slp->item[j]);
+      }
+    if (terminator)
+      ++len;
+    result = XNMALLOC (len, char);
+  }
+  {
+    size_t pos = 0;
+    for (size_t j = 0; j < slp->nitems; ++j)
+      {
+        if (j > 0)
+          {
+            memcpy (result + pos, separator, separator_len);
+            pos += separator_len;
+          }
+        size_t len = strlen (slp->item[j]);
+        memcpy (result + pos, slp->item[j], len);
+        pos += len;
+      }
     {
-      if (j > 0)
-        {
-          memcpy (result + pos, separator, separator_len);
-          pos += separator_len;
-        }
-      len = strlen (slp->item[j]);
-      memcpy (result + pos, slp->item[j], len);
-      pos += len;
+      size_t len;
+      if (terminator
+          && !(drop_redundant_terminator
+               && slp->nitems > 0
+               && (len = strlen (slp->item[slp->nitems - 1])) > 0
+               && slp->item[slp->nitems - 1][len - 1] == terminator))
+        result[pos++] = terminator;
     }
-  if (terminator
-      && !(drop_redundant_terminator
-           && slp->nitems > 0
-           && (len = strlen (slp->item[slp->nitems - 1])) > 0
-           && slp->item[slp->nitems - 1][len - 1] == terminator))
-    result[pos++] = terminator;
-  result[pos] = '\0';
+    result[pos] = '\0';
+  }
   return result;
 }
 
@@ -276,9 +266,7 @@ string_list_join (const string_list_ty *slp, const char *separator,
 bool
 string_list_member (const string_list_ty *slp, const char *s)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strcmp (slp->item[j], s) == 0)
       return true;
   return false;
@@ -288,9 +276,7 @@ string_list_member (const string_list_ty *slp, const char *s)
 bool
 string_list_member_desc (const string_list_ty *slp, const char *s, size_t s_len)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strlen (slp->item[j]) == s_len && memcmp (slp->item[j], s, s_len) == 0)
       return true;
   return false;
@@ -301,9 +287,7 @@ string_list_member_desc (const string_list_ty *slp, const char *s, size_t s_len)
 const char *
 string_list_remove (string_list_ty *slp, const char *s)
 {
-  size_t j;
-
-  for (j = 0; j < slp->nitems; ++j)
+  for (size_t j = 0; j < slp->nitems; ++j)
     if (strcmp (slp->item[j], s) == 0)
       {
         const char *found = slp->item[j];
index 723125be1d583546c58874a1dd0e9de2c46527c8..f198eaae24efcd6fec23a9cec74b806548c35a3e 100644 (file)
@@ -76,9 +76,6 @@ static void fetch (const char *url, const char *file);
 int
 main (int argc, char *argv[])
 {
-  bool do_help;
-  bool do_version;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -94,9 +91,9 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set default values for variables.  */
-  do_help = false;
-  do_version = false;
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
 
   /* Parse command line options.  */
   BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
@@ -109,25 +106,27 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':          /* Long option with key == 0.  */
-        break;
-      case 'h':           /* --help */
-        do_help = true;
-        break;
-      case 'q':           /* --quiet / --silent */
-        verbose = false;
-        break;
-      case 'V':           /* --version */
-        do_version = true;
-        break;
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':          /* Long option with key == 0.  */
+          break;
+        case 'h':           /* --help */
+          do_help = true;
+          break;
+        case 'q':           /* --quiet / --silent */
+          verbose = false;
+          break;
+        case 'V':           /* --version */
+          do_version = true;
+          break;
+        default:
+          usage (EXIT_FAILURE);
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -206,17 +205,16 @@ or by email to <%s>.\n"),
 static void
 cat_file (const char *src_filename)
 {
-  int src_fd;
-  char buf[4096];
-  const int buf_size = sizeof (buf);
-
-  src_fd = open (src_filename, O_RDONLY | O_BINARY);
+  int src_fd = open (src_filename, O_RDONLY | O_BINARY);
   if (src_fd < 0)
     error (EXIT_FAILURE, errno, _("error while opening \"%s\" for reading"),
            src_filename);
 
   for (;;)
     {
+      char buf[4096];
+      const int buf_size = sizeof (buf);
+
       ssize_t n_read = read (src_fd, buf, buf_size);
       if (n_read < 0)
         {
@@ -272,16 +270,15 @@ fetch (const char *url, const char *file)
   /* First try: using Java.  */
   {
     const char *class_name = "gnu.gettext.GetURL";
-    const char *gettextjar;
-    const char *args[2];
 
     /* Make it possible to override the gettext.jar location.  This is
        necessary for running the testsuite before "make install".  */
-    gettextjar = getenv ("GETTEXTJAR");
+    const char *gettextjar = getenv ("GETTEXTJAR");
     if (gettextjar == NULL || gettextjar[0] == '\0')
       gettextjar = relocate (GETTEXTJAR);
 
     /* Prepare arguments.  */
+    const char *args[2];
     args[0] = url;
     args[1] = NULL;
 
@@ -313,13 +310,12 @@ fetch (const char *url, const char *file)
       {
         /* Test for presence of wget: "wget --version > /dev/null"  */
         const char *argv[3];
-        int exitstatus;
-
         argv[0] = "wget";
         argv[1] = "--version";
         argv[2] = NULL;
-        exitstatus = execute ("wget", "wget", argv, NULL, NULL,
-                              false, false, true, true, true, false, NULL);
+
+        int exitstatus = execute ("wget", "wget", argv, NULL, NULL,
+                                  false, false, true, true, true, false, NULL);
         wget_present = (exitstatus == 0);
         wget_tested = true;
       }
@@ -327,8 +323,6 @@ fetch (const char *url, const char *file)
     if (wget_present)
       {
         const char *argv[10];
-        int exitstatus;
-
         argv[0] = "wget";
         argv[1] = "--quiet";
         argv[2] = "--output-document"; argv[3] = "-";
@@ -336,8 +330,9 @@ fetch (const char *url, const char *file)
         argv[6] = "--user-agent"; argv[7] = "urlget";
         argv[8] = url;
         argv[9] = NULL;
-        exitstatus = execute ("wget", "wget", argv, NULL, NULL,
-                              true, false, false, false, true, false, NULL);
+
+        int exitstatus = execute ("wget", "wget", argv, NULL, NULL,
+                                  true, false, false, false, true, false, NULL);
         if (exitstatus != 127)
           {
             if (exitstatus != 0)
@@ -358,13 +353,12 @@ fetch (const char *url, const char *file)
       {
         /* Test for presence of lynx: "lynx --version > /dev/null"  */
         const char *argv[3];
-        int exitstatus;
-
         argv[0] = "lynx";
         argv[1] = "--version";
         argv[2] = NULL;
-        exitstatus = execute ("lynx", "lynx", argv, NULL, NULL,
-                              false, false, true, true, true, false, NULL);
+
+        int exitstatus = execute ("lynx", "lynx", argv, NULL, NULL,
+                                  false, false, true, true, true, false, NULL);
         lynx_present = (exitstatus == 0);
         lynx_tested = true;
       }
@@ -372,15 +366,14 @@ fetch (const char *url, const char *file)
     if (lynx_present)
       {
         const char *argv[5];
-        int exitstatus;
-
         argv[0] = "lynx";
         argv[1] = "-useragent=urlget";
         argv[2] = "-source";
         argv[3] = url;
         argv[4] = NULL;
-        exitstatus = execute ("lynx", "lynx", argv, NULL, NULL,
-                              true, false, false, false, true, false, NULL);
+
+        int exitstatus = execute ("lynx", "lynx", argv, NULL, NULL,
+                                  true, false, false, false, true, false, NULL);
         if (exitstatus != 127)
           {
             if (exitstatus != 0)
@@ -401,13 +394,12 @@ fetch (const char *url, const char *file)
       {
         /* Test for presence of curl: "curl --version > /dev/null"  */
         const char *argv[3];
-        int exitstatus;
-
         argv[0] = "curl";
         argv[1] = "--version";
         argv[2] = NULL;
-        exitstatus = execute ("curl", "curl", argv, NULL, NULL,
-                              false, false, true, true, true, false, NULL);
+
+        int exitstatus = execute ("curl", "curl", argv, NULL, NULL,
+                                  false, false, true, true, true, false, NULL);
         curl_present = (exitstatus == 0 || exitstatus == 2);
         curl_tested = true;
       }
@@ -415,15 +407,14 @@ fetch (const char *url, const char *file)
     if (curl_present)
       {
         const char *argv[6];
-        int exitstatus;
-
         argv[0] = "curl";
         argv[1] = "--silent";
         argv[2] = "--user-agent"; argv[3] = "urlget";
         argv[4] = url;
         argv[5] = NULL;
-        exitstatus = execute ("curl", "curl", argv, NULL, NULL,
-                              true, false, false, false, true, false, NULL);
+
+        int exitstatus = execute ("curl", "curl", argv, NULL, NULL,
+                                  true, false, false, false, true, false, NULL);
         if (exitstatus != 127)
           {
             if (exitstatus != 0)
index 8f9cfcd98533c8c410f386afefe010cdec4a654c..94ed40b9c55e18423274365c94d296ec559e4ea5 100644 (file)
@@ -90,16 +90,12 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
                       xerror_handler_ty xeh,
                       bool force, bool debug)
 {
-  bool to_stdout;
-
   /* We will not write anything if, for every domain, we have no message
      or only the header entry.  */
   if (!force)
     {
       bool found_nonempty = false;
-      size_t k;
-
-      for (k = 0; k < mdlp->nitems; k++)
+      for (size_t k = 0; k < mdlp->nitems; k++)
         {
           message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -129,16 +125,12 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
     {
       if (!output_syntax->supports_contexts)
         {
-          const lex_pos_ty *has_context;
-          size_t k;
-
-          has_context = NULL;
-          for (k = 0; k < mdlp->nitems; k++)
+          const lex_pos_ty *has_context = NULL;
+          for (size_t k = 0; k < mdlp->nitems; k++)
             {
               message_list_ty *mlp = mdlp->item[k]->messages;
-              size_t j;
 
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 {
                   message_ty *mp = mlp->item[j];
 
@@ -159,16 +151,12 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
 
       if (!output_syntax->supports_plurals)
         {
-          const lex_pos_ty *has_plural;
-          size_t k;
-
-          has_plural = NULL;
-          for (k = 0; k < mdlp->nitems; k++)
+          const lex_pos_ty *has_plural = NULL;
+          for (size_t k = 0; k < mdlp->nitems; k++)
             {
               message_list_ty *mlp = mdlp->item[k]->messages;
-              size_t j;
 
-              for (j = 0; j < mlp->nitems; j++)
+              for (size_t j = 0; j < mlp->nitems; j++)
                 {
                   message_ty *mp = mlp->item[j];
 
@@ -196,8 +184,8 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
         }
     }
 
-  to_stdout = (filename == NULL || strcmp (filename, "-") == 0
-               || strcmp (filename, "/dev/stdout") == 0);
+  bool to_stdout = (filename == NULL || strcmp (filename, "-") == 0
+                    || strcmp (filename, "/dev/stdout") == 0);
 
 #if ENABLE_COLOR
   if (output_syntax->supports_color
@@ -206,10 +194,8 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
               && isatty (STDOUT_FILENO)
               && getenv ("NO_COLOR") == NULL)))
     {
-      int fd;
-      ostream_t stream;
-
       /* Open the output file.  */
+      int fd;
       if (!to_stdout)
         {
           fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC,
@@ -233,7 +219,7 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
       style_file_prepare ("PO_STYLE",
                           "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR),
                           "po-default.css");
-      stream =
+      ostream_t stream =
         styled_ostream_create (fd, filename, TTYCTL_AUTO, style_file_name);
       output_syntax->print (mdlp, stream, page_width, xeh, debug);
       ostream_free (stream);
@@ -251,10 +237,8 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
   else
 #endif
     {
-      FILE *fp;
-      file_ostream_t stream;
-
       /* Open the output file.  */
+      FILE *fp;
       if (!to_stdout)
         {
           fp = fopen (filename, "wb");
@@ -273,13 +257,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
           filename = _("standard output");
         }
 
-      stream = file_ostream_create (fp);
+      file_ostream_t stream = file_ostream_create (fp);
 
 #if ENABLE_COLOR
       if (output_syntax->supports_color && color_mode == color_html)
         {
-          html_styled_ostream_t html_stream;
-
           /* Convert mdlp to UTF-8 encoding.  */
           if (mdlp->encoding != po_charset_utf8)
             {
@@ -291,15 +273,15 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename,
           style_file_prepare ("PO_STYLE",
                               "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR),
                               "po-default.css");
-          html_stream = html_styled_ostream_create (stream, style_file_name);
+          html_styled_ostream_t html_stream =
+            html_styled_ostream_create (stream, style_file_name);
           output_syntax->print (mdlp, html_stream, page_width, xeh, debug);
           ostream_free (html_stream);
         }
       else
         {
-          noop_styled_ostream_t styled_stream;
-
-          styled_stream = noop_styled_ostream_create (stream, false);
+          noop_styled_ostream_t styled_stream =
+            noop_styled_ostream_create (stream, false);
           output_syntax->print (mdlp, styled_stream, page_width, xeh, debug);
           ostream_free (styled_stream);
         }
@@ -353,9 +335,7 @@ cmp_by_msgid (const void *va, const void *vb)
 void
 msgdomain_list_sort_by_msgid (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
@@ -372,9 +352,8 @@ cmp_filepos (const void *va, const void *vb)
 {
   const lex_pos_ty *a = (const lex_pos_ty *) va;
   const lex_pos_ty *b = (const lex_pos_ty *) vb;
-  int cmp;
 
-  cmp = strcmp (a->file_name, b->file_name);
+  int cmp = strcmp (a->file_name, b->file_name);
   if (cmp == 0)
     cmp = (int) a->line_number - (int) b->line_number;
 
@@ -384,13 +363,11 @@ cmp_filepos (const void *va, const void *vb)
 static void
 msgdomain_list_sort_filepos (msgdomain_list_ty *mdlp)
 {
-  size_t j, k;
-
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -409,10 +386,9 @@ cmp_by_filepos (const void *va, const void *vb)
 {
   const message_ty *a = *(const message_ty **) va;
   const message_ty *b = *(const message_ty **) vb;
-  int cmp;
 
   /* No filepos is smaller than any other filepos.  */
-  cmp = (a->filepos_count != 0) - (b->filepos_count != 0);
+  int cmp = (a->filepos_count != 0) - (b->filepos_count != 0);
   if (cmp != 0)
     return cmp;
 
@@ -451,13 +427,11 @@ cmp_by_filepos (const void *va, const void *vb)
 void
 msgdomain_list_sort_by_filepos (msgdomain_list_ty *mdlp)
 {
-  size_t k;
-
   /* It makes sense to compare filepos[0] of different messages only after
      the filepos[] array of each message has been sorted.  Sort it now.  */
   msgdomain_list_sort_filepos (mdlp);
 
-  for (k = 0; k < mdlp->nitems; k++)
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
       message_list_ty *mlp = mdlp->item[k]->messages;
 
index 539709225059f3bf21f1a029e6852caab41a29a8..64ef43a2cba986f2e26204635093554dada5e893 100644 (file)
@@ -64,16 +64,14 @@ construct_class_name (const char *resource_name)
      assuming that every assembly will only ever contain one
      GettextResourceSet subclass, but this assumption would break the day
      we want to support multi-domain PO files in the same format...  */
-  bool valid;
-  const char *p;
 
   /* Test for a valid ASCII identifier:
      - nonempty,
      - first character is A..Za..z_ - see x-csharp.c:is_identifier_start.
      - next characters are A..Za..z_0..9 - see x-csharp.c:is_identifier_part.
    */
-  valid = (resource_name[0] != '\0');
-  for (p = resource_name; valid && *p != '\0'; p++)
+  bool valid = (resource_name[0] != '\0');
+  for (const char *p = resource_name; valid && *p != '\0'; p++)
     {
       char c = *p;
       if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
@@ -88,9 +86,8 @@ construct_class_name (const char *resource_name)
       const char *str = resource_name;
       const char *str_limit = str + strlen (str);
       char *class_name = XNMALLOC (12 + 6 * (str_limit - str) + 1, char);
-      char *b;
 
-      b = class_name;
+      char *b = class_name;
       memcpy (b, "__UESCAPED__", 12); b += 12;
       while (str < str_limit)
         {
@@ -192,9 +189,8 @@ write_csharp_msgid (FILE *stream, message_ty *mp)
       size_t msgctxt_len = strlen (msgctxt);
       size_t msgid_len = strlen (msgid);
       size_t combined_len = msgctxt_len + 1 + msgid_len;
-      char *combined;
 
-      combined = (char *) xmalloca (combined_len + 1);
+      char *combined = (char *) xmalloca (combined_len + 1);
       memcpy (combined, msgctxt, msgctxt_len);
       combined[msgctxt_len] = MSGCTXT_SEPARATOR;
       memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1);
@@ -214,18 +210,19 @@ write_csharp_msgstr (FILE *stream, message_ty *mp)
 {
   if (mp->msgid_plural != NULL)
     {
-      bool first;
-      const char *p;
-
       fprintf (stream, "new System.String[] { ");
-      for (p = mp->msgstr, first = true;
-           p < mp->msgstr + mp->msgstr_len;
-           p += strlen (p) + 1, first = false)
-        {
-          if (!first)
-            fprintf (stream, ", ");
-          write_csharp_string (stream, p);
-        }
+      {
+        bool first = true;
+        for (const char *p = mp->msgstr;
+             p < mp->msgstr + mp->msgstr_len;
+             p += strlen (p) + 1)
+          {
+            if (!first)
+              fprintf (stream, ", ");
+            write_csharp_string (stream, p);
+            first = false;
+          }
+      }
       fprintf (stream, " }");
     }
   else
@@ -459,11 +456,6 @@ write_csharp_expression (FILE *stream, const struct expression *exp, bool as_boo
 static void
 write_csharp_code (FILE *stream, const char *culture_name, const char *class_name, message_list_ty *mlp)
 {
-  const char *last_dot;
-  const char *class_name_last_part;
-  unsigned int plurals;
-  size_t j;
-
   fprintf (stream,
            "/* Automatically generated by GNU msgfmt.  Do not modify!  */\n");
 
@@ -478,7 +470,9 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam
   write_csharp_string (stream, culture_name);
   fprintf (stream, ")]\n");
 
-  last_dot = strrchr (class_name, '.');
+  const char *last_dot = strrchr (class_name, '.');
+
+  const char *class_name_last_part;
   if (last_dot != NULL)
     {
       fprintf (stream, "namespace ");
@@ -492,8 +486,8 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam
            class_name_last_part);
 
   /* Determine whether there are plural messages.  */
-  plurals = 0;
-  for (j = 0; j < mlp->nitems; j++)
+  unsigned int plurals = 0;
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (mlp->item[j]->msgid_plural != NULL)
       plurals++;
 
@@ -521,7 +515,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam
   fprintf (stream, "          if (Table == null)\n");
   fprintf (stream, "            Table = new System.Collections.Hashtable();\n");
   fprintf (stream, "          System.Collections.Hashtable t = Table;\n");
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       fprintf (stream, "          t.Add(");
       write_csharp_msgid (stream, mlp->item[j]);
@@ -540,7 +534,7 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam
     {
       fprintf (stream, "  public static System.Collections.Hashtable GetMsgidPluralTable () {\n");
       fprintf (stream, "    System.Collections.Hashtable t = new System.Collections.Hashtable();\n");
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         if (mlp->item[j]->msgid_plural != NULL)
           {
             fprintf (stream, "    t.Add(");
@@ -556,11 +550,10 @@ write_csharp_code (FILE *stream, const char *culture_name, const char *class_nam
   /* Emit the PluralEval function.  It is a subroutine for GetPluralString.  */
   if (plurals)
     {
-      message_ty *header_entry;
+      message_ty *header_entry = message_list_search (mlp, NULL, "");
+
       const struct expression *plural;
       unsigned long int nplurals;
-
-      header_entry = message_list_search (mlp, NULL, "");
       extract_plural_expression (header_entry ? header_entry->msgstr : NULL,
                                  &plural, &nplurals);
 
@@ -585,23 +578,11 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
                         const char *resource_name, const char *locale_name,
                         const char *directory)
 {
-  int retval;
-  struct temp_dir *tmpdir;
-  char *culture_name;
-  char *output_file;
-  char *class_name;
-  char *csharp_file_name;
-  FILE *csharp_file;
-  const char *gettextlibdir;
-  const char *csharp_sources[1];
-  const char *libdirs[1];
-  const char *libraries[1];
-
   /* If no entry for this resource/domain, don't even create the file.  */
   if (mlp->nitems == 0)
     return 0;
 
-  retval = 1;
+  int retval = 1;
 
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL,
@@ -617,7 +598,7 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
      tmpnam(), tempnam() present a security risk, and on the other hand the
      function mkstemp() doesn't allow to specify a fixed suffix of the file.
      It is simpler to create a temporary directory.  */
-  tmpdir = create_temp_dir ("msg", NULL, false);
+  struct temp_dir *tmpdir = create_temp_dir ("msg", NULL, false);
   if (tmpdir == NULL)
     goto quit1;
 
@@ -626,14 +607,14 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
     resource_name = "Messages";
 
   /* Convert the locale name to a .NET specific culture name.  */
-  culture_name = xstrdup (locale_name);
+  char *culture_name = xstrdup (locale_name);
   {
-    char *p;
-    for (p = culture_name; *p != '\0'; p++)
+    for (char *p = culture_name; *p != '\0'; p++)
       if (*p == '_')
         *p = '-';
     if (str_startswith (culture_name, "sr-CS"))
       memcpy (culture_name, "sr-SP", 5);
+    char *p;
     p = strchr (culture_name, '@');
     if (p != NULL)
       {
@@ -656,11 +637,12 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
 
   /* Compute the output file name.  This code must be kept consistent with
      intl.cs, function GetSatelliteAssembly().  */
+  char *output_file;
   {
     char *output_dir = xconcatenated_filename (directory, culture_name, NULL);
-    struct stat statbuf;
 
     /* Try to create the output directory if it does not yet exist.  */
+    struct stat statbuf;
     if (stat (output_dir, &statbuf) < 0 && errno == ENOENT)
       if (mkdir (output_dir, S_IRUSR | S_IWUSR | S_IXUSR
                              | S_IRGRP | S_IWGRP | S_IXGRP
@@ -679,14 +661,14 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
 
   /* Compute the class name.  This code must be kept consistent with intl.cs,
      function InstantiateResourceSet().  */
+  char *class_name;
   {
     char *class_name_part1 = construct_class_name (resource_name);
-    char *p;
 
     class_name =
       XNMALLOC (strlen (class_name_part1) + 1 + strlen (culture_name) + 1, char);
     sprintf (class_name, "%s_%s", class_name_part1, culture_name);
-    for (p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++)
+    for (char *p = class_name + strlen (class_name_part1) + 1; *p != '\0'; p++)
       if (*p == '-')
         *p = '_';
     free (class_name_part1);
@@ -694,12 +676,12 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
 
   /* Compute the temporary C# file name.  It must end in ".cs", so that
      the C# compiler recognizes that it is C# source code.  */
-  csharp_file_name =
+  char *csharp_file_name =
     xconcatenated_filename (tmpdir->dir_name, "resset.cs", NULL);
 
   /* Create the C# file.  */
   register_temp_file (tmpdir, csharp_file_name);
-  csharp_file = fopen_temp (csharp_file_name, "w", false);
+  FILE *csharp_file = fopen_temp (csharp_file_name, "w", false);
   if (csharp_file == NULL)
     {
       error (0, errno, _("failed to create \"%s\""), csharp_file_name);
@@ -717,13 +699,16 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
 
   /* Make it possible to override the .dll location.  This is
      necessary for running the testsuite before "make install".  */
-  gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
+  const char *gettextlibdir = getenv ("GETTEXTCSHARPLIBDIR");
   if (gettextlibdir == NULL || gettextlibdir[0] == '\0')
     gettextlibdir = relocate (LIBDIR);
 
   /* Compile the C# file to a .dll file.  */
+  const char *csharp_sources[1];
   csharp_sources[0] = csharp_file_name;
+  const char *libdirs[1];
   libdirs[0] = gettextlibdir;
+  const char *libraries[1];
   libraries[0] = "GNU.Gettext";
   if (compile_csharp_class (csharp_sources, 1, libdirs, 1, libraries, 1,
                             output_file, true, false, verbose > 0))
index 440b44ba8378a297d5cd3f2e547122979b6ad3aa..db715505d19dc2bcade51d73f4997c1529028a3c 100644 (file)
@@ -66,19 +66,18 @@ msgfmt_desktop_handle_pair (desktop_reader_ty *reader,
                             const char *value)
 {
   msgfmt_desktop_reader_ty *msgfmt_reader = (msgfmt_desktop_reader_ty *) reader;
-  void *keyword_value;
 
   if (!locale)
     {
       /* Write translated pair, if any.  */
+      void *keyword_value;
       if (hash_find_entry (msgfmt_reader->keywords, key, strlen (key),
                            &keyword_value) == 0)
         {
           bool is_list = (bool) (uintptr_t) keyword_value;
           char *unescaped = desktop_unescape_string (value, is_list);
-          size_t i;
 
-          for (i = 0; i < msgfmt_reader->operands->nitems; i++)
+          for (size_t i = 0; i < msgfmt_reader->operands->nitems; i++)
             {
               msgfmt_operand_ty *operand = &msgfmt_reader->operands->items[i];
               message_ty *mp;
@@ -142,12 +141,8 @@ msgdomain_write_desktop_bulk (msgfmt_operand_list_ty *operands,
                               hash_table *keywords,
                               const char *file_name)
 {
-  desktop_reader_ty *reader;
-  msgfmt_desktop_reader_ty *msgfmt_reader;
-  FILE *template_file;
-
-  reader = desktop_reader_alloc (&msgfmt_methods);
-  msgfmt_reader = (msgfmt_desktop_reader_ty *) reader;
+  desktop_reader_ty *reader = desktop_reader_alloc (&msgfmt_methods);
+  msgfmt_desktop_reader_ty *msgfmt_reader = (msgfmt_desktop_reader_ty *) reader;
 
   msgfmt_reader->operands = operands;
   msgfmt_reader->keywords = keywords;
@@ -166,7 +161,7 @@ msgdomain_write_desktop_bulk (msgfmt_operand_list_ty *operands,
         }
     }
 
-  template_file = fopen (template_file_name, "r");
+  FILE *template_file = fopen (template_file_name, "r");
   if (template_file == NULL)
     {
       desktop_reader_free (reader);
@@ -198,9 +193,6 @@ msgdomain_write_desktop (message_list_ty *mlp,
                          hash_table *keywords,
                          const char *file_name)
 {
-  msgfmt_operand_ty operand;
-  msgfmt_operand_list_ty operands;
-
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL,
                       textmode_xerror_handler);
@@ -210,8 +202,10 @@ msgdomain_write_desktop (message_list_ty *mlp,
   message_list_delete_header_field (mlp, "POT-Creation-Date:");
 
   /* Create a single-element operands and run the bulk operation on it.  */
+  msgfmt_operand_ty operand;
   operand.language = (char *) locale_name;
   operand.mlp = mlp;
+  msgfmt_operand_list_ty operands;
   operands.nitems = 1;
   operands.items = &operand;
 
index 14aacbea9375049e6373229d4848ab33dd33f59b..d026a7df87872382da0c44dac39082753dfd7f81 100644 (file)
@@ -127,15 +127,13 @@ msgid_hashcode (const char *msgctxt, const char *msgid)
       size_t msgctxt_len = strlen (msgctxt);
       size_t msgid_len = strlen (msgid);
       size_t combined_len = msgctxt_len + 1 + msgid_len;
-      char *combined;
-      unsigned int result;
 
-      combined = (char *) xmalloca (combined_len + 1);
+      char *combined = (char *) xmalloca (combined_len + 1);
       memcpy (combined, msgctxt, msgctxt_len);
       combined[msgctxt_len] = MSGCTXT_SEPARATOR;
       memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1);
 
-      result = string_hashcode (combined);
+      unsigned int result = string_hashcode (combined);
 
       freea (combined);
 
@@ -155,12 +153,8 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp)
   unsigned int n = mlp->nitems;
   unsigned int *hashcodes =
     (unsigned int *) xmalloca (n * sizeof (unsigned int));
-  unsigned int hashsize;
-  unsigned int best_hashsize;
-  unsigned int best_score;
-  size_t j;
 
-  for (j = 0; j < n; j++)
+  for (size_t j = 0; j < n; j++)
     hashcodes[j] = msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid);
 
   /* Try all numbers between n and 3*n.  The score depends on the size of the
@@ -168,24 +162,21 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp)
      i.e. total number of times that 1 + (hashcode % (hashsize - 2))
      is added to the index during lookup.  If there are collisions, only odd
      hashsize values are allowed.  */
-  best_hashsize = 0;
-  best_score = UINT_MAX;
-  for (hashsize = n; hashsize <= XXN * n; hashsize++)
+  unsigned int best_hashsize = 0;
+  unsigned int best_score = UINT_MAX;
+  for (unsigned int hashsize = n; hashsize <= XXN * n; hashsize++)
     {
-      char *bitmap;
-      unsigned int score;
-
       /* Premature end of the loop if all future scores are known to be
          larger than the already reached best_score.  This relies on the
          ascending loop and on the fact that score >= hashsize.  */
       if (hashsize >= best_score)
         break;
 
-      bitmap = XNMALLOC (hashsize, char);
+      char *bitmap = XNMALLOC (hashsize, char);
       memset (bitmap, 0, hashsize);
 
-      score = 0;
-      for (j = 0; j < n; j++)
+      unsigned int score = 0;
+      for (size_t j = 0; j < n; j++)
         {
           unsigned int idx = hashcodes[j] % hashsize;
 
@@ -228,27 +219,22 @@ compute_hashsize (message_list_ty *mlp, bool *collisionp)
          an endless loop in the lookup function.  */
       if (score > hashsize)
         {
-          unsigned int incr;
-
           /* Since the set { idx0, idx0 + incr, ... } depends only on idx0
              and gcd(hashsize,incr), we only need to consider incr that
              divides hashsize.  */
-          for (incr = 1; incr <= hashsize / 2; incr++)
+          for (unsigned int incr = 1; incr <= hashsize / 2; incr++)
             if ((hashsize % incr) == 0)
               {
-                unsigned int idx0;
-
-                for (idx0 = 0; idx0 < incr; idx0++)
+                for (unsigned int idx0 = 0; idx0 < incr; idx0++)
                   {
                     bool full = true;
-                    unsigned int idx;
-
-                    for (idx = idx0; idx < hashsize; idx += incr)
+                    for (unsigned int idx = idx0; idx < hashsize; idx += incr)
                       if (bitmap[idx] == 0)
                         {
                           full = false;
                           break;
                         }
+
                     if (full)
                       /* A whole round is occupied.  */
                       goto bad_hashsize;
@@ -295,13 +281,11 @@ compute_table_items (message_list_ty *mlp, unsigned int hashsize)
 {
   unsigned int n = mlp->nitems;
   struct table_item *arr = XNMALLOC (n, struct table_item);
-  char *bitmap;
-  size_t j;
 
-  bitmap = XNMALLOC (hashsize, char);
+  char *bitmap = XNMALLOC (hashsize, char);
   memset (bitmap, 0, hashsize);
 
-  for (j = 0; j < n; j++)
+  for (size_t j = 0; j < n; j++)
     {
       unsigned int hashcode =
         msgid_hashcode (mlp->item[j]->msgctxt, mlp->item[j]->msgid);
@@ -337,9 +321,10 @@ static void
 write_java_string (FILE *stream, const char *str)
 {
   static const char hexdigit[] = "0123456789abcdef";
-  const char *str_limit = str + strlen (str);
 
   fprintf (stream, "\"");
+
+  const char *str_limit = str + strlen (str);
   while (str < str_limit)
     {
       ucs4_t uc;
@@ -375,6 +360,7 @@ write_java_string (FILE *stream, const char *str)
                    hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]);
         }
     }
+
   fprintf (stream, "\"");
 }
 
@@ -394,9 +380,8 @@ write_java_msgid (FILE *stream, message_ty *mp)
       size_t msgctxt_len = strlen (msgctxt);
       size_t msgid_len = strlen (msgid);
       size_t combined_len = msgctxt_len + 1 + msgid_len;
-      char *combined;
 
-      combined = (char *) xmalloca (combined_len + 1);
+      char *combined = (char *) xmalloca (combined_len + 1);
       memcpy (combined, msgctxt, msgctxt_len);
       combined[msgctxt_len] = MSGCTXT_SEPARATOR;
       memcpy (combined + msgctxt_len + 1, msgid, msgid_len + 1);
@@ -416,18 +401,19 @@ write_java_msgstr (FILE *stream, message_ty *mp)
 {
   if (mp->msgid_plural != NULL)
     {
-      bool first;
-      const char *p;
-
       fprintf (stream, "new java.lang.String[] { ");
-      for (p = mp->msgstr, first = true;
-           p < mp->msgstr + mp->msgstr_len;
-           p += strlen (p) + 1, first = false)
-        {
-          if (!first)
-            fprintf (stream, ", ");
-          write_java_string (stream, p);
-        }
+      {
+        bool first = true;
+        for (const char *p = mp->msgstr;
+             p < mp->msgstr + mp->msgstr_len;
+             p += strlen (p) + 1)
+          {
+            if (!first)
+              fprintf (stream, ", ");
+            write_java_string (stream, p);
+            first = false;
+          }
+      }
       fprintf (stream, " }");
     }
   else
@@ -699,9 +685,7 @@ static void
 write_java1_init_statements (FILE *stream, message_list_ty *mlp,
                              size_t start_index, size_t end_index)
 {
-  size_t j;
-
-  for (j = start_index; j < end_index; j++)
+  for (size_t j = start_index; j < end_index; j++)
     {
       fprintf (stream, "    t.put(");
       write_java_msgid (stream, mlp->item[j]);
@@ -719,9 +703,7 @@ write_java2_init_statements (FILE *stream, message_list_ty *mlp,
                              const struct table_item *table_items,
                              size_t start_index, size_t end_index)
 {
-  size_t j;
-
-  for (j = start_index; j < end_index; j++)
+  for (size_t j = start_index; j < end_index; j++)
     {
       const struct table_item *ti = &table_items[j];
 
@@ -743,13 +725,9 @@ static void
 write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
                  bool assume_java2)
 {
-  const char *last_dot;
-  unsigned int plurals;
-  size_t j;
-
   fprintf (stream,
            "/* Automatically generated by GNU msgfmt.  Do not modify!  */\n");
-  last_dot = strrchr (class_name, '.');
+  const char *last_dot = strrchr (class_name, '.');
   if (last_dot != NULL)
     {
       fprintf (stream, "package ");
@@ -761,30 +739,26 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
   fprintf (stream, " extends java.util.ResourceBundle {\n");
 
   /* Determine whether there are plural messages.  */
-  plurals = 0;
-  for (j = 0; j < mlp->nitems; j++)
+  unsigned int plurals = 0;
+  for (size_t j = 0; j < mlp->nitems; j++)
     if (mlp->item[j]->msgid_plural != NULL)
       plurals++;
 
   if (assume_java2)
     {
-      unsigned int hashsize;
-      bool collisions;
-      struct table_item *table_items;
-      const char *table_eltype;
-
       /* Determine the hash table size and whether it leads to collisions.  */
-      hashsize = compute_hashsize (mlp, &collisions);
+      bool collisions;
+      unsigned int hashsize = compute_hashsize (mlp, &collisions);
 
       /* Determines which indices in the table contain a message.  The others
          are null.  */
-      table_items = compute_table_items (mlp, hashsize);
+      struct table_item *table_items = compute_table_items (mlp, hashsize);
 
       /* Emit the table of pairs (msgid, msgstr).  If there are plurals,
          it is of type Object[], otherwise of type String[].  We use a static
          code block because that makes less code:  The Java compilers also
          generate code for the 'null' entries, which is dumb.  */
-      table_eltype = (plurals ? "java.lang.Object" : "java.lang.String");
+      const char *table_eltype = (plurals ? "java.lang.Object" : "java.lang.String");
       fprintf (stream, "  private static final %s[] table;\n", table_eltype);
       {
         /* With the Sun javac compiler, each assignment takes 5 to 8 bytes
@@ -836,21 +810,22 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
       /* Emit the msgid_plural strings.  Only used by msgunfmt.  */
       if (plurals)
         {
-          bool first;
           fprintf (stream, "  public static final java.lang.String[] get_msgid_plural_table () {\n");
           fprintf (stream, "    return new java.lang.String[] { ");
-          first = true;
-          for (j = 0; j < mlp->nitems; j++)
-            {
-              struct table_item *ti = &table_items[j];
-              if (ti->mp->msgid_plural != NULL)
-                {
-                  if (!first)
-                    fprintf (stream, ", ");
-                  write_java_string (stream, ti->mp->msgid_plural);
-                  first = false;
-                }
-            }
+          {
+            bool first = true;
+            for (size_t j = 0; j < mlp->nitems; j++)
+              {
+                struct table_item *ti = &table_items[j];
+                if (ti->mp->msgid_plural != NULL)
+                  {
+                    if (!first)
+                      fprintf (stream, ", ");
+                    write_java_string (stream, ti->mp->msgid_plural);
+                    first = false;
+                  }
+              }
+          }
           fprintf (stream, " };\n");
           fprintf (stream, "  }\n");
         }
@@ -952,7 +927,7 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
         {
           fprintf (stream, "  public static final java.util.Hashtable<java.lang.String,java.lang.Object> get_msgid_plural_table () {\n");
           fprintf (stream, "    java.util.Hashtable<java.lang.String,java.lang.Object> p = new java.util.Hashtable<java.lang.String,java.lang.Object>();\n");
-          for (j = 0; j < mlp->nitems; j++)
+          for (size_t j = 0; j < mlp->nitems; j++)
             if (mlp->item[j]->msgid_plural != NULL)
               {
                 fprintf (stream, "    p.put(");
@@ -996,11 +971,10 @@ write_java_code (FILE *stream, const char *class_name, message_list_ty *mlp,
   /* Emit the pluralEval function.  It is a subroutine for ngettext.  */
   if (plurals)
     {
-      message_ty *header_entry;
+      message_ty *header_entry = message_list_search (mlp, NULL, "");
+
       const struct expression *plural;
       unsigned long int nplurals;
-
-      header_entry = message_list_search (mlp, NULL, "");
       extract_plural_expression (header_entry ? header_entry->msgstr : NULL,
                                  &plural, &nplurals);
 
@@ -1027,21 +1001,11 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
                       bool assume_java2,
                       bool output_source)
 {
-  int retval;
-  struct temp_dir *tmpdir;
-  int ndots;
-  char *class_name;
-  char **subdirs;
-  char *java_file_name;
-  FILE *java_file;
-  const char *java_sources[1];
-  const char *source_dir_name;
-
   /* If no entry for this resource/domain, don't even create the file.  */
   if (mlp->nitems == 0)
     return 0;
 
-  retval = 1;
+  int retval = 1;
 
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL,
@@ -1051,6 +1015,8 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
      between builds in the same conditions.  */
   message_list_delete_header_field (mlp, "POT-Creation-Date:");
 
+  struct temp_dir *tmpdir;
+  const char *source_dir_name;
   if (output_source)
     {
       tmpdir = NULL;
@@ -1070,13 +1036,14 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
     resource_name = "Messages";
 
   /* Prepare the list of subdirectories.  */
-  ndots = check_resource_name (resource_name);
+  int ndots = check_resource_name (resource_name);
   if (ndots < 0)
     {
       error (0, 0, _("not a valid Java class name: %s"), resource_name);
       goto quit2;
     }
 
+  char *class_name;
   if (locale_name != NULL)
     {
       class_name = xasprintf ("%s_%s", resource_name, locale_name);
@@ -1085,15 +1052,12 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   else
     class_name = xstrdup (resource_name);
 
-  subdirs = (ndots > 0 ? (char **) xmalloca (ndots * sizeof (char *)) : NULL);
+  char **subdirs = (ndots > 0 ? (char **) xmalloca (ndots * sizeof (char *)) : NULL);
+  char *java_file_name;
   {
-    const char *p;
-    const char *last_dir;
-    int i;
-
-    last_dir = source_dir_name;
-    p = resource_name;
-    for (i = 0; i < ndots; i++)
+    const char *last_dir = source_dir_name;
+    const char *p = resource_name;
+    for (int i = 0; i < ndots; i++)
       {
         const char *q = strchr (p, '.');
         size_t n = q - p;
@@ -1119,9 +1083,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   /* If OUTPUT_SOURCE, write the Java file in DIRECTORY and return.  */
   if (output_source)
     {
-      int i;
-
-      for (i = 0; i < ndots; i++)
+      for (int i = 0; i < ndots; i++)
         {
           if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0)
             {
@@ -1130,7 +1092,7 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
             }
         }
 
-      java_file = fopen (java_file_name, "w");
+      FILE *java_file = fopen (java_file_name, "w");
       if (java_file == NULL)
         {
           error (0, errno, _("failed to create \"%s\""), java_file_name);
@@ -1153,43 +1115,42 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   /* Create the subdirectories.  This is needed because some older Java
      compilers verify that the source of class A.B.C really sits in a
      directory whose name ends in /A/B.  */
-  {
-    int i;
+  for (int i = 0; i < ndots; i++)
+    {
+      register_temp_subdir (tmpdir, subdirs[i]);
+      if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0)
+        {
+          error (0, errno, _("failed to create \"%s\""), subdirs[i]);
+          unregister_temp_subdir (tmpdir, subdirs[i]);
+          goto quit3;
+        }
+    }
 
-    for (i = 0; i < ndots; i++)
+  /* Create the Java file.  */
+  {
+    register_temp_file (tmpdir, java_file_name);
+    FILE *java_file = fopen_temp (java_file_name, "w", false);
+    if (java_file == NULL)
       {
-        register_temp_subdir (tmpdir, subdirs[i]);
-        if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0)
-          {
-            error (0, errno, _("failed to create \"%s\""), subdirs[i]);
-            unregister_temp_subdir (tmpdir, subdirs[i]);
-            goto quit3;
-          }
+        error (0, errno, _("failed to create \"%s\""), java_file_name);
+        unregister_temp_file (tmpdir, java_file_name);
+        goto quit3;
       }
-  }
 
-  /* Create the Java file.  */
-  register_temp_file (tmpdir, java_file_name);
-  java_file = fopen_temp (java_file_name, "w", false);
-  if (java_file == NULL)
-    {
-      error (0, errno, _("failed to create \"%s\""), java_file_name);
-      unregister_temp_file (tmpdir, java_file_name);
-      goto quit3;
-    }
+    write_java_code (java_file, class_name, mlp, assume_java2);
 
-  write_java_code (java_file, class_name, mlp, assume_java2);
-
-  if (fwriteerror_temp (java_file))
-    {
-      error (0, errno, _("error while writing \"%s\" file"), java_file_name);
-      goto quit3;
-    }
+    if (fwriteerror_temp (java_file))
+      {
+        error (0, errno, _("error while writing \"%s\" file"), java_file_name);
+        goto quit3;
+      }
+  }
 
   /* Compile the Java file to a .class file.
      directory must be non-NULL, because when the -d option is omitted, the
      Java compilers create the class files in the source file's directory -
      which is in a temporary directory in our case.  */
+  const char *java_sources[1];
   java_sources[0] = java_file_name;
   if (compile_java_class (java_sources, 1, NULL, 0, "1.8", "1.8", directory,
                           true, false, true, verbose > 0))
@@ -1207,9 +1168,8 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
 
  quit3:
   {
-    int i;
     free (java_file_name);
-    for (i = 0; i < ndots; i++)
+    for (int i = 0; i < ndots; i++)
       free (subdirs[i]);
   }
   freea (subdirs);
index 245372f0169bf34fea613f717f928aa05ca0b988..07f08d30e0dd16f754dd64862ad2824c0d85f4f5 100644 (file)
@@ -369,54 +369,27 @@ get_sysdep_segment_value (struct pre_sysdep_segment segment,
 static void
 write_table (FILE *output_file, message_list_ty *mlp)
 {
-  char **msgctid_arr;
-  size_t nstrings;
-  size_t msg_arr_allocated;
-  struct pre_message *msg_arr;
-  size_t n_sysdep_strings;
-  struct pre_sysdep_message *sysdep_msg_arr;
-  size_t n_sysdep_segments;
-  struct pre_sysdep_segment *sysdep_segments;
-  bool have_outdigits;
-  int major_revision;
-  int minor_revision;
-  bool omit_hash_table;
-  nls_uint32 hash_tab_size;
-  struct mo_file_header header; /* Header of the .mo file to be written.  */
-  size_t header_size;
-  size_t offset;
-  struct string_desc *orig_tab;
-  struct string_desc *trans_tab;
-  size_t sysdep_tab_offset = 0;
-  size_t end_offset;
-  char *null;
-
   /* First pass: Move the static string pairs into an array, for sorting,
      and at the same time, compute the segments of the system dependent
      strings.  */
-  msgctid_arr = XNMALLOC (mlp->nitems, char *);
-  nstrings = 0;
-  msg_arr_allocated = mlp->nitems;
-  msg_arr = XNMALLOC (msg_arr_allocated, struct pre_message);
-  n_sysdep_strings = 0;
-  sysdep_msg_arr = XNMALLOC (mlp->nitems, struct pre_sysdep_message);
-  n_sysdep_segments = 0;
-  sysdep_segments = NULL;
-  have_outdigits = false;
+  char **msgctid_arr = XNMALLOC (mlp->nitems, char *);
+  size_t nstrings = 0;
+  size_t msg_arr_allocated = mlp->nitems;
+  struct pre_message *msg_arr = XNMALLOC (msg_arr_allocated, struct pre_message);
+  size_t n_sysdep_strings = 0;
+  struct pre_sysdep_message *sysdep_msg_arr =
+    XNMALLOC (mlp->nitems, struct pre_sysdep_message);
+  size_t n_sysdep_segments = 0;
+  struct pre_sysdep_segment *sysdep_segments = NULL;
+  bool have_outdigits = false;
   {
-    size_t j;
-
-    for (j = 0; j < mlp->nitems; j++)
+    for (size_t 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);
+        size_t msgctlen = (mp->msgctxt != NULL ? strlen (mp->msgctxt) + 1 : 0);
+        char *msgctid = XNMALLOC (msgctlen + strlen (mp->msgid) + 1, char);
         if (mp->msgctxt != NULL)
           {
             memcpy (msgctid, mp->msgctxt, msgctlen - 1);
@@ -425,6 +398,8 @@ write_table (FILE *output_file, message_list_ty *mlp)
         strcpy (msgctid + msgctlen, mp->msgid);
         msgctid_arr[j] = msgctid;
 
+        struct interval *intervals[2];
+        size_t nintervals[2];
         intervals[M_ID] = NULL;
         nintervals[M_ID] = 0;
         intervals[M_STR] = NULL;
@@ -438,9 +413,6 @@ write_table (FILE *output_file, message_list_ty *mlp)
             /* Check whether msgid or msgstr contain ISO C 99 <inttypes.h>
                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)
@@ -450,9 +422,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
                 if (id_nintervals > 0)
                   {
-                    unsigned int i;
-
-                    for (i = 0; i < id_nintervals; i++)
+                    for (unsigned int i = 0; i < id_nintervals; i++)
                       {
                         id_intervals[i].startpos += msgctlen;
                         id_intervals[i].endpos += msgctlen;
@@ -460,26 +430,24 @@ write_table (FILE *output_file, message_list_ty *mlp)
                   }
               }
 
-            p_end = mp->msgstr + mp->msgstr_len;
-            for (p = mp->msgstr; p < p_end; p += strlen (p) + 1)
+            const char *p_end = mp->msgstr + mp->msgstr_len;
+            for (const char *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++)
+                    for (unsigned int i = 0; i < part_nintervals; i++)
                       {
                         intervals[M_STR][nintervals[M_STR] + i].startpos =
                           d + part_intervals[i].startpos;
@@ -494,20 +462,16 @@ write_table (FILE *output_file, message_list_ty *mlp)
         if (nintervals[M_ID] > 0 || nintervals[M_STR] > 0)
           {
             /* System dependent string pair.  */
-            size_t m;
-
-            for (m = 0; m < 2; m++)
+            for (size_t 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  */
@@ -519,19 +483,16 @@ write_table (FILE *output_file, message_list_ty *mlp)
                     str_len = mp->msgstr_len;
                   }
 
-                lastpos = 0;
+                size_t lastpos = 0;
                 pre->segmentcount = nintervals[m];
+                unsigned int i;
                 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;
+                    size_t length = intervals[m][i].endpos - intervals[m][i].startpos;
+                    const char *pointer = str + intervals[m][i].startpos;
                     if (length >= 2
                         && pointer[0] == '<' && pointer[length - 1] == '>')
                       {
@@ -540,6 +501,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
                         pointer += 1;
                       }
 
+                    size_t r;
                     for (r = 0; r < n_sysdep_segments; r++)
                       if (sysdep_segments[r].length == length
                           && memcmp (sysdep_segments[r].pointer, pointer, length)
@@ -589,13 +551,9 @@ write_table (FILE *output_file, message_list_ty *mlp)
             nstrings++;
           }
 
-        {
-          size_t m;
-
-          for (m = 0; m < 2; m++)
-            if (intervals[m] != NULL)
-              free (intervals[m]);
-        }
+        for (size_t m = 0; m < 2; m++)
+          if (intervals[m] != NULL)
+            free (intervals[m]);
       }
   }
 
@@ -606,69 +564,57 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Create a temporary hash table of msg_arr[*].str[M_ID], to guarantee
          fast lookups.  */
       hash_table static_msgids;
-
       hash_init (&static_msgids, 10);
-      {
-        size_t i;
-
-        for (i = 0; i < nstrings; i++)
-          hash_insert_entry (&static_msgids,
-                             msg_arr[i].str[M_ID].pointer,
-                             msg_arr[i].str[M_ID].length,
-                             NULL);
-      }
-
-      size_t ss;
+      for (size_t i = 0; i < nstrings; i++)
+        hash_insert_entry (&static_msgids,
+                           msg_arr[i].str[M_ID].pointer,
+                           msg_arr[i].str[M_ID].length,
+                           NULL);
 
-      for (ss = 0; ss < n_sysdep_strings; ss++)
+      for (size_t ss = 0; ss < n_sysdep_strings; ss++)
         {
-          size_t u;
-
-          for (u = 0; u < SIZEOF (useful_instantiation_rules); u++)
+          for (size_t u = 0; u < SIZEOF (useful_instantiation_rules); u++)
             {
               const struct sysdep_instantiation_rule *instrule =
                 &useful_instantiation_rules[u];
               bool supported = true;
               struct pre_string expansion[2];
-              size_t m;
 
-              for (m = 0; m < 2; m++)
+              for (size_t m = 0; m < 2; m++)
                 {
                   struct pre_sysdep_string *pre = sysdep_msg_arr[ss].str[m];
                   unsigned int segmentcount = pre->segmentcount;
-                  size_t expansion_length;
-                  char *expansion_pointer;
-                  unsigned int i;
 
                   /* Compute the length of the expansion.  */
-                  expansion_length = 0;
-                  i = 0;
-                  do
-                    {
-                      expansion_length += pre->segments[i].segsize;
+                  size_t expansion_length = 0;
+                  {
+                    unsigned int i = 0;
+                    do
+                      {
+                        expansion_length += pre->segments[i].segsize;
 
-                      size_t r = pre->segments[i].sysdepref;
-                      if (r == SEGMENTS_END)
-                        break;
-                      const char *segment_expansion =
-                        get_sysdep_segment_value (sysdep_segments[r], instrule);
-                      if (segment_expansion == NULL)
-                        {
-                          supported = false;
+                        size_t r = pre->segments[i].sysdepref;
+                        if (r == SEGMENTS_END)
                           break;
-                        }
-                      expansion_length += strlen (segment_expansion);
-                    }
-                  while (i++ < segmentcount);
+                        const char *segment_expansion =
+                          get_sysdep_segment_value (sysdep_segments[r], instrule);
+                        if (segment_expansion == NULL)
+                          {
+                            supported = false;
+                            break;
+                          }
+                        expansion_length += strlen (segment_expansion);
+                      }
+                    while (i++ < segmentcount);
+                  }
                   if (!supported)
                     break;
 
                   /* Compute the expansion.  */
-                  expansion_pointer = (char *) xmalloc (expansion_length);
+                  char *expansion_pointer = (char *) xmalloc (expansion_length);
                   {
                     char *p = expansion_pointer;
-
-                    i = 0;
+                    unsigned int i = 0;
                     do
                       {
                         memcpy (p, pre->segments[i].segptr, pre->segments[i].segsize);
@@ -732,16 +678,16 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* We need major revision 1 if there are system dependent strings that use
      "I" because older versions of gettext() crash when this occurs in a .mo
      file.  Otherwise use major revision 0.  */
-  major_revision =
+  int major_revision =
     (have_outdigits ? MO_REVISION_NUMBER_WITH_SYSDEP_I : MO_REVISION_NUMBER);
 
   /* We need minor revision 1 if there are system dependent strings.
      Otherwise we choose minor revision 0 because it's supported by older
      versions of libintl and revision 1 isn't.  */
-  minor_revision = (n_sysdep_strings > 0 ? 1 : 0);
+  int minor_revision = (n_sysdep_strings > 0 ? 1 : 0);
 
   /* In minor revision >= 1, the hash table is obligatory.  */
-  omit_hash_table = (no_hash_table && minor_revision == 0);
+  bool omit_hash_table = (no_hash_table && minor_revision == 0);
 
   /* This should be explained:
      Each string has an associate hashing value V, computed by a fixed
@@ -763,6 +709,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
      Because unsuccessful searches are unlikely this is a good value.
      Formulas: [Knuth, The Art of Computer Programming, Volume 3,
                 Sorting and Searching, 1973, Addison Wesley]  */
+  nls_uint32 hash_tab_size;
   if (!omit_hash_table)
     {
       /* N is the number of static string pairs (filled in here, below)
@@ -778,17 +725,18 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
   /* Third pass: Fill the structure describing the header.  At the same time,
      compute the sizes and offsets of the non-string parts of the file.  */
+  struct mo_file_header header; /* Header of the .mo file to be written.  */
 
   /* Magic number.  */
   header.magic = _MAGIC;
   /* Revision number of file format.  */
   header.revision = (major_revision << 16) + minor_revision;
 
-  header_size =
+  size_t header_size =
     (minor_revision == 0
      ? offsetof (struct mo_file_header, n_sysdep_segments)
      : sizeof (struct mo_file_header));
-  offset = header_size;
+  size_t offset = header_size;
 
   /* Number of static string pairs.  */
   header.nstrings = nstrings;
@@ -796,12 +744,12 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* Offset of table for original string offsets.  */
   header.orig_tab_offset = offset;
   offset += nstrings * sizeof (struct string_desc);
-  orig_tab = XNMALLOC (nstrings, struct string_desc);
+  struct string_desc *orig_tab = XNMALLOC (nstrings, struct string_desc);
 
   /* Offset of table for translated string offsets.  */
   header.trans_tab_offset = offset;
   offset += nstrings * sizeof (struct string_desc);
-  trans_tab = XNMALLOC (nstrings, struct string_desc);
+  struct string_desc *trans_tab = XNMALLOC (nstrings, struct string_desc);
 
   /* Size of hash table.  */
   header.hash_tab_size = hash_tab_size;
@@ -809,6 +757,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
   header.hash_tab_offset = offset;
   offset += hash_tab_size * sizeof (nls_uint32);
 
+  size_t sysdep_tab_offset = 0;
   if (minor_revision >= 1)
     {
       /* Size of table describing system dependent segments.  */
@@ -830,19 +779,14 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
       /* System dependent string descriptors.  */
       sysdep_tab_offset = offset;
-      {
-        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);
-      }
+      for (size_t m = 0; m < 2; m++)
+        for (size_t 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;
+  size_t end_offset = offset;
 
 
   /* Fourth pass: Write the non-string parts of the file.  At the same time,
@@ -873,9 +817,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* Here output_file is at position header.orig_tab_offset.  */
 
   {
-    size_t j;
-
-    for (j = 0; j < nstrings; j++)
+    for (size_t j = 0; j < nstrings; j++)
       {
         offset = roundup (offset, alignment);
         orig_tab[j].length =
@@ -886,7 +828,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
         orig_tab[j].length--;
       }
     if (byteswap)
-      for (j = 0; j < nstrings; j++)
+      for (size_t j = 0; j < nstrings; j++)
         {
           BSWAP32 (orig_tab[j].length);
           BSWAP32 (orig_tab[j].offset);
@@ -898,9 +840,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* Here output_file is at position header.trans_tab_offset.  */
 
   {
-    size_t j;
-
-    for (j = 0; j < nstrings; j++)
+    for (size_t j = 0; j < nstrings; j++)
       {
         offset = roundup (offset, alignment);
         trans_tab[j].length = msg_arr[j].str[M_STR].length;
@@ -910,7 +850,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
         trans_tab[j].length--;
       }
     if (byteswap)
-      for (j = 0; j < nstrings; j++)
+      for (size_t j = 0; j < nstrings; j++)
         {
           BSWAP32 (trans_tab[j].length);
           BSWAP32 (trans_tab[j].offset);
@@ -921,18 +861,15 @@ write_table (FILE *output_file, message_list_ty *mlp)
   /* Skip this part when no hash table is needed.  */
   if (!omit_hash_table)
     {
-      nls_uint32 *hash_tab;
-      size_t j;
-
       /* Here output_file is at position header.hash_tab_offset.  */
 
       /* Allocate room for the hashing table to be written out.  */
-      hash_tab = XNMALLOC (hash_tab_size, nls_uint32);
+      nls_uint32 *hash_tab = XNMALLOC (hash_tab_size, nls_uint32);
       memset (hash_tab, '\0', hash_tab_size * sizeof (nls_uint32));
 
       /* Insert all values in the hash table, following the algorithm described
          above.  */
-      for (j = 0; j < nstrings; j++)
+      for (size_t j = 0; j < nstrings; j++)
         {
           nls_uint32 hash_val = hash_string (msg_arr[j].str[M_ID].pointer);
           nls_uint32 idx = hash_val % hash_tab_size;
@@ -955,7 +892,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
       /* Write the hash table out.  */
       if (byteswap)
-        for (j = 0; j < hash_tab_size; j++)
+        for (size_t j = 0; j < hash_tab_size; j++)
           BSWAP32 (hash_tab[j]);
       fwrite (hash_tab, hash_tab_size * sizeof (nls_uint32), 1, output_file);
 
@@ -967,12 +904,9 @@ write_table (FILE *output_file, message_list_ty *mlp)
       /* Here output_file is at position header.sysdep_segments_offset.  */
 
       {
-        struct sysdep_segment *sysdep_segments_tab;
-        unsigned int i;
-
-        sysdep_segments_tab =
+        struct sysdep_segment *sysdep_segments_tab =
           XNMALLOC (n_sysdep_segments, struct sysdep_segment);
-        for (i = 0; i < n_sysdep_segments; i++)
+        for (unsigned int i = 0; i < n_sysdep_segments; i++)
           {
             offset = roundup (offset, alignment);
             /* The "+ 1" accounts for the trailing NUL byte.  */
@@ -982,7 +916,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
           }
 
         if (byteswap)
-          for (i = 0; i < n_sysdep_segments; i++)
+          for (unsigned int i = 0; i < n_sysdep_segments; i++)
             {
               BSWAP32 (sysdep_segments_tab[i].length);
               BSWAP32 (sysdep_segments_tab[i].offset);
@@ -995,21 +929,16 @@ write_table (FILE *output_file, message_list_ty *mlp)
       }
 
       {
-        nls_uint32 *sysdep_tab;
-        size_t stoffset;
-        size_t m;
-        size_t j;
-
-        sysdep_tab = XNMALLOC (n_sysdep_strings, nls_uint32);
-        stoffset = sysdep_tab_offset;
+        nls_uint32 *sysdep_tab = XNMALLOC (n_sysdep_strings, nls_uint32);
+        size_t stoffset = sysdep_tab_offset;
 
-        for (m = 0; m < 2; m++)
+        for (size_t 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++)
+            for (size_t j = 0; j < n_sysdep_strings; j++)
               {
                 sysdep_tab[j] = stoffset;
                 stoffset += sizeof (struct sysdep_string)
@@ -1018,7 +947,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
               }
             /* Write the table for original/translated sysdep string offsets.  */
             if (byteswap)
-              for (j = 0; j < n_sysdep_strings; j++)
+              for (size_t j = 0; j < n_sysdep_strings; j++)
                 BSWAP32 (sysdep_tab[j]);
             fwrite (sysdep_tab, n_sysdep_strings * sizeof (nls_uint32), 1,
                     output_file);
@@ -1029,51 +958,45 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
       /* Here output_file is at position sysdep_tab_offset.  */
 
-      {
-        size_t m;
-        size_t j;
+      for (size_t m = 0; m < 2; m++)
+        for (size_t 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));
 
-        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);
+            offset = roundup (offset, alignment);
+            str->offset = offset;
+            for (unsigned int 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 (unsigned int 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);
-            }
-      }
+            freea (str);
+          }
     }
 
   /* Here output_file is at position end_offset.  */
@@ -1087,49 +1010,37 @@ write_table (FILE *output_file, message_list_ty *mlp)
   offset = end_offset;
 
   /* A few zero bytes for padding.  */
-  null = (char *) alloca (alignment);
+  char *null = (char *) alloca (alignment);
   memset (null, '\0', alignment);
 
   /* Now write the original strings.  */
-  {
-    size_t j;
-
-    for (j = 0; j < nstrings; j++)
-      {
-        fwrite (null, roundup (offset, alignment) - offset, 1, output_file);
-        offset = roundup (offset, alignment);
+  for (size_t 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,
+      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,
                 output_file);
-        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;
-      }
-  }
+      offset += msg_arr[j].str[M_ID].length + msg_arr[j].id_plural_len;
+    }
 
   /* Now write the translated strings.  */
-  {
-    size_t j;
-
-    for (j = 0; j < nstrings; j++)
-      {
-        fwrite (null, roundup (offset, alignment) - offset, 1, output_file);
-        offset = roundup (offset, alignment);
+  for (size_t 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;
-      }
-  }
+      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++)
+      for (unsigned int i = 0; i < n_sysdep_segments; i++)
         {
           fwrite (null, roundup (offset, alignment) - offset, 1, output_file);
           offset = roundup (offset, alignment);
@@ -1140,8 +1051,8 @@ write_table (FILE *output_file, message_list_ty *mlp)
           offset += sysdep_segments[i].length + 1;
         }
 
-      for (m = 0; m < 2; m++)
-        for (j = 0; j < n_sysdep_strings; j++)
+      for (size_t m = 0; m < 2; m++)
+        for (size_t j = 0; j < n_sysdep_strings; j++)
           {
             struct pre_sysdep_message *msg = &sysdep_msg_arr[j];
             struct pre_sysdep_string *pre = msg->str[m];
@@ -1150,7 +1061,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
                     output_file);
             offset = roundup (offset, alignment);
 
-            for (i = 0; i <= pre->segmentcount; i++)
+            for (unsigned int i = 0; i <= pre->segmentcount; i++)
               {
                 fwrite (pre->segments[i].segptr, pre->segments[i].segsize, 1,
                         output_file);
@@ -1168,8 +1079,7 @@ write_table (FILE *output_file, message_list_ty *mlp)
 
   freea (null);
   {
-    size_t j;
-    for (j = 0; j < mlp->nitems; j++)
+    for (size_t j = 0; j < mlp->nitems; j++)
       free (msgctid_arr[j]);
   }
   free (sysdep_msg_arr);
index 02d6d3b82e02af3c258a5d61de64f5817fb907bd..69bfe8a0c9264b3bf254e9935eca1fabdceb646d 100644 (file)
@@ -110,9 +110,7 @@ significant_format_p (enum is_format is_format)
 static bool
 has_significant_format_p (const enum is_format is_format[NFORMATS])
 {
-  size_t i;
-
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     if (significant_format_p (is_format[i]))
       return true;
   return false;
@@ -247,20 +245,17 @@ message_print_comment (const message_ty *mp, ostream_t stream)
 {
   if (print_comment && mp->comment != NULL)
     {
-      size_t j;
-
       begin_css_class (stream, class_translator_comment);
 
-      for (j = 0; j < mp->comment->nitems; ++j)
+      for (size_t j = 0; j < mp->comment->nitems; ++j)
         {
           const char *s = mp->comment->item[j];
           do
             {
-              const char *e;
               ostream_write_str (stream, "#");
               if (*s != '\0')
                 ostream_write_str (stream, " ");
-              e = strchr (s, '\n');
+              const char *e = strchr (s, '\n');
               if (e == NULL)
                 {
                   ostream_write_str (stream, s);
@@ -288,11 +283,9 @@ message_print_comment_dot (const message_ty *mp, ostream_t stream)
 {
   if (mp->comment_dot != NULL)
     {
-      size_t j;
-
       begin_css_class (stream, class_extracted_comment);
 
-      for (j = 0; j < mp->comment_dot->nitems; ++j)
+      for (size_t j = 0; j < mp->comment_dot->nitems; ++j)
         {
           const char *s = mp->comment_dot->item[j];
           ostream_write_str (stream, "#.");
@@ -319,23 +312,20 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream,
   if (filepos_comment_type != filepos_comment_none
       && mp->filepos_count != 0)
     {
-      size_t filepos_count;
-      lex_pos_ty *filepos;
-
       begin_css_class (stream, class_reference_comment);
 
+      lex_pos_ty *filepos;
+      size_t filepos_count;
       if (filepos_comment_type == filepos_comment_file)
         {
-          size_t i;
-
           filepos_count = 0;
           filepos = XNMALLOC (mp->filepos_count, lex_pos_ty);
 
-          for (i = 0; i < mp->filepos_count; ++i)
+          for (size_t i = 0; i < mp->filepos_count; ++i)
             {
               lex_pos_ty *pp = &mp->filepos[i];
-              size_t j;
 
+              size_t j;
               for (j = 0; j < filepos_count; j++)
                 if (strcmp (filepos[j].file_name, pp->file_name) == 0)
                   break;
@@ -356,22 +346,20 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream,
 
       if (uniforum)
         {
-          size_t j;
-
-          for (j = 0; j < filepos_count; ++j)
+          for (size_t j = 0; j < filepos_count; ++j)
             {
               lex_pos_ty *pp = &filepos[j];
-              const char *cp = pp->file_name;
-              char *str;
 
+              const char *cp = pp->file_name;
               while (cp[0] == '.' && cp[1] == '/')
                 cp += 2;
+
               ostream_write_str (stream, "# ");
               begin_css_class (stream, class_reference);
               /* There are two Sun formats to choose from: SunOS and
                  Solaris.  Use the Solaris form here.  */
-              str = xasprintf ("File: %s, line: %ld",
-                               cp, (long) pp->line_number);
+              char *str = xasprintf ("File: %s, line: %ld",
+                                     cp, (long) pp->line_number);
               assume (str != NULL);
               ostream_write_str (stream, str);
               end_css_class (stream, class_reference);
@@ -381,25 +369,19 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream,
         }
       else
         {
-          const char *canon_charset;
-          size_t column;
-          size_t j;
-
-          canon_charset = po_charset_canonicalize (charset);
+          const char *canon_charset = po_charset_canonicalize (charset);
 
           ostream_write_str (stream, "#:");
-          column = 2;
-          for (j = 0; j < filepos_count; ++j)
+          size_t column = 2;
+          for (size_t j = 0; j < filepos_count; ++j)
             {
-              lex_pos_ty *pp;
-              char buffer[22];
-              const char *cp;
-              size_t width;
+              lex_pos_ty *pp = &filepos[j];
 
-              pp = &filepos[j];
-              cp = pp->file_name;
+              const char *cp = pp->file_name;
               while (cp[0] == '.' && cp[1] == '/')
                 cp += 2;
+
+              char buffer[22];
               if (filepos_comment_type == filepos_comment_file
                   /* Some xgettext input formats, like RST, lack line
                      numbers.  */
@@ -407,9 +389,10 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream,
                 buffer[0] = '\0';
               else
                 sprintf (buffer, ":%ld", (long) pp->line_number);
+
               /* File names are usually entirely ASCII.  Therefore strlen is
                  sufficient to determine their printed width.  */
-              width = strlen (cp) + strlen (buffer) + 1;
+              size_t width = strlen (cp) + strlen (buffer) + 1;
               if (column > 2 && column + width > page_width)
                 {
                   ostream_write_str (stream, "\n#:");
@@ -466,7 +449,6 @@ message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug)
       || mp->do_wrap == no)
     {
       bool first_flag = true;
-      size_t i;
 
       begin_css_class (stream, class_flag_comment);
 
@@ -486,18 +468,17 @@ message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug)
           first_flag = false;
         }
 
-      for (i = 0; i < NFORMATS; i++)
+      for (size_t i = 0; i < NFORMATS; i++)
         if (significant_format_p (mp->is_format[i]))
           {
-            char *string;
-
             if (!first_flag)
               ostream_write_str (stream, ",");
 
             ostream_write_str (stream, " ");
             begin_css_class (stream, class_flag);
-            string = make_format_description_string (mp->is_format[i],
-                                                     format_language[i], debug);
+            char *string =
+              make_format_description_string (mp->is_format[i],
+                                              format_language[i], debug);
             ostream_write_str (stream, string);
             free (string);
             end_css_class (stream, class_flag);
@@ -506,14 +487,12 @@ message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug)
 
       if (has_range_p (mp->range))
         {
-          char *string;
-
           if (!first_flag)
             ostream_write_str (stream, ",");
 
           ostream_write_str (stream, " ");
           begin_css_class (stream, class_flag);
-          string = make_range_description_string (mp->range);
+          char *string = make_range_description_string (mp->range);
           ostream_write_str (stream, string);
           free (string);
           end_css_class (stream, class_flag);
@@ -658,19 +637,9 @@ wrap (const message_ty *mp, ostream_t stream,
       enum is_wrap do_wrap, size_t page_width,
       const char *charset, xerror_handler_ty xeh)
 {
-  const char *canon_charset;
-  char *fmtdir;
-  char *fmtdirattr;
-  const char *s;
-  bool first_line;
-#if HAVE_ICONV
-  const char *envval;
-  iconv_t conv;
-#endif
-  bool weird_cjk;
-
-  canon_charset = po_charset_canonicalize (charset);
+  const char *canon_charset = po_charset_canonicalize (charset);
 
+  bool weird_cjk;
 #if HAVE_ICONV
   /* The old Solaris/openwin msgfmt and GNU msgfmt <= 0.10.35 don't know
      about multibyte encodings, and require a spurious backslash after
@@ -678,17 +647,20 @@ wrap (const message_ty *mp, ostream_t stream,
      like vim, distribute PO files in this broken format.  It is important
      for such programs that GNU msgmerge continues to support this old
      PO file format when the Makefile requests it.  */
-  envval = getenv ("OLD_PO_FILE_OUTPUT");
-  if (envval != NULL && *envval != '\0')
-    /* Write a PO file in old format, with extraneous backslashes.  */
-    conv = (iconv_t)(-1);
-  else
-    if (canon_charset == NULL)
-      /* Invalid PO file encoding.  */
+  iconv_t conv;
+  {
+    const char *envval = getenv ("OLD_PO_FILE_OUTPUT");
+    if (envval != NULL && *envval != '\0')
+      /* Write a PO file in old format, with extraneous backslashes.  */
       conv = (iconv_t)(-1);
     else
-      /* Use iconv() to parse multibyte characters.  */
-      conv = iconv_open ("UTF-8", canon_charset);
+      if (canon_charset == NULL)
+        /* Invalid PO file encoding.  */
+        conv = (iconv_t)(-1);
+      else
+        /* Use iconv() to parse multibyte characters.  */
+        conv = iconv_open ("UTF-8", canon_charset);
+  }
 
   if (conv != (iconv_t)(-1))
     weird_cjk = false;
@@ -703,35 +675,33 @@ wrap (const message_ty *mp, ostream_t stream,
     canon_charset = po_charset_ascii;
 
   /* Determine the extent of format string directives.  */
-  fmtdir = NULL;
-  fmtdirattr = NULL;
+  char *fmtdir = NULL;
+  char *fmtdirattr = NULL;
   if (value[0] != '\0')
     {
       bool is_msgstr =
         (strlen (name) >= 6 && memcmp (name, "msgstr", 6) == 0);
         /* or equivalent: = (css_class == class_msgstr) */
-      size_t i;
 
-      for (i = 0; i < NFORMATS; i++)
+      for (size_t i = 0; i < NFORMATS; i++)
         if (possible_format_p (mp->is_format[i]))
           {
             size_t len = strlen (value);
             struct formatstring_parser *parser = formatstring_parsers[i];
-            char *invalid_reason = NULL;
-            void *descr;
-            const char *fdp;
-            const char *fd_end;
-            char *fdap;
 
             fmtdir = XCALLOC (len, char);
-            descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason);
+
+            char *invalid_reason = NULL;
+            void *descr = parser->parse (value, is_msgstr, fmtdir, &invalid_reason);
             if (descr != NULL)
               parser->free (descr);
 
             /* Locate the FMTDIR_* bits and transform the array to an array
                of attributes.  */
             fmtdirattr = XCALLOC (len, char);
-            fd_end = fmtdir + len;
+            const char *fd_end = fmtdir + len;
+            const char *fdp;
+            char *fdap;
             for (fdp = fmtdir, fdap = fmtdirattr; fdp < fd_end; fdp++, fdap++)
               if (*fdp & FMTDIR_START)
                 {
@@ -759,8 +729,8 @@ wrap (const message_ty *mp, ostream_t stream,
     }
 
   /* Loop over the '\n' delimited portions of value.  */
-  s = value;
-  first_line = true;
+  const char *s = value;
+  bool first_line = true;
   do
     {
       /* The usual escapes, as defined by the ANSI C Standard.  */
@@ -769,23 +739,13 @@ wrap (const message_ty *mp, ostream_t stream,
          || (c) == '\r' || (c) == '\t' || (c) == '\v')
 
       const char *es;
-      const char *ep;
-      size_t portion_len;
-      char *portion;
-      char *overrides;
-      char *attributes;
-      char *linebreaks;
-      char *pp;
-      char *op;
-      char *ap;
-      int startcol, startcol_after_break, width;
-      size_t i;
-
       for (es = s; *es != '\0'; )
         if (*es++ == '\n')
           break;
 
       /* Expand escape sequences in each portion.  */
+      const char *ep;
+      size_t portion_len;
       for (ep = s, portion_len = 0; ep < es; ep++)
         {
           char c = *ep;
@@ -867,9 +827,13 @@ wrap (const message_ty *mp, ostream_t stream,
                 }
             }
         }
-      portion = XNMALLOC (portion_len, char);
-      overrides = XNMALLOC (portion_len, char);
-      attributes = XNMALLOC (portion_len, char);
+
+      char *portion = XNMALLOC (portion_len, char);
+      char *overrides = XNMALLOC (portion_len, char);
+      char *attributes = XNMALLOC (portion_len, char);
+      char *pp;
+      char *op;
+      char *ap;
       for (ep = s, pp = portion, op = overrides, ap = attributes; ep < es; ep++)
         {
           char c = *ep;
@@ -1015,17 +979,17 @@ wrap (const message_ty *mp, ostream_t stream,
       if (es > s && es[-1] == '\n')
         overrides[portion_len - 2] = UC_BREAK_PROHIBITED;
 
-      linebreaks = XNMALLOC (portion_len, char);
+      char *linebreaks = XNMALLOC (portion_len, char);
 
       /* Subsequent lines after a break are all indented.
          See INDENT-S.  */
-      startcol_after_break = (line_prefix ? strlen (line_prefix) : 0);
+      int startcol_after_break = (line_prefix ? strlen (line_prefix) : 0);
       if (indent)
         startcol_after_break = (startcol_after_break + extra_indent + 8) & ~7;
       startcol_after_break++;
 
       /* The line width.  Allow room for the closing quote character.  */
-      width = (wrap_strings && do_wrap != no ? page_width : INT_MAX) - 1;
+      int width = (wrap_strings && do_wrap != no ? page_width : INT_MAX) - 1;
       /* Adjust for indentation of subsequent lines.  */
       width -= startcol_after_break;
 
@@ -1033,7 +997,7 @@ wrap (const message_ty *mp, ostream_t stream,
       /* The line starts with different things depending on whether it
          is the first line, and if we are using the indented style.
          See INDENT-F.  */
-      startcol = (line_prefix ? strlen (line_prefix) : 0);
+      int startcol = (line_prefix ? strlen (line_prefix) : 0);
       if (first_line)
         {
           startcol += strlen (name);
@@ -1130,18 +1094,16 @@ wrap (const message_ty *mp, ostream_t stream,
 
       /* Print the portion itself, with linebreaks where necessary.  */
       {
-        char currattr = 0;
-
         begin_css_class (stream, class_string);
         ostream_write_str (stream, "\"");
         begin_css_class (stream, class_text);
 
-        for (i = 0; i < portion_len; i++)
+        char currattr = 0;
+
+        for (size_t i = 0; i < portion_len; i++)
           {
             if (linebreaks[i] == UC_BREAK_POSSIBLE)
               {
-                int currcol;
-
                 /* Change currattr so that it becomes 0.  */
                 if (currattr & ATTR_ESCAPE_SEQUENCE)
                   {
@@ -1166,7 +1128,7 @@ wrap (const message_ty *mp, ostream_t stream,
                 end_css_class (stream, class_string);
                 end_css_class (stream, css_class);
                 ostream_write_str (stream, "\n");
-                currcol = 0;
+                int currcol = 0;
                 /* INDENT-S.  */
                 if (line_prefix != NULL)
                   {
@@ -1291,8 +1253,6 @@ message_print (const message_ty *mp, ostream_t stream,
                const char *charset, size_t page_width, bool blank_line,
                xerror_handler_ty xeh, bool debug)
 {
-  int extra_indent;
-
   /* Separate messages with a blank line.  Uniforum doesn't like blank
      lines, so use an empty comment (unless there already is one).  */
   if (blank_line && (!uniforum
@@ -1339,10 +1299,10 @@ message_print (const message_ty *mp, ostream_t stream,
     wrap (mp, stream, "#| ", 0, class_previous, "msgid_plural",
           mp->prev_msgid_plural, mp->do_wrap, page_width, charset, xeh);
   end_css_class (stream, class_previous_comment);
-  extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
-                  || mp->prev_msgid_plural != NULL
-                  ? 3
-                  : 0);
+  int extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
+                      || mp->prev_msgid_plural != NULL
+                      ? 3
+                      : 0);
 
   end_css_class (stream, class_comment);
 
@@ -1387,14 +1347,13 @@ different from yours. Consider using a pure ASCII msgid instead.\n\
           mp->do_wrap, page_width, charset, xeh);
   else
     {
-      char prefix_buf[20];
       unsigned int i;
       const char *p;
-
       for (p = mp->msgstr, i = 0;
            p < mp->msgstr + mp->msgstr_len;
            p += strlen (p) + 1, i++)
         {
+          char prefix_buf[20];
           sprintf (prefix_buf, "msgstr[%u]", i);
           wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p,
                 mp->do_wrap, page_width, charset, xeh);
@@ -1417,8 +1376,6 @@ message_print_obsolete (const message_ty *mp, ostream_t stream,
                         const char *charset, size_t page_width, bool blank_line,
                         xerror_handler_ty xeh, bool debug)
 {
-  int extra_indent;
-
   /* If msgstr is the empty string we print nothing.  */
   if (mp->msgstr[0] == '\0')
     return;
@@ -1457,7 +1414,6 @@ message_print_obsolete (const message_ty *mp, ostream_t stream,
       || mp->do_wrap == no)
     {
       bool first_flag = true;
-      size_t i;
 
       ostream_write_str (stream, "#,");
 
@@ -1467,17 +1423,16 @@ message_print_obsolete (const message_ty *mp, ostream_t stream,
           first_flag = false;
         }
 
-      for (i = 0; i < NFORMATS; i++)
+      for (size_t i = 0; i < NFORMATS; i++)
         if (significant_format_p (mp->is_format[i]))
           {
-            char *string;
-
             if (!first_flag)
               ostream_write_str (stream, ",");
 
             ostream_write_str (stream, " ");
-            string = make_format_description_string (mp->is_format[i],
-                                                     format_language[i], debug);
+            char *string =
+              make_format_description_string (mp->is_format[i],
+                                              format_language[i], debug);
             ostream_write_str (stream, string);
             free (string);
             first_flag = false;
@@ -1510,10 +1465,10 @@ message_print_obsolete (const message_ty *mp, ostream_t stream,
     wrap (mp, stream, "#~| ", 0, class_previous, "msgid_plural",
           mp->prev_msgid_plural, mp->do_wrap, page_width, charset, xeh);
   end_css_class (stream, class_previous_comment);
-  extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
-                  || mp->prev_msgid_plural != NULL
-                  ? 1
-                  : 0);
+  int extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
+                      || mp->prev_msgid_plural != NULL
+                      ? 1
+                      : 0);
 
   end_css_class (stream, class_comment);
 
@@ -1557,14 +1512,13 @@ different from yours. Consider using a pure ASCII msgid instead.\n\
           mp->do_wrap, page_width, charset, xeh);
   else
     {
-      char prefix_buf[20];
       unsigned int i;
       const char *p;
-
       for (p = mp->msgstr, i = 0;
            p < mp->msgstr + mp->msgstr_len;
            p += strlen (p) + 1, i++)
         {
+          char prefix_buf[20];
           sprintf (prefix_buf, "msgstr[%u]", i);
           wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p,
                 mp->do_wrap, page_width, charset, xeh);
@@ -1579,18 +1533,10 @@ static void
 msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
                          size_t page_width, xerror_handler_ty xeh, bool debug)
 {
-  size_t j, k;
-  bool blank_line;
-
   /* Write out the messages for each domain.  */
-  blank_line = false;
-  for (k = 0; k < mdlp->nitems; k++)
+  bool blank_line = false;
+  for (size_t k = 0; k < mdlp->nitems; k++)
     {
-      message_list_ty *mlp;
-      const char *header;
-      const char *charset;
-      char *allocated_charset;
-
       /* If the first domain is the default, don't bother emitting
          the domain name, because it is the default.  */
       if (!(k == 0
@@ -1613,11 +1559,11 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
           blank_line = true;
         }
 
-      mlp = mdlp->item[k]->messages;
+      message_list_ty *mlp = mdlp->item[k]->messages;
 
       /* Search the header entry.  */
-      header = NULL;
-      for (j = 0; j < mlp->nitems; ++j)
+      const char *header = NULL;
+      for (size_t j = 0; j < mlp->nitems; ++j)
         if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
           {
             header = mlp->item[j]->msgstr;
@@ -1625,21 +1571,21 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
           }
 
       /* Extract the charset name.  */
-      charset = "ASCII";
-      allocated_charset = NULL;
+      const char *charset = "ASCII";
+      char *allocated_charset = NULL;
       if (header != NULL)
         {
           const char *charsetstr = c_strstr (header, "charset=");
 
           if (charsetstr != NULL)
             {
-              size_t len;
-
               charsetstr += strlen ("charset=");
-              len = strcspn (charsetstr, " \t\n");
+              size_t len = strcspn (charsetstr, " \t\n");
+
               allocated_charset = (char *) xmalloca (len + 1);
               memcpy (allocated_charset, charsetstr, len);
               allocated_charset[len] = '\0';
+
               charset = allocated_charset;
 
               /* Treat the dummy default value as if it were absent.  */
@@ -1649,7 +1595,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
         }
 
       /* Write out each of the messages for this domain.  */
-      for (j = 0; j < mlp->nitems; ++j)
+      for (size_t j = 0; j < mlp->nitems; ++j)
         if (!mlp->item[j]->obsolete)
           {
             message_print (mlp->item[j], stream, charset, page_width,
@@ -1658,7 +1604,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
           }
 
       /* Write out each of the obsolete messages for this domain.  */
-      for (j = 0; j < mlp->nitems; ++j)
+      for (size_t j = 0; j < mlp->nitems; ++j)
         if (mlp->item[j]->obsolete)
           {
             message_print_obsolete (mlp->item[j], stream, charset, page_width,
index 16cfdab7186c074b79fee2a970a715a5a985cfec..e4c2972539326468b8f9994087c32f42548f649b 100644 (file)
@@ -57,13 +57,11 @@ conv_to_java (const char *string)
   /* We cannot use iconv to "JAVA" because not all iconv() implementations
      know about the "JAVA" encoding.  */
   static const char hexdigit[] = "0123456789abcdef";
-  size_t length;
-  char *result;
 
   if (is_ascii_string (string))
     return string;
 
-  length = 0;
+  size_t length = 0;
   {
     const char *str = string;
     const char *str_limit = str + strlen (str);
@@ -76,7 +74,7 @@ conv_to_java (const char *string)
       }
   }
 
-  result = XNMALLOC (length + 1, char);
+  char *result = XNMALLOC (length + 1, char);
 
   {
     char *newstr = result;
@@ -128,8 +126,8 @@ write_escaped_string (ostream_t stream, const char *str, bool in_key)
 {
   static const char hexdigit[] = "0123456789abcdef";
   const char *str_limit = str + strlen (str);
-  bool first = true;
 
+  bool first = true;
   while (str < str_limit)
     {
       ucs4_t uc;
@@ -243,26 +241,23 @@ write_properties (ostream_t stream, message_list_ty *mlp,
                   const char *canon_encoding, size_t page_width,
                   xerror_handler_ty xeh, bool debug)
 {
-  bool blank_line;
-  size_t j, i;
-
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, xeh);
-  for (j = 0; j < mlp->nitems; ++j)
+  for (size_t j = 0; j < mlp->nitems; ++j)
     {
       message_ty *mp = mlp->item[j];
 
       if (mp->comment != NULL)
-        for (i = 0; i < mp->comment->nitems; ++i)
+        for (size_t i = 0; i < mp->comment->nitems; ++i)
           mp->comment->item[i] = conv_to_java (mp->comment->item[i]);
       if (mp->comment_dot != NULL)
-        for (i = 0; i < mp->comment_dot->nitems; ++i)
+        for (size_t i = 0; i < mp->comment_dot->nitems; ++i)
           mp->comment_dot->item[i] = conv_to_java (mp->comment_dot->item[i]);
     }
 
   /* Loop through the messages.  */
-  blank_line = false;
-  for (j = 0; j < mlp->nitems; ++j)
+  bool blank_line = false;
+  for (size_t j = 0; j < mlp->nitems; ++j)
     {
       const message_ty *mp = mlp->item[j];
 
@@ -285,11 +280,11 @@ msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream,
                                  bool debug)
 {
   message_list_ty *mlp;
-
   if (mdlp->nitems == 1)
     mlp = mdlp->item[0]->messages;
   else
     mlp = message_list_alloc (false);
+
   write_properties (stream, mlp, mdlp->encoding, page_width, xeh, debug);
 }
 
index 1fc68ea95462885d05640330527a116d3b628a0d..8de5212c170fcd86001c116c054744694b52f4e3 100644 (file)
@@ -194,7 +194,6 @@ MAYBE_UNUSED static inline void
 write_u16 (FILE *output_file, unsigned short value)
 {
   unsigned char data[2];
-
   data[0] = (value >> 8) & 0xff;
   data[1] = value & 0xff;
 
@@ -206,7 +205,6 @@ static inline void
 write_u32 (FILE *output_file, unsigned int value)
 {
   unsigned char data[4];
-
   data[0] = (value >> 24) & 0xff;
   data[1] = (value >> 16) & 0xff;
   data[2] = (value >> 8) & 0xff;
@@ -224,7 +222,6 @@ static void
 append_u8 (struct obstack *mempool, unsigned char value)
 {
   unsigned char data[1];
-
   data[0] = value;
 
   obstack_grow (mempool, data, 1);
@@ -235,7 +232,6 @@ static void
 append_u16 (struct obstack *mempool, unsigned short value)
 {
   unsigned char data[2];
-
   data[0] = (value >> 8) & 0xff;
   data[1] = value & 0xff;
 
@@ -247,7 +243,6 @@ static void
 append_u32 (struct obstack *mempool, unsigned int value)
 {
   unsigned char data[4];
-
   data[0] = (value >> 24) & 0xff;
   data[1] = (value >> 16) & 0xff;
   data[2] = (value >> 8) & 0xff;
@@ -291,20 +286,21 @@ conv_to_iso_8859_1 (const char *string)
   const char *str_limit = string + length;
   /* Conversion to ISO-8859-1 can only reduce the number of bytes.  */
   char *result = XNMALLOC (length + 1, char);
-  char *q = result;
-
-  while (str < str_limit)
-    {
-      ucs4_t uc;
-      str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
-      /* It has already been verified that the string fits in ISO-8859-1.  */
-      if (!(uc < 0x100))
-        abort ();
-      /* Store as ISO-8859-1.  */
-      *q++ = (unsigned char) uc;
-    }
-  *q = '\0';
-  assert (q - result <= length);
+  {
+    char *q = result;
+    while (str < str_limit)
+      {
+        ucs4_t uc;
+        str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
+        /* It has already been verified that the string fits in ISO-8859-1.  */
+        if (!(uc < 0x100))
+          abort ();
+        /* Store as ISO-8859-1.  */
+        *q++ = (unsigned char) uc;
+      }
+    *q = '\0';
+    assert (q - result <= length);
+  }
 
   return result;
 }
@@ -319,25 +315,25 @@ conv_to_utf16 (const char *string, size_t *sizep)
   const char *str_limit = string + length;
   /* Conversion to UTF-16 can at most double the number of bytes.  */
   unsigned short *result = XNMALLOC (length, unsigned short);
-  unsigned short *q = result;
-
-  while (str < str_limit)
-    {
-      ucs4_t uc;
-      str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
-      if (uc < 0x10000)
-        /* UCS-2 character.  */
-        *q++ = (unsigned short) uc;
-      else
-        {
-          /* UTF-16 surrogate.  */
-          *q++ = 0xd800 + ((uc - 0x10000) >> 10);
-          *q++ = 0xdc00 + ((uc - 0x10000) & 0x3ff);
-        }
-    }
-  assert (q - result <= 2 * length);
-
-  *sizep = q - result;
+  {
+    unsigned short *q = result;
+    while (str < str_limit)
+      {
+        ucs4_t uc;
+        str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
+        if (uc < 0x10000)
+          /* UCS-2 character.  */
+          *q++ = (unsigned short) uc;
+        else
+          {
+            /* UTF-16 surrogate.  */
+            *q++ = 0xd800 + ((uc - 0x10000) >> 10);
+            *q++ = 0xdc00 + ((uc - 0x10000) & 0x3ff);
+          }
+      }
+    assert (q - result <= 2 * length);
+    *sizep = q - result;
+  }
   return result;
 }
 
@@ -345,11 +341,10 @@ conv_to_utf16 (const char *string, size_t *sizep)
 static unsigned int
 string_hashcode (const char *str)
 {
-  unsigned int h;
-
-  h = hash_string (str);
+  unsigned int h = hash_string (str);
   if (h == 0)
     h = 1;
+
   return h;
 }
 
@@ -400,15 +395,15 @@ write_qm (FILE *output_file, message_list_ty *mlp)
       0x3C, 0xB8, 0x64, 0x18, 0xCA, 0xEF, 0x9C, 0x95,
       0xCD, 0x21, 0x1C, 0xBF, 0x60, 0xA1, 0xBD, 0xDD
     };
-  struct obstack hashes_pool;
-  struct obstack messages_pool;
-  size_t j;
 
+  struct obstack hashes_pool;
   obstack_init (&hashes_pool);
+
+  struct obstack messages_pool;
   obstack_init (&messages_pool);
 
   /* Prepare the hashes section and the messages section.  */
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -474,8 +469,7 @@ write_qm (FILE *output_file, message_list_ty *mlp)
   /* Decide whether to write a contexts section.  */
   {
     bool can_write_contexts = true;
-
-    for (j = 0; j < mlp->nitems; j++)
+    for (size_t j = 0; j < mlp->nitems; j++)
       {
         message_ty *mp = mlp->item[j];
 
@@ -490,13 +484,10 @@ write_qm (FILE *output_file, message_list_ty *mlp)
 
     if (can_write_contexts)
       {
-        hash_table all_contexts;
-        size_t num_contexts;
-        unsigned long table_size;
-
         /* Collect the contexts, removing duplicates.  */
+        hash_table all_contexts;
         hash_init (&all_contexts, 10);
-        for (j = 0; j < mlp->nitems; j++)
+        for (size_t j = 0; j < mlp->nitems; j++)
           {
             message_ty *mp = mlp->item[j];
 
@@ -507,26 +498,23 @@ write_qm (FILE *output_file, message_list_ty *mlp)
           }
 
         /* Compute the number of different contexts.  */
-        num_contexts = all_contexts.size;
+        size_t num_contexts = all_contexts.size;
 
         /* Compute a suitable hash table size.  */
-        table_size = next_prime (num_contexts * 1.7);
+        unsigned long table_size = next_prime (num_contexts * 1.7);
         if (table_size >= 0x10000)
           table_size = 65521;
 
         /* Put the contexts into a hash table of size table_size.  */
         {
           struct list_cell { const char *context; struct list_cell *next; };
-          struct list_cell *list_memory =
-            XNMALLOC (table_size, struct list_cell);
-          struct list_cell *freelist;
-          struct bucket { struct list_cell *head; struct list_cell **tail; };
-          struct bucket *buckets = XNMALLOC (table_size, struct bucket);
-          size_t i;
+          struct list_cell *list_memory = XNMALLOC (table_size, struct list_cell);
 
-          freelist = list_memory;
+          struct list_cell *freelist = list_memory;
 
-          for (i = 0; i < table_size; i++)
+          struct bucket { struct list_cell *head; struct list_cell **tail; };
+          struct bucket *buckets = XNMALLOC (table_size, struct bucket);
+          for (size_t i = 0; i < table_size; i++)
             {
               buckets[i].head = NULL;
               buckets[i].tail = &buckets[i].head;
@@ -543,7 +531,7 @@ write_qm (FILE *output_file, message_list_ty *mlp)
                    == 0)
               {
                 const char *context = (const char *)key;
-                i = string_hashcode (context) % table_size;
+                size_t i = string_hashcode (context) % table_size;
                 freelist->context = context;
                 freelist->next = NULL;
                 *buckets[i].tail = freelist;
@@ -554,71 +542,65 @@ write_qm (FILE *output_file, message_list_ty *mlp)
 
           /* Determine the total context pool size.  */
           {
-            size_t pool_size;
-
-            pool_size = 2;
-            for (i = 0; i < table_size; i++)
+            size_t pool_size = 2;
+            for (size_t i = 0; i < table_size; i++)
               if (buckets[i].head != NULL)
                 {
-                  const struct list_cell *p;
-
-                  for (p = buckets[i].head; p != NULL; p = p->next)
+                  for (const struct list_cell *p = buckets[i].head; p != NULL; p = p->next)
                     pool_size += 1 + strlen (p->context);
                   pool_size++;
                   if ((pool_size % 2) != 0)
                     pool_size++;
                 }
+
             if (pool_size <= 0x20000)
               {
                 /* Prepare the contexts section.  */
                 struct obstack contexts_pool;
-                size_t pool_offset;
-
                 obstack_init (&contexts_pool);
 
-                append_u16 (&contexts_pool, table_size);
-                pool_offset = 2;
-                for (i = 0; i < table_size; i++)
-                  if (buckets[i].head != NULL)
-                    {
-                      const struct list_cell *p;
-
-                      append_u16 (&contexts_pool, pool_offset / 2);
-                      for (p = buckets[i].head; p != NULL; p = p->next)
-                        pool_offset += 1 + strlen (p->context);
-                      pool_offset++;
-                      if ((pool_offset % 2) != 0)
-                        pool_offset++;
-                    }
-                  else
-                    append_u16 (&contexts_pool, 0);
-                if (!(pool_offset == pool_size))
-                  abort ();
-
-                append_u16 (&contexts_pool, 0);
-                pool_offset = 2;
-                for (i = 0; i < table_size; i++)
-                  if (buckets[i].head != NULL)
-                    {
-                      const struct list_cell *p;
-
-                      for (p = buckets[i].head; p != NULL; p = p->next)
-                        {
-                          append_u8 (&contexts_pool, strlen (p->context));
-                          obstack_grow (&contexts_pool,
-                                        p->context, strlen (p->context));
+                {
+                  append_u16 (&contexts_pool, table_size);
+                  size_t pool_offset = 2;
+                  for (size_t i = 0; i < table_size; i++)
+                    if (buckets[i].head != NULL)
+                      {
+                        append_u16 (&contexts_pool, pool_offset / 2);
+                        for (const struct list_cell *p = buckets[i].head; p != NULL; p = p->next)
                           pool_offset += 1 + strlen (p->context);
-                        }
-                      append_u8 (&contexts_pool, 0);
-                      pool_offset++;
-                      if ((pool_offset % 2) != 0)
-                        {
-                          append_u8 (&contexts_pool, 0);
+                        pool_offset++;
+                        if ((pool_offset % 2) != 0)
                           pool_offset++;
-                        }
-                    }
-                if (!(pool_offset == pool_size))
-                  abort ();
+                      }
+                    else
+                      append_u16 (&contexts_pool, 0);
+                  if (!(pool_offset == pool_size))
+                    abort ();
+                }
+                {
+                  append_u16 (&contexts_pool, 0);
+                  size_t pool_offset = 2;
+                  for (size_t i = 0; i < table_size; i++)
+                    if (buckets[i].head != NULL)
+                      {
+                        for (const struct list_cell *p = buckets[i].head; p != NULL; p = p->next)
+                          {
+                            append_u8 (&contexts_pool, strlen (p->context));
+                            obstack_grow (&contexts_pool,
+                                          p->context, strlen (p->context));
+                            pool_offset += 1 + strlen (p->context);
+                          }
+                        append_u8 (&contexts_pool, 0);
+                        pool_offset++;
+                        if ((pool_offset % 2) != 0)
+                          {
+                            append_u8 (&contexts_pool, 0);
+                            pool_offset++;
+                          }
+                      }
+                  if (!(pool_offset == pool_size))
+                    abort ();
+                }
 
                 if (!(obstack_object_size (&contexts_pool)
                       == 2 + 2 * table_size + pool_size))
@@ -652,17 +634,13 @@ msgdomain_write_qt (message_list_ty *mlp, const char *canon_encoding,
   /* If no entry for this domain don't even create the file.  */
   if (mlp->nitems != 0)
     {
-      FILE *output_file;
-
       /* Determine whether mlp has plural entries.  */
       {
-        bool has_plural;
-        size_t j;
-
-        has_plural = false;
-        for (j = 0; j < mlp->nitems; j++)
+        bool has_plural = false;
+        for (size_t j = 0; j < mlp->nitems; j++)
           if (mlp->item[j]->msgid_plural != NULL)
             has_plural = true;
+
         if (has_plural)
           {
             multiline_error (xstrdup (""),
@@ -678,58 +656,51 @@ but the Qt message catalog format doesn't support plural handling\n")));
                           textmode_xerror_handler);
 
       /* Determine whether mlp has non-ISO-8859-1 msgctxt entries.  */
-      {
-        size_t j;
-
-        for (j = 0; j < mlp->nitems; j++)
-          {
-            const char *string = mlp->item[j]->msgctxt;
+      for (size_t j = 0; j < mlp->nitems; j++)
+        {
+          const char *string = mlp->item[j]->msgctxt;
 
-            if (string != NULL)
-              {
-                /* An UTF-8 encoded string fits in ISO-8859-1 if and only if
-                   all its bytes are < 0xc4.  */
-                for (; *string; string++)
-                  if ((unsigned char) *string >= 0xc4)
-                    {
-                      multiline_error (xstrdup (""),
-                                       xstrdup (_("\
+          if (string != NULL)
+            {
+              /* An UTF-8 encoded string fits in ISO-8859-1 if and only if
+                 all its bytes are < 0xc4.  */
+              for (; *string; string++)
+                if ((unsigned char) *string >= 0xc4)
+                  {
+                    multiline_error (xstrdup (""),
+                                     xstrdup (_("\
 message catalog has msgctxt strings containing characters outside ISO-8859-1\n\
 but the Qt message catalog format supports Unicode only in the translated\n\
 strings, not in the context strings\n")));
-                      return 1;
-                    }
-              }
-          }
-      }
+                    return 1;
+                  }
+            }
+        }
 
       /* Determine whether mlp has non-ISO-8859-1 msgid entries.  */
-      {
-        size_t j;
-
-        for (j = 0; j < mlp->nitems; j++)
-          {
-            const char *string = mlp->item[j]->msgid;
+      for (size_t j = 0; j < mlp->nitems; j++)
+        {
+          const char *string = mlp->item[j]->msgid;
 
-            /* An UTF-8 encoded string fits in ISO-8859-1 if and only if all
-               its bytes are < 0xc4.  */
-            for (; *string; string++)
-              if ((unsigned char) *string >= 0xc4)
-                {
-                  multiline_error (xstrdup (""),
-                                   xstrdup (_("\
+          /* An UTF-8 encoded string fits in ISO-8859-1 if and only if all
+             its bytes are < 0xc4.  */
+          for (; *string; string++)
+            if ((unsigned char) *string >= 0xc4)
+              {
+                multiline_error (xstrdup (""),
+                                 xstrdup (_("\
 message catalog has msgid strings containing characters outside ISO-8859-1\n\
 but the Qt message catalog format supports Unicode only in the translated\n\
 strings, not in the untranslated strings\n")));
-                  return 1;
-                }
-          }
-      }
+                return 1;
+              }
+        }
 
       /* Support for "reproducible builds": Delete information that may vary
          between builds in the same conditions.  */
       message_list_delete_header_field (mlp, "POT-Creation-Date:");
 
+      FILE *output_file;
       if (strcmp (domain_name, "-") == 0)
         {
           output_file = stdout;
index bc11b295436e85159288a246ba77e611684415d4..7e2fe2635259aa7af2611622625b27d2e12ea953 100644 (file)
@@ -64,25 +64,21 @@ execute_writing_input (const char *progname,
                        void *private_data)
 {
   struct locals *l = (struct locals *) private_data;
-  pid_t child;
-  int fd[1];
-  FILE *fp;
-  int exitstatus;
 
   /* Open a pipe to the C# execution engine.  */
-  child = create_pipe_out (progname, prog_path, prog_argv, NULL, NULL,
-                           NULL, false, true, true, fd);
+  int fd[1];
+  pid_t child = create_pipe_out (progname, prog_path, prog_argv, NULL, NULL,
+                                 NULL, false, true, true, fd);
 
-  fp = fdopen (fd[0], "wb");
+  FILE *fp = fdopen (fd[0], "wb");
   if (fp == NULL)
     error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
   /* Write the message list.  */
   {
     message_list_ty *mlp = l->mlp;
-    size_t j;
 
-    for (j = 0; j < mlp->nitems; j++)
+    for (size_t j = 0; j < mlp->nitems; j++)
       {
         message_ty *mp = mlp->item[j];
 
@@ -99,7 +95,7 @@ execute_writing_input (const char *progname,
   /* He we can ignore SIGPIPE because WriteResource either writes to a file
      - then it never gets SIGPIPE - or to standard output, and in the latter
      case it has no side effects other than writing to standard output.  */
-  exitstatus =
+  int exitstatus =
     wait_subprocess (child, progname, true, false, true, true, NULL);
   if (exitstatus != 0)
     error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
@@ -119,13 +115,11 @@ msgdomain_write_csharp_resources (message_list_ty *mlp,
     {
       /* Determine whether mlp has entries with context.  */
       {
-        bool has_context;
-        size_t j;
-
-        has_context = false;
-        for (j = 0; j < mlp->nitems; j++)
+        bool has_context = false;
+        for (size_t j = 0; j < mlp->nitems; j++)
           if (mlp->item[j]->msgctxt != NULL)
             has_context = true;
+
         if (has_context)
           {
             multiline_error (xstrdup (""),
@@ -138,13 +132,11 @@ but the C# .resources format doesn't support contexts\n")));
 
       /* Determine whether mlp has plural entries.  */
       {
-        bool has_plural;
-        size_t j;
-
-        has_plural = false;
-        for (j = 0; j < mlp->nitems; j++)
+        bool has_plural = false;
+        for (size_t j = 0; j < mlp->nitems; j++)
           if (mlp->item[j]->msgid_plural != NULL)
             has_plural = true;
+
         if (has_plural)
           {
             multiline_error (xstrdup (""),
@@ -168,24 +160,21 @@ but the C# .resources format doesn't support plural handling\n")));
 
       /* Execute the WriteResource program.  */
       {
-        const char *args[2];
-        const char *gettextexedir;
-        char *assembly_path;
-        struct locals locals;
-
         /* Prepare arguments.  */
+        const char *args[2];
         args[0] = file_name_converted;
         args[1] = NULL;
 
         /* Make it possible to override the .exe location.  This is
            necessary for running the testsuite before "make install".  */
-        gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
+        const char *gettextexedir = getenv ("GETTEXTCSHARPEXEDIR");
         if (gettextexedir == NULL || gettextexedir[0] == '\0')
           gettextexedir = relocate (LIBDIR "/gettext");
 
-        assembly_path =
+        char *assembly_path =
           xconcatenated_filename (gettextexedir, "msgfmt.net", ".exe");
 
+        struct locals locals;
         locals.mlp = mlp;
 
         if (execute_csharp_program (assembly_path, NULL, 0,
index bdce20138e811d5da632326ddc4726af64155255..c20ab587fd2b6d54b8a24a90f4e66956e2f7c29c 100644 (file)
@@ -79,12 +79,14 @@ write_escaped_string (ostream_t stream, const char *str)
           char seq[2];
           seq[0] = '\\';
           seq[1] = c;
+
           ostream_write_mem (stream, seq, 2);
         }
       else
         {
           char seq[1];
           seq[0] = c;
+
           ostream_write_mem (stream, seq, 1);
         }
     }
@@ -99,9 +101,7 @@ write_message (ostream_t stream, const message_ty *mp,
   /* Print translator comment if available.  */
   if (mp->comment != NULL)
     {
-      size_t j;
-
-      for (j = 0; j < mp->comment->nitems; ++j)
+      for (size_t j = 0; j < mp->comment->nitems; ++j)
         {
           const char *s = mp->comment->item[j];
 
@@ -118,11 +118,10 @@ write_message (ostream_t stream, const message_ty *mp,
           else
             do
               {
-                const char *e;
                 ostream_write_str (stream, "//");
                 if (*s != '\0' && *s != '\n')
                   ostream_write_str (stream, " ");
-                e = strchr (s, '\n');
+                const char *e = strchr (s, '\n');
                 if (e == NULL)
                   {
                     ostream_write_str (stream, s);
@@ -142,9 +141,7 @@ write_message (ostream_t stream, const message_ty *mp,
   /* Print xgettext extracted comments.  */
   if (mp->comment_dot != NULL)
     {
-      size_t j;
-
-      for (j = 0; j < mp->comment_dot->nitems; ++j)
+      for (size_t j = 0; j < mp->comment_dot->nitems; ++j)
         {
           const char *s = mp->comment_dot->item[j];
 
@@ -161,13 +158,12 @@ write_message (ostream_t stream, const message_ty *mp,
               bool first = true;
               do
                 {
-                  const char *e;
                   ostream_write_str (stream, "//");
                   if (first || (*s != '\0' && *s != '\n'))
                     ostream_write_str (stream, " ");
                   if (first)
                     ostream_write_str (stream, "Comment: ");
-                  e = strchr (s, '\n');
+                  const char *e = strchr (s, '\n');
                   if (e == NULL)
                     {
                       ostream_write_str (stream, s);
@@ -189,17 +185,15 @@ write_message (ostream_t stream, const message_ty *mp,
   /* Print the file position comments.  */
   if (mp->filepos_count != 0)
     {
-      size_t j;
-
-      for (j = 0; j < mp->filepos_count; ++j)
+      for (size_t j = 0; j < mp->filepos_count; ++j)
         {
           lex_pos_ty *pp = &mp->filepos[j];
-          const char *cp = pp->file_name;
-          char *str;
 
+          const char *cp = pp->file_name;
           while (cp[0] == '.' && cp[1] == '/')
             cp += 2;
-          str = xasprintf ("/* File: %s:%ld */\n", cp, (long) pp->line_number);
+
+          char *str = xasprintf ("/* File: %s:%ld */\n", cp, (long) pp->line_number);
           ostream_write_str (stream, str);
           free (str);
         }
@@ -210,27 +204,21 @@ write_message (ostream_t stream, const message_ty *mp,
     ostream_write_str (stream, "/* Flag: untranslated */\n");
   if (mp->obsolete)
     ostream_write_str (stream, "/* Flag: unmatched */\n");
-  {
-    size_t i;
-    for (i = 0; i < NFORMATS; i++)
-      if (significant_format_p (mp->is_format[i]))
-        {
-          char *string;
-
-          ostream_write_str (stream, "/* Flag: ");
-          string = make_format_description_string (mp->is_format[i],
-                                                   format_language[i], debug);
-          ostream_write_str (stream, string);
-          free (string);
-          ostream_write_str (stream, " */\n");
-        }
-  }
+  for (size_t i = 0; i < NFORMATS; i++)
+    if (significant_format_p (mp->is_format[i]))
+      {
+        ostream_write_str (stream, "/* Flag: ");
+        char *string =
+          make_format_description_string (mp->is_format[i],
+                                          format_language[i], debug);
+        ostream_write_str (stream, string);
+        free (string);
+        ostream_write_str (stream, " */\n");
+      }
   if (has_range_p (mp->range))
     {
-      char *string;
-
       ostream_write_str (stream, "/* Flag: ");
-      string = make_range_description_string (mp->range);
+      char *string = make_range_description_string (mp->range);
       ostream_write_str (stream, string);
       free (string);
       ostream_write_str (stream, " */\n");
@@ -281,9 +269,6 @@ write_stringtable (ostream_t stream, message_list_ty *mlp,
                    const char *canon_encoding, size_t page_width,
                    xerror_handler_ty xeh, bool debug)
 {
-  bool blank_line;
-  size_t j;
-
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, xeh);
 
@@ -292,8 +277,8 @@ write_stringtable (ostream_t stream, message_list_ty *mlp,
     ostream_write_str (stream, "\xef\xbb\xbf");
 
   /* Loop through the messages.  */
-  blank_line = false;
-  for (j = 0; j < mlp->nitems; ++j)
+  bool blank_line = false;
+  for (size_t j = 0; j < mlp->nitems; ++j)
     {
       const message_ty *mp = mlp->item[j];
 
@@ -316,11 +301,11 @@ msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream,
                                   bool debug)
 {
   message_list_ty *mlp;
-
   if (mdlp->nitems == 1)
     mlp = mdlp->item[0]->messages;
   else
     mlp = message_list_alloc (false);
+
   write_stringtable (stream, mlp, mdlp->encoding, page_width, xeh, debug);
 }
 
index 831fb9ed94452af056682d2eded4c06732bdc23e..d1b62902d6dd0130b618c60bce15521c25c333e6 100644 (file)
@@ -61,8 +61,7 @@ write_tcl8_string (FILE *stream, const char *str)
   while (str < str_limit)
     {
       ucs4_t uc;
-      unsigned int count;
-      count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
+      unsigned int count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
       if (uc < 0x10000)
         {
           /* Single UCS-2 'char'.  */
@@ -119,8 +118,7 @@ write_tcl9_string (FILE *stream, const char *str)
   while (str < str_limit)
     {
       ucs4_t uc;
-      unsigned int count;
-      count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
+      unsigned int count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
       if (uc < 0x10000)
         {
           /* Single UCS-2 'char'.  */
@@ -171,8 +169,7 @@ is_entirely_ucs2 (const char *str)
   while (str < str_limit)
     {
       ucs4_t uc;
-      unsigned int count;
-      count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
+      unsigned int count = u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
       if (uc >= 0x10000)
         return false;
       str += count;
@@ -207,13 +204,11 @@ write_tcl_string (FILE *stream, const char *str)
 static void
 write_msg (FILE *output_file, message_list_ty *mlp, const char *locale_name)
 {
-  size_t j;
-
   /* We don't care about esthetic formattic of the output (like respecting
      a maximum line width, or including the translator comments) because
      the \unnnn notation is unesthetic anyway.  Translators shall edit
      the PO file.  */
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
@@ -242,13 +237,11 @@ msgdomain_write_tcl (message_list_ty *mlp, const char *canon_encoding,
 
   /* Determine whether mlp has entries with context.  */
   {
-    bool has_context;
-    size_t j;
-
-    has_context = false;
-    for (j = 0; j < mlp->nitems; j++)
+    bool has_context = false;
+    for (size_t j = 0; j < mlp->nitems; j++)
       if (mlp->item[j]->msgctxt != NULL)
         has_context = true;
+
     if (has_context)
       {
         multiline_error (xstrdup (""),
@@ -261,13 +254,11 @@ but the Tcl message catalog format doesn't support contexts\n")));
 
   /* Determine whether mlp has plural entries.  */
   {
-    bool has_plural;
-    size_t j;
-
-    has_plural = false;
-    for (j = 0; j < mlp->nitems; j++)
+    bool has_plural = false;
+    for (size_t j = 0; j < mlp->nitems; j++)
       if (mlp->item[j]->msgid_plural != NULL)
         has_plural = true;
+
     if (has_plural)
       {
         multiline_error (xstrdup (""),
@@ -288,28 +279,24 @@ but the Tcl message catalog format doesn't support plural handling\n")));
 
   /* Now create the file.  */
   {
-    size_t len;
-    char *frobbed_locale_name;
-    char *p;
-    char *file_name;
-    FILE *output_file;
-
     /* Convert the locale name to lowercase and remove any encoding.  */
-    len = strlen (locale_name);
-    frobbed_locale_name = (char *) xmalloca (len + 1);
-    memcpy (frobbed_locale_name, locale_name, len + 1);
-    for (p = frobbed_locale_name; *p != '\0'; p++)
-      if (*p >= 'A' && *p <= 'Z')
-        *p = *p - 'A' + 'a';
-      else if (*p == '.')
-        {
-          *p = '\0';
-          break;
-        }
+    size_t len = strlen (locale_name);
+    char *frobbed_locale_name = (char *) xmalloca (len + 1);
+    {
+      memcpy (frobbed_locale_name, locale_name, len + 1);
+      for (char *p = frobbed_locale_name; *p != '\0'; p++)
+        if (*p >= 'A' && *p <= 'Z')
+          *p = *p - 'A' + 'a';
+        else if (*p == '.')
+          {
+            *p = '\0';
+            break;
+          }
+    }
 
-    file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg");
+    char *file_name = xconcatenated_filename (directory, frobbed_locale_name, ".msg");
 
-    output_file = fopen (file_name, "wb");
+    FILE *output_file = fopen (file_name, "wb");
     if (output_file == NULL)
       {
         error (0, errno, _("error while opening \"%s\" for writing"),
index fe7660c2d558c80e4800b613cd43f75e01cb6eb4..9a479dd412fe272a8e38bf64deaf2d9649a005b6 100644 (file)
@@ -45,10 +45,7 @@ msgdomain_write_xml_bulk (msgfmt_operand_list_ty *operands,
                           bool replace_text,
                           const char *file_name)
 {
-  its_merge_context_ty *context;
-  size_t i;
   FILE *fp;
-
   if (strcmp (file_name, "-") == 0)
     fp = stdout;
   else
@@ -62,8 +59,9 @@ msgdomain_write_xml_bulk (msgfmt_operand_list_ty *operands,
         }
     }
 
-  context = its_merge_context_alloc (its_rules, template_file_name);
-  for (i = 0; i < operands->nitems; i++)
+  its_merge_context_ty *context =
+    its_merge_context_alloc (its_rules, template_file_name);
+  for (size_t i = 0; i < operands->nitems; i++)
     its_merge_context_merge (context,
                              operands->items[i].language,
                              operands->items[i].mlp,
@@ -91,9 +89,6 @@ msgdomain_write_xml (message_list_ty *mlp,
                      bool replace_text,
                      const char *file_name)
 {
-  msgfmt_operand_ty operand;
-  msgfmt_operand_list_ty operands;
-
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL,
                       textmode_xerror_handler);
@@ -103,8 +98,10 @@ msgdomain_write_xml (message_list_ty *mlp,
   message_list_delete_header_field (mlp, "POT-Creation-Date:");
 
   /* Create a single-element operands and run the bulk operation on it.  */
+  msgfmt_operand_ty operand;
   operand.language = (char *) locale_name;
   operand.mlp = mlp;
+  msgfmt_operand_list_ty operands;
   operands.nitems = 1;
   operands.items = &operand;
 
index 6fde77fe9da9ed64a1f43c9df84996508cbdd64a..5bdc0163457b51d5fdfac327b9db4e57fae7d515 100644 (file)
@@ -75,18 +75,16 @@ x_awk_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -170,7 +168,6 @@ phase1_ungetc (int c)
 static int
 phase2_getc ()
 {
-  int lineno;
   int c;
 
   c = phase1_getc ();
@@ -178,7 +175,7 @@ phase2_getc ()
     {
       struct string_buffer buffer;
       sb_init (&buffer);
-      lineno = line_number;
+      int lineno = line_number;
       for (;;)
         {
           c = phase1_getc ();
@@ -368,8 +365,6 @@ static int phase3_pushback_length;
 static void
 phase3_get (token_ty *tp)
 {
-  int c;
-
   if (phase3_pushback_length)
     {
       *tp = phase3_pushback[--phase3_pushback_length];
@@ -378,6 +373,8 @@ phase3_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase2_getc ();
 
@@ -679,13 +676,14 @@ phase4_get (token_ty *tp)
   for (;;)
     {
       token_ty tmp;
-
       phase3_get (&tmp);
+
       if (tmp.type != token_type_string)
         {
           phase3_unget (&tmp);
           return;
         }
+
       tp->string = string_concat_free1 (tp->string, tmp.string);
       free_token (&tmp);
     }
@@ -753,7 +751,6 @@ extract_parenthesized (message_list_ty *mlp,
   for (;;)
     {
       token_ty token;
-
       phase4_get (&token);
 
       if (next_is_argument && token.type != token_type_lparen)
@@ -772,7 +769,6 @@ extract_parenthesized (message_list_ty *mlp,
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
index 11285776ab43a715760d8471c2205e6672625a9a..c9b4310a5c4e41f6d14b6f73753ba01b0a41466e 100644 (file)
@@ -123,18 +123,16 @@ add_keyword (const char *name, hash_table *keywords)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords->table == NULL)
         hash_init (keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (keywords, name, end - name, &shape);
     }
@@ -711,13 +709,13 @@ static int phase2_pushback_length;
 static int
 phase2_getc ()
 {
-  int c;
-
   if (phase2_pushback_length)
     return phase2_pushback[--phase2_pushback_length];
   if (!trigraphs)
     return phase1_getc ();
 
+  int c;
+
   c = phase1_getc ();
   if (c != '?')
     return c;
@@ -865,7 +863,6 @@ static int
 phase4_getc ()
 {
   int c;
-  bool last_was_star;
 
   c = phase3_getc ();
   if (c != '/')
@@ -880,7 +877,7 @@ phase4_getc ()
     case '*':
       /* C comment.  */
       comment_start ();
-      last_was_star = false;
+      bool last_was_star = false;
       for (;;)
         {
           c = phase3_getc ();
@@ -1021,7 +1018,7 @@ struct token_ty
 static int
 get_string_element (int context)
 {
-  int c, j;
+  int c;
 
   /* Use phase 3, because phase 4 elides comments.  */
   c = phase3_getc ();
@@ -1108,12 +1105,9 @@ get_string_element (int context)
            - In wide strings, warn and assume the programmer meant Unicode code
              points.  */
         unsigned int n_limit = (context > 0 ? 0x110000 : 0x100);
-        unsigned int n;
-        bool overflow;
-
-        n = 0;
-        overflow = false;
 
+        unsigned int n = 0;
+        bool overflow = false;
         for (;;)
           {
             switch (c)
@@ -1166,10 +1160,8 @@ get_string_element (int context)
     case '0': case '1': case '2': case '3':
     case '4': case '5': case '6': case '7':
       {
-        int n;
-
-        n = 0;
-        for (j = 0; j < 3; ++j)
+        int n = 0;
+        for (int j = 0; j < 3; ++j)
           {
             n = n * 8 + c - '0';
             c = phase3_getc ();
@@ -1191,9 +1183,9 @@ get_string_element (int context)
     case 'U': case 'u':
       {
         unsigned char buf[8];
-        unsigned int n;
+        int j;
 
-        n = 0;
+        unsigned int n = 0;
         for (j = 0; j < (c == 'u' ? 4 : 8); j++)
           {
             int c1 = phase3_getc ();
@@ -1265,13 +1257,14 @@ static int phase5_pushback_length;
 static void
 phase5_get (token_ty *tp)
 {
-  int c;
-
   if (phase5_pushback_length)
     {
       *tp = phase5_pushback[--phase5_pushback_length];
       return;
     }
+
+  int c;
+
   tp->string = NULL;
   tp->number = 0;
   tp->line_number = line_number;
@@ -1441,16 +1434,17 @@ phase5_get (token_ty *tp)
                       if (c == '(')
                         {
                           struct mixed_string_buffer msb;
+
+                          /* Start accumulating the string.  */
+                          mixed_string_buffer_init (&msb, lc_string,
+                                                    logical_file_name, line_number);
+
                           /* The state is either 0 or
                              N, after a ')' and N-1 bytes of the delimiter have been
                              encountered.  */
                           int state;
 
-                          /* Start accumulating the string.  */
-                          mixed_string_buffer_init (&msb, lc_string,
-                                                    logical_file_name, line_number);
                           state = 0;
-
                           for (;;)
                             {
                               c = phase3_getc ();
@@ -1481,11 +1475,9 @@ phase5_get (token_ty *tp)
                                 }
                               else
                                 {
-                                  int i;
-
                                   /* None of the bytes raw_buf[0]...raw_buf[state-1]
                                      can be ')'.  */
-                                  for (i = 0; i < state; i++)
+                                  for (int i = 0; i < state; i++)
                                     mixed_string_buffer_append_char (&msb, raw_buf[i]);
 
                                   /* But c may be ')'.  */
@@ -1841,8 +1833,8 @@ phaseX_get (token_ty *tp)
           if (tp->type == token_type_white_space)
             {
               token_ty next;
-
               phase5_get (&next);
+
               if (next.type == token_type_hash)
                 *tp = next;
               else
@@ -1866,16 +1858,12 @@ static int phase6_pushback_length;
 static void
 phase6_get (token_ty *tp)
 {
-  static token_ty *buf;
-  static int bufmax;
-  int bufpos;
-  int j;
-
   if (phase6_pushback_length)
     {
       *tp = phase6_pushback[--phase6_pushback_length];
       return;
     }
+
   for (;;)
     {
       /* Get the next token.  If it is not a '#' at the beginning of a
@@ -1886,7 +1874,9 @@ phase6_get (token_ty *tp)
 
       /* Accumulate the rest of the directive in a buffer, until the
          "define" keyword is seen or until end of line.  */
-      bufpos = 0;
+      static token_ty *buf;
+      static int bufmax;
+      int bufpos = 0;
       for (;;)
         {
           phaseX_get (tp);
@@ -1933,7 +1923,7 @@ phase6_get (token_ty *tp)
         }
 
       /* Release the storage held by the directive.  */
-      for (j = 0; j < bufpos; ++j)
+      for (int j = 0; j < bufpos; ++j)
         free_token (&buf[j]);
 
       /* We must reset the selected comments.  */
@@ -2064,17 +2054,18 @@ phase8b_unget (token_ty *tp)
 static void
 phase8c_get (token_ty *tp)
 {
-  token_ty tmp;
-
   phase8b_get (tp);
   if (tp->type != token_type_objc_special)
     return;
+
+  token_ty tmp;
   phase8b_get (&tmp);
   if (tmp.type != token_type_string_literal)
     {
       phase8b_unget (&tmp);
       return;
     }
+
   /* Drop the '@' token and return immediately the following string.  */
   drop_reference (tmp.comment);
   tmp.comment = tp->comment;
@@ -2102,8 +2093,8 @@ phase8_get (token_ty *tp)
   for (;;)
     {
       token_ty tmp;
-
       phase8c_get (&tmp);
+
       if (tmp.type != token_type_string_literal)
         {
           phase8c_unget (&tmp);
@@ -2166,9 +2157,8 @@ x_c_lex (xgettext_token_ty *tp)
   for (;;)
     {
       token_ty token;
-      void *keyword_value;
-
       phase8_get (&token);
+
       switch (token.type)
         {
         case token_type_eof:
@@ -2176,22 +2166,25 @@ x_c_lex (xgettext_token_ty *tp)
           return;
 
         case token_type_name:
-          last_non_comment_line = newline_count;
+          {
+            last_non_comment_line = newline_count;
 
-          if (hash_find_entry (objc_extensions ? &objc_keywords : &c_keywords,
-                               token.string, strlen (token.string),
-                               &keyword_value)
-              == 0)
-            {
-              tp->type = xgettext_token_type_keyword;
-              tp->shapes = (const struct callshapes *) keyword_value;
-              tp->pos.file_name = logical_file_name;
-              tp->pos.line_number = token.line_number;
-            }
-          else
-            tp->type = xgettext_token_type_symbol;
-          tp->string = token.string;
-          return;
+            void *keyword_value;
+            if (hash_find_entry (objc_extensions ? &objc_keywords : &c_keywords,
+                                 token.string, strlen (token.string),
+                                 &keyword_value)
+                == 0)
+              {
+                tp->type = xgettext_token_type_keyword;
+                tp->shapes = (const struct callshapes *) keyword_value;
+                tp->pos.file_name = logical_file_name;
+                tp->pos.line_number = token.line_number;
+              }
+            else
+              tp->type = xgettext_token_type_symbol;
+            tp->string = token.string;
+            return;
+          }
 
         case token_type_lparen:
           last_non_comment_line = newline_count;
@@ -2305,8 +2298,8 @@ extract_parenthesized (message_list_ty *mlp,
   for (;;)
     {
       xgettext_token_ty token;
-
       x_c_lex (&token);
+
       switch (token.type)
         {
         case xgettext_token_type_keyword:
index 8f94c33acec37b1158e03c74c5021c606b8cfcef..9eab53e9e52efbd17e04418ea66c142c562206ce 100644 (file)
@@ -84,19 +84,17 @@ x_csharp_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C#
          identifier sequence with dots.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -280,8 +278,6 @@ Please specify the correct source encoding through --from-code.\n"),
               else if (errno == EINVAL)
                 {
                   /* An incomplete multibyte character.  */
-                  int c;
-
                   if (bufcount == MAX_PHASE1_PUSHBACK)
                     {
                       /* An overlong incomplete multibyte sequence was
@@ -295,7 +291,7 @@ Please specify the correct source encoding through --from-code.\n"),
                     }
 
                   /* Read one more byte and retry iconv.  */
-                  c = phase1_getc ();
+                  int c = phase1_getc ();
                   if (c == EOF)
                     {
                       multiline_error (xstrdup (""),
@@ -325,7 +321,6 @@ Please specify the correct source encoding through --from-code.\n"),
             {
               size_t outbytes = sizeof (scratchbuf) - outsize;
               size_t bytes = bufcount - insize;
-              ucs4_t uc;
 
               /* We expect that one character has been produced.  */
               if (bytes == 0)
@@ -336,6 +331,7 @@ Please specify the correct source encoding through --from-code.\n"),
               while (insize > 0)
                 phase1_ungetc (buf[--insize]);
               /* Convert the character from UTF-8 to UCS-4.  */
+              ucs4_t uc;
               if (u8_mbtoucr (&uc, scratchbuf, outbytes) < (int) outbytes)
                 {
                   /* scratchbuf contains an out-of-range Unicode character
@@ -363,7 +359,6 @@ Please specify the source encoding through --from-code.\n"),
       unsigned char buf[6];
       unsigned int count;
       int c;
-      ucs4_t uc;
 
       c = phase1_getc ();
       if (c == EOF)
@@ -426,6 +421,7 @@ Please specify the source encoding through --from-code.\n"),
           count = 6;
         }
 
+      ucs4_t uc;
       u8_mbtouc (&uc, buf, count);
       return uc;
     }
@@ -582,11 +578,9 @@ static int last_non_comment_line;
 static int
 phase4_getc ()
 {
-  int c0;
   int c;
-  bool last_was_star;
 
-  c0 = phase3_getc ();
+  int c0 = phase3_getc ();
   if (c0 != '/')
     return c0;
   c = phase3_getc ();
@@ -597,45 +591,47 @@ phase4_getc ()
       return c0;
 
     case '*':
-      /* C style comment.  */
-      comment_start ();
-      last_was_star = false;
-      for (;;)
-        {
-          c = phase3_getc ();
-          if (c == UEOF)
-            break;
-          /* We skip all leading white space, but not EOLs.  */
-          if (!(comment_at_start () && (c == ' ' || c == '\t')))
-            comment_add (c);
-          switch (c)
-            {
-            case UNL:
-              comment_line_end (1);
-              comment_start ();
-              last_was_star = false;
-              continue;
-
-            case '*':
-              last_was_star = true;
-              continue;
-
-            case '/':
-              if (last_was_star)
-                {
-                  comment_line_end (2);
-                  break;
-                }
-              FALLTHROUGH;
+      {
+        /* C style comment.  */
+        comment_start ();
+        bool last_was_star = false;
+        for (;;)
+          {
+            c = phase3_getc ();
+            if (c == UEOF)
+              break;
+            /* We skip all leading white space, but not EOLs.  */
+            if (!(comment_at_start () && (c == ' ' || c == '\t')))
+              comment_add (c);
+            switch (c)
+              {
+              case UNL:
+                comment_line_end (1);
+                comment_start ();
+                last_was_star = false;
+                continue;
+
+              case '*':
+                last_was_star = true;
+                continue;
+
+              case '/':
+                if (last_was_star)
+                  {
+                    comment_line_end (2);
+                    break;
+                  }
+                FALLTHROUGH;
 
-            default:
-              last_was_star = false;
-              continue;
-            }
-          break;
-        }
-      last_comment_line = logical_line_number;
-      return ' ';
+              default:
+                last_was_star = false;
+                continue;
+              }
+            break;
+          }
+        last_comment_line = logical_line_number;
+        return ' ';
+      }
 
     case '/':
       /* C++ style comment.  */
@@ -1198,11 +1194,11 @@ static int phase5_pushback_length;
 static int
 phase5_getc ()
 {
-  int c;
-
   if (phase5_pushback_length)
     return phase5_pushback[--phase5_pushback_length];
 
+  int c;
+
   c = phase4_getc ();
   if (c != UNL)
     return c;
@@ -1302,13 +1298,12 @@ do_getc_unicode_escaped (bool (*predicate) (int))
     return '\\';
   if (c == 'u' || c == 'U')
     {
+      int expect = (c == 'U' ? 8 : 4);
+
       unsigned char buf[8];
-      int expect;
-      unsigned int n;
       int i;
 
-      expect = (c == 'U' ? 8 : 4);
-      n = 0;
+      unsigned int n = 0;
       for (i = 0; i < expect; i++)
         {
           int c1 = phase3_getc ();
@@ -1352,8 +1347,6 @@ static int
 do_getc_escaped ()
 {
   int c;
-  int n;
-  int i;
 
   /* Use phase 3, because phase 4 elides comments.  */
   c = phase3_getc ();
@@ -1384,44 +1377,46 @@ do_getc_escaped ()
     case '0':
       return 0x0000;
     case 'x':
-      c = phase3_getc ();
-      switch (c)
-        {
-        default:
-          phase3_ungetc (c);
-          phase3_ungetc ('x');
-          return '\\';
-
-        case '0': case '1': case '2': case '3': case '4':
-        case '5': case '6': case '7': case '8': case '9':
-        case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
-        case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
-          break;
-        }
-      n = 0;
-      for (i = 0;; i++)
-        {
-          switch (c)
-            {
-            default:
-              phase3_ungetc (c);
-              return n;
-            case '0': case '1': case '2': case '3': case '4':
-            case '5': case '6': case '7': case '8': case '9':
-              n = n * 16 + c - '0';
-              break;
-            case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
-              n = n * 16 + 10 + c - 'A';
-              break;
-            case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
-              n = n * 16 + 10 + c - 'a';
-              break;
-            }
-          if (i == 3)
+      {
+        c = phase3_getc ();
+        switch (c)
+          {
+          default:
+            phase3_ungetc (c);
+            phase3_ungetc ('x');
+            return '\\';
+
+          case '0': case '1': case '2': case '3': case '4':
+          case '5': case '6': case '7': case '8': case '9':
+          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
             break;
-          c = phase3_getc ();
-        }
-      return n;
+          }
+        int n = 0;
+        for (int i = 0;; i++)
+          {
+             switch (c)
+              {
+              default:
+                phase3_ungetc (c);
+                return n;
+              case '0': case '1': case '2': case '3': case '4':
+              case '5': case '6': case '7': case '8': case '9':
+                n = n * 16 + c - '0';
+                break;
+              case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+                n = n * 16 + 10 + c - 'A';
+                break;
+              case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
+                n = n * 16 + 10 + c - 'a';
+                break;
+              }
+            if (i == 3)
+              break;
+            c = phase3_getc ();
+          }
+        return n;
+      }
     case 'u': case 'U':
       phase3_ungetc (c);
       return do_getc_unicode_escaped (is_any_character);
@@ -1502,8 +1497,6 @@ new_brace_depth_level (void)
 static void
 phase6_get (token_ty *tp)
 {
-  int c;
-
   if (phase6_pushback_length)
     {
       *tp = phase6_pushback[--phase6_pushback_length];
@@ -1513,6 +1506,8 @@ phase6_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       tp->logical_line_number = logical_line_number;
       c = phase5_getc ();
@@ -1602,13 +1597,14 @@ phase6_get (token_ty *tp)
           /* Regular string literal.  */
           {
             struct mixed_string_buffer literal;
-
             lexical_context = lc_string;
             mixed_string_buffer_init (&literal,
                                       lexical_context,
                                       logical_file_name,
                                       logical_line_number);
+
             accumulate_escaped (&literal, '"', '"');
+
             tp->mixed_string = mixed_string_buffer_result (&literal);
             tp->comment = add_reference (savable_comment);
             lexical_context = lc_outside;
@@ -1628,12 +1624,13 @@ phase6_get (token_ty *tp)
           /* String with embedded expressions, a.k.a. "interpolated string".  */
           {
             struct mixed_string_buffer msb;
-
             lexical_context = lc_string;
             /* Start accumulating the string.  */
             mixed_string_buffer_init (&msb, lexical_context,
                                       logical_file_name, logical_line_number);
+
             c = accumulate_escaped (&msb, '"', '{');
+
             /* Keep line_number in sync.  */
             msb.line_number = logical_line_number;
             if (c == '{')
@@ -1706,7 +1703,6 @@ phase6_get (token_ty *tp)
             {
               /* Verbatim string literal.  */
               struct mixed_string_buffer literal;
-
               lexical_context = lc_string;
               mixed_string_buffer_init (&literal, lexical_context,
                                         logical_file_name, logical_line_number);
@@ -1743,8 +1739,6 @@ phase6_get (token_ty *tp)
           if (is_identifier_start (c))
             {
               struct mixed_string_buffer buffer;
-              mixed_string_ty *mixed_string;
-
               mixed_string_buffer_init (&buffer, lexical_context,
                                         logical_file_name, logical_line_number);
               for (;;)
@@ -1757,7 +1751,7 @@ phase6_get (token_ty *tp)
                     break;
                 }
               phase4_ungetc (c);
-              mixed_string = mixed_string_buffer_result (&buffer);
+              mixed_string_ty *mixed_string = mixed_string_buffer_result (&buffer);
               tp->string = mixed_string_contents (mixed_string);
               mixed_string_free (mixed_string);
               tp->type = token_type_symbol;
@@ -1811,18 +1805,18 @@ phase7_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase6_get (&token2);
+
           if (token2.type == token_type_plus)
             {
               token_ty token3;
-
               phase6_get (&token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   token_ty token_after;
-
                   phase6_get (&token_after);
+
                   if (token_after.type != token_type_dot)
                     {
                       sum = mixed_string_concat_free1 (sum, token3.mixed_string);
@@ -1943,19 +1937,17 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                symbolJ.....symbolN with J > I.  */
             char *sum = token.string;
             size_t sum_len = strlen (sum);
-            const char *dottedname;
-            flag_context_list_ty *context_list;
 
             for (;;)
               {
                 token_ty token2;
-
                 x_csharp_lex (&token2);
+
                 if (token2.type == token_type_dot)
                   {
                     token_ty token3;
-
                     x_csharp_lex (&token3);
+
                     if (token3.type == token_type_symbol)
                       {
                         char *addend = token3.string;
@@ -1977,10 +1969,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                 break;
               }
 
-            for (dottedname = sum;;)
+            for (const char *dottedname = sum;;)
               {
                 void *keyword_value;
-
                 if (hash_find_entry (&keywords, dottedname, strlen (dottedname),
                                      &keyword_value)
                     == 0)
@@ -1999,7 +1990,8 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                 dottedname++;
               }
 
-            for (dottedname = sum;;)
+            flag_context_list_ty *context_list;
+            for (const char *dottedname = sum;;)
               {
                 context_list =
                   flag_context_list_table_lookup (
@@ -2102,7 +2094,6 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
         case token_type_template:
           {
             lex_pos_ty pos;
-
             pos.file_name = logical_file_name;
             pos.line_number = token.line_number;
 
index 8d6ce0164dac1dea88d8425f39302ffe32938734..5d1d8d289d1dbe33498f421e779f3a1c481ad39f 100644 (file)
@@ -104,21 +104,19 @@ x_d_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (function_keywords.table == NULL)
         hash_init (&function_keywords, 100);
       if (template_keywords.table == NULL)
         hash_init (&template_keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid identifier,
          possibly with a trailing '!'.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         {
           if (end > name && end[-1] == '!')
@@ -389,8 +387,7 @@ is_add_expression_with_tilde (TSNode node,
     {
       uint32_t count = ts_node_child_count (node);
       uint32_t other_subnodes = 0;
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           if (!(ts_node_symbol (subnode) == ts_symbol_comment
@@ -433,8 +430,7 @@ is_string_literal (TSNode node)
       fprintf (stderr, "[%s]|%s|%.*s|\n", ts_node_type (node), ts_node_string (node), (int) sd_length (node_contents), sd_data (node_contents));
       #if 0
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           string_desc_t subnode_contents =
@@ -442,8 +438,7 @@ is_string_literal (TSNode node)
                          contents + ts_node_start_byte (subnode));
           fprintf (stderr, "%u -> [%s]|%s|%.*s|\n", i, ts_node_type (subnode), ts_node_string (subnode), (int) sd_length (subnode_contents), sd_data (subnode_contents));
           uint32_t count2 = ts_node_child_count (subnode);
-          uint32_t j;
-          for (j = 0; j < count2; j++)
+          for (uint32_t j = 0; j < count2; j++)
             {
               fprintf (stderr, "%u %u -> [%s]|%s|\n", i, j, ts_node_type (ts_node_child (subnode, j)), ts_node_string (ts_node_child (subnode, j)));
             }
@@ -530,8 +525,7 @@ string_literal_accumulate_pieces (TSNode node,
           const char *ptr = sd_data (node_contents) + sd_length (node_contents);
           /* Iterate through the nodes of type escape_sequence under the subnode.  */
           uint32_t count = ts_node_named_child_count (subnode);
-          uint32_t i;
-          for (i = count; i > 0; )
+          for (uint32_t i = count; i > 0; )
             {
               i--;
               TSNode escnode = ts_node_named_child (subnode, i);
@@ -595,8 +589,7 @@ string_literal_accumulate_pieces (TSNode node,
                       /* Only up to 3 octal digits are accepted.  */
                       if (escape_end - escape_start <= 1 + 3)
                         {
-                          const char *p;
-                          for (p = escape_start + 1; p < escape_end; p++)
+                          for (const char *p = escape_start + 1; p < escape_end; p++)
                             {
                               /* No overflow is possible.  */
                               char c = *p;
@@ -616,8 +609,7 @@ string_literal_accumulate_pieces (TSNode node,
                            || (escape_start[1] == 'U' && escape_end - escape_start == 2 + 8))
                     {
                       unsigned int value = 0;
-                      const char *p;
-                      for (p = escape_start + 2; p < escape_end; p++)
+                      for (const char *p = escape_start + 2; p < escape_end; p++)
                         {
                           /* No overflow is possible.  */
                           char c = *p;
@@ -688,8 +680,7 @@ string_literal_accumulate_pieces (TSNode node,
           node_contents = sd_substring (node_contents, 2, sd_length (node_contents) - 1);
           int shift = 0;
           int value = 0;
-          ptrdiff_t i;
-          for (i = sd_length (node_contents) - 1; i >= 0; i--)
+          for (ptrdiff_t i = sd_length (node_contents) - 1; i >= 0; i--)
             {
               char c = sd_char_at (node_contents, i);
               if (c >= '0' && c <= '9')
@@ -972,8 +963,7 @@ extract_from_function_call (TSNode node,
                 /* Handle the potential comments in the callee_node, between
                    arg_expr_node and function_node.  */
                 uint32_t count = ts_node_child_count (callee_node);
-                uint32_t i;
-                for (i = 1; i < count; i++)
+                for (uint32_t i = 1; i < count; i++)
                   {
                     TSNode subnode = ts_node_child (callee_node, i);
                     if (ts_node_eq (subnode, function_node))
@@ -989,8 +979,7 @@ extract_from_function_call (TSNode node,
              callee_node and args_node.  */
           {
             uint32_t count = ts_node_child_count (node);
-            uint32_t i;
-            for (i = 1; i < count; i++)
+            for (uint32_t i = 1; i < count; i++)
               {
                 TSNode subnode = ts_node_child (node, i);
                 if (ts_node_eq (subnode, args_node))
@@ -999,8 +988,7 @@ extract_from_function_call (TSNode node,
               }
           }
 
-          uint32_t i;
-          for (i = 0; i < args_count; i++)
+          for (uint32_t i = 0; i < args_count; i++)
             {
               TSNode arg_node = ts_node_child (args_node, i);
               handle_comments (arg_node);
@@ -1102,8 +1090,7 @@ extract_from_function_call (TSNode node,
         /* Handle the potential comments in the callee_node, between
            arg_expr_node and function_node.  */
         uint32_t count = ts_node_child_count (callee_node);
-        uint32_t i;
-        for (i = 1; i < count; i++)
+        for (uint32_t i = 1; i < count; i++)
           {
             TSNode subnode = ts_node_child (callee_node, i);
             if (ts_node_eq (subnode, function_node))
@@ -1119,8 +1106,7 @@ extract_from_function_call (TSNode node,
      callee_node and args_node.  */
   {
     uint32_t count = ts_node_child_count (node);
-    uint32_t i;
-    for (i = 1; i < count; i++)
+    for (uint32_t i = 1; i < count; i++)
       {
         TSNode subnode = ts_node_child (node, i);
         if (ts_node_eq (subnode, args_node))
@@ -1129,8 +1115,7 @@ extract_from_function_call (TSNode node,
       }
   }
 
-  uint32_t i;
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -1257,8 +1242,7 @@ extract_from_function_call_without_args (TSNode callee_node,
             /* Handle the potential comments in the callee_node, between
                arg_expr_node and function_node.  */
             uint32_t count = ts_node_child_count (callee_node);
-            uint32_t i;
-            for (i = 1; i < count; i++)
+            for (uint32_t i = 1; i < count; i++)
               {
                 TSNode subnode = ts_node_child (callee_node, i);
                 if (ts_node_eq (subnode, function_node))
@@ -1305,8 +1289,7 @@ extract_from_function_call_without_args (TSNode callee_node,
     /* Handle the potential comments in the callee_node, between
        arg_expr_node and function_node.  */
     uint32_t count = ts_node_child_count (callee_node);
-    uint32_t i;
-    for (i = 1; i < count; i++)
+    for (uint32_t i = 1; i < count; i++)
       {
         TSNode subnode = ts_node_child (callee_node, i);
         if (ts_node_eq (subnode, function_node))
@@ -1339,8 +1322,7 @@ extract_from_template_instantiation (TSNode node,
      identifier_node and args_node.  */
   {
     uint32_t count = ts_node_child_count (node);
-    uint32_t i;
-    for (i = 1; i < count; i++)
+    for (uint32_t i = 1; i < count; i++)
       {
         TSNode subnode = ts_node_child (node, i);
         if (ts_node_eq (subnode, args_node))
@@ -1374,8 +1356,7 @@ extract_from_template_instantiation (TSNode node,
       /* Current argument number.  */
       uint32_t arg = 0;
 
-      uint32_t i;
-      for (i = 0; i < args_count; i++)
+      for (uint32_t i = 0; i < args_count; i++)
         {
           TSNode arg_node = ts_node_child (args_node, i);
           handle_comments (arg_node);
@@ -1502,8 +1483,7 @@ extract_from_template_instantiation (TSNode node,
   /* Current argument number.  */
   MAYBE_UNUSED uint32_t arg = 0;
 
-  uint32_t i;
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -1631,8 +1611,7 @@ extract_from_node (TSNode node,
               fprintf (stderr, "gettext arguments: %s\n", ts_node_string (argsnode));
               fprintf (stderr, "gettext children:\n");
               uint32_t count = ts_node_named_child_count (node);
-              uint32_t i;
-              for (i = 0; i < count; i++)
+              for (uint32_t i = 0; i < count; i++)
                 fprintf (stderr, "%u -> %s\n", i, ts_node_string (ts_node_named_child (node, i)));
             }
         }
@@ -1647,8 +1626,7 @@ extract_from_node (TSNode node,
     {
       ignore = ignore || is_string_literal (node);
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           handle_comments (subnode);
@@ -1710,9 +1688,8 @@ extract_d (FILE *f,
     }
 
   /* Read the file into memory.  */
-  char *contents_data;
   size_t contents_length;
-  contents_data = read_file (real_filename, 0, &contents_length);
+  char *contents_data = read_file (real_filename, 0, &contents_length);
   if (contents_data == NULL)
     error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
            real_filename);
@@ -1735,8 +1712,7 @@ extract_d (FILE *f,
          contain at least one U+000A, and U+0A000000 is invalid.  */
       if ((contents_length % 4) == 0)
         {
-          int round;
-          for (round = 0; round < 2; round++)
+          for (int round = 0; round < 2; round++)
             {
               if (u32_check ((uint32_t *) contents_data, contents_length / 4) == NULL)
                 {
index 1d1da1c7c4cf518eb65032d166995d39fed2b3a6..6ec2a8e9703493b9e3785a872395f9ccdb812988 100644 (file)
@@ -114,8 +114,8 @@ extract_desktop_handle_pair (struct desktop_reader_ty *reader,
 {
   extract_desktop_reader_ty *extract_reader =
     (extract_desktop_reader_ty *) reader;
-  void *keyword_value;
 
+  void *keyword_value;
   if (!locale                   /* Skip already translated entry.  */
       && hash_find_entry (&keywords, key, strlen (key), &keyword_value) == 0)
     {
@@ -186,6 +186,4 @@ extract_desktop (FILE *f,
 
   desktop_parse (reader, f, real_filename, logical_filename);
   desktop_reader_free (reader);
-
-  reader = NULL;
 }
index ade3908f411626af78181b814cadfdd701e7a16a..22e621af8199d9ae436b3757c250a4f5b132f3ad 100644 (file)
@@ -87,18 +87,17 @@ x_elisp_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
 
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Lisp
          symbol.  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -221,9 +220,7 @@ static inline bool
 is_float (const char *p)
 {
   enum { LEAD_INT = 1, DOT_CHAR = 2, TRAIL_INT = 4, E_CHAR = 8, EXP_INT = 16 };
-  int state;
-
-  state = 0;
+  int state = 0;
   if (*p == '+' || *p == '-')
     p++;
   if (*p >= '0' && *p <= '9')
@@ -279,14 +276,12 @@ is_float (const char *p)
 static bool
 read_token (struct token *tp, int first)
 {
-  int c;
-  bool quoted = false;
-
   init_token (tp);
 
-  c = first;
+  int c;
 
-  for (;; c = do_getc ())
+  bool quoted = false;
+  for (c = first;; c = do_getc ())
     {
       if (c == EOF)
         break;
@@ -414,15 +409,14 @@ free_object (struct object *op)
 static char *
 string_of_object (const struct object *op)
 {
-  char *str;
-  int n;
-
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
-  n = op->token->charcount;
-  str = XNMALLOC (n + 1, char);
+  int n = op->token->charcount;
+
+  char *str = XNMALLOC (n + 1, char);
   memcpy (str, op->token->chars, n);
   str[n] = '\0';
+
   return str;
 }
 
@@ -672,9 +666,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
 
             for (;; arg++)
               {
-                struct object inner;
                 flag_region_ty *inner_region;
-
                 if (arg == 0)
                   inner_region = null_context_region ();
                 else
@@ -684,6 +676,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                                          &context_iter));
 
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, arg == 0, new_backquote_flag,
                              inner_region);
                 nesting_depth--;
@@ -713,8 +706,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                     if (inner.type == t_symbol)
                       {
                         char *symbol_name = string_of_object (&inner);
-                        void *keyword_value;
 
+                        void *keyword_value;
                         if (hash_find_entry (&keywords,
                                              symbol_name, strlen (symbol_name),
                                              &keyword_value)
@@ -775,9 +768,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
           {
             for (;;)
               {
-                struct object inner;
-
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, false, new_backquote_flag,
                              null_context_region ());
                 nesting_depth--;
@@ -812,9 +804,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
 
         case '\'':
           {
-            struct object inner;
-
             ++nesting_depth;
+            struct object inner;
             read_object (&inner, false, new_backquote_flag,
                          null_context_region ());
             nesting_depth--;
@@ -832,9 +823,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
           if (first_in_list)
             goto default_label;
           {
-            struct object inner;
-
             ++nesting_depth;
+            struct object inner;
             read_object (&inner, false, true, null_context_region ());
             nesting_depth--;
 
@@ -858,9 +848,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
               do_ungetc (c);
           }
           {
-            struct object inner;
-
             ++nesting_depth;
+            struct object inner;
             read_object (&inner, false, false, null_context_region ());
             nesting_depth--;
 
@@ -875,10 +864,9 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
 
         case ';':
           {
-            bool all_semicolons = true;
-
             last_comment_line = line_number;
             comment_start ();
+            bool all_semicolons = true;
             for (;;)
               {
                 int c = do_getc ();
@@ -940,9 +928,9 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             if (extract_all)
               {
                 lex_pos_ty pos;
-
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
+
                 remember_a_message (mlp, NULL, string_of_object (op), false,
                                     false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
@@ -1000,9 +988,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
                       /* Read a char table, same syntax as a vector.  */
                       for (;;)
                         {
-                          struct object inner;
-
                           ++nesting_depth;
+                          struct object inner;
                           read_object (&inner, false, new_backquote_flag,
                                        null_context_region ());
                           nesting_depth--;
@@ -1073,9 +1060,9 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
               case '(':
                 /* Read a string with properties, same syntax as a list.  */
                 {
-                  struct object inner;
                   do_ungetc (dmc);
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, false, new_backquote_flag,
                                null_context_region ());
                   nesting_depth--;
@@ -1119,8 +1106,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
               case ':':
               case 'S': case 's': /* XEmacs only */
                 {
-                  struct object inner;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, false, new_backquote_flag,
                                null_context_region ());
                   nesting_depth--;
@@ -1226,8 +1213,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
               case '-': /* XEmacs only */
                 /* Simply assume every feature expression is true.  */
                 {
-                  struct object inner;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, false, new_backquote_flag,
                                null_context_region ());
                   nesting_depth--;
@@ -1269,10 +1256,8 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
             continue;
           /* Read a token.  */
           {
-            bool symbol;
-
             op->token = XMALLOC (struct token);
-            symbol = read_token (op->token, ch);
+            bool symbol = read_token (op->token, ch);
             if (symbol)
               {
                 op->type = t_symbol;
index 5bebfe185c58dc742b589922273a3618db955292..b5e6f86e38fa3a439a3a338bd40c78a280f5815b 100644 (file)
@@ -227,9 +227,8 @@ create_function_type (unsigned int n_values, struct go_type *values[])
 {
   go_type_t *result = XMALLOC (struct go_type);
   go_type_t **heap_values = XNMALLOC (n_values, go_type_t *);
-  unsigned int i;
 
-  for (i = 0; i < n_values; i++)
+  for (unsigned int i = 0; i < n_values; i++)
     heap_values[i] = values[i];
   result->e = function;
   result->u.function_def.n_values = n_values;
@@ -243,9 +242,8 @@ create_struct_type (unsigned int n_members, struct go_struct_member members[])
   go_type_t *result = XMALLOC (struct go_type);
   struct go_struct_member *heap_members =
     XNMALLOC (n_members, struct go_struct_member);
-  unsigned int i;
 
-  for (i = 0; i < n_members; i++)
+  for (unsigned int i = 0; i < n_members; i++)
     heap_members[i] = members[i];
   result->e = go_struct;
   result->u.struct_def.n_members = n_members;
@@ -264,11 +262,10 @@ create_interface_type (unsigned int n_methods, struct go_interface_member method
   struct go_interface_member *heap_methods =
     XNMALLOC (n_methods, struct go_interface_member);
   struct go_type **heap_interfaces = XNMALLOC (n_interfaces, struct go_type *);
-  unsigned int i;
 
-  for (i = 0; i < n_methods; i++)
+  for (unsigned int i = 0; i < n_methods; i++)
     heap_methods[i] = methods[i];
-  for (i = 0; i < n_interfaces; i++)
+  for (unsigned int i = 0; i < n_interfaces; i++)
     heap_interfaces[i] = interfaces[i];
   result->e = go_interface;
   result->u.interface_def.n_methods = n_methods;
@@ -322,9 +319,8 @@ print_type_recurse (go_type_t *type, int maxdepth, FILE *fp)
         print_type_recurse (type->u.function_def.values[0], maxdepth, fp);
       else
         {
-          unsigned int i;
           fprintf (fp, "(");
-          for (i = 0; i < type->u.function_def.n_values; i++)
+          for (unsigned int i = 0; i < type->u.function_def.n_values; i++)
             {
               if (i > 0)
                 fprintf (fp, ", ");
@@ -335,16 +331,15 @@ print_type_recurse (go_type_t *type, int maxdepth, FILE *fp)
       break;
     case go_struct:
       {
-        unsigned int i;
         fprintf (fp, "struct {\n");
-        for (i = 0; i < type->u.struct_def.n_members; i++)
+        for (unsigned int i = 0; i < type->u.struct_def.n_members; i++)
           {
             fprintf (fp, "  %s ", type->u.struct_def.members[i].name);
             print_type_recurse (type->u.struct_def.members[i].type, maxdepth, fp);
             fprintf (fp, ";\n");
           }
         fprintf (fp, "  -- methods:\n");
-        for (i = 0; i < type->u.struct_def.n_methods; i++)
+        for (unsigned int i = 0; i < type->u.struct_def.n_methods; i++)
           {
             fprintf (fp, "  %s ", type->u.struct_def.methods[i].name);
             print_type_recurse (type->u.struct_def.methods[i].type, maxdepth, fp);
@@ -355,16 +350,15 @@ print_type_recurse (go_type_t *type, int maxdepth, FILE *fp)
       break;
     case go_interface:
       {
-        unsigned int i;
         fprintf (fp, "interface {\n");
-        for (i = 0; i < type->u.interface_def.n_methods; i++)
+        for (unsigned int i = 0; i < type->u.interface_def.n_methods; i++)
           {
             fprintf (fp, "  %s ", type->u.interface_def.methods[i].name);
             print_type_recurse (type->u.interface_def.methods[i].type, maxdepth, fp);
             fprintf (fp, ";\n");
           }
         fprintf (fp, "  -- interfaces:\n");
-        for (i = 0; i < type->u.interface_def.n_interfaces; i++)
+        for (unsigned int i = 0; i < type->u.interface_def.n_interfaces; i++)
           {
             fprintf (fp, "  ");
             print_type_recurse (type->u.interface_def.interfaces[i], maxdepth, fp);
@@ -677,10 +671,6 @@ x_go_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         {
           hash_init (&keywords, 100);
@@ -690,10 +680,12 @@ x_go_keyword (const char *name)
           snapcore_type_keywords = gl_map_create_empty (GL_HASH_MAP, NULL, NULL, NULL, NULL);
         }
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         {
           /* The characters between name and end should form
@@ -1052,8 +1044,7 @@ string_literal_accumulate_pieces (TSNode node,
       || ts_node_symbol (node) == ts_symbol_interpreted_string_literal)
     {
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = count; i > 0; )
+      for (uint32_t i = count; i > 0; )
         {
           i--;
           TSNode subnode = ts_node_named_child (node, i);
@@ -1133,8 +1124,7 @@ string_literal_accumulate_pieces (TSNode node,
                   /* Only exactly 3 octal digits are accepted.  */
                   if (escape_end - escape_start == 1 + 3)
                     {
-                      const char *p;
-                      for (p = escape_start + 1; p < escape_end; p++)
+                      for (const char *p = escape_start + 1; p < escape_end; p++)
                         {
                           /* No overflow is possible.  */
                           char c = *p;
@@ -1154,8 +1144,7 @@ string_literal_accumulate_pieces (TSNode node,
                        || (escape_start[1] == 'U' && escape_end - escape_start == 2 + 8))
                 {
                   unsigned int value = 0;
-                  const char *p;
-                  for (p = escape_start + 2; p < escape_end; p++)
+                  for (const char *p = escape_start + 2; p < escape_end; p++)
                     {
                       /* No overflow is possible.  */
                       char c = *p;
@@ -1302,15 +1291,13 @@ static void
 scan_import_declaration (TSNode node)
 {
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_import_spec_list)
         {
           uint32_t count2 = ts_node_named_child_count (subnode);
-          uint32_t j;
-          for (j = 0; j < count2; j++)
+          for (uint32_t j = 0; j < count2; j++)
             {
               TSNode subsubnode = ts_node_named_child (subnode, j);
               if (ts_node_symbol (subsubnode) == ts_symbol_import_spec)
@@ -1335,8 +1322,7 @@ init_package_table (TSNode root_node)
   /* Single pass through all top-level import declarations.  */
   {
     uint32_t count = ts_node_named_child_count (root_node);
-    uint32_t i;
-    for (i = 0; i < count; i++)
+    for (uint32_t i = 0; i < count; i++)
       {
         TSNode node = ts_node_named_child (root_node, i);
         if (ts_node_symbol (node) == ts_symbol_import_declaration)
@@ -1434,29 +1420,26 @@ get_type_from_type_name (string_desc_t type_name, type_env_t tenv, bool use_indi
                            &found_type)
           == 0)
         return (go_type_t *) found_type;
-      {
-        size_t i;
-        for (i = 0; i < unqualified_packages.nitems; i++)
-          {
-            const char *unqualified_package = unqualified_packages.item[i];
-            if (strcmp (unqualified_package, GOTEXT_PACKAGE_FULLNAME) == 0)
-              {
-                if (hash_find_entry (&gotext_package.defined_types,
-                                     sd_data (type_name), sd_length (type_name),
-                                     &found_type)
-                    == 0)
-                  return (go_type_t *) found_type;
-              }
-            else if (strcmp (unqualified_package, SNAPCORE_PACKAGE_FULLNAME) == 0)
-              {
-                if (hash_find_entry (&snapcore_package.defined_types,
-                                     sd_data (type_name), sd_length (type_name),
-                                     &found_type)
-                    == 0)
-                  return (go_type_t *) found_type;
-              }
-          }
-      }
+      for (size_t i = 0; i < unqualified_packages.nitems; i++)
+        {
+          const char *unqualified_package = unqualified_packages.item[i];
+          if (strcmp (unqualified_package, GOTEXT_PACKAGE_FULLNAME) == 0)
+            {
+              if (hash_find_entry (&gotext_package.defined_types,
+                                   sd_data (type_name), sd_length (type_name),
+                                   &found_type)
+                  == 0)
+                return (go_type_t *) found_type;
+            }
+          else if (strcmp (unqualified_package, SNAPCORE_PACKAGE_FULLNAME) == 0)
+            {
+              if (hash_find_entry (&snapcore_package.defined_types,
+                                   sd_data (type_name), sd_length (type_name),
+                                   &found_type)
+                  == 0)
+                return (go_type_t *) found_type;
+            }
+        }
       return &unknown_type;
     }
 }
@@ -1487,10 +1470,9 @@ get_type_from_function_or_method_node (TSNode type_node, type_env_t tenv, bool u
       /* A function with multiple return values.  */
       uint32_t count = ts_node_named_child_count (result_node);
       unsigned int n_values;
-      uint32_t i;
       {
         n_values = 0;
-        for (i = 0; i < count; i++)
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (result_node, i);
             if (ts_node_symbol (subnode) == ts_symbol_parameter_declaration)
@@ -1500,7 +1482,7 @@ get_type_from_function_or_method_node (TSNode type_node, type_env_t tenv, bool u
       struct go_type **values = XNMALLOC (n_values, struct go_type *);
       {
         unsigned int n = 0;
-        for (i = 0; i < count; i++)
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (result_node, i);
             if (ts_node_symbol (subnode) == ts_symbol_parameter_declaration)
@@ -1609,17 +1591,15 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection
         {
           uint32_t count = ts_node_named_child_count (fdlnode);
           unsigned int n_members;
-          uint32_t i;
           {
             n_members = 0;
-            for (i = 0; i < count; i++)
+            for (uint32_t i = 0; i < count; i++)
               {
                 TSNode fdnode = ts_node_named_child (fdlnode, i);
                 if (ts_node_symbol (fdnode) == ts_symbol_field_declaration)
                   {
                     uint32_t count2 = ts_node_named_child_count (fdnode);
-                    uint32_t j;
-                    for (j = 0; j < count2; j++)
+                    for (uint32_t j = 0; j < count2; j++)
                       {
                         TSNode subnode = ts_node_named_child (fdnode, j);
                         if (ts_node_symbol (subnode) == ts_symbol_field_identifier)
@@ -1632,7 +1612,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection
           struct go_struct_member *members = XNMALLOC (n_members, struct go_struct_member);
           {
             unsigned int n = 0;
-            for (i = 0; i < count; i++)
+            for (uint32_t i = 0; i < count; i++)
               {
                 TSNode fdnode = ts_node_named_child (fdlnode, i);
                 if (ts_node_symbol (fdnode) == ts_symbol_field_declaration)
@@ -1641,8 +1621,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection
                     go_type_t *eltype =
                       get_type_from_type_node (eltype_node, tenv, use_indirections);
                     uint32_t count2 = ts_node_named_child_count (fdnode);
-                    uint32_t j;
-                    for (j = 0; j < count2; j++)
+                    for (uint32_t j = 0; j < count2; j++)
                       {
                         TSNode subnode = ts_node_named_child (fdnode, j);
                         if (ts_node_symbol (subnode) == ts_symbol_field_identifier)
@@ -1670,11 +1649,10 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection
       uint32_t count = ts_node_named_child_count (type_node);
       unsigned int n_methods;
       unsigned int n_interfaces;
-      uint32_t i;
       {
         n_methods = 0;
         n_interfaces = 0;
-        for (i = 0; i < count; i++)
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (type_node, i);
             if (ts_node_symbol (subnode) == ts_symbol_method_elem)
@@ -1689,7 +1667,7 @@ get_type_from_type_node (TSNode type_node, type_env_t tenv, bool use_indirection
       {
         unsigned int nm = 0;
         unsigned int ni = 0;
-        for (i = 0; i < count; i++)
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (type_node, i);
             if (ts_node_symbol (subnode) == ts_symbol_method_elem)
@@ -1748,8 +1726,7 @@ static void
 store_type_declaration (TSNode node)
 {
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_type_alias
@@ -1778,8 +1755,7 @@ static void
 store_top_level_type_declarations (TSNode root_node)
 {
   uint32_t count = ts_node_named_child_count (root_node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode node = ts_node_named_child (root_node, i);
       if (ts_node_symbol (node) == ts_symbol_type_declaration)
@@ -1871,36 +1847,31 @@ resolve_indirections (go_type_t **type_p)
     case function:
       {
         unsigned int n = type->u.function_def.n_values;
-        unsigned int i;
-        for (i = 0; i < n; i++)
+        for (unsigned int i = 0; i < n; i++)
           resolve_indirections (&type->u.function_def.values[i]);
       }
       break;
     case go_struct:
       {
         unsigned int n = type->u.struct_def.n_members;
-        unsigned int i;
-        for (i = 0; i < n; i++)
+        for (unsigned int i = 0; i < n; i++)
           resolve_indirections (&type->u.struct_def.members[i].type);
       }
       {
         unsigned int n = type->u.struct_def.n_methods;
-        unsigned int i;
-        for (i = 0; i < n; i++)
+        for (unsigned int i = 0; i < n; i++)
           resolve_indirections (&type->u.struct_def.methods[i].type);
       }
       break;
     case go_interface:
       {
         unsigned int n = type->u.interface_def.n_methods;
-        unsigned int i;
-        for (i = 0; i < n; i++)
+        for (unsigned int i = 0; i < n; i++)
           resolve_indirections (&type->u.interface_def.methods[i].type);
       }
       {
         unsigned int n = type->u.interface_def.n_interfaces;
-        unsigned int i;
-        for (i = 0; i < n; i++)
+        for (unsigned int i = 0; i < n; i++)
           resolve_indirections (&type->u.interface_def.interfaces[i]);
       }
       break;
@@ -2022,29 +1993,26 @@ variable_env_lookup (string_desc_t var_name, variable_env_t venv)
                          &found_type)
         == 0)
       return (go_type_t *) found_type;
-    {
-      size_t i;
-      for (i = 0; i < unqualified_packages.nitems; i++)
-        {
-          const char *unqualified_package = unqualified_packages.item[i];
-          if (strcmp (unqualified_package, GOTEXT_PACKAGE_FULLNAME) == 0)
-            {
-              if (hash_find_entry (&gotext_package.globals,
-                                   sd_data (var_name), sd_length (var_name),
-                                   &found_type)
-                  == 0)
-                return (go_type_t *) found_type;
-            }
-          else if (strcmp (unqualified_package, SNAPCORE_PACKAGE_FULLNAME) == 0)
-            {
-              if (hash_find_entry (&snapcore_package.globals,
-                                   sd_data (var_name), sd_length (var_name),
-                                   &found_type)
-                  == 0)
-                return (go_type_t *) found_type;
-            }
-        }
-    }
+    for (size_t i = 0; i < unqualified_packages.nitems; i++)
+      {
+        const char *unqualified_package = unqualified_packages.item[i];
+        if (strcmp (unqualified_package, GOTEXT_PACKAGE_FULLNAME) == 0)
+          {
+            if (hash_find_entry (&gotext_package.globals,
+                                 sd_data (var_name), sd_length (var_name),
+                                 &found_type)
+                == 0)
+              return (go_type_t *) found_type;
+          }
+        else if (strcmp (unqualified_package, SNAPCORE_PACKAGE_FULLNAME) == 0)
+          {
+            if (hash_find_entry (&snapcore_package.globals,
+                                 sd_data (var_name), sd_length (var_name),
+                                 &found_type)
+                == 0)
+              return (go_type_t *) found_type;
+          }
+      }
     return &unknown_type;
   }
 }
@@ -2076,8 +2044,7 @@ type_equals (go_type_t *type1, go_type_t *type2, unsigned int maxdepth)
           if (type1->u.function_def.n_values == type2->u.function_def.n_values)
             {
               unsigned int n = type1->u.function_def.n_values;
-              unsigned int i;
-              for (i = 0; i < n; i++)
+              for (unsigned int i = 0; i < n; i++)
                 if (!type_equals (type1->u.function_def.values[i],
                                   type2->u.function_def.values[i],
                                   maxdepth))
@@ -2091,12 +2058,11 @@ type_equals (go_type_t *type1, go_type_t *type2, unsigned int maxdepth)
             {
               {
                 unsigned int n = type1->u.struct_def.n_members;
-                unsigned int i;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (strcmp (type1->u.struct_def.members[i].name,
                               type2->u.struct_def.members[i].name) != 0)
                     return false;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (!type_equals (type1->u.struct_def.members[i].type,
                                     type2->u.struct_def.members[i].type,
                                     maxdepth))
@@ -2104,12 +2070,11 @@ type_equals (go_type_t *type1, go_type_t *type2, unsigned int maxdepth)
               }
               {
                 unsigned int n = type1->u.struct_def.n_methods;
-                unsigned int i;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (strcmp (type1->u.struct_def.methods[i].name,
                               type2->u.struct_def.methods[i].name) != 0)
                     return false;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (!type_equals (type1->u.struct_def.methods[i].type,
                                     type2->u.struct_def.methods[i].type,
                                     maxdepth))
@@ -2124,12 +2089,11 @@ type_equals (go_type_t *type1, go_type_t *type2, unsigned int maxdepth)
             {
               {
                 unsigned int n = type1->u.interface_def.n_methods;
-                unsigned int i;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (strcmp (type1->u.interface_def.methods[i].name,
                               type2->u.interface_def.methods[i].name) != 0)
                     return false;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (!type_equals (type1->u.interface_def.methods[i].type,
                                     type2->u.interface_def.methods[i].type,
                                     maxdepth))
@@ -2137,8 +2101,7 @@ type_equals (go_type_t *type1, go_type_t *type2, unsigned int maxdepth)
               }
               {
                 unsigned int n = type1->u.interface_def.n_interfaces;
-                unsigned int i;
-                for (i = 0; i < n; i++)
+                for (unsigned int i = 0; i < n; i++)
                   if (!type_equals (type1->u.interface_def.interfaces[i],
                                     type2->u.interface_def.interfaces[i],
                                     maxdepth))
@@ -2210,8 +2173,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result,
         {
           /* Each of the mvcount expressions in node is expected to produce
              a single value.  */
-          unsigned int i;
-          for (i = 0; i < mvcount; i++)
+          for (unsigned int i = 0; i < mvcount; i++)
             result[i] = get_type_of_expression (ts_node_named_child (node, i), tenv, venv);
           return mvcount;
         }
@@ -2315,11 +2277,10 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result,
         operand_type = operand_type->u.eltype;
       if (operand_type->e == go_struct)
         {
-          unsigned int i;
-          for (i = 0; i < operand_type->u.struct_def.n_members; i++)
+          for (unsigned int i = 0; i < operand_type->u.struct_def.n_members; i++)
             if (sd_equals (field_name, sd_from_c (operand_type->u.struct_def.members[i].name)))
               return1 (operand_type->u.struct_def.members[i].type);
-          for (i = 0; i < operand_type->u.struct_def.n_methods; i++)
+          for (unsigned int i = 0; i < operand_type->u.struct_def.n_methods; i++)
             if (sd_equals (field_name, sd_from_c (operand_type->u.struct_def.methods[i].name)))
               return1 (operand_type->u.struct_def.methods[i].type);
           /* TODO: Handle embedded fields.  */
@@ -2341,8 +2302,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result,
                 {
                   gl_set_add (visited_interfaces, itf);
                   /* Search among the methods directly defined in itf.  */
-                  unsigned int i;
-                  for (i = 0; i < itf->u.interface_def.n_methods; i++)
+                  for (unsigned int i = 0; i < itf->u.interface_def.n_methods; i++)
                     if (sd_equals (field_name, sd_from_c (itf->u.interface_def.methods[i].name)))
                       {
                         gl_set_free (visited_interfaces);
@@ -2350,7 +2310,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result,
                         return1 (itf->u.interface_def.methods[i].type);
                       }
                   /* Enqueue the embedded interfaces of itf.  */
-                  for (i = 0; i < itf->u.interface_def.n_interfaces; i++)
+                  for (unsigned int i = 0; i < itf->u.interface_def.n_interfaces; i++)
                     gl_list_add_last (queued_interfaces, itf->u.interface_def.interfaces[i]);
                 }
             }
@@ -2434,8 +2394,7 @@ get_mvtypes_of_expression (unsigned int mvcount, go_type_t **result,
       if (function_type->e == function
           && function_type->u.function_def.n_values == mvcount)
         {
-          unsigned int i;
-          for (i = 0; i < mvcount; i++)
+          for (unsigned int i = 0; i < mvcount; i++)
             result[i] = function_type->u.function_def.values[i];
           return mvcount;
         }
@@ -2485,8 +2444,7 @@ store_var_spec (TSNode node)
       /* "If a type is present, each variable is given that type."  */
       go_type_t *type = get_type_from_type_node (type_node, NULL, false);
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2511,11 +2469,9 @@ store_var_spec (TSNode node)
           initialization value in the assignment."  */
       uint32_t count = ts_node_named_child_count (node);
       unsigned int mvcount;
-
-      mvcount = 0;
       {
-        uint32_t i;
-        for (i = 0; i < count; i++)
+        mvcount = 0;
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (node, i);
             if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2531,13 +2487,11 @@ store_var_spec (TSNode node)
             get_mvtypes_of_expression (mvcount, value_types, value_node, NULL, NULL);
           if (value_mvcount != mvcount)
             {
-              unsigned int j;
-              for (j = 0; j < mvcount; j++)
+              for (unsigned int j = 0; j < mvcount; j++)
                 value_types[j] = &unknown_type;
             }
           unsigned int j = 0;
-          uint32_t i;
-          for (i = 0; i < count; i++)
+          for (uint32_t i = 0; i < count; i++)
             {
               TSNode subnode = ts_node_named_child (node, i);
               if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2566,8 +2520,7 @@ static void
 store_var_spec_list (TSNode node)
 {
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_var_spec)
@@ -2580,8 +2533,7 @@ static void
 store_var_declaration (TSNode node)
 {
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_var_spec_list)
@@ -2615,8 +2567,7 @@ static void
 store_const_declaration (TSNode node)
 {
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_const_spec)
@@ -2646,8 +2597,7 @@ static void
 store_top_level_declarations (TSNode root_node)
 {
   uint32_t count = ts_node_named_child_count (root_node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode node = ts_node_named_child (root_node, i);
       if (ts_node_symbol (node) == ts_symbol_var_declaration)
@@ -2678,8 +2628,7 @@ augment_for_type_declaration (TSNode node, type_env_t tenv)
 {
   /* Similar to store_type_declaration.  */
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_type_alias
@@ -2708,15 +2657,13 @@ augment_for_parameter_list (TSNode node, type_env_t tenv, variable_env_t venv)
 {
   variable_env_t augmented_venv = venv;
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_parameter_declaration)
         {
           uint32_t count2 = ts_node_named_child_count (subnode);
-          uint32_t j;
-          for (j = 0; j < count2; j++)
+          for (uint32_t j = 0; j < count2; j++)
             {
               TSNode subsubnode = ts_node_named_child (subnode, j);
               if (ts_node_symbol (subsubnode) == ts_symbol_identifier)
@@ -2737,8 +2684,7 @@ augment_for_parameter_list (TSNode node, type_env_t tenv, variable_env_t venv)
       else if (ts_node_symbol (subnode) == ts_symbol_variadic_parameter_declaration)
         {
           uint32_t count2 = ts_node_named_child_count (subnode);
-          uint32_t j;
-          for (j = 0; j < count2; j++)
+          for (uint32_t j = 0; j < count2; j++)
             {
               TSNode subsubnode = ts_node_named_child (subnode, j);
               if (ts_node_symbol (subsubnode) == ts_symbol_identifier)
@@ -2772,8 +2718,7 @@ augment_for_var_spec (TSNode node, type_env_t tenv, variable_env_t venv)
       /* "If a type is present, each variable is given that type."  */
       go_type_t *type = get_type_from_type_node (type_node, tenv, false);
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2795,11 +2740,9 @@ augment_for_var_spec (TSNode node, type_env_t tenv, variable_env_t venv)
           initialization value in the assignment."  */
       uint32_t count = ts_node_named_child_count (node);
       unsigned int mvcount;
-
-      mvcount = 0;
       {
-        uint32_t i;
-        for (i = 0; i < count; i++)
+        mvcount = 0;
+        for (uint32_t i = 0; i < count; i++)
           {
             TSNode subnode = ts_node_named_child (node, i);
             if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2815,13 +2758,11 @@ augment_for_var_spec (TSNode node, type_env_t tenv, variable_env_t venv)
             get_mvtypes_of_expression (mvcount, value_types, value_node, tenv, venv);
           if (value_mvcount != mvcount)
             {
-              unsigned int j;
-              for (j = 0; j < mvcount; j++)
+              for (unsigned int j = 0; j < mvcount; j++)
                 value_types[j] = &unknown_type;
             }
           unsigned int j = 0;
-          uint32_t i;
-          for (i = 0; i < count; i++)
+          for (uint32_t i = 0; i < count; i++)
             {
               TSNode subnode = ts_node_named_child (node, i);
               if (ts_node_symbol (subnode) == ts_symbol_identifier)
@@ -2849,8 +2790,7 @@ augment_for_var_spec_list (TSNode node, type_env_t tenv, variable_env_t venv)
 {
   /* Similar to store_var_spec_list.  */
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_var_spec)
@@ -2865,8 +2805,7 @@ augment_for_variable_declaration (TSNode node, type_env_t tenv, variable_env_t v
 {
   /* Similar to store_var_declaration.  */
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_var_spec_list)
@@ -2900,8 +2839,7 @@ augment_for_const_declaration (TSNode node, type_env_t tenv, variable_env_t venv
 {
   /* Similar to store_const_declaration.  */
   uint32_t count = ts_node_named_child_count (node);
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_const_spec)
@@ -2927,26 +2865,22 @@ augment_for_short_variable_declaration (TSNode node, type_env_t tenv, variable_e
     get_mvtypes_of_expression (mvcount, mvtypes, right_node, tenv, venv);
   if (right_mvcount != mvcount)
     {
-      unsigned int i;
-      for (i = 0; i < mvcount; i++)
+      for (unsigned int i = 0; i < mvcount; i++)
         mvtypes[i] = &unknown_type;
     }
   /* Now augment venv.  */
-  {
-    unsigned int i;
-    for (i = 0; i < mvcount; i++)
-      {
-        TSNode left_var_node = ts_node_named_child (left_node, i);
-        if (ts_node_symbol (left_var_node) == ts_symbol_identifier)
-          {
-            string_desc_t left_var_name =
-              sd_new_addr (ts_node_end_byte (left_var_node) - ts_node_start_byte (left_var_node),
-                           contents + ts_node_start_byte (left_var_node));
-            if (!sd_equals (left_var_name, sd_from_c ("_")))
-              venv = variable_env_augment (venv, left_var_name, mvtypes[i]);
-          }
-      }
-  }
+  for (unsigned int i = 0; i < mvcount; i++)
+    {
+      TSNode left_var_node = ts_node_named_child (left_node, i);
+      if (ts_node_symbol (left_var_node) == ts_symbol_identifier)
+        {
+          string_desc_t left_var_name =
+            sd_new_addr (ts_node_end_byte (left_var_node) - ts_node_start_byte (left_var_node),
+                         contents + ts_node_start_byte (left_var_node));
+          if (!sd_equals (left_var_name, sd_from_c ("_")))
+            venv = variable_env_augment (venv, left_var_name, mvtypes[i]);
+        }
+    }
   free (mvtypes);
   return venv;
 }
@@ -3205,10 +3139,9 @@ extract_from_function_call (TSNode callee_node,
 
       /* Current argument number.  */
       uint32_t arg;
-      uint32_t i;
 
       arg = 0;
-      for (i = 0; i < args_count; i++)
+      for (uint32_t i = 0; i < args_count; i++)
         {
           TSNode arg_node = ts_node_child (args_node, i);
           handle_comments (arg_node);
@@ -3273,9 +3206,7 @@ extract_from_function_call (TSNode callee_node,
 
   /* Recurse.  */
 
-  uint32_t i;
-
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -3362,8 +3293,7 @@ extract_from_node (TSNode node,
               /* Handle the potential comments before the 'arguments'.  */
               {
                 uint32_t count = ts_node_child_count (node);
-                uint32_t i;
-                for (i = 0; i < count; i++)
+                for (uint32_t i = 0; i < count; i++)
                   {
                     TSNode subnode = ts_node_child (node, i);
                     if (ts_node_eq (subnode, args_node))
@@ -3396,8 +3326,7 @@ extract_from_node (TSNode node,
               fprintf (stderr, "gettext arguments: %s\n", ts_node_string (argsnode));
               fprintf (stderr, "gettext children:\n");
               uint32_t count = ts_node_named_child_count (node);
-              uint32_t i;
-              for (i = 0; i < count; i++)
+              for (uint32_t i = 0; i < count; i++)
                 fprintf (stderr, "%u -> %s\n", i, ts_node_string (ts_node_named_child (node, i)));
             }
         }
@@ -3413,8 +3342,7 @@ extract_from_node (TSNode node,
                || (ts_node_symbol (node) == ts_symbol_import_declaration)
                || is_string_literal (node);
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           handle_comments (subnode);
@@ -3650,9 +3578,8 @@ extract_go (FILE *f,
     }
 
   /* Read the file into memory.  */
-  char *contents_data;
   size_t contents_length;
-  contents_data = read_file (real_filename, 0, &contents_length);
+  char *contents_data = read_file (real_filename, 0, &contents_length);
   if (contents_data == NULL)
     error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
            real_filename);
index cafbea3551364bc9ffd92207610efb705e6efd8f..a5dbd9e151390af399d371d78f79dbfa153483c3 100644 (file)
@@ -87,19 +87,17 @@ x_java_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Java
          identifier sequence with dots.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -266,11 +264,11 @@ static int phase2_pushback_length;
 static int
 phase2_getc ()
 {
-  int c;
-
   if (phase2_pushback_length)
     return phase2_pushback[--phase2_pushback_length];
 
+  int c;
+
   c = phase1_getc ();
   if (c == EOF)
     return P2_EOF;
@@ -280,10 +278,6 @@ phase2_getc ()
       if (c == 'u')
         {
           unsigned int u_count = 1;
-          unsigned char buf[4];
-          unsigned int n;
-          int i;
-
           for (;;)
             {
               c = phase1_getc ();
@@ -293,8 +287,9 @@ phase2_getc ()
             }
           phase1_ungetc (c);
 
-          n = 0;
-          for (i = 0; i < 4; i++)
+          unsigned char buf[4];
+          unsigned int n = 0;
+          for (int i = 0; i < 4; i++)
             {
               c = phase1_getc ();
 
@@ -481,11 +476,9 @@ static int last_non_comment_line;
 static int
 phase4_getc ()
 {
-  int c0;
   int c;
-  bool last_was_star;
 
-  c0 = phase3_getc ();
+  int c0 = phase3_getc ();
   if (RED (c0) != '/')
     return c0;
   c = phase3_getc ();
@@ -496,45 +489,47 @@ phase4_getc ()
       return c0;
 
     case '*':
-      /* C style comment.  */
-      comment_start ();
-      last_was_star = false;
-      for (;;)
-        {
-          c = phase3_getc ();
-          if (c == P2_EOF)
-            break;
-          /* We skip all leading white space, but not EOLs.  */
-          if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t')))
-            comment_add (c);
-          switch (RED (c))
-            {
-            case '\n':
-              comment_line_end (1);
-              comment_start ();
-              last_was_star = false;
-              continue;
-
-            case '*':
-              last_was_star = true;
-              continue;
-
-            case '/':
-              if (last_was_star)
-                {
-                  comment_line_end (2);
-                  break;
-                }
-              FALLTHROUGH;
+      {
+        /* C style comment.  */
+        comment_start ();
+        bool last_was_star = false;
+        for (;;)
+          {
+            c = phase3_getc ();
+            if (c == P2_EOF)
+              break;
+            /* We skip all leading white space, but not EOLs.  */
+            if (!(comment_at_start () && (RED (c) == ' ' || RED (c) == '\t')))
+              comment_add (c);
+            switch (RED (c))
+              {
+              case '\n':
+                comment_line_end (1);
+                comment_start ();
+                last_was_star = false;
+                continue;
+
+              case '*':
+                last_was_star = true;
+                continue;
+
+              case '/':
+                if (last_was_star)
+                  {
+                    comment_line_end (2);
+                    break;
+                  }
+                FALLTHROUGH;
 
-            default:
-              last_was_star = false;
-              continue;
-            }
-          break;
-        }
-      last_comment_line = line_number;
-      return ' ';
+              default:
+                last_was_star = false;
+                continue;
+              }
+            break;
+          }
+        last_comment_line = line_number;
+        return ' ';
+      }
 
     case '/':
       /* C++ style comment.  */
@@ -685,10 +680,10 @@ do_getc_escaped ()
 static void
 accumulate_escaped (struct mixed_string_buffer *literal, int delimiter)
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       /* Use phase 3, because phase 4 elides comments.  */
       c = phase3_getc ();
       if (c == P2_EOF || RED (c) == delimiter)
@@ -725,9 +720,8 @@ strip_indent (mixed_string_ty *ms)
   {
     size_t curr_line_indentation = 0;
     bool curr_line_blank = true;
-    size_t i;
 
-    for (i = 0; i < nsegments; i++)
+    for (size_t i = 0; i < nsegments; i++)
       {
         struct mixed_string_segment *segment = ms->segments[i];
 
@@ -737,9 +731,8 @@ strip_indent (mixed_string_ty *ms)
           {
             /* Consider Unicode whitespace characters.  */
             size_t seglength = segment->length;
-            size_t j;
 
-            for (j = 0; j < seglength; )
+            for (size_t j = 0; j < seglength; )
               {
                 ucs4_t uc;
                 int bytes =
@@ -775,9 +768,8 @@ strip_indent (mixed_string_ty *ms)
             /* When the encoding is not UTF-8, consider only ASCII whitespace
                characters.  */
             size_t seglength = segment->length;
-            size_t j;
 
-            for (j = 0; j < seglength; j++)
+            for (size_t j = 0; j < seglength; j++)
               {
                 char c = segment->contents[j];
                 if (c == '\n')
@@ -821,9 +813,8 @@ strip_indent (mixed_string_ty *ms)
     size_t start_of_trailing_whitespace_i = 0;
     size_t start_of_trailing_whitespace_j = 0;
     size_t whitespace_to_remove = minimum_indentation;
-    size_t i;
 
-    for (i = 0; i < nsegments; i++)
+    for (size_t i = 0; i < nsegments; i++)
       {
         struct mixed_string_segment *segment = ms->segments[i];
         /* Perform a sliding copy from segment->contents[from_j] to
@@ -853,9 +844,8 @@ strip_indent (mixed_string_ty *ms)
                            whitespace characters.  Remove all this whitespace.  */
                         if (start_of_curr_line_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j;
-                            for (k = start_of_curr_line_i + 1; k < i; k++)
+                            for (size_t k = start_of_curr_line_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -868,9 +858,8 @@ strip_indent (mixed_string_ty *ms)
                            current line.  */
                         if (start_of_trailing_whitespace_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j;
-                            for (k = start_of_trailing_whitespace_i + 1; k < i; k++)
+                            for (size_t k = start_of_trailing_whitespace_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -901,9 +890,8 @@ strip_indent (mixed_string_ty *ms)
                            characters from the current line.  */
                         if (start_of_curr_line_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j;
-                            for (k = start_of_curr_line_i + 1; k < i; k++)
+                            for (size_t k = start_of_curr_line_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -940,9 +928,8 @@ strip_indent (mixed_string_ty *ms)
                            whitespace characters.  Remove all this whitespace.  */
                         if (start_of_curr_line_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j;
-                            for (k = start_of_curr_line_i + 1; k < i; k++)
+                            for (size_t k = start_of_curr_line_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -955,9 +942,8 @@ strip_indent (mixed_string_ty *ms)
                            current line.  */
                         if (start_of_trailing_whitespace_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j;
-                            for (k = start_of_trailing_whitespace_i + 1; k < i; k++)
+                            for (size_t k = start_of_trailing_whitespace_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -987,9 +973,8 @@ strip_indent (mixed_string_ty *ms)
                            characters from the current line.  */
                         if (start_of_curr_line_i < i)
                           {
-                            size_t k;
                             ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j;
-                            for (k = start_of_curr_line_i + 1; k < i; k++)
+                            for (size_t k = start_of_curr_line_i + 1; k < i; k++)
                               ms->segments[k]->length = 0;
                             to_j = 0;
                           }
@@ -1016,9 +1001,8 @@ strip_indent (mixed_string_ty *ms)
                    whitespace characters.  Remove all this whitespace.  */
                 if (start_of_curr_line_i < i)
                   {
-                    size_t k;
                     ms->segments[start_of_curr_line_i]->length = start_of_curr_line_j;
-                    for (k = start_of_curr_line_i + 1; k < i; k++)
+                    for (size_t k = start_of_curr_line_i + 1; k < i; k++)
                       ms->segments[k]->length = 0;
                     to_j = 0;
                   }
@@ -1031,9 +1015,8 @@ strip_indent (mixed_string_ty *ms)
                    current line.  */
                 if (start_of_trailing_whitespace_i < i)
                   {
-                    size_t k;
                     ms->segments[start_of_trailing_whitespace_i]->length = start_of_trailing_whitespace_j;
-                    for (k = start_of_trailing_whitespace_i + 1; k < i; k++)
+                    for (size_t k = start_of_trailing_whitespace_i + 1; k < i; k++)
                       ms->segments[k]->length = 0;
                     to_j = 0;
                   }
@@ -1055,8 +1038,6 @@ static int phase5_pushback_length;
 static void
 phase5_get (token_ty *tp)
 {
-  int c;
-
   if (phase5_pushback_length)
     {
       *tp = phase5_pushback[--phase5_pushback_length];
@@ -1066,6 +1047,8 @@ phase5_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase4_getc ();
 
@@ -1201,9 +1184,6 @@ phase5_get (token_ty *tp)
                   {
                     /* Text block.  Specification:
                        <https://docs.oracle.com/javase/specs/jls/se13/preview/text-blocks.html>  */
-                    struct mixed_string_buffer block;
-                    unsigned int consecutive_unescaped_doublequotes;
-                    mixed_string_ty *block_content;
 
                     /* Parse the part up to and including the first newline.  */
                     for (;;)
@@ -1232,9 +1212,10 @@ phase5_get (token_ty *tp)
                       }
 
                     /* Parse the part after the first newline.  */
+                    struct mixed_string_buffer block;
                     mixed_string_buffer_init (&block, lc_string,
                                               logical_file_name, line_number);
-                    consecutive_unescaped_doublequotes = 0;
+                    unsigned int consecutive_unescaped_doublequotes = 0;
                     for (;;)
                       {
                         int ic = phase3_getc ();
@@ -1263,7 +1244,7 @@ phase5_get (token_ty *tp)
                             mixed_string_buffer_append (&block, ic);
                           }
                       }
-                    block_content = mixed_string_buffer_result (&block);
+                    mixed_string_ty *block_content = mixed_string_buffer_result (&block);
 
                     /* Remove the common indentation from the content.  */
                     strip_indent (block_content);
@@ -1280,7 +1261,6 @@ phase5_get (token_ty *tp)
           /* String literal.  */
           {
             struct mixed_string_buffer literal;
-
             mixed_string_buffer_init (&literal, lc_string,
                                       logical_file_name, line_number);
             accumulate_escaped (&literal, '"');
@@ -1294,7 +1274,6 @@ phase5_get (token_ty *tp)
           /* Character literal.  */
           {
             struct mixed_string_buffer literal;
-
             mixed_string_buffer_init (&literal, lc_outside,
                                       logical_file_name, line_number);
             accumulate_escaped (&literal, '\'');
@@ -1584,18 +1563,18 @@ phase6_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase5_get (&token2);
+
           if (token2.type == token_type_plus)
             {
               token_ty token3;
-
               phase5_get (&token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   token_ty token_after;
-
                   phase5_get (&token_after);
+
                   if (token_after.type != token_type_dot)
                     {
                       sum = mixed_string_concat_free1 (sum, token3.mixed_string);
@@ -1705,8 +1684,8 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
   for (;;)
     {
       token_ty token;
-
       x_java_lex (&token);
+
       switch (token.type)
         {
         case token_type_symbol:
@@ -1718,19 +1697,17 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                symbolJ.....symbolN with J > I.  */
             char *sum = token.string;
             size_t sum_len = strlen (sum);
-            const char *dottedname;
-            flag_context_list_ty *context_list;
 
             for (;;)
               {
                 token_ty token2;
-
                 x_java_lex (&token2);
+
                 if (token2.type == token_type_dot)
                   {
                     token_ty token3;
-
                     x_java_lex (&token3);
+
                     if (token3.type == token_type_symbol)
                       {
                         char *addend = token3.string;
@@ -1761,10 +1738,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                they should not.  */
             if (strcmp (sum, "return") != 0)
               {
-                for (dottedname = sum;;)
+                for (const char *dottedname = sum;;)
                   {
                     void *keyword_value;
-
                     if (hash_find_entry (&keywords, dottedname, strlen (dottedname),
                                          &keyword_value)
                         == 0)
@@ -1783,7 +1759,8 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
                     dottedname++;
                   }
 
-                for (dottedname = sum;;)
+                flag_context_list_ty *context_list;
+                for (const char *dottedname = sum;;)
                   {
                     context_list =
                       flag_context_list_table_lookup (
@@ -1952,7 +1929,6 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
         case token_type_string_literal:
           {
             lex_pos_ty pos;
-
             pos.file_name = logical_file_name;
             pos.line_number = token.line_number;
 
index 95a09ff492d727c446af9557d9a803866fbde21b..9e7b3ac560dc3fece1703c4f7a380538bff21cb6 100644 (file)
@@ -96,18 +96,16 @@ x_javascript_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -182,13 +180,12 @@ static char *
 gnome_step1 (string_list_ty *parts)
 {
   size_t n = parts->nitems - 1;
-  string_list_ty pieces;
-  unsigned long i;
 
+  string_list_ty pieces;
   pieces.nitems = 2 * n + 1;
   pieces.nitems_max = pieces.nitems;
   pieces.item = XNMALLOC (pieces.nitems, const char *);
-  for (i = 0; i <= n; i++)
+  for (unsigned long i = 0; i <= n; i++)
     {
       pieces.item[2 * i] = parts->item[i];
       if (i < n)
@@ -197,7 +194,7 @@ gnome_step1 (string_list_ty *parts)
 
   char *result = string_list_concat (&pieces);
 
-  for (i = 0; i < n; i++)
+  for (unsigned long i = 0; i < n; i++)
     free ((char *) pieces.item[2 * i + 1]);
 
   return result;
@@ -392,8 +389,6 @@ Please specify the correct source encoding through --from-code\n"),
               else if (errno == EINVAL)
                 {
                   /* An incomplete multibyte character.  */
-                  int c;
-
                   if (bufcount == MAX_PHASE1_PUSHBACK)
                     {
                       /* An overlong incomplete multibyte sequence was
@@ -407,7 +402,7 @@ Please specify the correct source encoding through --from-code\n"),
                     }
 
                   /* Read one more byte and retry iconv.  */
-                  c = phase1_getc ();
+                  int c = phase1_getc ();
                   if (c == EOF)
                     {
                       multiline_error (xstrdup (""),
@@ -437,7 +432,6 @@ Please specify the correct source encoding through --from-code\n"),
             {
               size_t outbytes = sizeof (scratchbuf) - outsize;
               size_t bytes = bufcount - insize;
-              ucs4_t uc;
 
               /* We expect that one character has been produced.  */
               if (bytes == 0)
@@ -448,6 +442,7 @@ Please specify the correct source encoding through --from-code\n"),
               while (insize > 0)
                 phase1_ungetc (buf[--insize]);
               /* Convert the character from UTF-8 to UCS-4.  */
+              ucs4_t uc;
               if (u8_mbtoucr (&uc, scratchbuf, outbytes) < (int) outbytes)
                 {
                   /* scratchbuf contains an out-of-range Unicode character
@@ -475,7 +470,6 @@ Please specify the source encoding through --from-code\n"),
       unsigned char buf[6];
       unsigned int count;
       int c;
-      ucs4_t uc;
 
       c = phase1_getc ();
       if (c == EOF)
@@ -538,6 +532,7 @@ Please specify the source encoding through --from-code\n"),
           count = 6;
         }
 
+      ucs4_t uc;
       u8_mbtouc (&uc, buf, count);
       return uc;
     }
@@ -633,10 +628,10 @@ static bool continuation_or_nonblank_line;
 static int
 phase3_getc ()
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       c = phase2_getc ();
       if (c == '\\')
         {
@@ -677,9 +672,9 @@ phase3_getc ()
           else if (c == '*')
             {
               /* C style comment.  */
-              bool last_was_star = false;
               last_comment_line = line_number;
               comment_start ();
+              bool last_was_star = false;
               for (;;)
                 {
                   c = phase2_getc ();
@@ -851,10 +846,10 @@ free_token (token_ty *tp)
 static int
 phase7_getuc (int quote_char)
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       /* Use phase 2, because phase 3 elides comments.  */
       c = phase2_getc ();
 
@@ -950,8 +945,8 @@ phase7_getuc (int quote_char)
         case 'x':
           {
             int c1 = phase2_getc ();
-            int n1;
 
+            int n1;
             if (c1 >= '0' && c1 <= '9')
               n1 = c1 - '0';
             else if (c1 >= 'A' && c1 <= 'F')
@@ -964,8 +959,8 @@ phase7_getuc (int quote_char)
             if (n1 >= 0)
               {
                 int c2 = phase2_getc ();
-                int n2;
 
+                int n2;
                 if (c2 >= '0' && c2 <= '9')
                   n2 = c2 - '0';
                 else if (c2 >= 'A' && c2 <= 'F')
@@ -990,9 +985,7 @@ phase7_getuc (int quote_char)
           {
             unsigned char buf[4];
             unsigned int n = 0;
-            int i;
-
-            for (i = 0; i < 4; i++)
+            for (int i = 0; i < 4; i++)
               {
                 int c1 = phase2_getc ();
 
@@ -1081,11 +1074,10 @@ is_after_expression (void)
 static void
 phase5_scan_regexp (void)
 {
-  bool at_start;
   int c;
 
   /* Scan for end of RegExp literal ('/').  */
-  for (at_start = true; ; at_start = false)
+  for (bool at_start = true; ; at_start = false)
     {
       /* Must use phase2 as there can't be comments.  */
       c = phase2_getc ();
@@ -1221,9 +1213,8 @@ phase5_scan_xml_markup (token_ty *tp)
       { "![CDATA[", "]]" },
       { "?", "?" }
     };
-  int i;
 
-  for (i = 0; i < SIZEOF (markers); i++)
+  for (int i = 0; i < SIZEOF (markers); i++)
     {
       const char *start = markers[i].start;
       const char *end = markers[i].end;
@@ -1232,10 +1223,8 @@ phase5_scan_xml_markup (token_ty *tp)
       /* Look for a start marker.  */
       for (j = 0; start[j] != '\0'; j++)
         {
-          int c;
-
           assert (phase2_pushback_length + j < SIZEOF (phase2_pushback));
-          c = phase2_getc ();
+          int c = phase2_getc ();
           if (c == UEOF)
             goto eof;
           if (c != start[j])
@@ -1255,12 +1244,10 @@ phase5_scan_xml_markup (token_ty *tp)
         /* 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 ();
+                int c = phase2_getc ();
                 if (c == UEOF)
                   goto eof;
                 if (c != end[j])
@@ -1283,7 +1270,7 @@ phase5_scan_xml_markup (token_ty *tp)
 
             if (end[j] == '\0')
               {
-                c = phase2_getc ();
+                int c = phase2_getc ();
                 if (c == UEOF)
                   goto eof;
                 if (c != '>')
@@ -1309,8 +1296,6 @@ phase5_scan_xml_markup (token_ty *tp)
 static void
 phase5_get (token_ty *tp)
 {
-  int c;
-
   if (phase5_pushback_length)
     {
       *tp = phase5_pushback[--phase5_pushback_length];
@@ -1320,6 +1305,8 @@ phase5_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase3_getc ();
 
@@ -1372,7 +1359,6 @@ phase5_get (token_ty *tp)
           /* Symbol, or part of a number.  */
           {
             struct string_buffer buffer;
-
             sb_init (&buffer);
             for (;;)
               {
@@ -1414,8 +1400,8 @@ phase5_get (token_ty *tp)
           {
             int quote_char = c;
             lexical_context_ty saved_lexical_context = lexical_context;
-            struct mixed_string_buffer msb;
 
+            struct mixed_string_buffer msb;
             lexical_context = lc_string;
             /* Start accumulating the string.  */
             mixed_string_buffer_init (&msb, lexical_context,
@@ -1451,7 +1437,6 @@ phase5_get (token_ty *tp)
           /* Template literals.  */
           {
             struct mixed_string_buffer msb;
-
             lexical_context = lc_string;
             /* Start accumulating the string.  */
             mixed_string_buffer_init (&msb, lexical_context,
@@ -1636,7 +1621,6 @@ phase5_get (token_ty *tp)
             {
               /* Middle or right part of template literal.  */
               struct mixed_string_buffer msb;
-
               lexical_context = lc_string;
               /* Start accumulating the string.  */
               mixed_string_buffer_init (&msb, lexical_context,
@@ -1743,13 +1727,13 @@ x_javascript_lex (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase5_get (&token2);
+
           if (token2.type == token_type_plus)
             {
               token_ty token3;
-
               phase5_get (&token3);
+
               if (token3.type == token_type_string
                   || token3.type == token_type_template)
                 {
@@ -1769,8 +1753,8 @@ x_javascript_lex (token_ty *tp)
   else if (tp->type == token_type_symbol)
     {
       token_ty token2;
-
       phase5_get (&token2);
+
       if (token2.type == token_type_template
           || token2.type == token_type_ltemplate)
         {
@@ -1872,14 +1856,13 @@ extract_balanced (message_list_ty *mlp,
   for (;;)
     {
       token_ty token;
-
       x_javascript_lex (&token);
+
       switch (token.type)
         {
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
@@ -2004,7 +1987,6 @@ extract_balanced (message_list_ty *mlp,
         case token_type_rtemplate:
           {
             lex_pos_ty pos;
-
             pos.file_name = logical_file_name;
             pos.line_number = token.line_number;
 
@@ -2016,8 +1998,8 @@ extract_balanced (message_list_ty *mlp,
                 && token.template_tag != NULL)
               {
                 const char *tag = token.template_tag;
-                string_list_ty *parts;
 
+                string_list_ty *parts;
                 if (token.type == token_type_template)
                   {
                     parts = string_list_alloc ();
index 5fb6734f13f5c57053278beff764d77b5259f664..89b94849eb7a586f71a407de4389d7ed7a4d9ac3 100644 (file)
@@ -89,18 +89,16 @@ x_librep_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Lisp
          symbol.  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -206,7 +204,15 @@ grow_token (struct token *tp)
 static bool
 read_token (struct token *tp, const int *first)
 {
+  init_token (tp);
+
   int c;
+
+  if (first)
+    c = *first;
+  else
+    c = do_getc ();
+
   /* Variables for speculative number parsing:  */
   int radix = -1;
   int nfirst = 0;
@@ -216,13 +222,6 @@ read_token (struct token *tp, const int *first)
   bool had_sign = false;
   bool expecting_prefix = false;
 
-  init_token (tp);
-
-  if (first)
-    c = *first;
-  else
-    c = do_getc ();
-
   for (;; c = do_getc ())
     {
       switch (c)
@@ -494,15 +493,14 @@ free_object (struct object *op)
 static char *
 string_of_object (const struct object *op)
 {
-  char *str;
-  int n;
-
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
-  n = op->token->charcount;
-  str = XNMALLOC (n + 1, char);
+  int n = op->token->charcount;
+
+  char *str = XNMALLOC (n + 1, char);
   memcpy (str, op->token->chars, n);
   str[n] = '\0';
+
   return str;
 }
 
@@ -634,9 +632,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
             for (;; arg++)
               {
-                struct object inner;
                 flag_region_ty *inner_region;
-
                 if (arg == 0)
                   inner_region = null_context_region ();
                 else
@@ -646,6 +642,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
                                          &context_iter));
 
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, inner_region);
                 nesting_depth--;
 
@@ -674,8 +671,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
                     if (inner.type == t_symbol)
                       {
                         char *symbol_name = string_of_object (&inner);
-                        void *keyword_value;
 
+                        void *keyword_value;
                         if (hash_find_entry (&keywords,
                                              symbol_name, strlen (symbol_name),
                                              &keyword_value)
@@ -729,9 +726,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
           {
             for (;;)
               {
-                struct object inner;
-
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, null_context_region ());
                 nesting_depth--;
 
@@ -775,9 +771,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
         case '\'':
         case '`':
           {
-            struct object inner;
-
             ++nesting_depth;
+            struct object inner;
             read_object (&inner, null_context_region ());
             nesting_depth--;
 
@@ -792,10 +787,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
         case ';':
           {
-            bool all_semicolons = true;
-
             last_comment_line = line_number;
             comment_start ();
+            bool all_semicolons = true;
             for (;;)
               {
                 int c = do_getc ();
@@ -857,9 +851,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
             if (extract_all)
               {
                 lex_pos_ty pos;
-
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
+
                 remember_a_message (mlp, NULL, string_of_object (op), false,
                                     false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
@@ -938,8 +932,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case '\'':
               case ':':
                 {
-                  struct object inner;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
@@ -953,9 +947,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case '[':
               case '(':
                 {
-                  struct object inner;
                   do_ungetc (dmc);
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
@@ -1057,11 +1051,10 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case 'E': case 'e':
               case 'I': case 'i':
                 {
-                  struct token token;
                   do_ungetc (dmc);
                   {
-                    int c;
-                    c = '#';
+                    struct token token;
+                    int c = '#';
                     read_token (&token, &c);
                     free_token (&token);
                   }
@@ -1084,10 +1077,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
         default:
           /* Read a token.  */
           {
-            bool symbol;
-
             op->token = XMALLOC (struct token);
-            symbol = read_token (op->token, &ch);
+            bool symbol = read_token (op->token, &ch);
             if (op->token->charcount == 1 && op->token->chars[0] == '.')
               {
                 free_token (op->token);
@@ -1109,10 +1100,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
               int c = do_getc ();
               if (c == '#')
                 {
-                  struct token second_token;
-
                   free_token (op->token);
                   free (op->token);
+                  struct token second_token;
                   read_token (&second_token, NULL);
                   free_token (&second_token);
                   op->type = t_other;
index 8ed6a538588c6c3c10d528af5d2f3290b4bd634d..2cbddefbd557b998c1c8391143c10d253f7c6267 100644 (file)
@@ -130,21 +130,16 @@ x_lisp_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-      size_t len;
-      char *symname;
-      size_t i;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Lisp symbol.
          Extract the symbol name part.  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon != NULL && colon < end)
         {
           name = colon + 1;
@@ -156,9 +151,9 @@ x_lisp_keyword (const char *name)
         }
 
       /* Uppercase it.  */
-      len = end - name;
-      symname = XNMALLOC (len, char);
-      for (i = 0; i < len; i++)
+      size_t len = end - name;
+      char *symname = XNMALLOC (len, char);
+      for (size_t i = 0; i < len; i++)
         symname[i] =
           (name[i] >= 'a' && name[i] <= 'z' ? name[i] - 'a' + 'A' : name[i]);
 
@@ -392,13 +387,11 @@ grow_token (struct token *tp)
 static void
 read_token (struct token *tp, const struct char_syntax *first)
 {
-  bool multiple_escape_flag;
-  struct char_syntax curr;
-
   init_token (tp);
   tp->with_escape = false;
 
-  multiple_escape_flag = false;
+  bool multiple_escape_flag = false;
+  struct char_syntax curr;
   if (first)
     curr = *first;
   else
@@ -488,9 +481,8 @@ static inline bool
 has_a_dot (const struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (tp->chars[i].attribute == a_dot)
       return true;
   return false;
@@ -500,9 +492,8 @@ static inline bool
 all_a_number (const struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (!is_number_attribute (tp->chars[i].attribute))
       return false;
   return true;
@@ -512,9 +503,8 @@ static inline void
 a_letter_to_digit (const struct token *tp, int base)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (is_letter_attribute (tp->chars[i].attribute))
       {
         int c = tp->chars[i].ch;
@@ -531,9 +521,8 @@ static inline bool
 has_a_digit (const struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (tp->chars[i].attribute == a_digit
         || tp->chars[i].attribute == a_letterdigit
         || tp->chars[i].attribute == a_expodigit)
@@ -545,9 +534,8 @@ static inline bool
 has_adjacent_letters (const struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 1; i < n; i++)
+  for (int i = 1; i < n; i++)
     if (is_letter_attribute (tp->chars[i-1].attribute)
         && is_letter_attribute (tp->chars[i].attribute))
       return true;
@@ -603,9 +591,6 @@ enum number_type
 static enum number_type
 is_number (const struct token *tp, int *basep)
 {
-  struct token_char *ptr_limit;
-  struct token_char *ptr1;
-
   if (!is_potential_number (tp, basep))
     return n_none;
 
@@ -614,8 +599,8 @@ is_number (const struct token *tp, int *basep)
      - there is at least one a_digit or a_letterdigit or a_expodigit, and
      - if there is an a_dot, then *basep = 10.  */
 
-  ptr1 = &tp->chars[0];
-  ptr_limit = &tp->chars[tp->charcount];
+  struct token_char *ptr1 = &tp->chars[0];
+  struct token_char *ptr_limit = &tp->chars[tp->charcount];
 
   if (ptr1->attribute == a_sign)
     ptr1++;
@@ -627,9 +612,8 @@ is_number (const struct token *tp, int *basep)
   {
     bool seen_a_ratio = false;
     bool seen_a_digit = false;  /* seen a digit in last digit block? */
-    struct token_char *ptr;
 
-    for (ptr = ptr1;; ptr++)
+    for (struct token_char *ptr = ptr1;; ptr++)
       {
         if (ptr >= ptr_limit)
           {
@@ -745,9 +729,8 @@ static void
 upcase_token (struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (tp->chars[i].attribute != a_escaped)
       {
         unsigned char c = tp->chars[i].ch;
@@ -760,9 +743,8 @@ static void
 downcase_token (struct token *tp)
 {
   int n = tp->charcount;
-  int i;
 
-  for (i = 0; i < n; i++)
+  for (int i = 0; i < n; i++)
     if (tp->chars[i].attribute != a_escaped)
       {
         unsigned char c = tp->chars[i].ch;
@@ -774,9 +756,6 @@ downcase_token (struct token *tp)
 static void
 case_convert_token (struct token *tp)
 {
-  int n = tp->charcount;
-  int i;
-
   switch (readtable_case)
     {
     case case_upcase:
@@ -792,9 +771,10 @@ case_convert_token (struct token *tp)
 
     case case_invert:
       {
+        int n = tp->charcount;
         bool seen_uppercase = false;
         bool seen_lowercase = false;
-        for (i = 0; i < n; i++)
+        for (int i = 0; i < n; i++)
           if (tp->chars[i].attribute != a_escaped)
             {
               unsigned char c = tp->chars[i].ch;
@@ -909,19 +889,17 @@ free_object (struct object *op)
 static char *
 string_of_object (const struct object *op)
 {
-  char *str;
-  const struct token_char *p;
-  char *q;
-  int n;
-
   if (!(op->type == t_symbol || op->type == t_string))
     abort ();
-  n = op->token->charcount;
-  str = XNMALLOC (n + 1, char);
-  q = str;
-  for (p = op->token->chars; n > 0; p++, n--)
-    *q++ = p->ch;
-  *q = '\0';
+  int n = op->token->charcount;
+  char *str = XNMALLOC (n + 1, char);
+  {
+    const struct token_char *p;
+    char *q = str;
+    for (p = op->token->chars; n > 0; p++, n--)
+      *q++ = p->ch;
+    *q = '\0';
+  }
   return str;
 }
 
@@ -948,7 +926,6 @@ read_object (struct object *op, flag_region_ty *outer_region)
   for (;;)
     {
       struct char_syntax curr;
-
       read_char_syntax (&curr);
 
       switch (curr.scode)
@@ -996,7 +973,6 @@ read_object (struct object *op, flag_region_ty *outer_region)
           /* Number.  */
           {
             int base = read_base;
-
             if (is_number (op->token, &base) != n_none)
               {
                 free_token (op->token);
@@ -1026,9 +1002,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
                 for (;; arg++)
                   {
-                    struct object inner;
                     flag_region_ty *inner_region;
-
                     if (arg == 0)
                       inner_region = null_context_region ();
                     else
@@ -1038,6 +1012,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
                                              &context_iter));
 
                     ++nesting_depth;
+                    struct object inner;
                     read_object (&inner, inner_region);
                     nesting_depth--;
 
@@ -1067,17 +1042,18 @@ read_object (struct object *op, flag_region_ty *outer_region)
                         if (inner.type == t_symbol)
                           {
                             char *symbol_name = string_of_object (&inner);
-                            int i;
-                            int prefix_len;
-                            void *keyword_value;
 
                             /* Omit any package name.  */
-                            i = inner.token->charcount;
-                            while (i > 0
-                                   && inner.token->chars[i-1].attribute != a_pack_m)
-                              i--;
-                            prefix_len = i;
+                            int prefix_len;
+                            {
+                              int i = inner.token->charcount;
+                              while (i > 0
+                                     && inner.token->chars[i-1].attribute != a_pack_m)
+                                i--;
+                              prefix_len = i;
+                            }
 
+                            void *keyword_value;
                             if (hash_find_entry (&keywords,
                                                  symbol_name + prefix_len,
                                                  strlen (symbol_name + prefix_len),
@@ -1148,9 +1124,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
             case '\'':
             case '`':
               {
-                struct object inner;
-
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, null_context_region ());
                 nesting_depth--;
 
@@ -1165,10 +1140,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
             case ';':
               {
-                bool all_semicolons = true;
-
                 last_comment_line = line_number;
                 comment_start ();
+                bool all_semicolons = true;
                 for (;;)
                   {
                     int c = do_getc ();
@@ -1215,9 +1189,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
                 if (extract_all)
                   {
                     lex_pos_ty pos;
-
                     pos.file_name = logical_file_name;
                     pos.line_number = op->line_number_at_start;
+
                     remember_a_message (mlp, NULL, string_of_object (op), false,
                                         false, null_context_region (), &pos,
                                         NULL, savable_comment, false);
@@ -1259,8 +1233,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
                   case 'P': case 'p':
                   case 'S': case 's':
                     {
-                      struct object inner;
                       ++nesting_depth;
+                      struct object inner;
                       read_object (&inner, null_context_region ());
                       nesting_depth--;
                       /* Dots and EOF are not allowed here.
@@ -1379,8 +1353,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
                   case '-':
                     /* Simply assume every feature expression is true.  */
                     {
-                      struct object inner;
                       ++nesting_depth;
+                      struct object inner;
                       read_object (&inner, null_context_region ());
                       nesting_depth--;
                       /* Dots and EOF are not allowed here.
index 6bfa2d29bb5bedb4331dfd43c7f0e8065967be92..415a471c8cb571c046de379b5cbeb6cf3a28ad72 100644 (file)
@@ -75,18 +75,16 @@ x_lua_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -268,7 +266,6 @@ static int
 phase2_getc ()
 {
   int c;
-  int lineno;
 
   c = phase1_getc ();
 
@@ -300,7 +297,7 @@ phase2_getc ()
                   bool end = false;
                   int esigns2 = 0;
 
-                  lineno = line_number;
+                  int lineno = line_number;
                   comment_start ();
                   while (!end)
                     {
@@ -353,7 +350,7 @@ phase2_getc ()
               else
                 {
                   /* One line (short) comment, starting with '--[=...='.  */
-                  lineno = last_comment_line;
+                  int lineno = last_comment_line;
                   comment_start ();
                   comment_add ('[');
                   while (esigns--)
@@ -367,7 +364,7 @@ phase2_getc ()
           else
             {
               /* One line (short) comment.  */
-              lineno = line_number;
+              int lineno = line_number;
               comment_start ();
               phase1_ungetc (c);
               eat_comment_line ();
@@ -448,16 +445,14 @@ phase3_unget (token_ty *tp)
 static void
 phase3_get (token_ty *tp)
 {
-  int c;
-  int c2;
-  int c_start;
-
   if (phase3_pushback_length)
     {
       *tp = phase3_pushback[--phase3_pushback_length];
       return;
     }
 
+  int c;
+
   tp->string = NULL;
 
   for (;;)
@@ -492,21 +487,25 @@ phase3_get (token_ty *tp)
         case '<':
         case '>':
         case '=':
-          c2 = phase1_getc ();
-          if (c2 != '=')
-            phase1_ungetc (c2);
-          tp->type = token_type_operator2;
-          return;
+          {
+            int c2 = phase1_getc ();
+            if (c2 != '=')
+              phase1_ungetc (c2);
+            tp->type = token_type_operator2;
+            return;
+          }
         case '~':
-          c2 = phase1_getc ();
-          if (c2 == '=')
-            {
-              tp->type = token_type_operator2;
-              return;
-            }
-          else
-            phase1_ungetc (c2);
-          continue;
+          {
+            int c2 = phase1_getc ();
+            if (c2 == '=')
+              {
+                tp->type = token_type_operator2;
+                return;
+              }
+            else
+              phase1_ungetc (c2);
+            continue;
+          }
         case '(':
           tp->type = token_type_lparen;
           return;
@@ -559,7 +558,7 @@ phase3_get (token_ty *tp)
         case '"':
         case '\'':
           {
-            c_start = c;
+            int c_start = c;
             struct string_buffer buffer;
             sb_init (&buffer);
 
@@ -607,7 +606,7 @@ phase3_get (token_ty *tp)
                       case 'x':
                         {
                           int num = 0;
-                          int i = 0;
+                          int i;
 
                           for (i = 0; i < 2; i++)
                             {
@@ -681,43 +680,43 @@ phase3_get (token_ty *tp)
           break;
 
         case '[':
-          c = phase1_getc ();
-
-          /* Count the number of equal signs.  */
-          int esigns = 0;
-          while (c == '=')
-            {
-              esigns++;
-              c = phase1_getc ();
-            }
+          {
+            c = phase1_getc ();
 
-          if (c != '[')
-            {
-              /* We did not find what we were looking for, ungetc it.  */
-              phase1_ungetc (c);
-              if (esigns == 0)
-                {
-                  /* Our current character isn't '[' and we got 0 equal
-                     signs, so the first '[' must have been a left
-                     bracket.  */
-                  tp->type = token_type_lbracket;
-                  return;
-                }
-              else
-                /* Lexical error, ignore it.  */
-                continue;
-            }
+            /* Count the number of equal signs.  */
+            int esigns = 0;
+            while (c == '=')
+              {
+                esigns++;
+                c = phase1_getc ();
+              }
 
-          /* Found an opening long bracket.  */
-          {
-            struct string_buffer buffer;
-            sb_init (&buffer);
+            if (c != '[')
+              {
+                /* We did not find what we were looking for, ungetc it.  */
+                phase1_ungetc (c);
+                if (esigns == 0)
+                  {
+                    /* Our current character isn't '[' and we got 0 equal
+                       signs, so the first '[' must have been a left
+                       bracket.  */
+                    tp->type = token_type_lbracket;
+                    return;
+                  }
+                else
+                  /* Lexical error, ignore it.  */
+                  continue;
+              }
 
+            /* Found an opening long bracket.  */
             /* See if it is immediately followed by a newline.  */
             c = phase1_getc ();
             if (c != '\n')
               phase1_ungetc (c);
 
+            struct string_buffer buffer;
+            sb_init (&buffer);
+
             for (;;)
               {
                 c = phase1_getc ();
@@ -890,18 +889,18 @@ phase4_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase3_get (&token2);
+
           if (token2.type == token_type_doubledot)
             {
               token_ty token3;
-
               phase3_get (&token3);
+
               if (token3.type == token_type_string)
                 {
                   token_ty token_after;
-
                   phase3_get (&token_after);
+
                   if (token_after.type != token_type_operator1)
                     {
                       char *addend = token3.string;
@@ -946,13 +945,13 @@ phase5_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase4_get (&token2);
+
           if (token2.type == token_type_dot)
             {
               token_ty token3;
-
               phase4_get (&token3);
+
               if (token3.type == token_type_symbol)
                 {
                   char *addend = token3.string;
@@ -1044,7 +1043,6 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
   for (;;)
     {
       token_ty token;
-
       x_lua_lex (&token);
 
       switch (token.type)
@@ -1052,7 +1050,6 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
index 2157c1ad094291124f331afe69e1e81c474c2114..a436c91c58d9f23a5b8e44260e9941367a49f771 100644 (file)
@@ -77,19 +77,17 @@ x_modula2_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Modula-2
          identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -198,11 +196,11 @@ static int phase2_pushback_length;
 static int
 phase2_getc ()
 {
-  int c;
-
   if (phase2_pushback_length)
     return phase2_pushback[--phase2_pushback_length];
 
+  int c;
+
   c = phase1_getc ();
   if (c == '(')
     {
@@ -210,17 +208,12 @@ phase2_getc ()
       if (c == '*')
         {
           /* A comment.  */
-          int lineno;
           struct string_buffer buffer;
-          unsigned int nesting;
-          bool last_was_star;
-          bool last_was_opening_paren;
-
-          lineno = line_number;
           sb_init (&buffer);
-          nesting = 0;
-          last_was_star = false;
-          last_was_opening_paren = false;
+          int lineno = line_number;
+          unsigned int nesting = 0;
+          bool last_was_star = false;
+          bool last_was_opening_paren = false;
           for (;;)
             {
               c = phase1_getc ();
@@ -338,8 +331,6 @@ static int phase3_pushback_length;
 static void
 phase3_get (token_ty *tp)
 {
-  int c;
-
   if (phase3_pushback_length)
     {
       *tp = phase3_pushback[--phase3_pushback_length];
@@ -347,6 +338,8 @@ phase3_get (token_ty *tp)
     }
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase2_getc ();
 
@@ -549,13 +542,13 @@ phase4_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase3_get (&token2);
+
           if (token2.type == token_type_plus)
             {
               token_ty token3;
-
               phase3_get (&token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   sum = string_concat_free1 (sum, token3.string);
@@ -658,7 +651,6 @@ extract_parenthesized (message_list_ty *mlp,
   for (;;)
     {
       token_ty token;
-
       x_modula2_lex (&token);
 
       switch (token.type)
@@ -666,7 +658,6 @@ extract_parenthesized (message_list_ty *mlp,
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
index d7755d1fcdc21826b3ca7f917b7e6794e3984a30..c4b5873ae464f2dec65375e0533c17e125c9c3ea 100644 (file)
@@ -90,18 +90,16 @@ x_ocaml_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -359,8 +357,7 @@ is_string_literal (TSNode node)
         {
           uint32_t subnodes = 0;
           uint32_t last_subnode_index = 0;
-          uint32_t i;
-          for (i = 1; i < count - 1; i++)
+          for (uint32_t i = 1; i < count - 1; i++)
             {
               TSNode subnode = ts_node_child (node, i);
               if (ts_node_is_named (subnode)
@@ -393,8 +390,7 @@ string_literal_accumulate_pieces (TSNode node,
   if (ts_node_symbol (node) == ts_symbol_string)
     {
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           if (ts_node_symbol (subnode) == ts_symbol_string_content)
@@ -405,16 +401,14 @@ string_literal_accumulate_pieces (TSNode node,
               #if DEBUG_OCAML
               {
                 fprintf (stderr, "string_content children:\n");
-                uint32_t j;
-                for (j = 0; j < subcount; j++)
+                for (uint32_t j = 0; j < subcount; j++)
                   fprintf (stderr, "%u -> [%s]|%s|\n", j, ts_node_type (ts_node_child (subnode, j)), ts_node_string (ts_node_child (subnode, j)));
               }
               #endif
               /* Iterate over the children nodes of type escape_sequence.
                  Other children nodes, such as conversion_specification or
                  pretty_printing_indication, can be ignored.  */
-              uint32_t j;
-              for (j = 0; j < subcount; j++)
+              for (uint32_t j = 0; j < subcount; j++)
                 {
                   TSNode subsubnode = ts_node_child (subnode, j);
                   if (ts_node_symbol (subsubnode) == ts_symbol_escape_sequence)
@@ -467,8 +461,7 @@ string_literal_accumulate_pieces (TSNode node,
                         {
                           /* Only exactly 3 decimal digits are accepted.  */
                           unsigned int value = 0;
-                          const char *p;
-                          for (p = escape_start + 1; p < escape_end; p++)
+                          for (const char *p = escape_start + 1; p < escape_end; p++)
                             {
                               /* No overflow is possible.  */
                               char c = *p;
@@ -487,8 +480,7 @@ string_literal_accumulate_pieces (TSNode node,
                         {
                           /* Only exactly 2 hexadecimal digits are accepted.  */
                           unsigned int value = 0;
-                          const char *p;
-                          for (p = escape_start + 2; p < escape_end; p++)
+                          for (const char *p = escape_start + 2; p < escape_end; p++)
                             {
                               /* No overflow is possible.  */
                               char c = *p;
@@ -508,8 +500,7 @@ string_literal_accumulate_pieces (TSNode node,
                         {
                           /* Only exactly 3 octal digits are accepted.  */
                           unsigned int value = 0;
-                          const char *p;
-                          for (p = escape_start + 2; p < escape_end; p++)
+                          for (const char *p = escape_start + 2; p < escape_end; p++)
                             {
                               /* No overflow is possible.  */
                               char c = *p;
@@ -531,8 +522,7 @@ string_literal_accumulate_pieces (TSNode node,
                             {
                               /* 1 to 6 hexadecimal digits are accepted.  */
                               unsigned int value = 0;
-                              const char *p;
-                              for (p = escape_start + 3; p < escape_end - 1; p++)
+                              for (const char *p = escape_start + 3; p < escape_end - 1; p++)
                                 {
                                   /* No overflow is possible.  */
                                   char c = *p;
@@ -585,8 +575,7 @@ string_literal_accumulate_pieces (TSNode node,
   else if (ts_node_symbol (node) == ts_symbol_quoted_string)
     {
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           if (ts_node_symbol (subnode) == ts_symbol_quoted_string_content)
@@ -617,8 +606,7 @@ string_literal_accumulate_pieces (TSNode node,
          one non-comment node.  */
       if (!(count > 0))
         abort ();
-      uint32_t i;
-      for (i = 1; i < count - 1; i++)
+      for (uint32_t i = 1; i < count - 1; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           if (ts_node_is_named (subnode)
@@ -724,10 +712,9 @@ extract_from_function_call (TSNode function_node,
 
       /* Current argument number.  */
       uint32_t arg;
-      uint32_t i;
 
       arg = 0;
-      for (i = 0; i < args_count; i++)
+      for (uint32_t i = 0; i < args_count; i++)
         {
           TSNode arg_node = ts_node_child (args_node, i);
           handle_comments (arg_node);
@@ -791,9 +778,7 @@ extract_from_function_call (TSNode function_node,
 
   /* Recurse.  */
 
-  uint32_t i;
-
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -870,8 +855,7 @@ extract_from_node (TSNode node,
     {
       ignore = ignore || is_string_literal (node);
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           handle_comments (subnode);
@@ -930,9 +914,8 @@ extract_ocaml (FILE *f,
     }
 
   /* Read the file into memory.  */
-  char *contents_data;
   size_t contents_length;
-  contents_data = read_file (real_filename, 0, &contents_length);
+  char *contents_data = read_file (real_filename, 0, &contents_length);
   if (contents_data == NULL)
     error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
            real_filename);
index 4bcbc9923adca37d071eba4ce9394380807ba862..16a0159ee4021d679426a1061d7780b33ff65561 100644 (file)
@@ -94,18 +94,16 @@ x_perl_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -430,18 +428,15 @@ get_here_document (struct perl_extractor *xp, const char *delimiter)
   /* Accumulator for the entire here document, including a NUL byte
      at the end.  */
   struct string_buffer buffer;
+  sb_init (&buffer);
+
   /* Current line being appended.  */
   static char *my_linebuf = NULL;
   static size_t my_linebuf_size = 0;
 
-  sb_init (&buffer);
-
   for (;;)
     {
       int read_bytes = getline (&my_linebuf, &my_linebuf_size, xp->input.fp);
-      char *my_line_utf8;
-      bool chomp;
-
       if (read_bytes < 0)
         {
           if (ferror (xp->input.fp))
@@ -462,7 +457,7 @@ get_here_document (struct perl_extractor *xp, const char *delimiter)
       ++(xp->eaten_here);
 
       /* Convert to UTF-8.  */
-      my_line_utf8 =
+      char *my_line_utf8 =
         from_current_source_encoding (my_linebuf, lc_string, logical_file_name,
                                       xp->line_number + xp->eaten_here);
       if (my_line_utf8 != my_linebuf)
@@ -491,7 +486,7 @@ get_here_document (struct perl_extractor *xp, const char *delimiter)
         }
 
       /* Temporarily remove the trailing newline from my_linebuf.  */
-      chomp = false;
+      bool chomp = false;
       if (read_bytes >= 1 && my_linebuf[read_bytes - 1] == '\n')
         {
           chomp = true;
@@ -554,7 +549,6 @@ skip_pod (struct perl_extractor *xp)
 static int
 phase2_getc (struct perl_extractor *xp)
 {
-  int lineno;
   int c;
 
   c = phase1_getc (xp);
@@ -562,7 +556,7 @@ phase2_getc (struct perl_extractor *xp)
     {
       struct string_buffer buffer;
       sb_init (&buffer);
-      lineno = xp->line_number;
+      int lineno = xp->line_number;
       /* Skip leading whitespace.  */
       for (;;)
         {
@@ -741,13 +735,12 @@ static rw_string_desc_t
 extract_quotelike_pass1 (struct perl_extractor *xp, int delim)
 {
   struct string_buffer buffer;
-  bool nested = true;
-  int counter_delim;
-
   sb_init (&buffer);
   sb_xappend1 (&buffer, delim);
 
   /* Find the closing delimiter.  */
+  bool nested = true;
+  int counter_delim;
   switch (delim)
     {
     case '(':
@@ -864,8 +857,8 @@ extract_hex (const char *string, size_t len, unsigned int *result)
   for (i = 0; i < len; i++)
     {
       char c = string[i];
-      int number;
 
+      int number;
       if (c >= 'A' && c <= 'F')
         number = c - 'A' + 10;
       else if (c >= 'a' && c <= 'f')
@@ -895,8 +888,8 @@ extract_oct (const char *string, size_t len, unsigned int *result)
   for (i = 0; i < len; i++)
     {
       char c = string[i];
-      int number;
 
+      int number;
       if (c >= '0' && c <= '7')
         number = c - '0';
       else
@@ -935,14 +928,14 @@ static void
 extract_triple_quotelike (struct perl_extractor *xp, token_ty *tp, int delim,
                           bool interpolate)
 {
-  rw_string_desc_t string;
-
   tp->type = token_type_regex_op;
 
-  string = extract_quotelike_pass1_utf8 (xp, delim);
-  if (interpolate)
-    interpolate_keywords (xp, sd_readonly (string), xp->line_number);
-  sd_free (string);
+  {
+    rw_string_desc_t string = extract_quotelike_pass1_utf8 (xp, delim);
+    if (interpolate)
+      interpolate_keywords (xp, sd_readonly (string), xp->line_number);
+    sd_free (string);
+  }
 
   if (delim == '(' || delim == '<' || delim == '{' || delim == '[')
     {
@@ -956,10 +949,13 @@ extract_triple_quotelike (struct perl_extractor *xp, token_ty *tp, int delim,
           delim = phase2_getc (xp);
         }
     }
-  string = extract_quotelike_pass1_utf8 (xp, delim);
-  if (interpolate)
-    interpolate_keywords (xp, sd_readonly (string), xp->line_number);
-  sd_free (string);
+
+  {
+    rw_string_desc_t string = extract_quotelike_pass1_utf8 (xp, delim);
+    if (interpolate)
+      interpolate_keywords (xp, sd_readonly (string), xp->line_number);
+    sd_free (string);
+  }
 }
 
 /* Perform pass 3 of quotelike extraction (interpolation).
@@ -971,12 +967,6 @@ extract_triple_quotelike (struct perl_extractor *xp, token_ty *tp, int delim,
 static void
 extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
 {
-  struct string_buffer buffer;
-  const char *crs;
-  bool uppercase;
-  bool lowercase;
-  bool quotemeta;
-
   #if DEBUG_PERL
   switch (tp->sub_type)
     {
@@ -1001,17 +991,16 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
   if (tp->sub_type == string_type_verbatim)
     return;
 
+  struct string_buffer buffer;
   sb_init (&buffer);
 
   /* Loop over tp->string, accumulating the expansion in buffer.  */
-  crs = tp->string;
-  uppercase = false;
-  lowercase = false;
-  quotemeta = false;
+  const char *crs = tp->string;
+  bool uppercase = false;
+  bool lowercase = false;
+  bool quotemeta = false;
   while (*crs)
     {
-      bool backslashed;
-
       if (tp->sub_type == string_type_q)
         {
           switch (*crs)
@@ -1069,7 +1058,6 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
             case '4': case '5': case '6': case '7':
               {
                 unsigned int oct_number;
-
                 crs = extract_oct (crs + 1, 3, &oct_number);
 
                 /* FIXME: If one of the variables UPPERCASE or LOWERCASE is
@@ -1098,9 +1086,9 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
               continue;
             case 'x':
               {
-                unsigned int hex_number = 0;
-
                 crs += 2;
+
+                unsigned int hex_number = 0;
                 if (*crs == '{')
                   {
                     const char *end = strchr (crs, '}');
@@ -1164,14 +1152,11 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
                   const char *end = strchr (crs + 1, '}');
                   if (end != NULL)
                     {
-                      char *name;
-                      unsigned int unicode;
-
-                      name = XNMALLOC (end - (crs + 1) + 1, char);
+                      char *name = XNMALLOC (end - (crs + 1) + 1, char);
                       memcpy (name, crs + 1, end - (crs + 1));
                       name[end - (crs + 1)] = '\0';
 
-                      unicode = unicode_name_character (name);
+                      unsigned int unicode = unicode_name_character (name);
                       if (unicode != UNINAME_INVALID)
                         {
                           /* FIXME: Convert to upper/lowercase if the
@@ -1194,6 +1179,7 @@ extract_quotelike_pass3 (struct perl_extractor *xp, token_ty *tp)
         }
 
       /* No escape sequence, go on.  */
+      bool backslashed;
       if (*crs == '\\')
         {
           ++crs;
@@ -1344,10 +1330,6 @@ static void
 extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
 {
   struct string_buffer buffer;
-  size_t varbody_length = 0;
-  bool maybe_hash_deref = false;
-  bool maybe_hash_value = false;
-
   sb_init (&buffer);
 
   tp->type = token_type_variable;
@@ -1357,6 +1339,10 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
            real_file_name, xp->line_number, first);
   #endif
 
+  size_t varbody_length = 0;
+  bool maybe_hash_deref = false;
+  bool maybe_hash_value = false;
+
   /*
    * 1) Consume dollars and so on (not euros ...).  Unconditionally
    *    accepting the hash sign (#) will maybe lead to inaccurate
@@ -1486,13 +1472,13 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
 
   if (maybe_hash_deref || maybe_hash_value)
     {
-      bool is_dereference = false;
       int c;
 
       do
         c = phase2_getc (xp);
       while (is_whitespace (c));
 
+      bool is_dereference = false;
       if (c == '-')
         {
           int c2 = phase1_getc (xp);
@@ -1532,13 +1518,12 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
       /* Do NOT change that into else if (see above).  */
       if ((maybe_hash_value || maybe_hash_deref) && c == '{')
         {
-          void *keyword_value;
-
           #if DEBUG_PERL
           fprintf (stderr, "%s:%d: first keys preceded by '{'\n",
                    real_file_name, xp->line_number);
           #endif
 
+          void *keyword_value;
           if (hash_find_entry (&keywords, tp->string, strlen (tp->string),
                                &keyword_value) == 0)
             {
@@ -1581,14 +1566,12 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
                     token_ty *t2 = x_perl_lex (xp);
                     if (t2->type == token_type_rbrace)
                       {
-                        flag_region_ty *region;
-                        lex_pos_ty pos;
-
-                        region =
+                        flag_region_ty *region =
                           inheriting_region (null_context_region (),
                                              flag_context_list_iterator_advance (
                                                &context_iter));
 
+                        lex_pos_ty pos;
                         pos.line_number = xp->line_number;
                         pos.file_name = logical_file_name;
 
@@ -1630,7 +1613,6 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
   for (;;)
     {
       int c = phase2_getc (xp);
-      int c2;
 
       switch (c)
         {
@@ -1659,23 +1641,25 @@ extract_variable (struct perl_extractor *xp, token_ty *tp, int first)
           break;
 
         case '-':
-          c2 = phase1_getc (xp);
-          if (c2 == '>')
-            {
-              #if DEBUG_PERL
-              fprintf (stderr, "%s:%d: another \"->\" after varname\n",
-                       real_file_name, xp->line_number);
-              #endif
-              break;
-            }
-          else if (c2 != '\n')
-            {
-              /* Discarding the newline is harmless here.  The only
-                 special character recognized after a minus is greater-than
-                 for dereference.  However, the sequence "-\n>" that we
-                 treat incorrectly here, is a syntax error.  */
-              phase1_ungetc (xp, c2);
-            }
+          {
+            int c2 = phase1_getc (xp);
+            if (c2 == '>')
+              {
+                #if DEBUG_PERL
+                fprintf (stderr, "%s:%d: another \"->\" after varname\n",
+                         real_file_name, xp->line_number);
+                #endif
+                break;
+              }
+            else if (c2 != '\n')
+              {
+                /* Discarding the newline is harmless here.  The only
+                   special character recognized after a minus is greater-than
+                   for dereference.  However, the sequence "-\n>" that we
+                   treat incorrectly here, is a syntax error.  */
+                phase1_ungetc (xp, c2);
+              }
+          }
           FALLTHROUGH;
 
         default:
@@ -1696,40 +1680,16 @@ static void
 interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
                       int lineno)
 {
-  struct string_buffer buffer;
-  flag_region_ty *region;
-  size_t length;
-  size_t index;
-  char c;
-  bool maybe_hash_deref = false;
-  enum parser_state
-    {
-      initial,
-      one_dollar,
-      two_dollars,
-      identifier,
-      seen_lbracket,
-      lbracket_dquote,
-      lbracket_squote,
-      minus,
-      wait_lbrace,
-      seen_lbrace,
-      lbrace_dquote,
-      lbrace_squote,
-      lbrace_barekey,
-      wait_rbrace
-    } state;
-  token_ty token;
-
-  lex_pos_ty pos;
-
-  sb_init (&buffer);
-
   if (++(xp->nesting_depth) > MAX_NESTING_DEPTH)
     if_error (IF_SEVERITY_FATAL_ERROR,
               logical_file_name, xp->line_number, (size_t)(-1), false,
               _("too deeply nested expressions"));
 
+  struct string_buffer buffer;
+  sb_init (&buffer);
+
+  bool maybe_hash_deref = false;
+
   /* States are:
    *
    * initial:           initial
@@ -1756,12 +1716,31 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
    * in the states minus...wait_rbrace the context is the one suitable for the
    * first argument of the last seen identifier.
    */
-  state = initial;
-  region = null_context_region ();
+  enum parser_state
+    {
+      initial,
+      one_dollar,
+      two_dollars,
+      identifier,
+      seen_lbracket,
+      lbracket_dquote,
+      lbracket_squote,
+      minus,
+      wait_lbrace,
+      seen_lbrace,
+      lbrace_dquote,
+      lbrace_squote,
+      lbrace_barekey,
+      wait_rbrace
+    }
+    state = initial;
 
-  length = sd_length (string);
-  index = 0;
+  flag_region_ty *region = null_context_region ();
 
+  size_t length = sd_length (string);
+  size_t index = 0;
+
+  token_ty token;
   token.type = token_type_string;
   token.sub_type = string_type_qq;
   token.line_number = xp->line_number;
@@ -1769,12 +1748,13 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
      We can let token.comment uninitialized here, and use savable_comment
      directly, because this function only parses the given string and does
      not call phase2_getc.  */
+  lex_pos_ty pos;
   pos.file_name = logical_file_name;
   pos.line_number = lineno;
 
   while (index < length)
     {
-      void *keyword_value;
+      char c;
 
       c = sd_char_at (string, index++);
       if (state == initial)
@@ -1851,6 +1831,7 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
             case '-':
               {
                 string_desc_t contents = sb_contents (&buffer);
+                void *keyword_value;
                 if (hash_find_entry (&keywords,
                                      sd_data (contents),
                                      sd_length (contents),
@@ -1882,6 +1863,7 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
                 string_desc_t contents = sb_contents (&buffer);
                 if (!maybe_hash_deref)
                   ((char *) sd_data (contents))[0] = '%';
+                void *keyword_value;
                 if (hash_find_entry (&keywords,
                                      sd_data (contents),
                                      sd_length (contents),
@@ -2290,10 +2272,10 @@ prefer_regexp_over_division (token_type_ty type)
 static void
 x_perl_prelex (struct perl_extractor *xp, token_ty *tp)
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       c = phase2_getc (xp);
       tp->line_number = xp->line_number;
       tp->last_type = xp->last_token_type;
@@ -2663,9 +2645,8 @@ x_perl_prelex (struct perl_extractor *xp, token_ty *tp)
               c = phase1_getc (xp);
               if (c == '\'')
                 {
-                  char *string;
                   extract_quotelike (xp, tp, c);
-                  string = get_here_document (xp, tp->string);
+                  char *string = get_here_document (xp, tp->string);
                   free (tp->string);
                   tp->string = string;
                   tp->type = token_type_string;
@@ -2675,9 +2656,8 @@ x_perl_prelex (struct perl_extractor *xp, token_ty *tp)
                 }
               else if (c == '"')
                 {
-                  char *string;
                   extract_quotelike (xp, tp, c);
-                  string = get_here_document (xp, tp->string);
+                  char *string = get_here_document (xp, tp->string);
                   free (tp->string);
                   tp->string = string;
                   tp->type = token_type_string;
@@ -2709,9 +2689,9 @@ x_perl_prelex (struct perl_extractor *xp, token_ty *tp)
                     }
                   else
                     {
-                      char *string;
                       phase1_ungetc (xp, c);
-                      string = get_here_document (xp, sb_xdupfree_c (&buffer));
+                      char *string =
+                        get_here_document (xp, sb_xdupfree_c (&buffer));
                       tp->string = string;
                       tp->type = token_type_string;
                       tp->sub_type = string_type_qq;
@@ -2797,10 +2777,8 @@ x_perl_prelex (struct perl_extractor *xp, token_ty *tp)
 static int
 token_stack_dump (token_stack_ty *stack)
 {
-  size_t i;
-
   fprintf (stderr, "BEGIN STACK DUMP\n");
-  for (i = 0; i < stack->nitems; i++)
+  for (size_t i = 0; i < stack->nitems; i++)
     {
       token_ty *token = stack->items[i];
       fprintf (stderr, "  [%s]\n", token2string (token));
@@ -2829,10 +2807,8 @@ token_stack_push (token_stack_ty *stack, token_ty *token)
 {
   if (stack->nitems >= stack->nitems_max)
     {
-      size_t nbytes;
-
       stack->nitems_max = 2 * stack->nitems_max + 4;
-      nbytes = stack->nitems_max * sizeof (token_ty *);
+      size_t nbytes = stack->nitems_max * sizeof (token_ty *);
       stack->items = xrealloc (stack->items, nbytes);
     }
   stack->items[stack->nitems++] = token;
@@ -2864,9 +2840,7 @@ token_stack_peek (const token_stack_ty *stack)
 static inline void
 token_stack_free (token_stack_ty *stack)
 {
-  size_t i;
-
-  for (i = 0; i < stack->nitems; i++)
+  for (size_t i = 0; i < stack->nitems; i++)
     free_token (stack->items[i]);
   free (stack->items);
 }
@@ -3020,13 +2994,14 @@ x_perl_lex (struct perl_extractor *xp)
              characters is allowed inside parentheses but we leave
              complaints to the interpreter and are prepared for
              future extensions to the Perl syntax.  */
-          int c;
 
           #if DEBUG_PERL
           fprintf (stderr, "%s:%d: consuming prototype information\n",
                    real_file_name, xp->line_number);
           #endif
 
+          int c;
+
           do
             {
               c = phase1_getc (xp);
@@ -3060,10 +3035,10 @@ x_perl_unlex (struct perl_extractor *xp, token_ty *tp)
 static char *
 collect_message (struct perl_extractor *xp, token_ty *tp)
 {
+  extract_quotelike_pass3 (xp, tp);
+
   char *string;
   size_t len;
-
-  extract_quotelike_pass3 (xp, tp);
   if (tp->type == token_type_string)
     {
       string = xstrdup (tp->string);
@@ -3248,9 +3223,7 @@ extract_balanced (struct perl_extractor *xp,
   for (;;)
     {
       /* The current token.  */
-      token_ty *tp;
-
-      tp = x_perl_lex (xp);
+      token_ty *tp = x_perl_lex (xp);
 
       if (first)
         {
@@ -3315,19 +3288,16 @@ extract_balanced (struct perl_extractor *xp,
       if (next_is_argument && tp->type != token_type_lparen)
         {
           /* An argument list starts, even though there is no '('.  */
-          bool next_comma_delim;
-
           x_perl_unlex (xp, tp);
 
+          bool next_comma_delim;
           if (next_shapes != NULL)
             /* We know something about the function being called.  Assume
                that it consumes only one argument if no argument number or
                total > 1 is specified.  */
             {
-              size_t i;
-
               next_comma_delim = true;
-              for (i = 0; i < next_shapes->nshapes; i++)
+              for (size_t i = 0; i < next_shapes->nshapes; i++)
                 {
                   const struct callshape *shape = &next_shapes->shapes[i];
 
@@ -3387,7 +3357,6 @@ extract_balanced (struct perl_extractor *xp,
 
               {
                 void *keyword_value;
-
                 if (hash_find_entry (&keywords, tp->string, strlen (tp->string),
                                      &keyword_value) == 0)
                   {
@@ -3561,9 +3530,9 @@ extract_balanced (struct perl_extractor *xp,
                   if (string != NULL)
                     {
                       lex_pos_ty pos;
-
                       pos.file_name = logical_file_name;
                       pos.line_number = tp->line_number;
+
                       remember_a_message (xp->mlp, NULL, string, true, false,
                                           inner_region, &pos, NULL, tp->comment,
                                           true);
@@ -3576,9 +3545,8 @@ extract_balanced (struct perl_extractor *xp,
                   bool must_collect = false;
                   {
                     size_t nalternatives = argparser->nalternatives;
-                    size_t i;
 
-                    for (i = 0; i < nalternatives; i++)
+                    for (size_t i = 0; i < nalternatives; i++)
                       {
                         struct partial_call *cp = &argparser->alternative[i];
 
index a921f019ea5f010c93a03f7e519caf65fde6e413..1e7b1fbc111d6151835841b61a65b7984a35cbbf 100644 (file)
@@ -82,18 +82,16 @@ x_php_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -527,11 +525,11 @@ skip_html (struct php_extractor *xp)
 static int
 phase2_getc (struct php_extractor *xp)
 {
-  int c;
-
   if (xp->phase2_pushback_length)
     return xp->phase2_pushback[--(xp->phase2_pushback_length)];
 
+  int c;
+
   c = phase1_getc (xp);
   switch (c)
     {
@@ -659,7 +657,6 @@ comment_line_end (struct php_extractor *xp, size_t chars_to_remove)
 static int
 phase3_getc (struct php_extractor *xp)
 {
-  int lineno;
   int c;
 
   if (xp->phase3_pushback_length)
@@ -670,10 +667,9 @@ phase3_getc (struct php_extractor *xp)
   if (c == '#')
     {
       /* sh comment.  */
-      bool last_was_qmark = false;
-
       comment_start (xp);
-      lineno = xp->line_number;
+      int lineno = xp->line_number;
+      bool last_was_qmark = false;
       for (;;)
         {
           c = phase1_getc (xp);
@@ -709,11 +705,9 @@ phase3_getc (struct php_extractor *xp)
         case '*':
           {
             /* C comment.  */
-            bool last_was_star;
-
             comment_start (xp);
-            lineno = xp->line_number;
-            last_was_star = false;
+            int lineno = xp->line_number;
+            bool last_was_star = false;
             for (;;)
               {
                 c = phase1_getc (xp);
@@ -757,10 +751,9 @@ phase3_getc (struct php_extractor *xp)
         case '/':
           {
             /* C++ comment.  */
-            bool last_was_qmark = false;
-
             comment_start (xp);
-            lineno = xp->line_number;
+            int lineno = xp->line_number;
+            bool last_was_qmark = false;
             for (;;)
               {
                 c = phase1_getc (xp);
@@ -877,8 +870,6 @@ process_dquote_or_heredoc (struct php_extractor *xp, bool heredoc)
           }
         if (c == '\\')
           {
-            int n, j;
-
             c = phase1_getc (xp);
             switch (c)
               {
@@ -888,60 +879,65 @@ process_dquote_or_heredoc (struct php_extractor *xp, bool heredoc)
 
               case '0': case '1': case '2': case '3':
               case '4': case '5': case '6': case '7':
-                n = 0;
-                for (j = 0; j < 3; ++j)
-                  {
-                    n = n * 8 + c - '0';
-                    c = phase1_getc (xp);
-                    switch (c)
-                      {
-                      default:
-                        break;
+                {
+                  int n = 0;
+                  for (int j = 0; j < 3; ++j)
+                    {
+                      n = n * 8 + c - '0';
+                      c = phase1_getc (xp);
+                      switch (c)
+                        {
+                        default:
+                          break;
 
-                      case '0': case '1': case '2': case '3':
-                      case '4': case '5': case '6': case '7':
-                        continue;
-                      }
-                    break;
-                  }
-                phase1_ungetc (xp, c);
-                c = n;
+                        case '0': case '1': case '2': case '3':
+                        case '4': case '5': case '6': case '7':
+                          continue;
+                        }
+                      break;
+                    }
+                  phase1_ungetc (xp, c);
+                  c = n;
+                }
                 break;
 
               case 'x':
-                n = 0;
-                for (j = 0; j < 2; ++j)
-                  {
-                    c = phase1_getc (xp);
-                    switch (c)
-                      {
-                      case '0': case '1': case '2': case '3': case '4':
-                      case '5': case '6': case '7': case '8': case '9':
-                        n = n * 16 + c - '0';
-                        break;
-                      case 'A': case 'B': case 'C': case 'D': case 'E':
-                      case 'F':
-                        n = n * 16 + 10 + c - 'A';
-                        break;
-                      case 'a': case 'b': case 'c': case 'd': case 'e':
-                      case 'f':
-                        n = n * 16 + 10 + c - 'a';
-                        break;
-                      default:
-                        phase1_ungetc (xp, c);
-                        c = 0;
+                {
+                  int j;
+                  int n = 0;
+                  for (j = 0; j < 2; ++j)
+                    {
+                      c = phase1_getc (xp);
+                      switch (c)
+                        {
+                        case '0': case '1': case '2': case '3': case '4':
+                        case '5': case '6': case '7': case '8': case '9':
+                          n = n * 16 + c - '0';
+                          break;
+                        case 'A': case 'B': case 'C': case 'D': case 'E':
+                        case 'F':
+                          n = n * 16 + 10 + c - 'A';
+                          break;
+                        case 'a': case 'b': case 'c': case 'd': case 'e':
+                        case 'f':
+                          n = n * 16 + 10 + c - 'a';
+                          break;
+                        default:
+                          phase1_ungetc (xp, c);
+                          c = 0;
+                          break;
+                        }
+                      if (c == 0)
                         break;
-                      }
-                    if (c == 0)
-                      break;
-                  }
-                if (j == 0)
-                  {
-                    phase1_ungetc (xp, 'x');
-                    c = '\\';
-                  }
-                else
-                  c = n;
+                    }
+                  if (j == 0)
+                    {
+                      phase1_ungetc (xp, 'x');
+                      c = '\\';
+                    }
+                  else
+                    c = n;
+                }
                 break;
 
               case 'n':
@@ -1058,8 +1054,6 @@ process_dquote_or_heredoc (struct php_extractor *xp, bool heredoc)
 static void
 phase4_get (struct php_extractor *xp, token_ty *tp)
 {
-  int c;
-
   if (xp->phase4_pushback_length)
     {
       *tp = xp->phase4_pushback[--(xp->phase4_pushback_length)];
@@ -1069,6 +1063,8 @@ phase4_get (struct php_extractor *xp, token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = xp->line_number;
       c = phase3_getc (xp);
       switch (c)
@@ -1448,11 +1444,10 @@ phase4_get (struct php_extractor *xp, token_ty *tp)
                     if (end_label_indent > 0)
                       {
                         /* Scan through the doc string, copying *q = *p.  */
-                        const char *p;
                         char *q = doc;
                         int curr_line_indent = 0;
 
-                        for (p = doc; p < doc + doc_len; p++)
+                        for (const char *p = doc; p < doc + doc_len; p++)
                           {
                             /* Invariant: doc <= q <= p <= doc + doc_len.  */
                             char d = *p;
@@ -1640,18 +1635,18 @@ x_php_lex (struct php_extractor *xp, token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase4_get (xp, &token2);
+
           if (token2.type == token_type_dot)
             {
               token_ty token3;
-
               phase4_get (xp, &token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   token_ty token_after;
-
                   phase4_get (xp, &token_after);
+
                   if (token_after.type != token_type_operator1)
                     {
                       char *addend = token3.string;
@@ -1733,14 +1728,13 @@ extract_balanced (struct php_extractor *xp,
   for (;;)
     {
       token_ty token;
-
       x_php_lex (xp, &token);
+
       switch (token.type)
         {
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
index 7d826d269d71fa8f5b5a215ef887713171d6197f..d8aa2a7195b77afbf5489b447138a0952b7eb99b 100644 (file)
@@ -76,12 +76,10 @@ extract_add_message (default_catalog_reader_ty *this,
 
         if (charsetstr != NULL)
           {
-            size_t len;
-            char *charset;
-
             charsetstr += strlen ("charset=");
-            len = strcspn (charsetstr, " \t\n");
-            charset = XNMALLOC (len + 1, char);
+            size_t len = strcspn (charsetstr, " \t\n");
+
+            char *charset = XNMALLOC (len + 1, char);
             memcpy (charset, charsetstr, len);
             charset[len] = '\0';
 
index 3ae7374ca9e0ac08ba8d554cdadfc40479a93151..be9686b2bc22d251a8346586e56e7e824632a814 100644 (file)
@@ -95,18 +95,16 @@ x_python_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -334,8 +332,6 @@ as specified in https://www.python.org/peps/pep-0263.html.\n")));
               else if (errno == EINVAL)
                 {
                   /* An incomplete multibyte character.  */
-                  int c;
-
                   if (bufcount == MAX_PHASE1_PUSHBACK)
                     {
                       /* An overlong incomplete multibyte sequence was
@@ -350,7 +346,7 @@ comment as specified in https://www.python.org/peps/pep-0263.html.\n"),
                     }
 
                   /* Read one more byte and retry iconv.  */
-                  c = phase1_getc ();
+                  int c = phase1_getc ();
                   if (c == EOF)
                     goto incomplete_at_eof;
                   if (c == '\n')
@@ -366,7 +362,6 @@ comment as specified in https://www.python.org/peps/pep-0263.html.\n"),
             {
               size_t outbytes = sizeof (scratchbuf) - outsize;
               size_t bytes = bufcount - insize;
-              ucs4_t uc;
 
               /* We expect that one character has been produced.  */
               if (bytes == 0)
@@ -377,6 +372,7 @@ comment as specified in https://www.python.org/peps/pep-0263.html.\n"),
               while (insize > 0)
                 phase1_ungetc (buf[--insize]);
               /* Convert the character from UTF-8 to UCS-4.  */
+              ucs4_t uc;
               if (u8_mbtoucr (&uc, scratchbuf, outbytes) < (int) outbytes)
                 {
                   /* scratchbuf contains an out-of-range Unicode character
@@ -666,8 +662,8 @@ try_to_extract_coding (const char *comment)
                 {
                   /* Extract the encoding string.  */
                   size_t encoding_len = encoding_end - encoding_start;
-                  char *encoding = XNMALLOC (encoding_len + 1, char);
 
+                  char *encoding = XNMALLOC (encoding_len + 1, char);
                   memcpy (encoding, encoding_start, encoding_len);
                   encoding[encoding_len] = '\0';
 
@@ -706,10 +702,10 @@ static bool continuation_or_nonblank_line;
 static int
 phase3_getc ()
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       c = phase2_getc ();
       if (c == '\\')
         {
@@ -727,8 +723,6 @@ phase3_getc ()
       else if (c == '#')
         {
           /* Eat a comment.  */
-          const char *comment;
-
           last_comment_line = line_number;
           comment_start ();
           for (;;)
@@ -740,7 +734,7 @@ phase3_getc ()
               if (!(comment_at_start () && (c == ' ' || c == '\t')))
                 comment_add (c);
             }
-          comment = comment_line_end ();
+          const char *comment = comment_line_end ();
           if (line_number - 1 <= 2 && !continuation_or_nonblank_line)
             try_to_extract_coding (comment);
           continuation_or_nonblank_line = false;
@@ -851,10 +845,10 @@ phase7_getuc (int quote_char,
               bool f_string,
               unsigned int *backslash_counter)
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       /* Use phase 2, because phase 3 elides comments.  */
       c = phase2_getc ();
 
@@ -1012,8 +1006,8 @@ phase7_getuc (int quote_char,
           case 'x':
             {
               int c1 = phase2_getc ();
-              int n1;
 
+              int n1;
               if (c1 >= '0' && c1 <= '9')
                 n1 = c1 - '0';
               else if (c1 >= 'A' && c1 <= 'F')
@@ -1026,8 +1020,8 @@ phase7_getuc (int quote_char,
               if (n1 >= 0)
                 {
                   int c2 = phase2_getc ();
-                  int n2;
 
+                  int n2;
                   if (c2 >= '0' && c2 <= '9')
                     n2 = c2 - '0';
                   else if (c2 >= 'A' && c2 <= 'F')
@@ -1068,9 +1062,8 @@ phase7_getuc (int quote_char,
             {
               unsigned char buf[4];
               unsigned int n = 0;
-              int i;
 
-              for (i = 0; i < 4; i++)
+              for (int i = 0; i < 4; i++)
                 {
                   int c1 = phase2_getc ();
 
@@ -1148,7 +1141,6 @@ phase7_getuc (int quote_char,
                 {
                   unsigned char buf[UNINAME_MAX + 1];
                   int i;
-                  unsigned int n;
 
                   for (i = 0; i < UNINAME_MAX; i++)
                     {
@@ -1169,7 +1161,7 @@ phase7_getuc (int quote_char,
                     }
                   buf[i] = '\0';
 
-                  n = unicode_name_character ((char *) buf);
+                  unsigned int n = unicode_name_character ((char *) buf);
                   if (n != UNINAME_INVALID)
                     {
                       *backslash_counter = 0;
@@ -1247,8 +1239,6 @@ static int phase5_pushback_length;
 static void
 phase5_get (token_ty *tp)
 {
-  int c;
-
   if (phase5_pushback_length)
     {
       *tp = phase5_pushback[--phase5_pushback_length];
@@ -1257,6 +1247,8 @@ phase5_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase3_getc ();
 
@@ -1316,7 +1308,6 @@ phase5_get (token_ty *tp)
           /* Symbol, or part of a number.  */
           {
             struct string_buffer buffer;
-
             sb_init (&buffer);
             for (;;)
               {
@@ -1484,10 +1475,10 @@ phase5_get (token_ty *tp)
               backslash_counter = 0;
               {
                 struct mixed_string_buffer msb;
-
                 /* Start accumulating the string.  */
                 mixed_string_buffer_init (&msb, lexical_context,
                                           logical_file_name, line_number);
+
                 for (;;)
                   {
                     int uc = phase7_getuc (quote_char, triple, interpret_ansic,
@@ -1636,15 +1627,17 @@ x_python_lex (token_ty *tp)
       for (;;)
         {
           token_ty token2;
+          phase5_get (&token2);
+
           token_ty token3;
           token_ty *tp2 = NULL;
 
-          phase5_get (&token2);
           switch (token2.type)
             {
             case token_type_plus:
               {
                 phase5_get (&token3);
+
                 if (token3.type == token_type_string
                     || token3.type == token_type_498)
                   {
@@ -1740,14 +1733,13 @@ extract_balanced (message_list_ty *mlp,
   for (;;)
     {
       token_ty token;
-
       x_python_lex (&token);
+
       switch (token.type)
         {
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
@@ -1841,7 +1833,6 @@ extract_balanced (message_list_ty *mlp,
         case token_type_498:
           {
             lex_pos_ty pos;
-
             pos.file_name = logical_file_name;
             pos.line_number = token.line_number;
 
index 2245aa3428401443c1fdab180a8238a6f5a9ba5c..4b069849a7a3191dfe37f761e81dd090489376d1 100644 (file)
@@ -70,15 +70,11 @@ extract_rst (FILE *f,
              msgdomain_list_ty *mdlp)
 {
   message_list_ty *mlp = mdlp->item[0]->messages;
-  int line_number;
 
-  line_number = 1;
+  int line_number = 1;
   for (;;)
     {
       int c;
-      char *location;
-      char *msgid;
-      lex_pos_ty pos;
 
       c = getc (f);
       if (c == EOF)
@@ -104,6 +100,7 @@ extract_rst (FILE *f,
         }
 
       /* Read ModuleName.ConstName.  */
+      char *location;
       {
         struct string_buffer buffer;
         sb_init (&buffer);
@@ -127,6 +124,7 @@ extract_rst (FILE *f,
       }
 
       /* Read StringExpression.  */
+      char *msgid;
       {
         struct string_buffer buffer;
         sb_init (&buffer);
@@ -161,7 +159,6 @@ extract_rst (FILE *f,
               }
             else if (c == '#')
               {
-                int n;
                 c = getc (f);
                 if (c == EOF && ferror (f))
                   {
@@ -172,7 +169,7 @@ extract_rst (FILE *f,
                   if_error (IF_SEVERITY_FATAL_ERROR,
                             logical_filename, line_number, (size_t)(-1), false,
                             _("missing number after #"));
-                n = (c - '0');
+                int n = (c - '0');
                 for (;;)
                   {
                     c = getc (f);
@@ -203,6 +200,7 @@ extract_rst (FILE *f,
         msgid = sb_xdupfree_c (&buffer);
       }
 
+      lex_pos_ty pos;
       pos.file_name = location;
       pos.line_number = (size_t)(-1);
 
@@ -344,9 +342,10 @@ static enum parse_result
 parse_integer ()
   _GL_ATTRIBUTE_ACQUIRE_CAPABILITY (buffer.data)
 {
+  sb_init (&buffer);
+
   int c;
 
-  sb_init (&buffer);
   c = phase2_getc ();
   for (;;)
     {
@@ -374,6 +373,7 @@ parse_string ()
       phase2_ungetc (c);
       return pr_none;
     }
+
   mixed_string_buffer_init (&stringbuf, lc_string,
                             logical_file_name, line_number);
   for (;;)
@@ -391,9 +391,8 @@ parse_string ()
           if (c == 'u')
             {
               unsigned int n = 0;
-              int i;
 
-              for (i = 0; i < 4; i++)
+              for (int i = 0; i < 4; i++)
                 {
                   c = phase1_getc ();
 
@@ -450,7 +449,6 @@ extract_rsj (FILE *f,
              msgdomain_list_ty *mdlp)
 {
   message_list_ty *mlp = mdlp->item[0]->messages;
-  int c;
 
   fp = f;
   real_file_name = real_filename;
@@ -460,197 +458,200 @@ extract_rsj (FILE *f,
   /* JSON is always in UTF-8.  */
   xgettext_current_source_encoding = po_charset_utf8;
 
-  /* Parse the initial opening brace.  */
-  c = phase2_getc ();
-  if (c != '{')
-    goto invalid_json;
+  {
+    int c;
 
-  c = phase2_getc ();
-  if (c != '}')
-    {
-      phase2_ungetc (c);
-      for (;;)
-        {
-          /* Parse a string.  */
-          char *s1;
-          if (parse_string () != pr_parsed)
-            goto invalid_json;
-          s1 = mixed_string_contents_free1 (
-                 mixed_string_buffer_result (&stringbuf));
-
-          /* Parse a colon.  */
-          c = phase2_getc ();
-          if (c != ':')
-            goto invalid_json;
-
-          if (strcmp (s1, "version") == 0)
-            {
-              /* Parse an integer.  */
-              if (parse_integer () != pr_parsed)
-                {
-                  sb_free (&buffer);
+    /* Parse the initial opening brace.  */
+    c = phase2_getc ();
+    if (c != '{')
+      goto invalid_json;
+
+    c = phase2_getc ();
+    if (c != '}')
+      {
+        phase2_ungetc (c);
+        for (;;)
+          {
+            /* Parse a string.  */
+            if (parse_string () != pr_parsed)
+              goto invalid_json;
+            char *s1 = mixed_string_contents_free1 (
+                         mixed_string_buffer_result (&stringbuf));
+
+            /* Parse a colon.  */
+            c = phase2_getc ();
+            if (c != ':')
+              goto invalid_json;
+
+            if (strcmp (s1, "version") == 0)
+              {
+                /* Parse an integer.  */
+                if (parse_integer () != pr_parsed)
+                  {
+                    sb_free (&buffer);
+                    goto invalid_rsj;
+                  }
+                if (strcmp (sb_xcontents_c (&buffer), "1") != 0)
+                  {
+                    sb_free (&buffer);
+                    goto invalid_rsj_version;
+                  }
+                sb_free (&buffer);
+              }
+            else if (strcmp (s1, "strings") == 0)
+              {
+                /* Parse an array.  */
+                c = phase2_getc ();
+                if (c != '[')
                   goto invalid_rsj;
-                }
-              if (strcmp (sb_xcontents_c (&buffer), "1") != 0)
-                {
-                  sb_free (&buffer);
-                  goto invalid_rsj_version;
-                }
-              sb_free (&buffer);
-            }
-          else if (strcmp (s1, "strings") == 0)
-            {
-              /* Parse an array.  */
-              c = phase2_getc ();
-              if (c != '[')
-                goto invalid_rsj;
 
-              c = phase2_getc ();
-              if (c != ']')
-                {
-                  phase2_ungetc (c);
-                  for (;;)
-                    {
-                      char *location = NULL;
-                      char *msgid = NULL;
-                      lex_pos_ty pos;
-
-                      /* Parse an object.  */
-                      c = phase2_getc ();
-                      if (c != '{')
-                        goto invalid_rsj;
-
-                      c = phase2_getc ();
-                      if (c != '}')
-                        {
-                          phase2_ungetc (c);
-                          for (;;)
-                            {
-                              /* Parse a string.  */
-                              char *s2;
-                              if (parse_string () != pr_parsed)
-                                goto invalid_json;
-                              s2 = mixed_string_contents_free1 (
-                                     mixed_string_buffer_result (&stringbuf));
-
-                              /* Parse a colon.  */
-                              c = phase2_getc ();
-                              if (c != ':')
-                                goto invalid_json;
-
-                              if (strcmp (s2, "hash") == 0)
-                                {
-                                  /* Parse an integer.  */
-                                  if (parse_integer () != pr_parsed)
-                                    {
-                                      sb_free (&buffer);
+                c = phase2_getc ();
+                if (c != ']')
+                  {
+                    phase2_ungetc (c);
+                    for (;;)
+                      {
+                        /* Parse an object.  */
+                        c = phase2_getc ();
+                        if (c != '{')
+                          goto invalid_rsj;
+
+                        char *location = NULL;
+                        char *msgid = NULL;
+
+                        c = phase2_getc ();
+                        if (c != '}')
+                          {
+                            phase2_ungetc (c);
+                            for (;;)
+                              {
+                                /* Parse a string.  */
+                                if (parse_string () != pr_parsed)
+                                  goto invalid_json;
+                                char *s2 =
+                                  mixed_string_contents_free1 (
+                                    mixed_string_buffer_result (&stringbuf));
+
+                                /* Parse a colon.  */
+                                c = phase2_getc ();
+                                if (c != ':')
+                                  goto invalid_json;
+
+                                if (strcmp (s2, "hash") == 0)
+                                  {
+                                    /* Parse an integer.  */
+                                    if (parse_integer () != pr_parsed)
+                                      {
+                                        sb_free (&buffer);
+                                        goto invalid_rsj;
+                                      }
+                                    sb_free (&buffer);
+                                  }
+                                else if (strcmp (s2, "name") == 0)
+                                  {
+                                    /* Parse a string.  */
+                                    enum parse_result r = parse_string ();
+                                    if (r == pr_none)
+                                      goto invalid_rsj;
+                                    if (r == pr_syntax || location != NULL)
+                                      goto invalid_json;
+                                    location =
+                                      mixed_string_contents_free1 (
+                                        mixed_string_buffer_result (&stringbuf));
+                                  }
+                                else if (strcmp (s2, "sourcebytes") == 0)
+                                  {
+                                    /* Parse an array.  */
+                                    c = phase2_getc ();
+                                    if (c != '[')
                                       goto invalid_rsj;
-                                    }
-                                  sb_free (&buffer);
-                                }
-                              else if (strcmp (s2, "name") == 0)
-                                {
-                                  /* Parse a string.  */
-                                  enum parse_result r = parse_string ();
-                                  if (r == pr_none)
-                                    goto invalid_rsj;
-                                  if (r == pr_syntax || location != NULL)
-                                    goto invalid_json;
-                                  location =
-                                    mixed_string_contents_free1 (
-                                      mixed_string_buffer_result (&stringbuf));
-                                }
-                              else if (strcmp (s2, "sourcebytes") == 0)
-                                {
-                                  /* Parse an array.  */
-                                  c = phase2_getc ();
-                                  if (c != '[')
-                                    goto invalid_rsj;
-
-                                  c = phase2_getc ();
-                                  if (c != ']')
-                                    {
-                                      phase2_ungetc (c);
-                                      for (;;)
-                                        {
-                                          /* Parse an integer.  */
-                                          if (parse_integer () != pr_parsed)
-                                            {
-                                              sb_free (&buffer);
-                                              goto invalid_rsj;
-                                            }
-                                          sb_free (&buffer);
-
-                                          /* Parse a comma.  */
-                                          c = phase2_getc ();
-                                          if (c == ']')
-                                            break;
-                                          if (c != ',')
-                                            goto invalid_json;
-                                        }
-                                    }
-                                }
-                              else if (strcmp (s2, "value") == 0)
-                                {
-                                  /* Parse a string.  */
-                                  enum parse_result r = parse_string ();
-                                  if (r == pr_none)
-                                    goto invalid_rsj;
-                                  if (r == pr_syntax || msgid != NULL)
-                                    goto invalid_json;
-                                  msgid =
-                                    mixed_string_contents_free1 (
-                                      mixed_string_buffer_result (&stringbuf));
-                                }
-                              else
-                                goto invalid_rsj;
-
-                              free (s2);
-
-                              /* Parse a comma.  */
-                              c = phase2_getc ();
-                              if (c == '}')
-                                break;
-                              if (c != ',')
-                                goto invalid_json;
-                            }
-                        }
-
-                      if (location == NULL || msgid == NULL)
-                        goto invalid_rsj;
-
-                      pos.file_name = location;
-                      pos.line_number = (size_t)(-1);
-
-                      remember_a_message (mlp, NULL, msgid, true, false,
-                                          null_context_region (), &pos,
-                                          NULL, NULL, false);
-
-                      /* Parse a comma.  */
-                      c = phase2_getc ();
-                      if (c == ']')
-                        break;
-                      if (c != ',')
-                        goto invalid_json;
-                    }
-                }
-            }
-          else
-            goto invalid_rsj;
 
-          /* Parse a comma.  */
-          c = phase2_getc ();
-          if (c == '}')
-            break;
-          if (c != ',')
-            goto invalid_json;
-        }
-    }
+                                    c = phase2_getc ();
+                                    if (c != ']')
+                                      {
+                                        phase2_ungetc (c);
+                                        for (;;)
+                                          {
+                                            /* Parse an integer.  */
+                                            if (parse_integer () != pr_parsed)
+                                              {
+                                                sb_free (&buffer);
+                                                goto invalid_rsj;
+                                              }
+                                            sb_free (&buffer);
+
+                                            /* Parse a comma.  */
+                                            c = phase2_getc ();
+                                            if (c == ']')
+                                              break;
+                                            if (c != ',')
+                                              goto invalid_json;
+                                          }
+                                      }
+                                  }
+                                else if (strcmp (s2, "value") == 0)
+                                  {
+                                    /* Parse a string.  */
+                                    enum parse_result r = parse_string ();
+                                    if (r == pr_none)
+                                      goto invalid_rsj;
+                                    if (r == pr_syntax || msgid != NULL)
+                                      goto invalid_json;
+                                    msgid =
+                                      mixed_string_contents_free1 (
+                                        mixed_string_buffer_result (&stringbuf));
+                                  }
+                                else
+                                  goto invalid_rsj;
+
+                                free (s2);
+
+                                /* Parse a comma.  */
+                                c = phase2_getc ();
+                                if (c == '}')
+                                  break;
+                                if (c != ',')
+                                  goto invalid_json;
+                              }
+                          }
+
+                        if (location == NULL || msgid == NULL)
+                          goto invalid_rsj;
+
+                        lex_pos_ty pos;
+                        pos.file_name = location;
+                        pos.line_number = (size_t)(-1);
+
+                        remember_a_message (mlp, NULL, msgid, true, false,
+                                            null_context_region (), &pos,
+                                            NULL, NULL, false);
+
+                        /* Parse a comma.  */
+                        c = phase2_getc ();
+                        if (c == ']')
+                          break;
+                        if (c != ',')
+                          goto invalid_json;
+                      }
+                  }
+              }
+            else
+              goto invalid_rsj;
 
-  /* Seen the closing brace.  */
-  c = phase2_getc ();
-  if (c != EOF)
-    goto invalid_json;
+            /* Parse a comma.  */
+            c = phase2_getc ();
+            if (c == '}')
+              break;
+            if (c != ',')
+              goto invalid_json;
+          }
+      }
+
+    /* Seen the closing brace.  */
+    c = phase2_getc ();
+    if (c != EOF)
+      goto invalid_json;
+  }
 
   fp = NULL;
   real_file_name = NULL;
index 765d2c3475fc41f715fea5928ae037cab7935278..ff9f7c2985cc976ec83146b0ca32d7289c7f83e3 100644 (file)
@@ -87,43 +87,36 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
               msgdomain_list_ty *mdlp)
 {
   const char *progname = "rxgettext";
-  char *dummy_filename;
-  msgdomain_list_ty *mdlp2;
-  int pass;
 
-  dummy_filename = xasprintf (_("(output from '%s')"), progname);
+  char *dummy_filename = xasprintf (_("(output from '%s')"), progname);
 
   /* Invoke rgettext twice:
      1. to get the messages, without ruby-format flags.
      2. to get the 'xgettext:' comments that guide us while adding
         [no-]ruby-format flags.  */
-  mdlp2 = msgdomain_list_alloc (true);
-  for (pass = 0; pass < 2; pass++)
+  msgdomain_list_ty *mdlp2 = msgdomain_list_alloc (true);
+  for (int pass = 0; pass < 2; pass++)
     {
-      const char *argv[4];
-      unsigned int i;
-      pid_t child;
-      int fd[1];
-      FILE *fp;
-      int exitstatus;
-
       /* Prepare arguments.  */
-      argv[0] = progname;
-      i = 1;
+      const char *argv[4];
+      {
+        argv[0] = progname;
+        unsigned int i = 1;
 
-      if (pass > 0)
-        argv[i++] = "--add-comments=xgettext:";
-      else
-        {
-          if (add_all_comments)
-            argv[i++] = "--add-comments";
-          else if (comment_tag != NULL)
-            argv[i++] = xasprintf ("--add-comments=%s", comment_tag);
-        }
+        if (pass > 0)
+          argv[i++] = "--add-comments=xgettext:";
+        else
+          {
+            if (add_all_comments)
+              argv[i++] = "--add-comments";
+            else if (comment_tag != NULL)
+              argv[i++] = xasprintf ("--add-comments=%s", comment_tag);
+          }
 
-      argv[i++] = logical_filename;
+        argv[i++] = logical_filename;
 
-      argv[i] = NULL;
+        argv[i] = NULL;
+      }
 
       if (verbose)
         {
@@ -132,10 +125,11 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
           free (command);
         }
 
-      child = create_pipe_in (progname, progname, argv, NULL, found_in_dir,
-                              DEV_NULL, false, true, true, fd);
+      int fd[1];
+      pid_t child = create_pipe_in (progname, progname, argv, NULL, found_in_dir,
+                                    DEV_NULL, false, true, true, fd);
 
-      fp = fdopen (fd[0], "r");
+      FILE *fp = fdopen (fd[0], "r");
       if (fp == NULL)
         error (EXIT_FAILURE, errno, _("fdopen() failed"));
 
@@ -146,7 +140,7 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
       fclose (fp);
 
       /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus =
+      int exitstatus =
         wait_subprocess (child, progname, false, false, true, true, NULL);
       if (exitstatus != 0)
         error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
@@ -159,9 +153,8 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
     {
       message_list_ty *mlp = mdlp->item[0]->messages;
       message_list_ty *mlp2 = mdlp2->item[0]->messages;
-      size_t j;
 
-      for (j = 0; j < mlp->nitems; j++)
+      for (size_t j = 0; j < mlp->nitems; j++)
         {
           message_ty *mp = mlp->item[j];
 
@@ -174,9 +167,8 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
               if (mp2 != NULL && mp2->comment_dot != NULL)
                 {
                   string_list_ty *mp2_comment_dot = mp2->comment_dot;
-                  size_t k;
 
-                  for (k = 0; k < mp2_comment_dot->nitems; k++)
+                  for (size_t k = 0; k < mp2_comment_dot->nitems; k++)
                     {
                       const char *s = mp2_comment_dot->item[k];
 
@@ -186,22 +178,19 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
                       const char *t = c_strstr (s, "xgettext:");
                       if (t != NULL)
                         {
+                          t += strlen ("xgettext:");
+
                           bool tmp_fuzzy;
                           enum is_format tmp_format[NFORMATS];
                           struct argument_range tmp_range;
                           enum is_wrap tmp_wrap;
                           enum is_syntax_check tmp_syntax_check[NSYNTAXCHECKS];
-                          bool interesting;
-                          size_t i;
-
-                          t += strlen ("xgettext:");
-
                           parse_comment_special (t, &tmp_fuzzy, tmp_format,
                                                  &tmp_range, &tmp_wrap,
                                                  tmp_syntax_check);
 
-                          interesting = false;
-                          for (i = 0; i < NFORMATS; i++)
+                          bool interesting = false;
+                          for (size_t i = 0; i < NFORMATS; i++)
                             if (tmp_format[i] != undecided)
                               {
                                 mp->is_format[i] = tmp_format[i];
@@ -217,7 +206,7 @@ extract_ruby (const char *found_in_dir, const char *real_filename,
                               mp->do_wrap = tmp_wrap;
                               interesting = true;
                             }
-                          for (i = 0; i < NSYNTAXCHECKS; i++)
+                          for (size_t i = 0; i < NSYNTAXCHECKS; i++)
                             if (tmp_syntax_check[i] != undecided)
                               {
                                 mp->do_syntax_check[i] = tmp_syntax_check[i];
index be769cefac1b755518a736ddb77e17a574ac9532..5c16fdc1b04a97e0da17df30fc7a23fe07205ec0 100644 (file)
@@ -87,21 +87,19 @@ x_rust_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (function_keywords.table == NULL)
         hash_init (&function_keywords, 100);
       if (macro_keywords.table == NULL)
         hash_init (&macro_keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Rust
          identifier, possibly with a trailing '!'.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         {
           if (end > name && end[-1] == '!')
@@ -351,8 +349,7 @@ string_literal_value (TSNode node)
   sb_init (&buffer);
   uint32_t count = ts_node_named_child_count (node);
   bool skip_leading_whitespace = false;
-  uint32_t i;
-  for (i = 0; i < count; i++)
+  for (uint32_t i = 0; i < count; i++)
     {
       TSNode subnode = ts_node_named_child (node, i);
       if (ts_node_symbol (subnode) == ts_symbol_string_content)
@@ -412,8 +409,7 @@ string_literal_value (TSNode node)
           else if (escape_start[1] == 'x')
             {
               unsigned int value = 0;
-              const char *p;
-              for (p = escape_start + 2; p < escape_end; p++)
+              for (const char *p = escape_start + 2; p < escape_end; p++)
                 {
                   /* Only 2 hexadecimal digits are accepted.
                      No overflow is possible.  */
@@ -442,8 +438,7 @@ string_literal_value (TSNode node)
                    && escape_start[2] == '{' && escape_end[-1] == '}')
             {
               unsigned int value = 0;
-              const char *p;
-              for (p = escape_start + 3; p < escape_end - 1; p++)
+              for (const char *p = escape_start + 3; p < escape_end - 1; p++)
                 {
                   char c = *p;
                   if (c >= '0' && c <= '9')
@@ -564,10 +559,9 @@ extract_from_function_call (TSNode callee_node,
 
       /* Current argument number.  */
       uint32_t arg;
-      uint32_t i;
 
       arg = 0;
-      for (i = 0; i < args_count; i++)
+      for (uint32_t i = 0; i < args_count; i++)
         {
           TSNode arg_node = ts_node_child (args_node, i);
           handle_comments (arg_node);
@@ -633,10 +627,9 @@ extract_from_function_call (TSNode callee_node,
 
   /* Current argument number.  */
   uint32_t arg;
-  uint32_t i;
 
   arg = 0;
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -684,8 +677,8 @@ extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro,
 
   /* Context iterator.  */
   flag_context_list_iterator_ty next_context_iter;
-  void *keyword_value;
 
+  void *keyword_value;
   if (callee_node != NULL)
     {
       string_desc_t callee_name =
@@ -725,8 +718,7 @@ extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro,
       #if DEBUG_RUST
       {
         fprintf (stderr, "children:\n");
-        uint32_t i;
-        for (i = 0; i < args_count; i++)
+        for (uint32_t i = 0; i < args_count; i++)
           fprintf (stderr, "%u -> [%s]|%s|\n", i, ts_node_type (ts_node_child (args_node, i)), ts_node_string (ts_node_child (args_node, i)));
       }
       #endif
@@ -742,12 +734,11 @@ extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro,
           /* Current argument number.  */
           uint32_t arg;
           flag_region_ty *arg_region;
-          uint32_t i;
           uint32_t prev2_token_in_same_arg;
           uint32_t prev1_token_in_same_arg;
 
           arg = 0;
-          for (i = 0; i < args_count; i++)
+          for (uint32_t i = 0; i < args_count; i++)
             {
               TSNode arg_node = ts_node_child (args_node, i);
               handle_comments (arg_node);
@@ -861,12 +852,11 @@ extract_from_function_call_like (TSNode *callee_node, bool callee_is_macro,
   /* Current argument number.  */
   uint32_t arg;
   flag_region_ty *arg_region;
-  uint32_t i;
   uint32_t prev2_token_in_same_arg;
   uint32_t prev1_token_in_same_arg;
 
   arg = 0;
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -981,8 +971,7 @@ extract_from_node (TSNode node,
               /* Handle the potential comments between 'function' and 'arguments'.  */
               {
                 uint32_t count = ts_node_child_count (node);
-                uint32_t i;
-                for (i = 0; i < count; i++)
+                for (uint32_t i = 0; i < count; i++)
                   {
                     TSNode subnode = ts_node_child (node, i);
                     if (ts_node_eq (subnode, args_node))
@@ -1012,23 +1001,19 @@ extract_from_node (TSNode node,
              It is not always = ts_node_named_child (node, 1),
              namely when there are comments before it.  */
           uint32_t count = ts_node_child_count (node);
-          uint32_t args_index;
-          for (args_index = 0; args_index < count; args_index++)
+          for (uint32_t args_index = 0; args_index < count; args_index++)
             {
               TSNode args_node = ts_node_child (node, args_index);
               if (ts_node_symbol (args_node) == ts_symbol_token_tree)
                 {
                   /* Handle the potential comments between 'macro' and the args_node.  */
-                  {
-                    uint32_t i;
-                    for (i = 0; i < count; i++)
-                      {
-                        TSNode subnode = ts_node_child (node, i);
-                        if (ts_node_eq (subnode, args_node))
-                          break;
-                        handle_comments (subnode);
-                      }
-                  }
+                  for (uint32_t i = 0; i < count; i++)
+                    {
+                      TSNode subnode = ts_node_child (node, i);
+                      if (ts_node_eq (subnode, args_node))
+                        break;
+                      handle_comments (subnode);
+                    }
                   extract_from_function_call_like (&callee_node, true,
                                                    args_node,
                                                    outer_region,
@@ -1055,8 +1040,7 @@ extract_from_node (TSNode node,
               fprintf (stderr, "gettext arguments: %s\n", ts_node_string (argsnode));
               fprintf (stderr, "gettext children:\n");
               uint32_t count = ts_node_named_child_count (node);
-              uint32_t i;
-              for (i = 0; i < count; i++)
+              for (uint32_t i = 0; i < count; i++)
                 fprintf (stderr, "%u -> %s\n", i, ts_node_string (ts_node_named_child (node, i)));
             }
         }
@@ -1074,8 +1058,7 @@ extract_from_node (TSNode node,
             {
               fprintf (stderr, "children:\n");
               uint32_t count = ts_node_child_count (node);
-              uint32_t i;
-              for (i = 0; i < count; i++)
+              for (uint32_t i = 0; i < count; i++)
                 fprintf (stderr, "%u -> [%s]|%s|\n", i, ts_node_type (ts_node_child (node, i)), ts_node_string (ts_node_child (node, i)));
             }
         }
@@ -1087,8 +1070,7 @@ extract_from_node (TSNode node,
         || ts_node_symbol (node) == ts_symbol_block_comment))
     {
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           handle_comments (subnode);
@@ -1146,9 +1128,8 @@ extract_rust (FILE *f,
     }
 
   /* Read the file into memory.  */
-  char *contents_data;
   size_t contents_length;
-  contents_data = read_file (real_filename, 0, &contents_length);
+  char *contents_data = read_file (real_filename, 0, &contents_length);
   if (contents_data == NULL)
     error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
            real_filename);
index 3f952fb85e91d158c51c8296e8d6dbd28bf0195d..12d3f2ffe29f3c6e22abc42246678fb127b469e1 100644 (file)
@@ -121,18 +121,16 @@ x_scheme_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Lisp symbol.
          Extract the symbol name part.  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon != NULL && colon < end)
         {
           name = colon + 1;
@@ -366,8 +364,6 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained)
 {
   const char *p = str;
   const char *p_end = str + len;
-  bool seen_sign;
-  bool seen_digits;
 
   /* The accepted syntaxes are:
      for a floating-point number:
@@ -386,8 +382,9 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained)
    */
   if (p == p_end)
     return false;
+
   /* Parse leading sign.  */
-  seen_sign = false;
+  bool seen_sign = false;
   if (*p == '+' || *p == '-')
     {
       p++;
@@ -398,8 +395,9 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained)
       if (unconstrained && (*p == 'I' || *p == 'i') && p + 1 == p_end)
         return true;
     }
+
   /* Parse digits before dot or exponent or slash.  */
-  seen_digits = false;
+  bool seen_digits = false;
   do
     {
       int c = *p;
@@ -426,6 +424,7 @@ is_other_number_syntax (const char *str, int len, int radix, bool unconstrained)
       p++;
     }
   while (p < p_end);
+
   /* If p == p_end, we know that seen_digits = true, and the number is an
      integer without exponent.  */
   if (p < p_end)
@@ -564,13 +563,14 @@ is_number (const struct token *tp)
 {
   const char *str = tp->chars;
   int len = tp->charcount;
-  enum { unknown, exact, inexact } exactness = unknown;
-  bool seen_radix_prefix = false;
-  bool seen_exactness_prefix = false;
 
   if (len == 1)
     if (*str == '+' || *str == '-')
       return false;
+
+  enum { unknown, exact, inexact } exactness = unknown;
+  bool seen_radix_prefix = false;
+  bool seen_exactness_prefix = false;
   while (len >= 2 && *str == '#')
     {
       switch (str[1])
@@ -718,12 +718,8 @@ accumulate_escaped (struct mixed_string_buffer *literal)
                   break;
                 }
               {
-                unsigned int n;
-                bool overflow;
-
-                n = 0;
-                overflow = false;
-
+                unsigned int n = 0;
+                bool overflow = false;
                 for (;;)
                   {
                     switch (c)
@@ -784,14 +780,10 @@ accumulate_escaped (struct mixed_string_buffer *literal)
                  digits and then a semicolon.  See
                  R6RS Â§ 4.2.7, R7RS Â§ 6.7 and Â§ 7.1.1.  */
               unsigned int const n_limit = 0x110000;
-              unsigned int count;
-              unsigned int n;
-              bool overflow;
-
-              count = 0;
-              n = 0;
-              overflow = false;
 
+              unsigned int count = 0;
+              unsigned int n = 0;
+              bool overflow = false;
               for (;;)
                 {
                   c = phase1_getc ();
@@ -1042,10 +1034,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
         case ';':
           {
-            bool all_semicolons = true;
-
             last_comment_line = line_number;
             comment_start ();
+            bool all_semicolons = true;
             for (;;)
               {
                 int c = phase1_getc ();
@@ -1073,9 +1064,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
 
             for (;; arg++)
               {
-                struct object inner;
                 flag_region_ty *inner_region;
-
                 if (arg == 0)
                   inner_region = null_context_region ();
                 else
@@ -1085,6 +1074,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
                                          &context_iter));
 
                 ++nesting_depth;
+                struct object inner;
                 read_object (&inner, inner_region);
                 nesting_depth--;
 
@@ -1138,7 +1128,6 @@ read_object (struct object *op, flag_region_ty *outer_region)
                           }
 
                         void *keyword_value;
-
                         if (hash_find_entry (&keywords,
                                              symbol_name, strlen (symbol_name),
                                              &keyword_value)
@@ -1208,9 +1197,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
         case '\'':
         case '`':
           {
-            struct object inner;
-
             ++nesting_depth;
+            struct object inner;
             read_object (&inner, null_context_region ());
             nesting_depth--;
 
@@ -1239,8 +1227,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case '(': /* Vector */
                 phase1_ungetc (dmc);
                 {
-                  struct object inner;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
@@ -1267,8 +1255,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case 'v':
               case 'y':
                 {
-                  struct token token;
                   phase1_ungetc (dmc);
+                  struct token token;
                   read_token (&token, '#');
                   if ((token.charcount == 2
                        && (token.chars[1] == 'a' || token.chars[1] == 'c'
@@ -1321,8 +1309,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
                                #vu8(...) - vector of byte
                                #y(...) - vector of byte (old)
                            */
-                          struct object inner;
                           ++nesting_depth;
+                          struct object inner;
                           read_object (&inner, null_context_region ());
                           nesting_depth--;
                           /* Dots and EOF are not allowed here.
@@ -1348,8 +1336,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case 'E': case 'e':
               case 'I': case 'i':
                 {
-                  struct token token;
                   phase1_ungetc (dmc);
+                  struct token token;
                   read_token (&token, '#');
                   if (is_number (&token))
                     {
@@ -1373,8 +1361,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
                                    #e(...) - vector of long (old)
                                    #i(...) - vector of double-float (old)
                                */
-                              struct object inner;
                               ++nesting_depth;
+                              struct object inner;
                               read_object (&inner, null_context_region ());
                               nesting_depth--;
                               /* Dots and EOF are not allowed here.
@@ -1398,10 +1386,10 @@ read_object (struct object *op, flag_region_ty *outer_region)
                 /* Datum comment '#; <datum>'.
                    See R6RS Â§ 4.2.3, R7RS Â§ 2.2.  */
                 {
-                  struct object inner;
                   int saved_last_non_comment_line = last_non_comment_line;
                   ++datum_comment_nesting_depth;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, null_context_region ());
                   nesting_depth--;
                   datum_comment_nesting_depth--;
@@ -1427,8 +1415,7 @@ read_object (struct object *op, flag_region_ty *outer_region)
                   int num_directives = SIZEOF (directives);
                   enum { max_directive_len = 29 };
                   bool seen_directive = false;
-                  int d;
-                  for (d = 0; d < num_directives; d++)
+                  for (int d = 0; d < num_directives; d++)
                     {
                       const char *directive = directives[d];
                       int directive_len = strlen (directive);
@@ -1658,10 +1645,10 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case '\\':
                 /* Character.  */
                 {
-                  struct token token;
                   int c = phase1_getc ();
                   if (c != EOF)
                     {
+                      struct token token;
                       read_token (&token, c);
                       free_token (&token);
                     }
@@ -1703,8 +1690,8 @@ read_object (struct object *op, flag_region_ty *outer_region)
               case '.': /* boot-9.scm */
               case ',': /* srfi-10.scm */
                 {
-                  struct object inner;
                   ++nesting_depth;
+                  struct object inner;
                   read_object (&inner, null_context_region ());
                   nesting_depth--;
                   /* Dots and EOF are not allowed here.
@@ -1768,9 +1755,9 @@ read_object (struct object *op, flag_region_ty *outer_region)
             if (seen_underscore_prefix || extract_all)
               {
                 lex_pos_ty pos;
-
                 pos.file_name = logical_file_name;
                 pos.line_number = op->line_number_at_start;
+
                 remember_a_message (mlp, NULL, string_of_object (op), true,
                                     false, null_context_region (), &pos,
                                     NULL, savable_comment, false);
index 4e29b9196305db1331c484783d812c91593f7354..4d3474d1b9ae88ab7b6271c4002b92fbfbd39748 100644 (file)
@@ -94,18 +94,16 @@ x_sh_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -510,15 +508,16 @@ phase2_getc ()
          final output.  */
       unsigned int expected_count =
         (unsigned int) 1 << debackslashify;
+
       /* Number of backslashes found.  */
       unsigned int count;
-
       for (count = 1; count < expected_count; count++)
         {
           c = phase1_getc ();
           if (c != '\\')
             break;
         }
+
       if (count == expected_count)
         return '\\';
 
@@ -677,8 +676,6 @@ static void
 read_word (struct word *wp, int looking_for, flag_region_ty *region)
 {
   int c;
-  bool all_unquoted_digits;
-  bool all_unquoted_name_characters;
 
   do
     {
@@ -787,13 +784,13 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
                             logical_file_name, line_number);
   wp->line_number_at_start = line_number;
   /* True while all characters in the token seen so far are digits.  */
-  all_unquoted_digits = true;
+  bool all_unquoted_digits = true;
   /* True while all characters in the token seen so far form a "name":
      all characters are unquoted underscores, digits, or alphabetics from the
      portable character set, and the first character is not a digit.  Cf.
      <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_235>
    */
-  all_unquoted_name_characters = true;
+  bool all_unquoted_name_characters = true;
 
   for (;; c = phase2_getc ())
     {
@@ -844,8 +841,6 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
 
       if (c == '$')
         {
-          int c2;
-
           /* An unquoted dollar indicates we are not inside '...'.  */
           if (open_singlequote)
             abort ();
@@ -853,6 +848,9 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
              character from an earlier lookahead.  */
           if (phase2_pushback_length > 0)
             abort ();
+
+          int c2;
+
           /* Therefore we can use phase1 without interfering with phase2.
              We need to recognize $( outside and inside double-quotes.
              It would be incorrect to do
@@ -862,21 +860,18 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
           c2 = phase1_getc ();
           if (c2 == '(')
             {
-              bool saved_open_doublequote;
-              int c3;
-
               phase1_ungetc (c2);
 
               /* The entire inner command or arithmetic expression is read
                  ignoring possible surrounding double-quotes.  */
-              saved_open_doublequote = open_doublequote;
+              bool saved_open_doublequote = open_doublequote;
               open_doublequote = false;
 
               c2 = phase2_getc ();
               if (c2 != '(')
                 abort ();
 
-              c3 = phase2_getc ();
+              int c3 = phase2_getc ();
               if (c3 == '(')
                 {
                   /* Arithmetic expression (Bash syntax).  Skip until the
@@ -1010,7 +1005,6 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
                                   || (c >= 'a' && c <= 'f'))
                                 {
                                   int n;
-
                                   if (c >= '0' && c <= '9')
                                     n = c - '0';
                                   else if (c >= 'A' && c <= 'F')
@@ -1074,9 +1068,8 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
                               {
                                 unsigned char buf[8];
                                 int j;
-                                unsigned int n;
 
-                                n = 0;
+                                unsigned int n = 0;
                                 for (j = 0; j < (c == 'u' ? 4 : 8); j++)
                                   {
                                     int c1 = phase1_getc ();
@@ -1126,13 +1119,14 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
               else if (c2 == '"' && !open_doublequote)
                 {
                   /* $"...": Bash builtin for internationalized string.  */
-                  lex_pos_ty pos;
-                  struct mixed_string_buffer string;
-
                   saw_opening_singlequote ();
                   open_singlequote_terminator = '"';
+
+                  lex_pos_ty pos;
                   pos.file_name = logical_file_name;
                   pos.line_number = line_number;
+
+                  struct mixed_string_buffer string;
                   mixed_string_buffer_init (&string, lc_string,
                                             logical_file_name, line_number);
                   for (;;)
@@ -1219,13 +1213,11 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
 
       if (c == '<' || c == '>')
         {
-          int c2;
-
           /* An unquoted c indicates we are not inside '...' nor "...".  */
           if (open_singlequote || open_doublequote)
             abort ();
 
-          c2 = phase2_getc ();
+          int c2 = phase2_getc ();
           if (c2 == '(')
             {
               /* Process substitution (Bash syntax).  */
@@ -1286,9 +1278,7 @@ read_command (int looking_for, flag_region_ty *outer_region)
 
   for (;;)
     {
-      struct word inner;
       flag_region_ty *inner_region;
-
       if (arg == 0)
         inner_region = null_context_region ();
       else
@@ -1297,6 +1287,7 @@ read_command (int looking_for, flag_region_ty *outer_region)
                              flag_context_list_iterator_advance (
                                &context_iter));
 
+      struct word inner;
       read_word (&inner, looking_for, inner_region);
 
       /* Recognize end of command.  */
@@ -1315,9 +1306,9 @@ read_command (int looking_for, flag_region_ty *outer_region)
           if (inner.type == t_string)
             {
               lex_pos_ty pos;
-
               pos.file_name = logical_file_name;
               pos.line_number = inner.line_number_at_start;
+
               remember_a_message (mlp, NULL,
                                   mixed_string_contents_free1 (
                                     mixed_string_buffer_cloned_result (inner.token)),
@@ -1367,7 +1358,6 @@ read_command (int looking_for, flag_region_ty *outer_region)
                   else
                     {
                       void *keyword_value;
-
                       if (hash_find_entry (&keywords,
                                            function_name,
                                            strlen (function_name),
@@ -1514,9 +1504,7 @@ read_command_list (int looking_for, flag_region_ty *outer_region)
               _("too deeply nested command list"));
   for (;;)
     {
-      enum word_type terminator;
-
-      terminator = read_command (looking_for, outer_region);
+      enum word_type terminator = read_command (looking_for, outer_region);
       if (terminator != t_separator)
         return terminator;
     }
index f818d693d932239d4e9d2fba969e13c983bc56bc..779bf9c0e70b5be756155bb9e5a468021cb17f43 100644 (file)
@@ -194,8 +194,6 @@ static int phase2_pushback_length;
 static void
 phase2_get (token_ty *tp)
 {
-  int c;
-
   if (phase2_pushback_length)
     {
       *tp = phase2_pushback[--phase2_pushback_length];
@@ -206,6 +204,8 @@ phase2_get (token_ty *tp)
 
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase1_getc ();
       switch (c)
@@ -217,10 +217,8 @@ phase2_get (token_ty *tp)
         case '"':
           {
             /* Comment.  */
-            int lineno;
-
             comment_start ();
-            lineno = line_number;
+            int lineno = line_number;
             for (;;)
               {
                 c = phase1_getc ();
@@ -301,7 +299,6 @@ phase2_get (token_ty *tp)
         case '%':
         case '\\':
           {
-            char *name;
             int c2 = phase1_getc ();
             switch (c2)
               {
@@ -319,18 +316,20 @@ phase2_get (token_ty *tp)
               case '@':
               case '?':
               case '%':
-                name = XNMALLOC (3, char);
-                name[0] = c;
-                name[1] = c2;
-                name[2] = '\0';
-                tp->type = token_type_symbol;
-                tp->string = name;
-                return;
+                {
+                  char *name = XNMALLOC (3, char);
+                  name[0] = c;
+                  name[1] = c2;
+                  name[2] = '\0';
+                  tp->type = token_type_symbol;
+                  tp->string = name;
+                  return;
+                }
               default:
                 phase1_ungetc (c2);
                 break;
               }
-            name = XNMALLOC (2, char);
+            char *name = XNMALLOC (2, char);
             name[0] = c;
             name[1] = '\0';
             tp->type = token_type_symbol;
@@ -453,8 +452,8 @@ phase3_get (token_ty *tp)
   if (tp->type == token_type_uniq)
     {
       token_ty token2;
-
       phase2_get (&token2);
+
       if (token2.type == token_type_symbol
           || token2.type == token_type_string_literal)
         {
@@ -519,14 +518,14 @@ phase4_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase3_get (&token2);
+
           if (token2.type == token_type_symbol
               && strcmp (token2.string, ",") == 0)
             {
               token_ty token3;
-
               phase3_get (&token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   sum = string_concat_free1 (sum, token3.string);
@@ -609,7 +608,6 @@ extract_smalltalk (FILE *f,
     for (;;)
       {
         token_ty token;
-
         phase4_get (&token);
 
         switch (token.type)
@@ -638,11 +636,10 @@ extract_smalltalk (FILE *f,
             if (state == 3)
               {
                 lex_pos_ty pos;
-                token_ty token2;
-
                 pos.file_name = logical_file_name;
                 pos.line_number = token.line_number;
 
+                token_ty token2;
                 phase4_get (&token2);
 
                 plural_mp =
index c9ba45c8b0cc35a32ab4bcf0d30f21b6ebe97083..c9edc07698caa5fb9d8dd4b87c3a92d7ab3b3637 100644 (file)
@@ -94,12 +94,11 @@ x_tcl_keyword (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid Tcl
@@ -445,15 +444,14 @@ free_word (struct word *wp)
 static char *
 string_of_word (const struct word *wp)
 {
-  char *str;
-  int n;
-
   if (!(wp->type == t_string))
     abort ();
-  n = wp->token->charcount;
-  str = XNMALLOC (n + 1, char);
+  int n = wp->token->charcount;
+
+  char *str = XNMALLOC (n + 1, char);
   memcpy (str, wp->token->chars, n);
   str[n] = '\0';
+
   return str;
 }
 
@@ -669,10 +667,10 @@ static int
 accumulate_word (struct word *wp, enum terminator looking_for,
                  flag_region_ty *region)
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       c = phase2_getc ();
 
       if (c == EOF || c == CL_BRACE)
@@ -705,7 +703,6 @@ accumulate_word (struct word *wp, enum terminator looking_for,
           else
             {
               bool nonempty = false;
-
               for (; c != EOF && c != CL_BRACE; c = phase2_getc ())
                 {
                   if (c_isalnum ((unsigned char) c) || (c == '_'))
@@ -731,6 +728,7 @@ accumulate_word (struct word *wp, enum terminator looking_for,
                     }
                   break;
                 }
+
               if (c == '(')
                 {
                   /* $varname(index) */
@@ -806,10 +804,9 @@ accumulate_word (struct word *wp, enum terminator looking_for,
           {
             unsigned char utf8buf[6];
             int count = u8_uctomb (utf8buf, uc, 6);
-            int i;
             assert (count > 0);
             if (wp->type == t_string)
-              for (i = 0; i < count; i++)
+              for (int i = 0; i < count; i++)
                 {
                   grow_token (wp->token);
                   wp->token->chars[wp->token->charcount++] = utf8buf[i];
@@ -880,19 +877,17 @@ read_word (struct word *wp, int looking_for, flag_region_ty *region)
 
   if (c == '{')
     {
-      int previous_depth;
-      enum word_type terminator;
-
       /* Start a new nested character group, which lasts until the next
          balanced '}' (ignoring \} things).  */
-      previous_depth = phase2_push () - 1;
+      int previous_depth = phase2_push () - 1;
 
       /* Interpret it as a command list.  */
       if (++brace_nesting_depth > MAX_NESTING_DEPTH)
         if_error (IF_SEVERITY_FATAL_ERROR,
                   logical_file_name, line_number, (size_t)(-1), false,
                   _("too many open braces"));
-      terminator = read_command_list ('\0', null_context_region ());
+      enum word_type terminator =
+        read_command_list ('\0', null_context_region ());
       brace_nesting_depth--;
 
       if (terminator == t_brace)
@@ -1010,9 +1005,9 @@ read_command (int looking_for, flag_region_ty *outer_region)
             if (inner.type == t_string)
               {
                 lex_pos_ty pos;
-
                 pos.file_name = logical_file_name;
                 pos.line_number = inner.line_number_at_start;
+
                 remember_a_message (mlp, NULL, string_of_word (&inner), false,
                                     false, inner_region, &pos,
                                     NULL, savable_comment, false);
@@ -1025,14 +1020,13 @@ read_command (int looking_for, flag_region_ty *outer_region)
             if (inner.type == t_string)
               {
                 char *function_name = string_of_word (&inner);
-                char *stripped_name;
-                void *keyword_value;
 
                 /* A leading "::" is redundant.  */
-                stripped_name = function_name;
+                char *stripped_name = function_name;
                 if (function_name[0] == ':' && function_name[1] == ':')
                   stripped_name += 2;
 
+                void *keyword_value;
                 if (hash_find_entry (&keywords,
                                      stripped_name, strlen (stripped_name),
                                      &keyword_value)
@@ -1087,9 +1081,7 @@ read_command_list (int looking_for, flag_region_ty *outer_region)
 {
   for (;;)
     {
-      enum word_type terminator;
-
-      terminator = read_command (looking_for, outer_region);
+      enum word_type terminator = read_command (looking_for, outer_region);
       if (terminator != t_separator)
         return terminator;
     }
index 525067d99d8424b0cf56e8a85af9c3c2d6d88967..4f9a48ca0c6ccb0e1e266dba05d0a03e7ea123e4 100644 (file)
@@ -81,18 +81,16 @@ NOTE_OPTION_KEYWORD (const char *name)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords.table == NULL)
         hash_init (&keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (&keywords, name, end - name, &shape);
     }
@@ -391,10 +389,10 @@ sbru_xprepend_unicode (struct string_buffer_reversed_unicode *buffer,
   if (buffer->utf16_surr != 0 && (c >= 0xd800 && c < 0xdc00))
     {
       unsigned short utf16buf[2];
-      ucs4_t uc;
-
       utf16buf[0] = c;
       utf16buf[1] = buffer->utf16_surr;
+
+      ucs4_t uc;
       if (u16_mbtouc (&uc, utf16buf, 2) != 2)
         abort ();
 
@@ -459,8 +457,7 @@ is_string_literal (TSNode node)
          'escape_sequence' (and thus none of type 'template_substitution' or
          'ERROR').  */
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_named_child (node, i);
           if (!(ts_node_symbol (subnode) == ts_symbol_string_fragment
@@ -491,8 +488,7 @@ string_literal_accumulate_pieces (TSNode node,
       || ts_node_symbol (node) == ts_symbol_template_string)
     {
       uint32_t count = ts_node_named_child_count (node);
-      uint32_t i;
-      for (i = count; i > 0; )
+      for (uint32_t i = count; i > 0; )
         {
           i--;
           TSNode subnode = ts_node_named_child (node, i);
@@ -561,8 +557,7 @@ string_literal_accumulate_pieces (TSNode node,
                   /* Only up to 3 octal digits are accepted.  */
                   if (escape_end - escape_start <= 1 + 3)
                     {
-                      const char *p;
-                      for (p = escape_start + 1; p < escape_end; p++)
+                      for (const char *p = escape_start + 1; p < escape_end; p++)
                         {
                           /* No overflow is possible.  */
                           char c = *p;
@@ -581,8 +576,7 @@ string_literal_accumulate_pieces (TSNode node,
                        || (escape_start[1] == 'u' && escape_end - escape_start == 2 + 4))
                 {
                   unsigned int value = 0;
-                  const char *p;
-                  for (p = escape_start + 2; p < escape_end; p++)
+                  for (const char *p = escape_start + 2; p < escape_end; p++)
                     {
                       /* No overflow is possible.  */
                       char c = *p;
@@ -608,8 +602,7 @@ string_literal_accumulate_pieces (TSNode node,
                        && escape_start[2] == '{' && escape_end[-1] == '}')
                 {
                   unsigned int value = 0;
-                  const char *p;
-                  for (p = escape_start + 3; p < escape_end - 1; p++)
+                  for (const char *p = escape_start + 3; p < escape_end - 1; p++)
                     {
                       char c = *p;
                       if (c >= '0' && c <= '9')
@@ -757,10 +750,9 @@ extract_from_function_call (TSNode callee_node,
 
       /* Current argument number.  */
       uint32_t arg;
-      uint32_t i;
 
       arg = 0;
-      for (i = 0; i < args_count; i++)
+      for (uint32_t i = 0; i < args_count; i++)
         {
           TSNode arg_node = ts_node_child (args_node, i);
           handle_comments (arg_node);
@@ -825,10 +817,9 @@ extract_from_function_call (TSNode callee_node,
 
   /* Current argument number.  */
   uint32_t arg;
-  uint32_t i;
 
   arg = 0;
-  for (i = 0; i < args_count; i++)
+  for (uint32_t i = 0; i < args_count; i++)
     {
       TSNode arg_node = ts_node_child (args_node, i);
       handle_comments (arg_node);
@@ -894,8 +885,7 @@ extract_from_node (TSNode node,
               /* Handle the potential comments between 'function' and 'arguments'.  */
               {
                 uint32_t count = ts_node_child_count (node);
-                uint32_t i;
-                for (i = 0; i < count; i++)
+                for (uint32_t i = 0; i < count; i++)
                   {
                     TSNode subnode = ts_node_child (node, i);
                     if (ts_node_eq (subnode, args_node))
@@ -927,8 +917,7 @@ extract_from_node (TSNode node,
               fprintf (stderr, "gettext arguments: %s\n", ts_node_string (argsnode));
               fprintf (stderr, "gettext children:\n");
               uint32_t count = ts_node_named_child_count (node);
-              uint32_t i;
-              for (i = 0; i < count; i++)
+              for (uint32_t i = 0; i < count; i++)
                 fprintf (stderr, "%u -> %s\n", i, ts_node_string (ts_node_named_child (node, i)));
             }
         }
@@ -940,8 +929,7 @@ extract_from_node (TSNode node,
     {
       ignore = ignore || is_string_literal (node);
       uint32_t count = ts_node_child_count (node);
-      uint32_t i;
-      for (i = 0; i < count; i++)
+      for (uint32_t i = 0; i < count; i++)
         {
           TSNode subnode = ts_node_child (node, i);
           handle_comments (subnode);
index c5ce48551ee1caf6d741092f50a5865baa9ec0e4..35d124407107c215c037c5cbd3d8c2853bc5a877 100644 (file)
@@ -86,18 +86,16 @@ add_keyword (const char *name, hash_table *keywords)
     default_keywords = false;
   else
     {
-      const char *end;
-      struct callshape shape;
-      const char *colon;
-
       if (keywords->table == NULL)
         hash_init (keywords, 100);
 
+      const char *end;
+      struct callshape shape;
       split_keywordspec (name, &end, &shape);
 
       /* The characters between name and end should form a valid C identifier.
          A colon means an invalid parse in split_keywordspec().  */
-      colon = strchr (name, ':');
+      const char *colon = strchr (name, ':');
       if (colon == NULL || colon >= end)
         insert_keyword_callshape (keywords, name, end - name, &shape);
     }
@@ -307,7 +305,6 @@ static int
 phase2_getc ()
 {
   int c;
-  bool last_was_star;
 
   c = phase1_getc ();
   if (c != '/')
@@ -322,41 +319,43 @@ phase2_getc ()
     case '*':
       /* C comment.  */
       comment_start ();
-      last_was_star = false;
-      for (;;)
-        {
-          c = phase1_getc ();
-          if (c == EOF)
-            break;
-          /* We skip all leading white space, but not EOLs.  */
-          if (!(buflen == 0 && (c == ' ' || c == '\t')))
-            comment_add (c);
-          switch (c)
-            {
-            case '\n':
-              comment_line_end (1);
-              comment_start ();
-              last_was_star = false;
-              continue;
+      {
+        bool last_was_star = false;
+        for (;;)
+          {
+            c = phase1_getc ();
+            if (c == EOF)
+              break;
+            /* We skip all leading white space, but not EOLs.  */
+            if (!(buflen == 0 && (c == ' ' || c == '\t')))
+              comment_add (c);
+            switch (c)
+              {
+              case '\n':
+                comment_line_end (1);
+                comment_start ();
+                last_was_star = false;
+                continue;
 
-            case '*':
-              last_was_star = true;
-              continue;
+              case '*':
+                last_was_star = true;
+                continue;
 
-            case '/':
-              if (last_was_star)
-                {
-                  comment_line_end (2);
-                  break;
-                }
-              FALLTHROUGH;
+              case '/':
+                if (last_was_star)
+                  {
+                    comment_line_end (2);
+                    break;
+                  }
+                FALLTHROUGH;
 
-            default:
-              last_was_star = false;
-              continue;
-            }
-          break;
-        }
+              default:
+                last_was_star = false;
+                continue;
+              }
+            break;
+          }
+      }
       last_comment_line = line_number;
       return ' ';
 
@@ -465,7 +464,7 @@ free_token (token_ty *tp)
 static int
 get_string_element ()
 {
-  int c, j;
+  int c;
 
   /* Use phase 1, because phase 2 elides comments.  */
   c = phase1_getc ();
@@ -544,12 +543,8 @@ get_string_element ()
           break;
         }
       {
-        int n;
-        bool overflow;
-
-        n = 0;
-        overflow = false;
-
+        int n = 0;
+        bool overflow = false;
         for (;;)
           {
             switch (c)
@@ -590,10 +585,8 @@ get_string_element ()
 
     case '0':
       {
-        int n;
-
-        n = 0;
-        for (j = 0; j < 3; ++j)
+        int n = 0;
+        for (int j = 0; j < 3; ++j)
           {
             n = n * 8 + c - '0';
             c = phase1_getc ();
@@ -615,9 +608,9 @@ get_string_element ()
     case 'u':
       {
         unsigned char buf[8];
-        int n;
+        int j;
 
-        n = 0;
+        int n = 0;
         for (j = 0; j < 4; j++)
           {
             int c1 = phase1_getc ();
@@ -718,8 +711,6 @@ phase3_get (token_ty *tp)
 
   for (;;)
     {
-      bool template;
-      bool verbatim;
       int c;
 
       tp->line_number = line_number;
@@ -745,8 +736,8 @@ phase3_get (token_ty *tp)
         }
 
       last_non_comment_line = tp->line_number;
-      template = false;
-      verbatim = false;
+      bool template = false;
+      bool verbatim = false;
 
       switch (c)
         {
@@ -923,7 +914,6 @@ phase3_get (token_ty *tp)
             struct mixed_string_buffer msb;
             {
               int c2 = phase1_getc ();
-
               if (c2 == '"')
                 {
                   int c3 = phase1_getc ();
@@ -1273,13 +1263,13 @@ phase4_get (token_ty *tp)
       for (;;)
         {
           token_ty token2;
-
           phase3_get (&token2);
+
           if (token2.type == token_type_plus)
             {
               token_ty token3;
-
               phase3_get (&token3);
+
               if (token3.type == token_type_string_literal)
                 {
                   sum = mixed_string_concat_free1 (sum, token3.mixed_string);
@@ -1385,7 +1375,6 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
   for (;;)
     {
       token_ty token;
-
       x_vala_lex (&token);
 
       switch (token.type)
@@ -1393,7 +1382,6 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
         case token_type_symbol:
           {
             void *keyword_value;
-
             if (hash_find_entry (&keywords, token.string, strlen (token.string),
                                  &keyword_value)
                 == 0)
@@ -1538,7 +1526,6 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
         case token_type_string_literal:
           {
             lex_pos_ty pos;
-
             pos.file_name = logical_file_name;
             pos.line_number = token.line_number;
 
index 57985a7db5262fe04fd14f85d3ab80d93a8310b3..ce146283db5ac97893e3bd34284b14c66e549eda 100644 (file)
@@ -135,13 +135,11 @@ static int phase2_pushback_length;
 static int
 phase2_getc ()
 {
-  int lineno;
-  int c;
-  bool last_was_star;
-
   if (phase2_pushback_length)
     return phase2_pushback[--phase2_pushback_length];
 
+  int c;
+
   if (char_in_line == 0)
     {
       /* Eat whitespace, to recognize ^[\t ]*# pattern.  */
@@ -154,7 +152,7 @@ phase2_getc ()
           /* sh comment.  */
           struct string_buffer buffer;
           sb_init (&buffer);
-          lineno = line_number;
+          int lineno = line_number;
           for (;;)
             {
               c = phase1_getc ();
@@ -188,8 +186,8 @@ phase2_getc ()
           {
             struct string_buffer buffer;
             sb_init (&buffer);
-            lineno = line_number;
-            last_was_star = false;
+            int lineno = line_number;
+            bool last_was_star = false;
             for (;;)
               {
                 c = phase1_getc ();
@@ -249,7 +247,7 @@ phase2_getc ()
           {
             struct string_buffer buffer;
             sb_init (&buffer);
-            lineno = line_number;
+            int lineno = line_number;
             for (;;)
               {
                 c = phase1_getc ();
@@ -317,10 +315,10 @@ struct token_ty
 static int
 get_string_element ()
 {
-  int c;
-
   for (;;)
     {
+      int c;
+
       /* Use phase 1, because phase 2 elides comments.  */
       c = phase1_getc ();
 
@@ -351,10 +349,8 @@ get_string_element ()
           case '0': case '1': case '2': case '3':
           case '4': case '5': case '6': case '7':
             {
-              int n, j;
-
-              n = 0;
-              for (j = 0; j < 3; ++j)
+              int n = 0;
+              for (int j = 0; j < 3; ++j)
                 {
                   n = n * 8 + c - '0';
                   c = phase1_getc ();
@@ -400,8 +396,6 @@ static int phase5_pushback_length;
 static void
 phase5_get (token_ty *tp)
 {
-  int c;
-
   if (phase5_pushback_length)
     {
       *tp = phase5_pushback[--phase5_pushback_length];
@@ -409,6 +403,8 @@ phase5_get (token_ty *tp)
     }
   for (;;)
     {
+      int c;
+
       tp->line_number = line_number;
       c = phase2_getc ();
 
@@ -564,15 +560,15 @@ phase8_get (token_ty *tp)
   for (;;)
     {
       token_ty tmp;
-      size_t len;
-
       phase5_get (&tmp);
+
       if (tmp.type != token_type_string_literal)
         {
           phase5_unget (&tmp);
           return;
         }
-      len = strlen (tp->string);
+
+      size_t len = strlen (tp->string);
       tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1);
       strcpy (tp->string + len, tmp.string);
       free_token (&tmp);
@@ -647,7 +643,6 @@ extract_parenthesized (message_list_ty *mlp,
   for (;;)
     {
       token_ty token;
-
       if (in_i18n)
         phase8_get (&token);
       else
@@ -682,7 +677,6 @@ extract_parenthesized (message_list_ty *mlp,
                 {
                   /* Seen an msgid.  */
                   token_ty token2;
-
                   if (in_i18n)
                     phase8_get (&token2);
                   else
index a163c146d58de195af2f25f3cbe1b99e514954d4..46b783753db41f32ab9051ac58597fa69d39c524 100644 (file)
@@ -45,8 +45,8 @@ xerror (int severity, const char *prefix_tail,
   if (multiline_p)
     {
       bool old_error_with_progname = error_with_progname;
-      char *prefix;
 
+      char *prefix;
       if (filename != NULL)
         {
           if (lineno != (size_t)(-1))
index 7536baf695158e257a409a08a338b623c9b8e299..ecb4d83e9d873db9b213d8315cc71605be9b686b 100644 (file)
@@ -32,7 +32,6 @@ void
 split_keywordspec (const char *spec,
                    const char **endp, struct callshape *shapep)
 {
-  const char *p;
   int argnum1 = 0;
   int argnum2 = 0;
   int argnumc = 0;
@@ -40,11 +39,10 @@ split_keywordspec (const char *spec,
   bool argnum2_glib_context = false;
   int argtotal = 0;
   string_list_ty xcomments;
-
   string_list_init (&xcomments);
 
   /* Start parsing from the end.  */
-  p = spec + strlen (spec);
+  const char *p = spec + strlen (spec);
   while (p > spec)
     {
       if (isdigit ((unsigned char) p[-1])
@@ -94,27 +92,23 @@ split_keywordspec (const char *spec,
         }
       else if (p[-1] == '"')
         {
-          const char *xcomment_end;
-
           p--;
-          xcomment_end = p;
+          const char *xcomment_end = p;
 
           while (p > spec && p[-1] != '"')
             p--;
 
           if (p > spec /* && p[-1] == '"' */)
             {
-              const char *xcomment_start;
-
-              xcomment_start = p;
+              const char *xcomment_start = p;
               p--;
               if (p > spec && (p[-1] == ',' || p[-1] == ':'))
                 {
                   size_t xcomment_len = xcomment_end - xcomment_start;
                   char *xcomment = XNMALLOC (xcomment_len + 1, char);
-
                   memcpy (xcomment, xcomment_start, xcomment_len);
                   xcomment[xcomment_len] = '\0';
+
                   string_list_append (&xcomments, xcomment);
                 }
               else
@@ -132,8 +126,6 @@ split_keywordspec (const char *spec,
       p--;
       if (*p == ':')
         {
-          size_t i;
-
           if (argnum1 == 0 && argnum2 == 0)
             /* At least one non-context argument must be given.  */
             break;
@@ -150,7 +142,7 @@ split_keywordspec (const char *spec,
           shapep->argtotal = argtotal;
           /* Reverse the order of the xcomments.  */
           string_list_init (&shapep->xcomments);
-          for (i = xcomments.nitems; i > 0; )
+          for (size_t i = xcomments.nitems; i > 0; )
             string_list_append (&shapep->xcomments, xcomments.item[--i]);
           string_list_destroy (&xcomments);
           return;
@@ -195,11 +187,9 @@ insert_keyword_callshape (hash_table *table,
       /* Found a 'struct callshapes'.  See whether it already contains the
          desired shape.  */
       struct callshapes *old_shapes = (struct callshapes *) old_value;
-      bool found;
-      size_t i;
 
-      found = false;
-      for (i = 0; i < old_shapes->nshapes; i++)
+      bool found = false;
+      for (size_t i = 0; i < old_shapes->nshapes; i++)
         if (old_shapes->shapes[i].argnum1 == shape->argnum1
             && old_shapes->shapes[i].argnum2 == shape->argnum2
             && old_shapes->shapes[i].argnumc == shape->argnumc
@@ -226,9 +216,12 @@ insert_keyword_callshape (hash_table *table,
           shapes->keyword = old_shapes->keyword;
           shapes->keyword_len = old_shapes->keyword_len;
           shapes->nshapes = old_shapes->nshapes + 1;
-          for (i = 0; i < old_shapes->nshapes; i++)
-            shapes->shapes[i] = old_shapes->shapes[i];
-          shapes->shapes[i] = *shape;
+          {
+            size_t i;
+            for (i = 0; i < old_shapes->nshapes; i++)
+              shapes->shapes[i] = old_shapes->shapes[i];
+            shapes->shapes[i] = *shape;
+          }
           if (hash_set_value (table, keyword, keyword_len, shapes))
             abort ();
           free (old_shapes);
index 76d0e096a44f6ebc30d315eaf0a7ab8506f4dbf7..9868cc0caa6c55d3acdc3d4b325177830dbbf46c 100644 (file)
@@ -118,13 +118,13 @@ flag_context_list_ty *
 flag_context_list_table_lookup (flag_context_list_table_ty *flag_table,
                                 const void *key, size_t keylen)
 {
-  void *entry;
-
-  if (flag_table->table != NULL
-      && hash_find_entry (flag_table, key, keylen, &entry) == 0)
-    return (flag_context_list_ty *) entry;
-  else
-    return NULL;
+  if (flag_table->table != NULL)
+    {
+      void *entry;
+      if (hash_find_entry (flag_table, key, keylen, &entry) == 0)
+        return (flag_context_list_ty *) entry;
+    }
+  return NULL;
 }
 
 
@@ -158,6 +158,7 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
         memset (&list->flags, '\0', sizeof (list->flags));
         set_flags_for_formatstring_type (&list->flags, fi, value, pass);
         list->next = NULL;
+
         hash_insert_entry (table, name_start, name_end - name_start, list);
       }
     else
@@ -186,6 +187,7 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
             list->argnum = argnum;
             memset (&list->flags, '\0', sizeof (list->flags));
             set_flags_for_formatstring_type (&list->flags, fi, value, pass);
+
             list->next = *lastp;
             *lastp = list;
           }
@@ -201,6 +203,7 @@ flag_context_list_table_add (flag_context_list_table_ty *table,
             list->argnum = argnum;
             memset (&list->flags, '\0', sizeof (list->flags));
             set_flags_for_formatstring_type (&list->flags, fi, value, pass);
+
             list->next = copy;
           }
       }
@@ -225,10 +228,8 @@ remembered_message_list_append (struct remembered_message_list_ty *list,
 {
   if (list->nitems >= list->nitems_max)
     {
-      size_t nbytes;
-
       list->nitems_max = list->nitems_max * 2 + 4;
-      nbytes = list->nitems_max * sizeof (struct remembered_message_ty);
+      size_t nbytes = list->nitems_max * sizeof (struct remembered_message_ty);
       list->item = xrealloc (list->item, nbytes);
     }
   list->item[list->nitems++] = element;
@@ -283,7 +284,6 @@ inheriting_region (flag_region_ty *outer_region,
                    flag_context_ty modifier_context)
 {
   flag_region_ty *region = XMALLOC (flag_region_ty);
-
   region->refcount = 1;
   for (size_t fi = 0; fi < NXFORMATS; fi++)
     {
@@ -321,7 +321,6 @@ new_sub_region (flag_region_ty *outer_region, flag_context_ty modifier_context)
 {
   /* Create the new region.  */
   flag_region_ty *region = XMALLOC (flag_region_ty);
-
   region->refcount = 1;
   for (size_t fi = 0; fi < NXFORMATS; fi++)
     {
@@ -346,10 +345,8 @@ new_sub_region (flag_region_ty *outer_region, flag_context_ty modifier_context)
       /* Register it as child of outer_region.  */
       if (outer_region->nsubregions >= outer_region->nsubregions_max)
         {
-          size_t nbytes;
-
           outer_region->nsubregions_max = outer_region->nsubregions_max * 2 + 4;
-          nbytes = outer_region->nsubregions_max * sizeof (struct flag_region_ty *);
+          size_t nbytes = outer_region->nsubregions_max * sizeof (struct flag_region_ty *);
           outer_region->subregion = xrealloc (outer_region->subregion, nbytes);
         }
       outer_region->subregion[outer_region->nsubregions++] = region;
@@ -392,13 +389,11 @@ void
 set_format_flag_on_region (flag_region_ty *region,
                            size_t fi, enum is_format value)
 {
-  size_t i;
-
   /* First, on this region.  */
   region->for_formatstring[fi].is_format = value;
   struct remembered_message_list_ty *rmlp =
     region->for_formatstring[fi].remembered;
-  for (i = 0; i < rmlp->nitems; i++)
+  for (size_t i = 0; i < rmlp->nitems; i++)
     {
       struct remembered_message_ty *rmp = &rmlp->item[i];
       set_format_flag_from_context (rmp->mp, rmp->plural, &rmp->pos,
@@ -406,7 +401,7 @@ set_format_flag_on_region (flag_region_ty *region,
     }
 
   /* Then, recurse through the sub-regions that inherit.  */
-  for (i = 0; i < region->nsubregions; i++)
+  for (size_t i = 0; i < region->nsubregions; i++)
     {
       flag_region_ty *sub_region = region->subregion[i];
       if (sub_region->inherit_from_parent_region
index 0ccb33136c49623fb0f8c4309560ffa8f753eafe..06ad3610b92cfbf57ddedf1d5bc40269bc90471a 100644 (file)
@@ -43,7 +43,6 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
       struct arglist_parser *ap =
         (struct arglist_parser *)
         xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative, 0));
-
       ap->mlp = mlp;
       ap->keyword = NULL;
       ap->keyword_len = 0;
@@ -58,14 +57,12 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
         (struct arglist_parser *)
         xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative,
                               shapes->nshapes));
-      size_t i;
-
       ap->mlp = mlp;
       ap->keyword = shapes->keyword;
       ap->keyword_len = shapes->keyword_len;
       ap->next_is_msgctxt = false;
       ap->nalternatives = shapes->nshapes;
-      for (i = 0; i < shapes->nshapes; i++)
+      for (size_t i = 0; i < shapes->nshapes; i++)
         {
           ap->alternative[i].argnumc = shapes->shapes[i].argnumc;
           ap->alternative[i].argnum1 = shapes->shapes[i].argnum1;
@@ -103,14 +100,12 @@ arglist_parser_clone (struct arglist_parser *ap)
     (struct arglist_parser *)
     xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative,
                           ap->nalternatives));
-  size_t i;
-
   copy->mlp = ap->mlp;
   copy->keyword = ap->keyword;
   copy->keyword_len = ap->keyword_len;
   copy->next_is_msgctxt = ap->next_is_msgctxt;
   copy->nalternatives = ap->nalternatives;
-  for (i = 0; i < ap->nalternatives; i++)
+  for (size_t i = 0; i < ap->nalternatives; i++)
     {
       const struct partial_call *cp = &ap->alternative[i];
       struct partial_call *ccp = &copy->alternative[i];
@@ -148,13 +143,12 @@ arglist_parser_remember (struct arglist_parser *ap,
                          refcounted_string_list_ty *comment,
                          bool comment_is_utf8)
 {
-  bool stored_string = false;
-  size_t nalternatives = ap->nalternatives;
-  size_t i;
-
   if (!(argnum > 0))
     abort ();
-  for (i = 0; i < nalternatives; i++)
+
+  bool stored_string = false;
+  size_t nalternatives = ap->nalternatives;
+  for (size_t i = 0; i < nalternatives; i++)
     {
       struct partial_call *cp = &ap->alternative[i];
 
@@ -208,12 +202,9 @@ arglist_parser_remember_msgctxt (struct arglist_parser *ap,
 {
   bool stored_string = false;
   size_t nalternatives = ap->nalternatives;
-  size_t i;
-
-  for (i = 0; i < nalternatives; i++)
+  for (size_t i = 0; i < nalternatives; i++)
     {
       struct partial_call *cp = &ap->alternative[i];
-
       cp->msgctxt = string;
       cp->msgctxt_pos.file_name = file_name;
       cp->msgctxt_pos.line_number = line_number;
@@ -231,8 +222,6 @@ arglist_parser_remember_msgctxt (struct arglist_parser *ap,
 bool
 arglist_parser_decidedp (struct arglist_parser *ap, int argnum)
 {
-  size_t i;
-
   /* Test whether all alternatives are decided.
      Note: A decided alternative can be complete
        cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0
@@ -243,7 +232,7 @@ arglist_parser_decidedp (struct arglist_parser *ap, int argnum)
      or it can be failed if the number of arguments is exceeded:
        cp->argtotal > 0 && cp->argtotal < argnum
    */
-  for (i = 0; i < ap->nalternatives; i++)
+  for (size_t i = 0; i < ap->nalternatives; i++)
     {
       struct partial_call *cp = &ap->alternative[i];
 
@@ -261,12 +250,9 @@ arglist_parser_decidedp (struct arglist_parser *ap, int argnum)
 void
 arglist_parser_done (struct arglist_parser *ap, int argnum)
 {
-  size_t ncomplete;
-  size_t i;
-
   /* Determine the number of complete calls.  */
-  ncomplete = 0;
-  for (i = 0; i < ap->nalternatives; i++)
+  size_t ncomplete = 0;
+  for (size_t i = 0; i < ap->nalternatives; i++)
     {
       struct partial_call *cp = &ap->alternative[i];
 
@@ -282,7 +268,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
 
       /* Find complete calls where msgctxt, msgid, msgid_plural are all
          provided.  */
-      for (i = 0; i < ap->nalternatives; i++)
+      for (size_t i = 0; i < ap->nalternatives; i++)
         {
           struct partial_call *cp = &ap->alternative[i];
 
@@ -307,7 +293,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
           struct partial_call *best_cp2 = NULL;
 
           /* Find complete calls where msgctxt, msgid are provided.  */
-          for (i = 0; i < ap->nalternatives; i++)
+          for (size_t i = 0; i < ap->nalternatives; i++)
             {
               struct partial_call *cp = &ap->alternative[i];
 
@@ -326,7 +312,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
             }
 
           /* Find complete calls where msgid, msgid_plural are provided.  */
-          for (i = 0; i < ap->nalternatives; i++)
+          for (size_t i = 0; i < ap->nalternatives; i++)
             {
               struct partial_call *cp = &ap->alternative[i];
 
@@ -358,7 +344,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
       if (best_cp == NULL)
         {
           /* Find complete calls where msgid is provided.  */
-          for (i = 0; i < ap->nalternatives; i++)
+          for (size_t i = 0; i < ap->nalternatives; i++)
             {
               struct partial_call *cp = &ap->alternative[i];
 
@@ -388,15 +374,9 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
         {
           /* best_cp indicates the best found complete call.
              Now call remember_a_message.  */
-          flag_region_ty *msgid_region;
-          flag_region_ty *msgid_plural_region;
-          char *best_msgctxt;
-          char *best_msgid;
-          char *best_msgid_plural;
-          message_ty *mp;
 
-          msgid_region = best_cp->msgid_region;
-          msgid_plural_region = best_cp->msgid_plural_region;
+          flag_region_ty *msgid_region = best_cp->msgid_region;
+          flag_region_ty *msgid_plural_region = best_cp->msgid_plural_region;
 
           /* Special support for the 3-argument tr operator in Qt:
              When --qt and --keyword=tr:1,1,2c,3t are specified, add to the
@@ -409,15 +389,15 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
               msgid_plural_region->for_formatstring[XFORMAT_FOURTH].is_format = yes_according_to_context;
             }
 
-          best_msgctxt =
+          char *best_msgctxt =
             (best_cp->msgctxt != NULL
              ? mixed_string_contents_free1 (best_cp->msgctxt)
              : NULL);
-          best_msgid =
+          char *best_msgid =
             (best_cp->msgid != NULL
              ? mixed_string_contents_free1 (best_cp->msgid)
              : NULL);
-          best_msgid_plural =
+          char *best_msgid_plural =
             (best_cp->msgid_plural != NULL
              ? /* Special support for the 3-argument tr operator in Qt.  */
                (best_cp->msgid_plural == best_cp->msgid
@@ -468,9 +448,9 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
                 {
                   size_t ctxt_len = separator - best_msgid_plural;
                   char *ctxt = XNMALLOC (ctxt_len + 1, char);
-
                   memcpy (ctxt, best_msgid_plural, ctxt_len);
                   ctxt[ctxt_len] = '\0';
+
                   if (best_msgctxt == NULL)
                     best_msgctxt = ctxt;
                   else
@@ -487,12 +467,13 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
                 }
             }
 
-          mp = remember_a_message (ap->mlp, best_msgctxt, best_msgid, true,
-                                   best_msgid_plural != NULL,
-                                   msgid_region,
-                                   &best_cp->msgid_pos,
-                                   NULL, best_cp->msgid_comment,
-                                   best_cp->msgid_comment_is_utf8);
+          message_ty *mp =
+            remember_a_message (ap->mlp, best_msgctxt, best_msgid, true,
+                                best_msgid_plural != NULL,
+                                msgid_region,
+                                &best_cp->msgid_pos,
+                                NULL, best_cp->msgid_comment,
+                                best_cp->msgid_comment_is_utf8);
           if (mp != NULL && best_msgid_plural != NULL)
             remember_a_message_plural (mp, best_msgid_plural, true,
                                        msgid_plural_region,
@@ -503,24 +484,21 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
             {
               /* Add best_cp->xcomments to mp->comment_dot, unless already
                  present.  */
-              size_t j;
-
-              for (j = 0; j < best_cp->xcomments.nitems; j++)
+              for (size_t j = 0; j < best_cp->xcomments.nitems; j++)
                 {
                   const char *xcomment = best_cp->xcomments.item[j];
-                  bool found = false;
 
+                  bool found = false;
                   if (mp != NULL && mp->comment_dot != NULL)
                     {
-                      size_t k;
-
-                      for (k = 0; k < mp->comment_dot->nitems; k++)
+                      for (size_t k = 0; k < mp->comment_dot->nitems; k++)
                         if (strcmp (xcomment, mp->comment_dot->item[k]) == 0)
                           {
                             found = true;
                             break;
                           }
                     }
+
                   if (!found)
                     message_comment_dot_append (mp, xcomment);
                 }
@@ -544,7 +522,7 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
         }
     }
 
-  for (i = 0; i < ap->nalternatives; i++)
+  for (size_t i = 0; i < ap->nalternatives; i++)
     {
       drop_reference (ap->alternative[i].msgid_comment);
       unref_region (ap->alternative[i].msgid_region);
index 98e401cf794d85dde7dbc6905f53de27a1212845..b9e53b4a195a673e39d7e5fdfd56c86228e7b2ce 100644 (file)
@@ -55,28 +55,28 @@ typedef int (* syntax_check_function) (const message_ty *mp, const char *msgid);
 static int
 syntax_check_ellipsis_unicode (const message_ty *mp, const char *msgid)
 {
-  const char *str = msgid;
-  const char *str_limit = str + strlen (msgid);
   int seen_errors = 0;
+  {
+    const char *str = msgid;
+    const char *str_limit = str + strlen (msgid);
+    while (str < str_limit)
+      {
+        ucs4_t ending_char;
+        const char *end = sentence_end (str, &ending_char);
 
-  while (str < str_limit)
-    {
-      const char *end, *cp;
-      ucs4_t ending_char;
-
-      end = sentence_end (str, &ending_char);
+        /* sentence_end doesn't treat '...' specially.  */
+        const char *cp = end - (ending_char == '.' ? 2 : 3);
 
-      /* sentence_end doesn't treat '...' specially.  */
-      cp = end - (ending_char == '.' ? 2 : 3);
-      if (cp >= str && memcmp (cp, "...", 3) == 0)
-        {
-          po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
-                     _("ASCII ellipsis ('...') instead of Unicode"));
-          seen_errors++;
-        }
+        if (cp >= str && memcmp (cp, "...", 3) == 0)
+          {
+            po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
+                       _("ASCII ellipsis ('...') instead of Unicode"));
+            seen_errors++;
+          }
 
-      str = end + 1;
-    }
+        str = end + 1;
+      }
+  }
 
   return seen_errors;
 }
@@ -87,72 +87,69 @@ syntax_check_ellipsis_unicode (const message_ty *mp, const char *msgid)
 static int
 syntax_check_space_ellipsis (const message_ty *mp, const char *msgid)
 {
-  const char *str = msgid;
-  const char *str_limit = str + strlen (msgid);
   int seen_errors = 0;
+  {
+    const char *str = msgid;
+    const char *str_limit = str + strlen (msgid);
+    while (str < str_limit)
+      {
+        ucs4_t ending_char;
+        const char *end = sentence_end (str, &ending_char);
 
-  while (str < str_limit)
-    {
-      const char *end, *ellipsis = NULL;
-      ucs4_t ending_char;
-
-      end = sentence_end (str, &ending_char);
-
-      if (ending_char == 0x2026)
-        ellipsis = end;
-      else if (ending_char == '.')
-        {
-          /* sentence_end doesn't treat '...' specially.  */
-          const char *cp = end - 2;
-          if (cp >= str && memcmp (cp, "...", 3) == 0)
-            ellipsis = cp;
-        }
-      else
-        {
-          /* Look for a '...'.  */
-          const char *cp = end - 3;
-          if (cp >= str && memcmp (cp, "...", 3) == 0)
-            ellipsis = cp;
-          else
-            {
-              ucs4_t uc = 0xfffd;
-
-              /* Look for a U+2026.  */
-              for (cp = end - 1; cp >= str; cp--)
-                {
-                  u8_mbtouc (&uc, (const unsigned char *) cp, end - cp);
-                  if (uc != 0xfffd)
-                    break;
-                }
-
-              if (uc == 0x2026)
-                ellipsis = cp;
-            }
-        }
+        const char *ellipsis = NULL;
+        if (ending_char == 0x2026)
+          ellipsis = end;
+        else if (ending_char == '.')
+          {
+            /* sentence_end doesn't treat '...' specially.  */
+            const char *cp = end - 2;
+            if (cp >= str && memcmp (cp, "...", 3) == 0)
+              ellipsis = cp;
+          }
+        else
+          {
+            /* Look for a '...'.  */
+            const char *cp = end - 3;
+            if (cp >= str && memcmp (cp, "...", 3) == 0)
+              ellipsis = cp;
+            else
+              {
+                /* Look for a U+2026.  */
+                ucs4_t uc = 0xfffd;
+                for (cp = end - 1; cp >= str; cp--)
+                  {
+                    u8_mbtouc (&uc, (const unsigned char *) cp, end - cp);
+                    if (uc != 0xfffd)
+                      break;
+                  }
 
-      if (ellipsis)
-        {
-          const char *cp;
-          ucs4_t uc = 0xfffd;
+                if (uc == 0x2026)
+                  ellipsis = cp;
+              }
+          }
 
-          /* Look at the character before ellipsis.  */
-          for (cp = ellipsis - 1; cp >= str; cp--)
-            {
-              u8_mbtouc (&uc, (const unsigned char *) cp, ellipsis - cp);
-              if (uc != 0xfffd)
-                break;
-            }
+        if (ellipsis)
+          {
+            /* Look at the character before ellipsis.  */
+            ucs4_t uc = 0xfffd;
+            for (const char *cp = ellipsis - 1; cp >= str; cp--)
+              {
+                u8_mbtouc (&uc, (const unsigned char *) cp, ellipsis - cp);
+                if (uc != 0xfffd)
+                  break;
+              }
 
-          if (uc != 0xfffd && uc_is_space (uc))
-            {
-              po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
-                         _("space before ellipsis found in user visible strings"));
-              seen_errors++;
-            }
-        }
+            if (uc != 0xfffd && uc_is_space (uc))
+              {
+                po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false,
+                           _("space before ellipsis found in user visible strings"));
+                seen_errors++;
+              }
+          }
 
-      str = end + 1;
-    }
+        str = end + 1;
+      }
+  }
 
   return seen_errors;
 }
@@ -195,7 +192,6 @@ static int
 syntax_check_quote_unicode (const message_ty *mp, const char *msgid)
 {
   struct callback_arg arg;
-
   arg.mp = mp;
   arg.seen_errors = 0;
 
@@ -226,82 +222,82 @@ static struct bullet_stack_ty bullet_stack;
 static int
 syntax_check_bullet_unicode (const message_ty *mp, const char *msgid)
 {
-  const char *str = msgid;
-  const char *str_limit = str + strlen (msgid);
-  struct bullet_ty *last_bullet = NULL;
   bool seen_error = false;
 
   bullet_stack.nitems = 0;
+  struct bullet_ty *last_bullet = NULL;
 
-  while (str < str_limit)
-    {
-      const char *p = str, *end;
-
-      while (p < str_limit && c_isspace (*p))
-        p++;
-
-      if ((*p == '*' || *p == '-') && *(p + 1) == ' ')
-        {
-          size_t depth = p - str;
-          if (last_bullet == NULL || depth > last_bullet->depth)
-            {
-              struct bullet_ty bullet;
-
-              bullet.c = *p;
-              bullet.depth = depth;
-
-              if (bullet_stack.nitems >= bullet_stack.nitems_max)
-                {
-                  bullet_stack.nitems_max = 2 * bullet_stack.nitems_max + 4;
-                  bullet_stack.items = xrealloc (bullet_stack.items,
-                                                 bullet_stack.nitems_max
-                                                 * sizeof (struct bullet_ty));
-                }
+  {
+    const char *str = msgid;
+    const char *str_limit = str + strlen (msgid);
+    while (str < str_limit)
+      {
+        const char *p = str;
 
-              last_bullet = &bullet_stack.items[bullet_stack.nitems++];
-              memcpy (last_bullet, &bullet, sizeof (struct bullet_ty));
-            }
-          else
-            {
-              if (depth < last_bullet->depth)
-                {
-                  if (bullet_stack.nitems > 1)
-                    {
-                      bullet_stack.nitems--;
-                      last_bullet =
-                        &bullet_stack.items[bullet_stack.nitems - 1];
-                    }
-                  else
-                    last_bullet = NULL;
-                }
+        while (p < str_limit && c_isspace (*p))
+          p++;
 
-              if (last_bullet && depth == last_bullet->depth)
-                {
-                  if (last_bullet->c != *p)
-                    last_bullet->c = *p;
-                  else
-                    {
-                      seen_error = true;
-                      break;
-                    }
-                }
-            }
-        }
-      else
-        {
-          bullet_stack.nitems = 0;
-          last_bullet = NULL;
-        }
+        if ((*p == '*' || *p == '-') && *(p + 1) == ' ')
+          {
+            size_t depth = p - str;
+            if (last_bullet == NULL || depth > last_bullet->depth)
+              {
+                struct bullet_ty bullet;
+                bullet.c = *p;
+                bullet.depth = depth;
+
+                if (bullet_stack.nitems >= bullet_stack.nitems_max)
+                  {
+                    bullet_stack.nitems_max = 2 * bullet_stack.nitems_max + 4;
+                    bullet_stack.items = xrealloc (bullet_stack.items,
+                                                   bullet_stack.nitems_max
+                                                   * sizeof (struct bullet_ty));
+                  }
+
+                last_bullet = &bullet_stack.items[bullet_stack.nitems++];
+                memcpy (last_bullet, &bullet, sizeof (struct bullet_ty));
+              }
+            else
+              {
+                if (depth < last_bullet->depth)
+                  {
+                    if (bullet_stack.nitems > 1)
+                      {
+                        bullet_stack.nitems--;
+                        last_bullet =
+                          &bullet_stack.items[bullet_stack.nitems - 1];
+                      }
+                    else
+                      last_bullet = NULL;
+                  }
+
+                if (last_bullet && depth == last_bullet->depth)
+                  {
+                    if (last_bullet->c != *p)
+                      last_bullet->c = *p;
+                    else
+                      {
+                        seen_error = true;
+                        break;
+                      }
+                  }
+              }
+          }
+        else
+          {
+            bullet_stack.nitems = 0;
+            last_bullet = NULL;
+          }
 
-      end = strchrnul (str, '\n');
-      str = end + 1;
-    }
+        const char *end = strchrnul (str, '\n');
+        str = end + 1;
+      }
+  }
 
   if (seen_error)
     {
-      char *msg;
-      msg = xasprintf (_("ASCII bullet ('%c') instead of Unicode"),
-                       last_bullet->c);
+      char *msg = xasprintf (_("ASCII bullet ('%c') instead of Unicode"),
+                             last_bullet->c);
       po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, msg);
       free (msg);
       return 1;
@@ -327,9 +323,8 @@ static int
 syntax_check_message (const message_ty *mp)
 {
   int seen_errors = 0;
-  int i;
 
-  for (i = 0; i < NSYNTAXCHECKS; i++)
+  for (int i = 0; i < NSYNTAXCHECKS; i++)
     {
       if (mp->do_syntax_check[i] == yes)
         {
@@ -359,8 +354,8 @@ formatstring_error_logger (void *data, const char *format, ...)
 {
   struct formatstring_error_logger_locals *l =
     (struct formatstring_error_logger_locals *) data;
-  va_list args;
 
+  va_list args;
   va_start (args, format);
   if_verror (IF_SEVERITY_ERROR,
              l->pos->file_name, l->pos->line_number, (size_t)(-1), false,
@@ -375,13 +370,12 @@ static int
 format_check_message (const message_ty *mp)
 {
   int seen_errors = 0;
-  size_t i;
 
   if (mp->msgid_plural != NULL)
     {
       /* Look for format string incompatibilities between msgid and
          msgid_plural.  */
-      for (i = 0; i < NFORMATS; i++)
+      for (size_t i = 0; i < NFORMATS; i++)
         if (possible_format_p (mp->is_format[i]))
           {
             struct formatstring_parser *parser = formatstring_parsers[i];
@@ -430,16 +424,14 @@ string_has_url (const char *string)
     "ftp://",
     "irc://", "ircs://"
   };
-  size_t i;
 
-  for (i = 0; i < SIZEOF (patterns); i++)
+  for (size_t i = 0; i < SIZEOF (patterns); i++)
     {
       const char *pattern = patterns[i];
       /* msgid and msgid_plural are typically entirely ASCII.  Therefore here
          it's OK to use the <c-ctype.h> functions; no need for UTF-8 aware
          <unictype.h> functions.  */
-      const char *string_tail;
-      for (string_tail = string;;)
+      for (const char *string_tail = string;;)
         {
           const char *found = c_strstr (string_tail, pattern);
           if (found == NULL)
@@ -487,8 +479,7 @@ message_has_url (const message_ty *mp)
 static bool
 string_has_email (const char *string)
 {
-  const char *string_tail;
-  for (string_tail = string;;)
+  for (const char *string_tail = string;;)
     {
       /* An email address consists of LOCALPART@DOMAIN.  */
       const char *at = strchr (string_tail, '@');
@@ -584,9 +575,8 @@ int
 xgettext_check_message_list (message_list_ty *mlp)
 {
   int seen_errors = 0;
-  size_t j;
 
-  for (j = 0; j < mlp->nitems; j++)
+  for (size_t j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
index 3acda611e221b370b9b66b2e0f314e987df97387..8cc4cbbf79d36d026efff709a975fb9352767514 100644 (file)
@@ -61,13 +61,12 @@ non_ascii_error_message (lexical_context_ty lcontext,
                          const char *file_name, size_t line_number)
 {
   char buffer[22];
-  char *errmsg;
-
   if (line_number == (size_t)(-1))
     buffer[0] = '\0';
   else
     sprintf (buffer, ":%ld", (long) line_number);
 
+  char *errmsg;
   switch (lcontext)
     {
     case lc_outside:
@@ -101,13 +100,12 @@ non_utf8_error_message (lexical_context_ty lcontext,
                         const char *file_name, size_t line_number)
 {
   char buffer[22];
-  char *errmsg;
-
   if (line_number == (size_t)(-1))
     buffer[0] = '\0';
   else
     sprintf (buffer, ":%ld", (long) line_number);
 
+  char *errmsg;
   switch (lcontext)
     {
     case lc_outside:
@@ -176,7 +174,6 @@ from_current_source_encoding (const char *string,
     {
 #if HAVE_ICONV
       struct conversion_context context;
-
       context.from_code = xgettext_current_source_encoding;
       context.to_code = po_charset_utf8;
       context.from_filename = file_name;
@@ -234,7 +231,6 @@ string_desc_from_current_source_encoding (string_desc_t string,
     {
 #if HAVE_ICONV
       struct conversion_context context;
-
       context.from_code = xgettext_current_source_encoding;
       context.to_code = po_charset_utf8;
       context.from_filename = file_name;
index d189883163924c16592344a53553fe455ff23fc9..685713adf6aebb0aa04d22ace3ed7daa2fdd3ee5 100644 (file)
@@ -132,8 +132,6 @@ is_relevant (struct formatstring_parser *parser)
 void
 decide_is_format (message_ty *mp)
 {
-  size_t i;
-
   bool already_c_format = possible_format_p (mp->is_format[format_c]);
   bool already_qt_or_kde_or_boost_format =
     (possible_format_p (mp->is_format[format_qt])
@@ -145,7 +143,7 @@ decide_is_format (message_ty *mp)
 
   /* If it is not already decided, through programmer comments, whether the
      msgid is a format string, examine the msgid.  This is a heuristic.  */
-  for (i = 0; i < NFORMATS; i++)
+  for (size_t i = 0; i < NFORMATS; i++)
     {
       if (mp->is_format[i] == undecided
           && is_relevant (formatstring_parsers[i])
@@ -231,9 +229,7 @@ decide_do_wrap (message_ty *mp)
 void
 decide_syntax_check (message_ty *mp)
 {
-  size_t i;
-
-  for (i = 0; i < NSYNTAXCHECKS; i++)
+  for (size_t i = 0; i < NSYNTAXCHECKS; i++)
     if (mp->do_syntax_check[i] == undecided)
       mp->do_syntax_check[i] = default_syntax_check[i] == yes ? yes : no;
 }
@@ -263,10 +259,6 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid,
                     const char *extracted_comment,
                     refcounted_string_list_ty *comment, bool comment_is_utf8)
 {
-  struct argument_range range;
-  message_ty *mp;
-  size_t i;
-
   /* See whether we shall exclude this message.  */
   if (exclude != NULL && message_list_search (exclude, msgctxt, msgid) != NULL)
     {
@@ -284,6 +276,7 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid,
 
   savable_comment_to_xgettext_comment (comment);
 
+  struct argument_range range;
   range.min = -1;
   range.max = -1;
 
@@ -303,15 +296,13 @@ gettext(\"\") returns the header entry with\n\
 meta information, not the empty string.\n"));
 
   /* See if we have seen this message before.  */
-  mp = message_list_search (mlp, msgctxt, msgid);
+  message_ty *mp = message_list_search (mlp, msgctxt, msgid);
   if (mp != NULL)
     {
       if (pluralp != (mp->msgid_plural != NULL))
         {
           lex_pos_ty pos1;
           lex_pos_ty pos2;
-          char buffer1[22];
-          char buffer2[22];
 
           if (pluralp)
             {
@@ -324,10 +315,12 @@ meta information, not the empty string.\n"));
               pos2 = mp->pos;
             }
 
+          char buffer1[22];
           if (pos1.line_number == (size_t)(-1))
             buffer1[0] = '\0';
           else
             sprintf (buffer1, ":%ld", (long) pos1.line_number);
+          char buffer2[22];
           if (pos2.line_number == (size_t)(-1))
             buffer2[0] = '\0';
           else
@@ -374,48 +367,44 @@ meta information, not the empty string.\n"));
 
   /* Ask the lexer for the comments it has seen.  */
   {
-    size_t nitems_before;
-    size_t nitems_after;
-    int j;
-    bool add_all_remaining_comments;
-    /* The string before the comment tag.  For example, If "** TRANSLATORS:"
-       is seen and the comment tag is "TRANSLATORS:",
-       then comment_tag_prefix is set to "** ".  */
-    const char *comment_tag_prefix = "";
-    size_t comment_tag_prefix_length = 0;
-
-    nitems_before = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
+    size_t nitems_before =
+      (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
 
     if (extracted_comment != NULL)
       {
         char *copy = xstrdup (extracted_comment);
-        char *rest;
-
-        rest = copy;
-        while (*rest != '\0')
-          {
-            char *newline = strchr (rest, '\n');
+        {
+          char *rest = copy;
+          while (*rest != '\0')
+            {
+              char *newline = strchr (rest, '\n');
 
-            if (newline != NULL)
-              {
-                *newline = '\0';
-                message_comment_dot_append (mp, rest);
-                rest = newline + 1;
-              }
-            else
-              {
-                message_comment_dot_append (mp, rest);
-                break;
-              }
-          }
+              if (newline != NULL)
+                {
+                  *newline = '\0';
+                  message_comment_dot_append (mp, rest);
+                  rest = newline + 1;
+                }
+              else
+                {
+                  message_comment_dot_append (mp, rest);
+                  break;
+                }
+            }
+        }
         free (copy);
       }
 
-    add_all_remaining_comments = add_all_comments;
-    for (j = 0; ; ++j)
+    /* The string before the comment tag.  For example, If "** TRANSLATORS:"
+       is seen and the comment tag is "TRANSLATORS:",
+       then comment_tag_prefix is set to "** ".  */
+    const char *comment_tag_prefix = "";
+    size_t comment_tag_prefix_length = 0;
+
+    bool add_all_remaining_comments = add_all_comments;
+    for (int j = 0; ; ++j)
       {
         const char *s = xgettext_comment (j);
-        const char *t;
         if (s == NULL)
           break;
 
@@ -425,56 +414,58 @@ meta information, not the empty string.\n"));
         /* To reduce the possibility of unwanted matches we do a two
            step match: the line must contain 'xgettext:' and one of
            the possible format description strings.  */
-        if ((t = c_strstr (s, "xgettext:")) != NULL)
-          {
-            bool tmp_fuzzy;
-            enum is_format tmp_format[NFORMATS];
-            struct argument_range tmp_range;
-            enum is_wrap tmp_wrap;
-            enum is_syntax_check tmp_syntax_check[NSYNTAXCHECKS];
-            bool interesting;
-
-            t += strlen ("xgettext:");
-
-            parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_range,
-                                   &tmp_wrap, tmp_syntax_check);
-
-            interesting = false;
-            for (i = 0; i < NFORMATS; i++)
-              if (tmp_format[i] != undecided)
+        {
+          const char *t = c_strstr (s, "xgettext:");
+          if (t != NULL)
+            {
+              t += strlen ("xgettext:");
+
+              bool tmp_fuzzy;
+              enum is_format tmp_format[NFORMATS];
+              struct argument_range tmp_range;
+              enum is_wrap tmp_wrap;
+              enum is_syntax_check tmp_syntax_check[NSYNTAXCHECKS];
+              parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_range,
+                                     &tmp_wrap, tmp_syntax_check);
+
+              bool interesting = false;
+              for (size_t i = 0; i < NFORMATS; i++)
+                if (tmp_format[i] != undecided)
+                  {
+                    mp->is_format[i] = tmp_format[i];
+                    interesting = true;
+                  }
+              if (has_range_p (tmp_range))
                 {
-                  mp->is_format[i] = tmp_format[i];
+                  range = tmp_range;
                   interesting = true;
                 }
-            if (has_range_p (tmp_range))
-              {
-                range = tmp_range;
-                interesting = true;
-              }
-            if (tmp_wrap != undecided)
-              {
-                mp->do_wrap = tmp_wrap;
-                interesting = true;
-              }
-            for (i = 0; i < NSYNTAXCHECKS; i++)
-              if (tmp_syntax_check[i] != undecided)
+              if (tmp_wrap != undecided)
                 {
-                  mp->do_syntax_check[i] = tmp_syntax_check[i];
+                  mp->do_wrap = tmp_wrap;
                   interesting = true;
                 }
-
-            /* If the "xgettext:" marker was followed by an interesting
-               keyword, and we updated our mp->is_format/mp->do_wrap variables,
-               we don't print the comment as a #. comment.  */
-            if (interesting)
-              continue;
-          }
+              for (size_t i = 0; i < NSYNTAXCHECKS; i++)
+                if (tmp_syntax_check[i] != undecided)
+                  {
+                    mp->do_syntax_check[i] = tmp_syntax_check[i];
+                    interesting = true;
+                  }
+
+              /* If the "xgettext:" marker was followed by an interesting
+                 keyword, and we updated our mp->is_format/mp->do_wrap
+                 variables, we don't print the comment as a #. comment.  */
+              if (interesting)
+                continue;
+            }
+        }
 
         if (!add_all_remaining_comments && comment_tag != NULL)
           {
             /* When the comment tag is seen, it drags in not only the line
                which it starts, but all remaining comment lines.  */
-            if ((t = c_strstr (s, comment_tag)) != NULL)
+            const char *t = c_strstr (s, comment_tag);
+            if (t != NULL)
               {
                 add_all_remaining_comments = true;
                 comment_tag_prefix = s;
@@ -490,7 +481,8 @@ meta information, not the empty string.\n"));
           }
       }
 
-    nitems_after = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
+    size_t nitems_after =
+      (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
 
     /* Don't add the comments if they are a repetition of the tail of the
        already present comments.  This avoids unneeded duplication if the
@@ -502,8 +494,7 @@ meta information, not the empty string.\n"));
         if (added <= nitems_before)
           {
             bool repeated = true;
-
-            for (i = 0; i < added; i++)
+            for (size_t i = 0; i < added; i++)
               if (strcmp (mp->comment_dot->item[nitems_before - added + i],
                           mp->comment_dot->item[nitems_before + i]) != 0)
                 {
@@ -513,7 +504,7 @@ meta information, not the empty string.\n"));
 
             if (repeated)
               {
-                for (i = 0; i < added; i++)
+                for (size_t i = 0; i < added; i++)
                   free ((char *) mp->comment_dot->item[nitems_before + i]);
                 mp->comment_dot->nitems = nitems_before;
               }
@@ -551,9 +542,7 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
                            refcounted_string_list_ty *comment,
                            bool comment_is_utf8)
 {
-  char *msgid_plural;
-
-  msgid_plural = string;
+  char *msgid_plural = string;
 
   savable_comment_to_xgettext_comment (comment);
 
@@ -563,17 +552,13 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
   /* See if the message is already a plural message.  */
   if (mp->msgid_plural == NULL)
     {
-      char *msgstr1_malloc = NULL;
-      const char *msgstr1;
-      size_t msgstr1_len;
-      char *msgstr;
-      size_t i;
-
       mp->msgid_plural = msgid_plural;
 
       /* Construct the first plural form from the prefix and suffix,
          otherwise use the empty string.  The translator will have to
          provide additional plural forms.  */
+      char *msgstr1_malloc = NULL;
+      const char *msgstr1;
       if (msgstr_prefix)
         {
           msgstr1_malloc =
@@ -583,12 +568,15 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
         }
       else
         msgstr1 = "";
-      msgstr1_len = strlen (msgstr1) + 1;
-      msgstr = XNMALLOC (mp->msgstr_len + msgstr1_len, char);
+      size_t msgstr1_len = strlen (msgstr1) + 1;
+
+      char *msgstr = XNMALLOC (mp->msgstr_len + msgstr1_len, char);
       memcpy (msgstr, mp->msgstr, mp->msgstr_len);
       memcpy (msgstr + mp->msgstr_len, msgstr1, msgstr1_len);
+
       mp->msgstr = msgstr;
       mp->msgstr_len = mp->msgstr_len + msgstr1_len;
+
       free (msgstr1_malloc);
 
       /* Determine whether the context specifies that the msgid_plural is a
@@ -607,7 +595,7 @@ remember_a_message_plural (message_ty *mp, char *string, bool is_utf8,
       /* If it is not already decided, through programmer comments or
          the msgid, whether the msgid is a format string, examine the
          msgid_plural.  This is a heuristic.  */
-      for (i = 0; i < NFORMATS; i++)
+      for (size_t i = 0; i < NFORMATS; i++)
         if (is_relevant (formatstring_parsers[i])
             && (mp->is_format[i] == undecided || mp->is_format[i] == possible)
             /* But avoid redundancy: objc-format is stronger than c-format.  */
index b5109832c2b1c3645bf83825d272af6f2d743257..47754f86428e68a7db48ec01c58e2e6d2e2982b1 100644 (file)
@@ -65,7 +65,6 @@ mixed_string_alloc_simple (const char *string,
                            int line_number)
 {
   struct mixed_string *ms = XMALLOC (struct mixed_string);
-
   if (*string == '\0')
     {
       /* An empty string.  */
@@ -101,7 +100,6 @@ mixed_string_alloc_utf8 (const char *string,
                          int line_number)
 {
   struct mixed_string *ms = XMALLOC (struct mixed_string);
-
   if (*string == '\0')
     {
       /* An empty string.  */
@@ -124,9 +122,9 @@ mixed_string_alloc_utf8 (const char *string,
 mixed_string_ty *
 mixed_string_clone (const mixed_string_ty *ms1)
 {
-  struct mixed_string *ms = XMALLOC (struct mixed_string);
   size_t nsegments = ms1->nsegments;
 
+  struct mixed_string *ms = XMALLOC (struct mixed_string);
   if (nsegments == 0)
     {
       ms->segments = NULL;
@@ -134,10 +132,8 @@ mixed_string_clone (const mixed_string_ty *ms1)
     }
   else
     {
-      size_t i;
-
       ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
-      for (i = 0; i < nsegments; i++)
+      for (size_t i = 0; i < nsegments; i++)
         ms->segments[i] = segment_clone (ms1->segments[i]);
       ms->nsegments = nsegments;
     }
@@ -165,80 +161,63 @@ mixed_string_contents (const mixed_string_ty *ms)
       return string;
     }
   /* General case.  */
+  for (size_t i = 0; i < nsegments - 1; i++)
+    if (memchr (ms->segments[i]->contents, '\0', ms->segments[i]->length)
+        != NULL)
+      {
+        /* Segment i contains a NUL character.  Ignore the remaining
+           segments.  */
+        nsegments = i + 1;
+        break;
+      }
   {
-    size_t i;
-
-    for (i = 0; i < nsegments - 1; i++)
-      if (memchr (ms->segments[i]->contents, '\0', ms->segments[i]->length)
-          != NULL)
+    char **converted_segments = XNMALLOC (nsegments, char *);
+    size_t length = 0;
+    for (size_t i = 0; i < nsegments; i++)
+      if (ms->segments[i]->type == source_encoded)
         {
-          /* Segment i contains a NUL character.  Ignore the remaining
-             segments.  */
-          nsegments = i + 1;
-          break;
+          /* Copy the segment's contents, with a NUL at the end.  */
+          char *source_encoded_string;
+          {
+            size_t len = ms->segments[i]->length;
+            source_encoded_string = XNMALLOC (len + 1, char);
+            memcpy (source_encoded_string, ms->segments[i]->contents, len);
+            source_encoded_string[len] = '\0';
+          }
+          /* Convert it to UTF-8 encoding.  */
+          char *utf8_encoded_string =
+            from_current_source_encoding (source_encoded_string,
+                                          ms->lcontext,
+                                          ms->logical_file_name,
+                                          ms->line_number);
+          if (utf8_encoded_string != source_encoded_string)
+            free (source_encoded_string);
+          converted_segments[i] = utf8_encoded_string;
+          length += strlen (utf8_encoded_string);
         }
-  }
-  {
-    char **converted_segments = XNMALLOC (nsegments, char *);
-    size_t length;
+      else
+        length += ms->segments[i]->length;
 
-    length = 0;
+    char *string = XNMALLOC (length + 1, char);
     {
-      size_t i;
-
-      for (i = 0; i < nsegments; i++)
+      char *p = string;
+      for (size_t i = 0; i < nsegments; i++)
         if (ms->segments[i]->type == source_encoded)
           {
-            char *source_encoded_string;
-            char *utf8_encoded_string;
-
-            /* Copy the segment's contents, with a NUL at the end.  */
-            {
-              size_t len = ms->segments[i]->length;
-              source_encoded_string = XNMALLOC (len + 1, char);
-              memcpy (source_encoded_string, ms->segments[i]->contents, len);
-              source_encoded_string[len] = '\0';
-            }
-            /* Convert it to UTF-8 encoding.  */
-            utf8_encoded_string =
-              from_current_source_encoding (source_encoded_string,
-                                            ms->lcontext,
-                                            ms->logical_file_name,
-                                            ms->line_number);
-            if (utf8_encoded_string != source_encoded_string)
-              free (source_encoded_string);
-            converted_segments[i] = utf8_encoded_string;
-            length += strlen (utf8_encoded_string);
+            p = stpcpy (p, converted_segments[i]);
+            free (converted_segments[i]);
           }
         else
-          length += ms->segments[i]->length;
+          {
+            memcpy (p, ms->segments[i]->contents, ms->segments[i]->length);
+            p += ms->segments[i]->length;
+          }
+      assert (p == string + length);
+      *p = '\0';
     }
 
-    {
-      char *string = XNMALLOC (length + 1, char);
-      {
-        char *p;
-        size_t i;
-
-        p = string;
-        for (i = 0; i < nsegments; i++)
-          if (ms->segments[i]->type == source_encoded)
-            {
-              p = stpcpy (p, converted_segments[i]);
-              free (converted_segments[i]);
-            }
-          else
-            {
-              memcpy (p, ms->segments[i]->contents, ms->segments[i]->length);
-              p += ms->segments[i]->length;
-            }
-        assert (p == string + length);
-        *p = '\0';
-      }
-
-      free (converted_segments);
-      return string;
-    }
+    free (converted_segments);
+    return string;
   }
 }
 
@@ -249,8 +228,7 @@ mixed_string_free (mixed_string_ty *ms)
   size_t nsegments = ms->nsegments;
   if (nsegments > 0)
     {
-      size_t i;
-      for (i = 0; i < nsegments; i++)
+      for (size_t i = 0; i < nsegments; i++)
         free (segments[i]);
     }
   free (segments);
@@ -282,38 +260,37 @@ mixed_string_concat (const mixed_string_ty *ms1,
     if (ms1->segments[ms1->nsegments-1]->type == ms2->segments[0]->type)
       {
         /* Combine the last segment of ms1 with the first segment of ms2.  */
-        size_t i;
-
         nsegments -= 1;
         ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
         j = 0;
-        for (i = 0; i < ms1->nsegments - 1; i++)
-          ms->segments[j++] = segment_clone (ms1->segments[i]);
         {
-          size_t len1 = ms1->segments[i]->length;
-          size_t len2 = ms2->segments[0]->length;
-          struct mixed_string_segment *newseg =
-            (struct mixed_string_segment *)
-            xmalloc (FLEXSIZEOF (struct mixed_string_segment, contents,
-                                 len1 + len2));
-          newseg->type = ms2->segments[0]->type;
-          newseg->length = len1 + len2;
-          memcpy (newseg->contents, ms1->segments[i]->contents, len1);
-          memcpy (newseg->contents + len1, ms2->segments[0]->contents, len2);
-          ms->segments[j++] = newseg;
+          size_t i;
+          for (i = 0; i < ms1->nsegments - 1; i++)
+            ms->segments[j++] = segment_clone (ms1->segments[i]);
+          {
+            size_t len1 = ms1->segments[i]->length;
+            size_t len2 = ms2->segments[0]->length;
+            struct mixed_string_segment *newseg =
+              (struct mixed_string_segment *)
+              xmalloc (FLEXSIZEOF (struct mixed_string_segment, contents,
+                                   len1 + len2));
+            newseg->type = ms2->segments[0]->type;
+            newseg->length = len1 + len2;
+            memcpy (newseg->contents, ms1->segments[i]->contents, len1);
+            memcpy (newseg->contents + len1, ms2->segments[0]->contents, len2);
+            ms->segments[j++] = newseg;
+          }
         }
-        for (i = 1; i < ms2->nsegments; i++)
+        for (size_t i = 1; i < ms2->nsegments; i++)
           ms->segments[j++] = segment_clone (ms2->segments[i]);
       }
     else
       {
-        size_t i;
-
         ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
         j = 0;
-        for (i = 0; i < ms1->nsegments; i++)
+        for (size_t i = 0; i < ms1->nsegments; i++)
           ms->segments[j++] = segment_clone (ms1->segments[i]);
-        for (i = 0; i < ms2->nsegments; i++)
+        for (size_t i = 0; i < ms2->nsegments; i++)
           ms->segments[j++] = segment_clone (ms2->segments[i]);
       }
     assert (j == nsegments);
@@ -345,39 +322,38 @@ mixed_string_concat_free1 (mixed_string_ty *ms1, const mixed_string_ty *ms2)
     if (ms1->segments[ms1->nsegments-1]->type == ms2->segments[0]->type)
       {
         /* Combine the last segment of ms1 with the first segment of ms2.  */
-        size_t i;
-
         nsegments -= 1;
         ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
         j = 0;
-        for (i = 0; i < ms1->nsegments - 1; i++)
-          ms->segments[j++] = ms1->segments[i];
         {
-          size_t len1 = ms1->segments[i]->length;
-          size_t len2 = ms2->segments[0]->length;
-          struct mixed_string_segment *newseg =
-            (struct mixed_string_segment *)
-            xmalloc (FLEXSIZEOF (struct mixed_string_segment, contents,
-                                 len1 + len2));
-          newseg->type = ms2->segments[0]->type;
-          newseg->length = len1 + len2;
-          memcpy (newseg->contents, ms1->segments[i]->contents, len1);
-          memcpy (newseg->contents + len1, ms2->segments[0]->contents, len2);
-          ms->segments[j++] = newseg;
+          size_t i;
+          for (i = 0; i < ms1->nsegments - 1; i++)
+            ms->segments[j++] = ms1->segments[i];
+          {
+            size_t len1 = ms1->segments[i]->length;
+            size_t len2 = ms2->segments[0]->length;
+            struct mixed_string_segment *newseg =
+              (struct mixed_string_segment *)
+              xmalloc (FLEXSIZEOF (struct mixed_string_segment, contents,
+                                   len1 + len2));
+            newseg->type = ms2->segments[0]->type;
+            newseg->length = len1 + len2;
+            memcpy (newseg->contents, ms1->segments[i]->contents, len1);
+            memcpy (newseg->contents + len1, ms2->segments[0]->contents, len2);
+            ms->segments[j++] = newseg;
+          }
+          free (ms1->segments[i]);
         }
-        free (ms1->segments[i]);
-        for (i = 1; i < ms2->nsegments; i++)
+        for (size_t i = 1; i < ms2->nsegments; i++)
           ms->segments[j++] = segment_clone (ms2->segments[i]);
       }
     else
       {
-        size_t i;
-
         ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
         j = 0;
-        for (i = 0; i < ms1->nsegments; i++)
+        for (size_t i = 0; i < ms1->nsegments; i++)
           ms->segments[j++] = ms1->segments[i];
-        for (i = 0; i < ms2->nsegments; i++)
+        for (size_t i = 0; i < ms2->nsegments; i++)
           ms->segments[j++] = segment_clone (ms2->segments[i]);
       }
     assert (j == nsegments);
@@ -616,10 +592,10 @@ mixed_string_buffer_append_unicode (struct mixed_string_buffer *bp, int c)
   if (bp->utf16_surr != 0 && (c >= 0xdc00 && c < 0xe000))
     {
       unsigned short utf16buf[2];
-      ucs4_t uc;
-
       utf16buf[0] = bp->utf16_surr;
       utf16buf[1] = c;
+
+      ucs4_t uc;
       if (u16_mbtouc (&uc, utf16buf, 2) != 2)
         abort ();
 
@@ -646,8 +622,7 @@ mixed_string_buffer_destroy (struct mixed_string_buffer *bp)
   size_t nsegments = bp->nsegments;
   if (nsegments > 0)
     {
-      size_t i;
-      for (i = 0; i < nsegments; i++)
+      for (size_t i = 0; i < nsegments; i++)
         free (segments[i]);
     }
   free (segments);
@@ -695,10 +670,8 @@ mixed_string_buffer_cloned_result (struct mixed_string_buffer *bp)
 
     if (nsegments > 0)
       {
-        size_t i;
-
         ms->segments = XNMALLOC (nsegments, struct mixed_string_segment *);
-        for (i = 0; i < nsegments; i++)
+        for (size_t i = 0; i < nsegments; i++)
           ms->segments[i] = segment_clone (bp->segments[i]);
       }
     else
index 6471a3c680aa31dd9c84fd4f83236a6e29066e7d..0b1f89f8bf93cca5cb574dc07a1ccdabaf69e267 100644 (file)
@@ -304,26 +304,6 @@ static const char *extension_to_language (const char *extension);
 int
 main (int argc, char *argv[])
 {
-  bool do_help = false;
-  bool do_version = false;
-  msgdomain_list_ty *mdlp;
-  bool join_existing = false;
-  bool no_default_keywords = false;
-  bool some_additional_keywords = false;
-  bool sort_by_msgid = false;
-  bool sort_by_filepos = false;
-  char **dirs;
-  char **its_dirs = NULL;
-  char *explicit_its_filename = NULL;
-  const char *file_name;
-  const char *files_from = NULL;
-  string_list_ty *file_list;
-  char *output_file = NULL;
-  const char *language = NULL;
-  extractor_ty extractor = { NULL, NULL, NULL, { NULL, NULL, NULL, NULL } };
-  int cnt;
-  size_t i;
-
   /* Set program name for messages.  */
   set_program_name (argv[0]);
   error_print_progname = maybe_print_progname;
@@ -341,7 +321,18 @@ main (int argc, char *argv[])
   /* Ensure that write errors on stdout are detected.  */
   atexit (close_stdout);
 
-  /* Set initial value of variables.  */
+  /* Default values for command line options.  */
+  bool do_help = false;
+  bool do_version = false;
+  bool join_existing = false;
+  bool no_default_keywords = false;
+  bool some_additional_keywords = false;
+  bool sort_by_msgid = false;
+  bool sort_by_filepos = false;
+  char *explicit_its_filename = NULL;
+  const char *files_from = NULL;
+  char *output_file = NULL;
+  const char *language = NULL;
   default_domain = MESSAGE_DOMAIN_DEFAULT;
   string_list_init (&files_for_vc_mtime);
   generated_files =
@@ -440,331 +431,335 @@ main (int argc, char *argv[])
   };
   END_ALLOW_OMITTING_FIELD_INITIALIZERS
   start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0);
-  int optchar;
-  while ((optchar = get_next_option ()) != -1)
-    switch (optchar)
-      {
-      case '\0':                /* Long option with key == 0.  */
-        break;
+  {
+    int optchar;
+    while ((optchar = get_next_option ()) != -1)
+      switch (optchar)
+        {
+        case '\0':                /* Long option with key == 0.  */
+          break;
 
-      case 'a':
-        x_c_extract_all ();
-        x_python_extract_all ();
-        x_java_extract_all ();
-        x_csharp_extract_all ();
-        x_javascript_extract_all ();
-        x_typescript_extract_all ();
-        x_typescriptx_extract_all ();
-        x_scheme_extract_all ();
-        x_lisp_extract_all ();
-        x_elisp_extract_all ();
-        x_librep_extract_all ();
-        x_rust_extract_all ();
-        x_go_extract_all ();
-        x_ruby_extract_all ();
-        x_sh_extract_all ();
-        x_awk_extract_all ();
-        x_lua_extract_all ();
-        x_modula2_extract_all ();
-        x_d_extract_all ();
-        x_ocaml_extract_all ();
-        x_vala_extract_all ();
-        x_tcl_extract_all ();
-        x_perl_extract_all ();
-        x_php_extract_all ();
-        break;
+        case 'a':
+          x_c_extract_all ();
+          x_python_extract_all ();
+          x_java_extract_all ();
+          x_csharp_extract_all ();
+          x_javascript_extract_all ();
+          x_typescript_extract_all ();
+          x_typescriptx_extract_all ();
+          x_scheme_extract_all ();
+          x_lisp_extract_all ();
+          x_elisp_extract_all ();
+          x_librep_extract_all ();
+          x_rust_extract_all ();
+          x_go_extract_all ();
+          x_ruby_extract_all ();
+          x_sh_extract_all ();
+          x_awk_extract_all ();
+          x_lua_extract_all ();
+          x_modula2_extract_all ();
+          x_d_extract_all ();
+          x_ocaml_extract_all ();
+          x_vala_extract_all ();
+          x_tcl_extract_all ();
+          x_perl_extract_all ();
+          x_php_extract_all ();
+          break;
 
-      case 'c':
-        if (optarg == NULL)
-          {
-            add_all_comments = true;
-            comment_tag = NULL;
-          }
-        else
-          {
-            add_all_comments = false;
-            comment_tag = optarg;
-            /* We ignore leading white space.  */
-            while (isspace ((unsigned char) *comment_tag))
-              ++comment_tag;
-          }
-        break;
+        case 'c':
+          if (optarg == NULL)
+            {
+              add_all_comments = true;
+              comment_tag = NULL;
+            }
+          else
+            {
+              add_all_comments = false;
+              comment_tag = optarg;
+              /* We ignore leading white space.  */
+              while (isspace ((unsigned char) *comment_tag))
+                ++comment_tag;
+            }
+          break;
 
-      case 'C':
-        language = "C++";
-        break;
+        case 'C':
+          language = "C++";
+          break;
 
-      case 'd':
-        default_domain = optarg;
-        break;
+        case 'd':
+          default_domain = optarg;
+          break;
 
-      case 'D':
-        dir_list_append (optarg);
-        break;
+        case 'D':
+          dir_list_append (optarg);
+          break;
 
-      case 'e':
-        message_print_style_escape (false);
-        break;
+        case 'e':
+          message_print_style_escape (false);
+          break;
 
-      case 'E':
-        message_print_style_escape (true);
-        break;
+        case 'E':
+          message_print_style_escape (true);
+          break;
 
-      case 'f':
-        files_from = optarg;
-        break;
+        case 'f':
+          files_from = optarg;
+          break;
 
-      case 'F':
-        sort_by_filepos = true;
-        break;
+        case 'F':
+          sort_by_filepos = true;
+          break;
 
-      case 'h':
-        do_help = true;
-        break;
+        case 'h':
+          do_help = true;
+          break;
 
-      case 'i':
-        message_print_style_indent ();
-        break;
+        case 'i':
+          message_print_style_indent ();
+          break;
 
-      case 'j':
-        join_existing = true;
-        break;
+        case 'j':
+          join_existing = true;
+          break;
 
-      case 'k':
-        if (optarg != NULL && *optarg == '\0')
-          /* Make "--keyword=" work like "--keyword" and "-k".  */
-          optarg = NULL;
-        x_c_keyword (optarg);
-        x_objc_keyword (optarg);
-        x_python_keyword (optarg);
-        x_java_keyword (optarg);
-        x_csharp_keyword (optarg);
-        x_javascript_keyword (optarg);
-        x_typescript_keyword (optarg);
-        x_typescriptx_keyword (optarg);
-        x_scheme_keyword (optarg);
-        x_lisp_keyword (optarg);
-        x_elisp_keyword (optarg);
-        x_librep_keyword (optarg);
-        x_rust_keyword (optarg);
-        x_go_keyword (optarg);
-        x_ruby_keyword (optarg);
-        x_sh_keyword (optarg);
-        x_awk_keyword (optarg);
-        x_lua_keyword (optarg);
-        x_modula2_keyword (optarg);
-        x_d_keyword (optarg);
-        x_ocaml_keyword (optarg);
-        x_vala_keyword (optarg);
-        x_tcl_keyword (optarg);
-        x_perl_keyword (optarg);
-        x_php_keyword (optarg);
-        x_desktop_keyword (optarg);
-        if (optarg == NULL)
-          no_default_keywords = true;
-        else
-          some_additional_keywords = true;
-        break;
+        case 'k':
+          if (optarg != NULL && *optarg == '\0')
+            /* Make "--keyword=" work like "--keyword" and "-k".  */
+            optarg = NULL;
+          x_c_keyword (optarg);
+          x_objc_keyword (optarg);
+          x_python_keyword (optarg);
+          x_java_keyword (optarg);
+          x_csharp_keyword (optarg);
+          x_javascript_keyword (optarg);
+          x_typescript_keyword (optarg);
+          x_typescriptx_keyword (optarg);
+          x_scheme_keyword (optarg);
+          x_lisp_keyword (optarg);
+          x_elisp_keyword (optarg);
+          x_librep_keyword (optarg);
+          x_rust_keyword (optarg);
+          x_go_keyword (optarg);
+          x_ruby_keyword (optarg);
+          x_sh_keyword (optarg);
+          x_awk_keyword (optarg);
+          x_lua_keyword (optarg);
+          x_modula2_keyword (optarg);
+          x_d_keyword (optarg);
+          x_ocaml_keyword (optarg);
+          x_vala_keyword (optarg);
+          x_tcl_keyword (optarg);
+          x_perl_keyword (optarg);
+          x_php_keyword (optarg);
+          x_desktop_keyword (optarg);
+          if (optarg == NULL)
+            no_default_keywords = true;
+          else
+            some_additional_keywords = true;
+          break;
 
-      case 'l':
-        /* Accepted for backward compatibility with 0.10.35.  */
-        break;
+        case 'l':
+          /* Accepted for backward compatibility with 0.10.35.  */
+          break;
 
-      case 'L':
-        language = optarg;
-        break;
+        case 'L':
+          language = optarg;
+          break;
 
-      case 'm':
-        /* -m takes an optional argument.  If none is given "" is assumed. */
-        msgstr_prefix = optarg == NULL ? "" : optarg;
-        break;
+        case 'm':
+          /* -m takes an optional argument.  If none is given "" is assumed. */
+          msgstr_prefix = optarg == NULL ? "" : optarg;
+          break;
 
-      case 'M':
-        /* -M takes an optional argument.  If none is given "" is assumed. */
-        msgstr_suffix = optarg == NULL ? "" : optarg;
-        break;
+        case 'M':
+          /* -M takes an optional argument.  If none is given "" is assumed. */
+          msgstr_suffix = optarg == NULL ? "" : optarg;
+          break;
 
-      case 'n':            /* -n */
-      case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
-        if (handle_filepos_comment_option (optarg))
-          usage (EXIT_FAILURE);
-        break;
+        case 'n':            /* -n */
+        case CHAR_MAX + 'n': /* --add-location[={full|yes|file|never|no}] */
+          if (handle_filepos_comment_option (optarg))
+            usage (EXIT_FAILURE);
+          break;
 
-      case 'o':
-        output_file = optarg;
-        break;
+        case 'o':
+          output_file = optarg;
+          break;
 
-      case 'p':
-        {
-          size_t len = strlen (optarg);
+        case 'p':
+          {
+            size_t len = strlen (optarg);
 
-          if (output_dir != NULL)
-            free (output_dir);
+            if (output_dir != NULL)
+              free (output_dir);
 
-          if (optarg[len - 1] == '/')
-            output_dir = xstrdup (optarg);
-          else
-            output_dir = xasprintf ("%s/", optarg);
-        }
-        break;
+            if (optarg[len - 1] == '/')
+              output_dir = xstrdup (optarg);
+            else
+              output_dir = xasprintf ("%s/", optarg);
+          }
+          break;
 
-      case 's':
-        sort_by_msgid = true;
-        break;
+        case 's':
+          sort_by_msgid = true;
+          break;
 
-      case CHAR_MAX + 25: /* --strict */
-        message_print_style_uniforum ();
-        break;
+        case CHAR_MAX + 25: /* --strict */
+          message_print_style_uniforum ();
+          break;
 
-      case 'T':
-        x_c_trigraphs ();
-        break;
+        case 'T':
+          x_c_trigraphs ();
+          break;
 
-      case 'v':
-        verbose++;
-        break;
+        case 'v':
+          verbose++;
+          break;
 
-      case 'V':
-        do_version = true;
-        break;
+        case 'V':
+          do_version = true;
+          break;
 
-      case 'w':
-        {
-          int value;
-          char *endp;
-          value = strtol (optarg, &endp, 10);
-          if (endp != optarg)
-            message_page_width_set (value);
-        }
-        break;
+        case 'w':
+          {
+            char *endp;
+            int value = strtol (optarg, &endp, 10);
+            if (endp != optarg)
+              message_page_width_set (value);
+          }
+          break;
 
-      case 'x':
-        read_exclusion_file (optarg);
-        break;
+        case 'x':
+          read_exclusion_file (optarg);
+          break;
 
-      case CHAR_MAX + 1:        /* --copyright-holder */
-        copyright_holder = optarg;
-        break;
+        case CHAR_MAX + 1:        /* --copyright-holder */
+          copyright_holder = optarg;
+          break;
 
-      case CHAR_MAX + 2:        /* --foreign-user */
-        copyright_holder = "";
-        break;
+        case CHAR_MAX + 2:        /* --foreign-user */
+          copyright_holder = "";
+          break;
 
-      case CHAR_MAX + 3:        /* --from-code */
-        xgettext_global_source_encoding = po_charset_canonicalize (optarg);
-        if (xgettext_global_source_encoding == NULL)
-          {
-            multiline_warning (xasprintf (_("warning: ")),
-                               xasprintf (_("'%s' is not a valid encoding name.  Using ASCII as fallback.\n"),
-                                          optarg));
-            xgettext_global_source_encoding = po_charset_ascii;
-          }
-        break;
+        case CHAR_MAX + 3:        /* --from-code */
+          xgettext_global_source_encoding = po_charset_canonicalize (optarg);
+          if (xgettext_global_source_encoding == NULL)
+            {
+              multiline_warning (xasprintf (_("warning: ")),
+                                 xasprintf (_("'%s' is not a valid encoding name.  Using ASCII as fallback.\n"),
+                                            optarg));
+              xgettext_global_source_encoding = po_charset_ascii;
+            }
+          break;
 
-      case CHAR_MAX + 4:        /* --no-wrap */
-        message_page_width_ignore ();
-        break;
+        case CHAR_MAX + 4:        /* --no-wrap */
+          message_page_width_ignore ();
+          break;
 
-      case CHAR_MAX + 5:        /* --msgid-bugs-address */
-        msgid_bugs_address = optarg;
-        break;
+        case CHAR_MAX + 5:        /* --msgid-bugs-address */
+          msgid_bugs_address = optarg;
+          break;
 
-      case CHAR_MAX + 6:        /* --properties-output */
-        output_syntax = &output_format_properties;
-        break;
+        case CHAR_MAX + 6:        /* --properties-output */
+          output_syntax = &output_format_properties;
+          break;
 
-      case CHAR_MAX + 7:        /* --stringtable-output */
-        output_syntax = &output_format_stringtable;
-        break;
+        case CHAR_MAX + 7:        /* --stringtable-output */
+          output_syntax = &output_format_stringtable;
+          break;
 
-      case CHAR_MAX + 8:        /* --flag */
-        xgettext_record_flag (optarg);
-        break;
+        case CHAR_MAX + 8:        /* --flag */
+          xgettext_record_flag (optarg);
+          break;
 
-      case CHAR_MAX + 9:        /* --qt */
-        recognize_format_qt = true;
-        break;
+        case CHAR_MAX + 9:        /* --qt */
+          recognize_format_qt = true;
+          break;
 
-      case CHAR_MAX + 10:       /* --kde */
-        recognize_format_kde = true;
-        activate_additional_keywords_kde ();
-        break;
+        case CHAR_MAX + 10:       /* --kde */
+          recognize_format_kde = true;
+          activate_additional_keywords_kde ();
+          break;
 
-      case CHAR_MAX + 11:       /* --boost */
-        recognize_format_boost = true;
-        break;
+        case CHAR_MAX + 11:       /* --boost */
+          recognize_format_boost = true;
+          break;
 
-      case CHAR_MAX + 12:       /* --package-name */
-        package_name = optarg;
-        break;
+        case CHAR_MAX + 12:       /* --package-name */
+          package_name = optarg;
+          break;
 
-      case CHAR_MAX + 13:       /* --package-version */
-        package_version = optarg;
-        break;
+        case CHAR_MAX + 13:       /* --package-version */
+          package_version = optarg;
+          break;
 
-      case CHAR_MAX + 14: /* --color */
-        if (handle_color_option (optarg) || color_test_mode)
-          usage (EXIT_FAILURE);
-        break;
+        case CHAR_MAX + 14: /* --color */
+          if (handle_color_option (optarg) || color_test_mode)
+            usage (EXIT_FAILURE);
+          break;
 
-      case CHAR_MAX + 15: /* --style */
-        handle_style_option (optarg);
-        break;
+        case CHAR_MAX + 15: /* --style */
+          handle_style_option (optarg);
+          break;
 
-      case CHAR_MAX + 16: /* --no-location */
-        message_print_style_filepos (filepos_comment_none);
-        break;
+        case CHAR_MAX + 16: /* --no-location */
+          message_print_style_filepos (filepos_comment_none);
+          break;
 
-      case CHAR_MAX + 17: /* --check */
-        for (i = 0; i < NSYNTAXCHECKS; i++)
+        case CHAR_MAX + 17: /* --check */
           {
-            if (strcmp (optarg, syntax_check_name[i]) == 0)
+            size_t i;
+            for (i = 0; i < NSYNTAXCHECKS; i++)
               {
-                default_syntax_check[i] = yes;
-                break;
+                if (strcmp (optarg, syntax_check_name[i]) == 0)
+                  {
+                    default_syntax_check[i] = yes;
+                    break;
+                  }
               }
+            if (i == NSYNTAXCHECKS)
+              error (EXIT_FAILURE, 0, _("syntax check '%s' unknown"), optarg);
           }
-        if (i == NSYNTAXCHECKS)
-          error (EXIT_FAILURE, 0, _("syntax check '%s' unknown"), optarg);
-        break;
+          break;
 
-      case CHAR_MAX + 18: /* --sentence-end */
-        if (strcmp (optarg, "single-space") == 0)
-          sentence_end_required_spaces = 1;
-        else if (strcmp (optarg, "double-space") == 0)
-          sentence_end_required_spaces = 2;
-        else
-          error (EXIT_FAILURE, 0, _("sentence end type '%s' unknown"), optarg);
-        break;
+        case CHAR_MAX + 18: /* --sentence-end */
+          if (strcmp (optarg, "single-space") == 0)
+            sentence_end_required_spaces = 1;
+          else if (strcmp (optarg, "double-space") == 0)
+            sentence_end_required_spaces = 2;
+          else
+            error (EXIT_FAILURE, 0, _("sentence end type '%s' unknown"), optarg);
+          break;
 
-      case CHAR_MAX + 19: /* --itstool */
-        add_itstool_comments = true;
-        break;
+        case CHAR_MAX + 19: /* --itstool */
+          add_itstool_comments = true;
+          break;
 
-      case CHAR_MAX + 20: /* --its */
-        explicit_its_filename = optarg;
-        break;
+        case CHAR_MAX + 20: /* --its */
+          explicit_its_filename = optarg;
+          break;
 
-      case CHAR_MAX + 21: /* --tag */
-        x_javascript_tag (optarg);
-        break;
+        case CHAR_MAX + 21: /* --tag */
+          x_javascript_tag (optarg);
+          break;
 
-      case CHAR_MAX + 22: /* --reference */
-        string_list_append (&files_for_vc_mtime, optarg);
-        break;
+        case CHAR_MAX + 22: /* --reference */
+          string_list_append (&files_for_vc_mtime, optarg);
+          break;
 
-      case CHAR_MAX + 23: /* --no-git */
-        xgettext_no_git = true;
-        break;
+        case CHAR_MAX + 23: /* --no-git */
+          xgettext_no_git = true;
+          break;
 
-      case CHAR_MAX + 24: /* --generated */
-        gl_set_add (generated_files, optarg);
-        break;
+        case CHAR_MAX + 24: /* --generated */
+          gl_set_add (generated_files, optarg);
+          break;
 
-      default:
-        usage (EXIT_FAILURE);
-        /* NOTREACHED */
-      }
+        default:
+          usage (EXIT_FAILURE);
+          /* NOTREACHED */
+        }
+  }
 
   /* Version information requested.  */
   if (do_version)
@@ -833,15 +828,17 @@ xgettext cannot work without keywords to look for"));
     error (EXIT_SUCCESS, 0, _("The option '%s' is deprecated."),
            "--sort-output");
 
+  char **its_dirs = NULL;
   if (explicit_its_filename == NULL)
     {
       its_dirs = get_search_path ("its");
       its_locating_rules = locating_rule_list_alloc ();
-      for (dirs = its_dirs; *dirs != NULL; dirs++)
+      for (char **dirs = its_dirs; *dirs != NULL; dirs++)
         locating_rule_list_add_from_directory (its_locating_rules, *dirs);
     }
 
   /* Determine extractor from language.  */
+  extractor_ty extractor = { NULL, NULL, NULL, { NULL, NULL, NULL, NULL } };
   if (language != NULL)
     extractor = language_to_extractor (language);
 
@@ -851,6 +848,8 @@ xgettext cannot work without keywords to look for"));
   else if (msgstr_prefix == NULL && msgstr_suffix != NULL)
     msgstr_prefix = "";
 
+  /* Determine the name of the output file.  */
+  const char *file_name;
   {
     /* Default output directory is the current directory.  */
     const char *defaulted_output_dir = (output_dir != NULL ? output_dir : ".");
@@ -874,6 +873,7 @@ xgettext cannot work without keywords to look for"));
   }
 
   /* Determine list of files we have to process.  */
+  string_list_ty *file_list;
   if (files_from != NULL)
     {
       if (strcmp (files_from, "-") != 0)
@@ -883,7 +883,7 @@ xgettext cannot work without keywords to look for"));
   else
     file_list = string_list_alloc ();
   /* Append names from command line.  */
-  for (cnt = optind; cnt < argc; ++cnt)
+  for (int cnt = optind; cnt < argc; ++cnt)
     string_list_append_unique (file_list, argv[cnt]);
 
   /* Allocate converter from xgettext_global_source_encoding to UTF-8 (except
@@ -911,7 +911,7 @@ xgettext cannot work without keywords to look for"));
     }
 
   /* Allocate a message list to remember all the messages.  */
-  mdlp = msgdomain_list_alloc (true);
+  msgdomain_list_ty *mdlp = msgdomain_list_alloc (true);
 
   /* Generate a header, so that we know how and when this PO file was
      created.  */
@@ -924,10 +924,11 @@ xgettext cannot work without keywords to look for"));
       /* Temporarily reset the directory list to empty, because file_name
          is an output file and therefore should not be searched for.  */
       void *saved_directory_list = dir_list_save_reset ();
+
       extractor_ty po_extractor =
         { extract_po, NULL, NULL, { NULL, NULL, NULL, NULL } };
-
       extract_from_file (file_name, po_extractor, mdlp);
+
       if (!is_ascii_msgdomain_list (mdlp))
         mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, true, file_name,
                                      textmode_xerror_handler);
@@ -936,14 +937,12 @@ xgettext cannot work without keywords to look for"));
     }
 
   /* Process all input files.  */
-  for (i = 0; i < file_list->nitems; i++)
+  for (size_t i = 0; i < file_list->nitems; i++)
     {
-      const char *filename;
+      const char *filename = file_list->item[i];
+
       extractor_ty this_file_extractor;
       its_rule_list_ty *its_rules = NULL;
-
-      filename = file_list->item[i];
-
       if (extractor.extract_from_stream || extractor.extract_from_file)
         this_file_extractor = extractor;
       else if (explicit_its_filename != NULL)
@@ -957,27 +956,22 @@ xgettext cannot work without keywords to look for"));
         }
       else
         {
-          const char *language_from_extension = NULL;
-          const char *base;
-          char *reduced;
-
-          base = strrchr (filename, '/');
+          const char *base = strrchr (filename, '/');
           if (!base)
             base = filename;
 
-          reduced = xstrdup (base);
+          char *reduced = xstrdup (base);
           /* Remove a trailing ".in" - it's a generic suffix.  */
           while (strlen (reduced) >= 3
                  && memcmp (reduced + strlen (reduced) - 3, ".in", 3) == 0)
             reduced[strlen (reduced) - 3] = '\0';
 
           /* If no language is specified with -L, deduce it the extension.  */
+          const char *language_from_extension = NULL;
           if (language == NULL)
             {
-              const char *p;
-
               /* Work out what the file extension is.  */
-              p = reduced + strlen (reduced);
+              const char *p = reduced + strlen (reduced);
               for (; p > reduced && language_from_extension == NULL; p--)
                 {
                   if (*p == '.')
@@ -997,16 +991,12 @@ xgettext cannot work without keywords to look for"));
           if (language_from_extension == NULL
               && strcmp (filename, "-") != 0)
             {
-              const char *its_basename;
-
-              its_basename = locating_rule_list_locate (its_locating_rules,
-                                                        filename,
-                                                        language);
+              const char *its_basename =
+                locating_rule_list_locate (its_locating_rules,
+                                           filename, language);
 
               if (its_basename != NULL)
                 {
-                  size_t j;
-
                   its_rules = its_rule_list_alloc ();
 
                   /* If the ITS file is identified by the name,
@@ -1015,6 +1005,7 @@ xgettext cannot work without keywords to look for"));
                     its_rule_list_add_from_string (its_rules,
                                                    ITS_ROOT_UNTRANSLATABLE);
 
+                  size_t j;
                   for (j = 0; its_dirs[j] != NULL; j++)
                     {
                       char *its_filename =
@@ -1098,7 +1089,7 @@ xgettext cannot work without keywords to look for"));
   {
     int nerrors = 0;
 
-    for (i = 0; i < mdlp->nitems; i++)
+    for (size_t i = 0; i < mdlp->nitems; i++)
       {
         message_list_ty *mlp = mdlp->item[i]->messages;
         nerrors += xgettext_check_message_list (mlp);
@@ -1127,7 +1118,7 @@ xgettext cannot work without keywords to look for"));
 
   if (its_dirs != NULL)
     {
-      for (i = 0; its_dirs[i] != NULL; i++)
+      for (size_t i = 0; its_dirs[i] != NULL; i++)
         free (its_dirs[i]);
       free (its_dirs);
     }
@@ -1397,12 +1388,10 @@ exclude_directive_message (abstract_catalog_reader_ty *catr,
                            char *prev_msgid_plural,
                            bool force_fuzzy, bool obsolete)
 {
-  message_ty *mp;
-
   /* See if this message ID has been seen before.  */
   if (exclude == NULL)
     exclude = message_list_alloc (true);
-  mp = message_list_search (exclude, msgctxt, msgid);
+  message_ty *mp = message_list_search (exclude, msgctxt, msgid);
   if (mp != NULL)
     free (msgid);
   else
@@ -1471,9 +1460,8 @@ flag_context_list_table_insert (flag_context_list_table_ty *table,
       /* Convert NAME to upper case.  */
       size_t name_len = name_end - name_start;
       char *name = allocated_name = (char *) xmalloca (name_len);
-      size_t i;
 
-      for (i = 0; i < name_len; i++)
+      for (size_t i = 0; i < name_len; i++)
         name[i] = (name_start[i] >= 'a' && name_start[i] <= 'z'
                    ? name_start[i] - 'a' + 'A'
                    : name_start[i]);
@@ -1525,15 +1513,13 @@ xgettext_record_flag (const char *optionstring)
     const char *argnum_start = colon1 + 1;
     const char *argnum_end = colon2;
     const char *flag_start = colon2 + 1;
-    const char *flag_end;
-    const char *backend;
-    int argnum;
 
     /* Check the parts' syntax.  */
     if (name_end == name_start)
       goto err;
     if (argnum_end == argnum_start)
       goto err;
+    int argnum;
     {
       char *endp;
       argnum = strtol (argnum_start, &endp, 10);
@@ -1543,7 +1529,8 @@ xgettext_record_flag (const char *optionstring)
     if (argnum <= 0)
       goto err;
 
-    flag_end = strchr (flag_start, '!');
+    const char *flag_end = strchr (flag_start, '!');
+    const char *backend;
     if (flag_end != NULL)
       backend = flag_end + 1;
     else
@@ -1554,9 +1541,7 @@ xgettext_record_flag (const char *optionstring)
 
     /* Analyze the flag part.  */
     {
-      bool pass;
-
-      pass = false;
+      bool pass = false;
       if (flag_end - flag_start >= 5 && memcmp (flag_start, "pass-", 5) == 0)
         {
           pass = true;
@@ -1568,14 +1553,10 @@ xgettext_record_flag (const char *optionstring)
       if (flag_end - flag_start >= 7
           && memcmp (flag_end - 7, "-format", 7) == 0)
         {
-          const char *p;
-          size_t n;
-          enum is_format value;
-          size_t type;
-
-          p = flag_start;
-          n = flag_end - flag_start - 7;
+          const char *p = flag_start;
+          size_t n = flag_end - flag_start - 7;
 
+          enum is_format value;
           if (n >= 3 && memcmp (p, "no-", 3) == 0)
             {
               p += 3;
@@ -1603,7 +1584,7 @@ xgettext_record_flag (const char *optionstring)
           else
             value = yes_according_to_context;
 
-          for (type = 0; type < NFORMATS; type++)
+          for (size_t type = 0; type < NFORMATS; type++)
             if (strlen (format_language[type]) == n
                 && memcmp (format_language[type], p, n) == 0)
               {
@@ -1916,16 +1897,13 @@ savable_comment_add (const char *str)
   else if (savable_comment->refcount > 1)
     {
       /* Unshare the list by making copies.  */
-      struct string_list_ty *oldcontents;
-      size_t i;
-
       savable_comment->refcount--;
-      oldcontents = &savable_comment->contents;
+      struct string_list_ty *oldcontents = &savable_comment->contents;
 
       savable_comment = XMALLOC (refcounted_string_list_ty);
       savable_comment->refcount = 1;
       string_list_init (&savable_comment->contents);
-      for (i = 0; i < oldcontents->nitems; i++)
+      for (size_t i = 0; i < oldcontents->nitems; i++)
         string_list_append (&savable_comment->contents, oldcontents->item[i]);
     }
   string_list_append (&savable_comment->contents, str);
@@ -1944,9 +1922,7 @@ savable_comment_to_xgettext_comment (refcounted_string_list_ty *rslp)
   xgettext_comment_reset ();
   if (rslp != NULL)
     {
-      size_t i;
-
-      for (i = 0; i < rslp->contents.nitems; i++)
+      for (size_t i = 0; i < rslp->contents.nitems; i++)
         xgettext_comment_add (rslp->contents.item[i]);
     }
 }
@@ -1966,20 +1942,15 @@ xgettext_find_file (const char *fn,
                     const char **found_in_dir_p,
                     char **real_file_name_p)
 {
-  char *new_name;
-  const char *found_in_dir;
   char *logical_file_name;
-  struct stat statbuf;
-
-  found_in_dir = NULL;
+  const char *found_in_dir = NULL;
+  char *new_name;
 
   /* We cannot handle "-" here.  "/dev/fd/0" is not portable, and it cannot
      be opened multiple times.  */
   if (IS_RELATIVE_FILE_NAME (fn))
     {
-      int j;
-
-      for (j = 0; ; ++j)
+      for (int j = 0; ; ++j)
         {
           const char *dir = dir_list_nth (j);
 
@@ -1989,6 +1960,7 @@ xgettext_find_file (const char *fn,
 
           new_name = xconcatenated_filename (dir, fn, NULL);
 
+          struct stat statbuf;
           if (stat (new_name, &statbuf) == 0)
             {
               found_in_dir = dir;
@@ -2011,6 +1983,7 @@ xgettext_find_file (const char *fn,
   else
     {
       new_name = xstrdup (fn);
+      struct stat statbuf;
       if (stat (fn, &statbuf) != 0)
         error (EXIT_FAILURE, errno,
                _("error while opening \"%s\" for reading"), fn);
@@ -2027,8 +2000,8 @@ xgettext_open (const char *fn,
                char **logical_file_name_p, char **real_file_name_p)
 {
   FILE *fp;
-  char *new_name;
   char *logical_file_name;
+  char *new_name;
 
   if (strcmp (fn, "-") == 0)
     {
@@ -2038,9 +2011,7 @@ xgettext_open (const char *fn,
     }
   else if (IS_RELATIVE_FILE_NAME (fn))
     {
-      int j;
-
-      for (j = 0; ; ++j)
+      for (int j = 0; ; ++j)
         {
           const char *dir = dir_list_nth (j);
 
@@ -2087,12 +2058,11 @@ static void
 extract_from_file (const char *file_name, extractor_ty extractor,
                    msgdomain_list_ty *mdlp)
 {
-  char *logical_file_name;
-  char *real_file_name;
-
   for (size_t fi = 0; fi < NXFORMATS; fi++)
     current_formatstring_parser[fi] = extractor.formatstring_parser[fi];
 
+  char *logical_file_name;
+  char *real_file_name;
   if (extractor.extract_from_stream)
     {
       FILE *fp = xgettext_open (file_name, &logical_file_name, &real_file_name);
@@ -2141,14 +2111,13 @@ xgettext_its_extract_callback (message_list_ty *mlp,
                                const char *marker,
                                enum its_whitespace_type_ty whitespace)
 {
-  message_ty *message;
-
-  message = remember_a_message (mlp,
-                                msgctxt == NULL ? NULL : xstrdup (msgctxt),
-                                xstrdup (msgid),
-                                false, false,
-                                null_context_region (), pos,
-                                extracted_comment, NULL, false);
+  message_ty *message =
+    remember_a_message (mlp,
+                        msgctxt == NULL ? NULL : xstrdup (msgctxt),
+                        xstrdup (msgid),
+                        false, false,
+                        null_context_region (), pos,
+                        extracted_comment, NULL, false);
 
   if (add_itstool_comments)
     {
@@ -2206,11 +2175,6 @@ static message_ty *
 construct_header ()
 {
   char *project_id_version;
-  message_ty *mp;
-  char *msgstr;
-  char *comment;
-  static lex_pos_ty pos = { __FILE__, __LINE__ };
-
   if (package_name != NULL)
     {
       if (package_version != NULL)
@@ -2230,7 +2194,7 @@ the MSGID_BUGS_ADDRESS variable there; otherwise please\n\
 specify an --msgid-bugs-address command line option.\n\
 ")));
 
-  msgstr = xasprintf ("\
+  char *msgstr = xasprintf ("\
 Project-Id-Version: %s\n\
 Report-Msgid-Bugs-To: %s\n\
 POT-Creation-Date: \n\
@@ -2246,8 +2210,11 @@ Content-Transfer-Encoding: 8bit\n",
   assume (msgstr != NULL);
   free (project_id_version);
 
-  mp = message_alloc (NULL, "", NULL, msgstr, strlen (msgstr) + 1, &pos);
+  static lex_pos_ty pos = { __FILE__, __LINE__ };
+  message_ty *mp =
+    message_alloc (NULL, "", NULL, msgstr, strlen (msgstr) + 1, &pos);
 
+  char *comment;
   if (copyright_holder[0] != '\0')
     comment = xasprintf ("\
 SOME DESCRIPTIVE TITLE.\n\
@@ -2409,15 +2376,12 @@ finalize_header (msgdomain_list_ty *mdlp)
   /* If the generated PO file has plural forms, add a Plural-Forms template
      to the constructed header.  */
   {
-    bool has_plural;
-    size_t i, j;
-
-    has_plural = false;
-    for (i = 0; i < mdlp->nitems; i++)
+    bool has_plural = false;
+    for (size_t i = 0; i < mdlp->nitems; i++)
       {
         message_list_ty *mlp = mdlp->item[i]->messages;
 
-        for (j = 0; j < mlp->nitems; j++)
+        for (size_t j = 0; j < mlp->nitems; j++)
           {
             message_ty *mp = mlp->item[j];
 
@@ -2439,15 +2403,14 @@ finalize_header (msgdomain_list_ty *mdlp)
             && c_strstr (header->msgstr, "Plural-Forms:") == NULL)
           {
             size_t insertpos = strlen (header->msgstr);
-            const char *suffix;
-            size_t suffix_len;
-            char *new_msgstr;
 
-            suffix = "\nPlural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n";
+            const char *suffix =
+              "\nPlural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n";
             if (insertpos == 0 || header->msgstr[insertpos-1] == '\n')
               suffix++;
-            suffix_len = strlen (suffix);
-            new_msgstr = XNMALLOC (header->msgstr_len + suffix_len, char);
+            size_t suffix_len = strlen (suffix);
+
+            char *new_msgstr = XNMALLOC (header->msgstr_len + suffix_len, char);
             memcpy (new_msgstr, header->msgstr, insertpos);
             memcpy (new_msgstr + insertpos, suffix, suffix_len);
             memcpy (new_msgstr + insertpos + suffix_len,
@@ -2536,13 +2499,10 @@ language_to_extractor (const char *name)
        Make sure new scanners honor the --exclude-file option.  */
   };
 
-  table_ty *tp;
-
-  for (tp = table; tp < ENDOF(table); ++tp)
+  for (table_ty *tp = table; tp < ENDOF(table); ++tp)
     if (c_strcasecmp (name, tp->name) == 0)
       {
         extractor_ty result;
-
         result.extract_from_stream = tp->extract_from_stream;
         result.extract_from_file = tp->extract_from_file;
         result.flag_table = tp->flag_table;
@@ -2635,9 +2595,7 @@ extension_to_language (const char *extension)
     /* Here may follow more file extensions... */
   };
 
-  table_ty *tp;
-
-  for (tp = table; tp < ENDOF(table); ++tp)
+  for (table_ty *tp = table; tp < ENDOF(table); ++tp)
     if (strcmp (extension, tp->extension) == 0)
       return tp->language;
   return NULL;
index 074dd04c0d2c722a5a392954242cfcac53e05625..a32dad86ca4757e34d28e90e9dc97abda284931c 100644 (file)
@@ -1,6 +1,5 @@
 /* addext.c -- add an extension to a file name
-   Copyright (C) 1990, 1997-1999, 2001-2003, 2005-2006, 2020 Free Software
-   Foundation, Inc.
+   Copyright (C) 1990, 1997-1999, 2001-2003, 2005-2006, 2020, 2025 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
@@ -51,9 +50,10 @@ void
 addext (char *filename, char const *ext, char e)
 {
   char *s = last_component (filename);
-  size_t slen = strlen (s), extlen = strlen (ext);
-  long slen_max = -1;
+  size_t slen = strlen (s);
+  size_t extlen = strlen (ext);
 
+  long slen_max = -1;
 #if HAVE_PATHCONF && defined _PC_NAME_MAX
   if (slen + extlen <= _POSIX_NAME_MAX && ! HAVE_DOS_FILE_NAMES)
     /* The file name is so short there's no need to call pathconf.  */
index 17fe775367679948229c62e9265e42949f9d13fd..c94fc21b72bcde1e2d60cc5f3a0de125f71a5ce1 100644 (file)
@@ -84,19 +84,18 @@ static int version_number (const char *, const char *, size_t);
 char *
 find_backup_file_name (const char *file, enum backup_type backup_type)
 {
-  size_t backup_suffix_size_max;
   size_t file_len = strlen (file);
   size_t numbered_suffix_size_max = INT_STRLEN_BOUND (int) + 4;
-  char *s;
-  const char *suffix = simple_backup_suffix;
 
   /* Allow room for simple or '.~N~' backups.  */
-  backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
+  size_t backup_suffix_size_max = strlen (simple_backup_suffix) + 1;
   if (HAVE_DIR && backup_suffix_size_max < numbered_suffix_size_max)
     backup_suffix_size_max = numbered_suffix_size_max;
 
-  s = (char *) malloc (file_len + backup_suffix_size_max
-                       + numbered_suffix_size_max);
+  const char *suffix = simple_backup_suffix;
+
+  char *s = (char *) malloc (file_len + backup_suffix_size_max
+                             + numbered_suffix_size_max);
   if (s)
     {
       strcpy (s, file);
@@ -104,11 +103,9 @@ find_backup_file_name (const char *file, enum backup_type backup_type)
 #if HAVE_DIR
       if (backup_type != simple)
         {
-          int highest_backup;
           size_t dir_len = last_component (s) - s;
-
           strcpy (s + dir_len, ".");
-          highest_backup = max_backup_version (file + dir_len, s);
+          int highest_backup = max_backup_version (file + dir_len, s);
           if (! (backup_type == numbered_existing && highest_backup == 0))
             {
               char *numbered_suffix = s + (file_len + backup_suffix_size_max);
@@ -134,30 +131,28 @@ find_backup_file_name (const char *file, enum backup_type backup_type)
 static int
 max_backup_version (const char *file, const char *dir)
 {
-  DIR *dirp;
-  struct dirent *dp;
-  int highest_version;
-  int this_version;
-  size_t file_name_length;
-
-  dirp = opendir (dir);
+  DIR *dirp = opendir (dir);
   if (!dirp)
     return 0;
 
-  highest_version = 0;
-  file_name_length = strlen (file);
+  int highest_version = 0;
+  size_t file_name_length = strlen (file);
 
+  struct dirent *dp;
   while ((dp = readdir (dirp)) != 0)
     {
       if (REAL_DIR_ENTRY (dp) && strlen (dp->d_name) >= file_name_length + 4)
         {
-          this_version = version_number (file, dp->d_name, file_name_length);
+          int this_version =
+            version_number (file, dp->d_name, file_name_length);
           if (this_version > highest_version)
             highest_version = this_version;
         }
     }
+
   if (closedir (dirp))
     return 0;
+
   return highest_version;
 }
 
@@ -168,14 +163,12 @@ max_backup_version (const char *file, const char *dir)
 static int
 version_number (const char *base, const char *backup, size_t base_length)
 {
-  int version;
-  const char *p;
-
-  version = 0;
+  int version = 0;
   if (strncmp (base, backup, base_length) == 0
       && backup[base_length] == '.'
       && backup[base_length + 1] == '~')
     {
+      const char *p;
       for (p = &backup[base_length + 2]; ISDIGIT (*p); ++p)
         version = version * 10 + *p - '0';
       if (p[0] != '~' || p[1])
index 0dd4d0080a6ceed06a1b762248b8706f61b4ae4f..e6cea28682ad7370c429a57e9ccf9b0d6ee1eb22 100644 (file)
@@ -300,12 +300,11 @@ dcpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
-      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcgettext (domain, msg_ctxt_id, category);
-      found_translation = (translation != msg_ctxt_id);
+      int found_translation = (translation != msg_ctxt_id);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
@@ -348,12 +347,11 @@ dcnpgettext_expr (const char *domain,
   if (msg_ctxt_id != NULL)
 #endif
     {
-      int found_translation;
       memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
       msg_ctxt_id[msgctxt_len - 1] = '\004';
       memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
       translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
-      found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
+      int found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
       if (msg_ctxt_id != buf)
         free (msg_ctxt_id);
index 8479ef7ccebd2218c9d939b86bee25371fad3a21..6c5798e707120f2a30b4a0220430aeab68c1bfe9 100644 (file)
@@ -248,11 +248,9 @@ markup_parse_context_new (const markup_parser_ty *parser,
                           markup_parse_flags_ty flags,
                           void *user_data)
 {
-  markup_parse_context_ty *context;
-
   assert (parser != NULL);
 
-  context = XMALLOC (markup_parse_context_ty);
+  markup_parse_context_ty *context = XMALLOC (markup_parse_context_ty);
 
   context->parser = parser;
   context->flags = flags;
@@ -358,30 +356,33 @@ emit_error (markup_parse_context_ty *context, const char *error_text)
 static bool
 slow_name_validate (markup_parse_context_ty *context, const char *name)
 {
-  const char *p = name;
-  ucs4_t uc;
-
   if (u8_check ((const uint8_t *) name, strlen (name)) != NULL)
     {
       emit_error (context, _("invalid UTF-8 sequence"));
       return false;
     }
 
-  if (!(c_isalpha (*p)
-        || (!IS_COMMON_NAME_END_CHAR (*p)
-            && (*p == '_'
-                || *p == ':'
-                || (u8_mbtouc (&uc, (const uint8_t *) name, strlen (name)) > 0
-                    && uc_is_alpha (uc))))))
-    {
-      char *error_text = xasprintf (_("'%s' is not a valid name: %c"),
-                                    name, *p);
-      emit_error (context, error_text);
-      free (error_text);
-      return false;
-    }
+  ucs4_t uc;
 
-  for (p = (const char *) u8_next (&uc, (const uint8_t *) name);
+  {
+    const char *p = name;
+
+    if (!(c_isalpha (*p)
+          || (!IS_COMMON_NAME_END_CHAR (*p)
+              && (*p == '_'
+                  || *p == ':'
+                  || (u8_mbtouc (&uc, (const uint8_t *) name, strlen (name)) > 0
+                      && uc_is_alpha (uc))))))
+      {
+        char *error_text = xasprintf (_("'%s' is not a valid name: %c"),
+                                      name, *p);
+        emit_error (context, error_text);
+        free (error_text);
+        return false;
+      }
+  }
+
+  for (const char *p = (const char *) u8_next (&uc, (const uint8_t *) name);
        p != NULL;
        p = (const char *) u8_next (&uc, (const uint8_t *) p))
     {
@@ -398,6 +399,7 @@ slow_name_validate (markup_parse_context_ty *context, const char *name)
           return false;
         }
     }
+
   return true;
 }
 
@@ -407,28 +409,29 @@ slow_name_validate (markup_parse_context_ty *context, const char *name)
 static bool
 name_validate (markup_parse_context_ty *context, const char *name)
 {
-  char mask;
-  const char *p;
-
   /* name start char */
-  p = name;
+  const char *p = name;
   if (IS_COMMON_NAME_END_CHAR (*p)
       || !(c_isalpha (*p) || *p == '_' || *p == ':'))
     goto slow_validate;
 
-  for (mask = *p++; *p != '\0'; p++)
-    {
-      mask |= *p;
+  {
+    char mask;
 
-      /* is_name_char */
-      if (!(c_isalnum (*p)
-            || (!IS_COMMON_NAME_END_CHAR (*p)
-                && (*p == '.' || *p == '-' || *p == '_' || *p == ':'))))
-        goto slow_validate;
-    }
+    for (mask = *p++; *p != '\0'; p++)
+      {
+        mask |= *p;
 
-  if (mask & 0x80) /* un-common / non-ascii */
-    goto slow_validate;
+        /* is_name_char */
+        if (!(c_isalnum (*p)
+              || (!IS_COMMON_NAME_END_CHAR (*p)
+                  && (*p == '.' || *p == '-' || *p == '_' || *p == ':'))))
+          goto slow_validate;
+      }
+
+    if (mask & 0x80) /* un-common / non-ascii */
+      goto slow_validate;
+  }
 
   return true;
 
@@ -459,16 +462,13 @@ unescape_string_inplace (markup_parse_context_ty *context,
                          markup_string_ty *string,
                          bool *is_ascii)
 {
-  char mask, *to;
-  const char *from;
-  bool normalize_attribute;
-
   if (string->buflen == 0)
     return true;
 
   *is_ascii = false;
 
   /* are we unescaping an attribute or not ? */
+  bool normalize_attribute;
   if (context->state == STATE_INSIDE_ATTRIBUTE_VALUE_SQ
       || context->state == STATE_INSIDE_ATTRIBUTE_VALUE_DQ)
     normalize_attribute = true;
@@ -480,7 +480,9 @@ unescape_string_inplace (markup_parse_context_ty *context,
    * for &lt; etc. this is obvious, for &#xffff; more
    * thought is required, but this is patently so.
    */
-  mask = 0;
+  char mask = 0;
+  const char *from;
+  char *to;
   for (from = to = string->buffer; *from != '\0'; from++, to++)
     {
       *to = *from;
@@ -499,18 +501,17 @@ unescape_string_inplace (markup_parse_context_ty *context,
           from++;
           if (*from == '#')
             {
-              int base = 10;
-              unsigned long l;
-              char *end = NULL;
-
               from++;
 
+              int base = 10;
               if (*from == 'x')
                 {
                   base = 16;
                   from++;
                 }
 
+              unsigned long l;
+              char *end = NULL;
               if (!(base == 16 ? c_isxdigit (*from) : c_isdigit (*from))
                   || /* No need to reset and test errno here, because in case
                         of overflow, l will be == ULONG_MAX, which is
@@ -539,8 +540,7 @@ unescape_string_inplace (markup_parse_context_ty *context,
                        || (0xE000 <= l && l <= 0xFFFD) || (0x10000 <= l && l <= 0x10FFFF))
                 {
                   char buf[8];
-                  int length;
-                  length = u8_uctomb ((uint8_t *) buf, l, 8);
+                  int length = u8_uctomb ((uint8_t *) buf, l, 8);
                   memcpy (to, buf, length);
                   to += length - 1;
                   from = end;
@@ -586,8 +586,6 @@ unescape_string_inplace (markup_parse_context_ty *context,
           else
             {
               const char *reason;
-              char *error_text;
-
               if (*from == ';')
                 reason = _("empty");
               else
@@ -598,8 +596,9 @@ unescape_string_inplace (markup_parse_context_ty *context,
                   else
                     reason = _("no ending ';'");
                 }
-              error_text = xasprintf (_("invalid entity reference: %s"),
-                                      reason);
+
+              char *error_text = xasprintf (_("invalid entity reference: %s"),
+                                            reason);
               emit_error (context, error_text);
               free (error_text);
               return false;
@@ -623,9 +622,9 @@ advance_char (markup_parse_context_ty *context)
   context->char_number++;
 
   if (context->iter == context->current_text_end)
-      return false;
+    return false;
 
-  else if (*context->iter == '\n')
+  if (*context->iter == '\n')
     {
       context->line_number++;
       context->char_number = 1;
@@ -776,9 +775,7 @@ markup_parse_context_push (markup_parse_context_ty *context,
                            const markup_parser_ty *parser,
                            void *user_data)
 {
-  markup_recursion_tracker_ty *tracker;
-
-  tracker = XMALLOC (markup_recursion_tracker_ty);
+  markup_recursion_tracker_ty *tracker = XMALLOC (markup_recursion_tracker_ty);
   tracker->prev_element = context->subparser_element;
   tracker->prev_parser = context->parser;
   tracker->prev_user_data = context->user_data;
@@ -808,11 +805,6 @@ markup_parse_context_pop (markup_parse_context_ty *context)
 static inline void
 emit_start_element (markup_parse_context_ty *context)
 {
-  int i, j = 0;
-  const char *start_name;
-  const char **attr_names;
-  const char **attr_values;
-
   /* In case we want to ignore qualified tags and we see that we have
    * one here, we push a subparser.  This will ignore all tags inside of
    * the qualified tag.
@@ -828,24 +820,27 @@ emit_start_element (markup_parse_context_ty *context)
       return;
     }
 
-  attr_names = XCALLOC (context->cur_attr + 2, const char *);
-  attr_values = XCALLOC (context->cur_attr + 2, const char *);
-  for (i = 0; i < context->cur_attr + 1; i++)
-    {
-      /* Possibly omit qualified attribute names from the list */
-      if (!((context->flags & MARKUP_IGNORE_QUALIFIED)
-            && strchr (context->attr_names[i], ':')))
-        {
-          attr_names[j] = context->attr_names[i];
-          attr_values[j] = context->attr_values[i];
-          j++;
-        }
-    }
-  attr_names[j] = NULL;
-  attr_values[j] = NULL;
+  const char **attr_names = XCALLOC (context->cur_attr + 2, const char *);
+  const char **attr_values = XCALLOC (context->cur_attr + 2, const char *);
+  {
+    int j = 0;
+    for (int i = 0; i < context->cur_attr + 1; i++)
+      {
+        /* Possibly omit qualified attribute names from the list */
+        if (!((context->flags & MARKUP_IGNORE_QUALIFIED)
+              && strchr (context->attr_names[i], ':')))
+          {
+            attr_names[j] = context->attr_names[i];
+            attr_values[j] = context->attr_values[i];
+            j++;
+          }
+      }
+    attr_names[j] = NULL;
+    attr_values[j] = NULL;
+  }
 
   /* Call user callback for element start */
-  start_name = current_element (context);
+  const char *start_name = current_element (context);
 
   if (context->parser->start_element && name_validate (context, start_name))
     (* context->parser->start_element) (context,
@@ -1202,7 +1197,6 @@ markup_parse_context_parse (markup_parse_context_ty *context,
             }
           else
             {
-              bool is_ascii;
               /* The value has ended at the quote mark. Combine it
                * with the partial chunk if any; set it for the current
                * attribute.
@@ -1211,6 +1205,7 @@ markup_parse_context_parse (markup_parse_context_ty *context,
 
               assert (context->cur_attr >= 0);
 
+              bool is_ascii;
               if (unescape_string_inplace (context, context->partial_chunk,
                                            &is_ascii)
                   && (is_ascii
@@ -1248,11 +1243,10 @@ markup_parse_context_parse (markup_parse_context_ty *context,
 
           if (context->iter != context->current_text_end)
             {
-              bool is_ascii;
-
               /* The text has ended at the open angle. Call the text
                * callback.
                */
+              bool is_ascii;
               if (unescape_string_inplace (context, context->partial_chunk,
                                            &is_ascii)
                   && (is_ascii
@@ -1311,9 +1305,7 @@ markup_parse_context_parse (markup_parse_context_ty *context,
 
           if (context->iter != context->current_text_end)
             {
-              markup_string_ty *close_name;
-
-              close_name = context->partial_chunk;
+              markup_string_ty *close_name = context->partial_chunk;
               context->partial_chunk = NULL;
 
               if (*context->iter != '>')
@@ -1354,15 +1346,12 @@ markup_parse_context_parse (markup_parse_context_ty *context,
                 context->balance++;
               if (*context->iter == '>')
                 {
-                  char *str;
-                  size_t len;
-
                   context->balance--;
                   add_to_partial (context, context->start, context->iter);
                   context->start = context->iter;
 
-                  str = context->partial_chunk->buffer;
-                  len = context->partial_chunk->buflen;
+                  char *str = context->partial_chunk->buffer;
+                  size_t len = context->partial_chunk->buflen;
 
                   if (str[1] == '?' && str[len - 1] == '?')
                     break;
@@ -1448,8 +1437,6 @@ markup_parse_context_parse (markup_parse_context_ty *context,
 bool
 markup_parse_context_end_parse (markup_parse_context_ty *context)
 {
-  const char *location = NULL;
-
   assert (context != NULL);
   assert (!context->parsing);
   assert (context->state != STATE_ERROR);
@@ -1468,6 +1455,7 @@ markup_parse_context_end_parse (markup_parse_context_ty *context)
 
   context->parsing = true;
 
+  const char *location = NULL;
   switch (context->state)
     {
     case STATE_START:
index d10c005ae62b2ddc9a6cf3d60131ac34e5a18264..6401ee51fb12ce2ae7d9d003a76555013377b487 100644 (file)
@@ -1,5 +1,5 @@
 /* Multiline error-reporting functions.
-   Copyright (C) 2001-2024 Free Software Foundation, Inc.
+   Copyright (C) 2001-2025 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software: you can redistribute it and/or modify
 static size_t
 multiline_internal (char *prefix, size_t prefix_width, char *message)
 {
-  size_t width;
-  const char *cp;
-
   fflush (stdout);
 
-  cp = message;
+  const char *cp = message;
 
+  size_t width;
   if (prefix != NULL)
     {
       width = 0;
@@ -66,17 +64,11 @@ multiline_internal (char *prefix, size_t prefix_width, char *message)
 
   for (;;)
     {
-      const char *np;
-
-      {
-        size_t i;
-
-        for (i = width; i > 0; i--)
-          putc (' ', stderr);
-      }
+      for (size_t i = width; i > 0; i--)
+        putc (' ', stderr);
 
     after_indent:
-      np = strchr (cp, '\n');
+      const char *np = strchr (cp, '\n');
 
       if (np == NULL || np[1] == '\0')
         {
index 95fcec9c9b1ec29fbf06c330041b66975f9ea466..9bac262a89b105b019472ca0a99b9c5dab14b293 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream referring to an stdio FILE.
-   Copyright (C) 2006, 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2019-2020, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -100,7 +100,6 @@ file_ostream_t
 file_ostream_create (FILE *fp)
 {
   file_ostream_t stream = XMALLOC (struct file_ostream_representation);
-
   stream->base.vtable = &file_ostream_vtable;
   stream->fp = fp;
 
index ea00ba563b8d2acab5071a8504e13e2d269e2465..080a43495d4dcf0874176252be7fd1708d537a69 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream that produces HTML output.
-   Copyright (C) 2006-2009, 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2006-2009, 2019-2020, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -128,9 +128,7 @@ emit_pending_spans (html_ostream_t stream, bool shrink_stack)
 {
   if (stream->curr_class_stack_size > stream->last_class_stack_size)
     {
-      size_t i;
-
-      for (i = stream->last_class_stack_size; i < stream->curr_class_stack_size; i++)
+      for (size_t i = stream->last_class_stack_size; i < stream->curr_class_stack_size; i++)
         {
           char *classname = (char *) gl_list_get_at (stream->class_stack, i);
 
@@ -142,9 +140,7 @@ emit_pending_spans (html_ostream_t stream, bool shrink_stack)
     }
   else if (stream->curr_class_stack_size < stream->last_class_stack_size)
     {
-      size_t i;
-
-      for (i = stream->last_class_stack_size; i > stream->curr_class_stack_size; i--)
+      for (size_t i = stream->last_class_stack_size; i > stream->curr_class_stack_size; i--)
         ostream_write_str (stream->destination, "</span>");
       stream->last_class_stack_size = stream->curr_class_stack_size;
       if (shrink_stack)
@@ -162,9 +158,7 @@ html_ostream::write_mem (html_ostream_t stream, const void *data, size_t len)
     {
       #define BUFFERSIZE 2048
       char inbuffer[BUFFERSIZE];
-      size_t inbufcount;
-
-      inbufcount = stream->buflen;
+      size_t inbufcount = stream->buflen;
       if (inbufcount > 0)
         memcpy (inbuffer, stream->buf, inbufcount);
       for (;;)
@@ -190,16 +184,14 @@ html_ostream::write_mem (html_ostream_t stream, const void *data, size_t len)
 
             while (insize > 0)
               {
-                unsigned char c0;
-                ucs4_t uc;
-                int nbytes;
-
-                c0 = ((const unsigned char *) inptr)[0];
+                unsigned char c0 = ((const unsigned char *) inptr)[0];
                 if (insize < (c0 < 0xc0 ? 1 : c0 < 0xe0 ? 2 : c0 < 0xf0 ? 3 :
                               c0 < 0xf8 ? 4 : c0 < 0xfc ? 5 : 6))
                   break;
 
-                nbytes = u8_mbtouc (&uc, (const unsigned char *) inptr, insize);
+                ucs4_t uc;
+                int nbytes =
+                  u8_mbtouc (&uc, (const unsigned char *) inptr, insize);
 
                 if (uc == '\n')
                   {
@@ -424,7 +416,6 @@ html_ostream_t
 html_ostream_create (ostream_t destination)
 {
   html_ostream_t stream = XMALLOC (struct html_ostream_representation);
-
   stream->base.vtable = &html_ostream_vtable;
   stream->destination = destination;
   stream->hyperlink_ref = NULL;
index 9a965082874f652926f52330725e29605036c08c..457d169f919c341fd325d82fbd9ee334d2f609e3 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for CSS styled text, producing HTML output.
-   Copyright (C) 2006-2024 Free Software Foundation, Inc.
+   Copyright (C) 2006-2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -131,7 +131,6 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename)
 {
   html_styled_ostream_t stream =
     XMALLOC (struct html_styled_ostream_representation);
-
   stream->base.base.vtable = &html_styled_ostream_vtable;
   stream->destination = destination;
   stream->css_filename = xstrdup (css_filename);
@@ -160,10 +159,7 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename)
 
       /* Include the contents of CSS_FILENAME literally.  */
       {
-        int fd;
-        char buf[4096];
-
-        fd = open (css_filename, O_RDONLY | O_TEXT);
+        int fd = open (css_filename, O_RDONLY | O_TEXT);
         if (fd < 0)
           error (EXIT_FAILURE, errno,
                  _("error while opening \"%s\" for reading"),
@@ -171,6 +167,7 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename)
 
         for (;;)
           {
+            char buf[4096];
             size_t n_read = safe_read (fd, buf, sizeof (buf));
             if (n_read == SAFE_READ_ERROR)
               error (EXIT_FAILURE, errno, _("error reading \"%s\""),
index 60cb17437f4258dddc2c4d4110af7d80c2b33b46..76cc07569a79e3301e44d217ec393e5c057c27cb 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream that converts the output to another encoding.
-   Copyright (C) 2006-2024 Free Software Foundation, Inc.
+   Copyright (C) 2006-2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -65,9 +65,7 @@ iconv_ostream::write_mem (iconv_ostream_t stream, const void *data, size_t len)
     {
       #define BUFFERSIZE 256
       char inbuffer[BUFFERSIZE];
-      size_t inbufcount;
-
-      inbufcount = stream->buflen;
+      size_t inbufcount = stream->buflen;
       if (inbufcount > 0)
         memcpy (inbuffer, stream->buf, inbufcount);
       for (;;)
@@ -182,7 +180,6 @@ iconv_ostream_create (const char *from_encoding, const char *to_encoding,
                       ostream_t destination)
 {
   iconv_ostream_t stream = XMALLOC (struct iconv_ostream_representation);
-
   stream->base.vtable = &iconv_ostream_vtable;
   stream->destination = destination;
   stream->from_encoding = xstrdup (from_encoding);
index be57fb997806d2d9835ecaf44c3912caac4860e4..f2b7c5e0442522669fc82fc41cf06ad382c0a1be 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream that accumulates the output in memory.
-   Copyright (C) 2006-2024 Free Software Foundation, Inc.
+   Copyright (C) 2006-2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -91,7 +91,6 @@ memory_ostream_t
 memory_ostream_create (void)
 {
   memory_ostream_t stream = XMALLOC (struct memory_ostream_representation);
-
   stream->base.vtable = &memory_ostream_vtable;
   stream->allocated = 250;
   stream->buffer = XNMALLOC (stream->allocated, char);
index 4a57566956f4248767150ab6fc77ca58d3deacf9..3e2eb497c38e5e40713df50934b5a5e3ee866113 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream with no-op styling.
-   Copyright (C) 2006, 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2019-2020, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2019.
 
    This program is free software: you can redistribute it and/or modify
@@ -112,7 +112,6 @@ noop_styled_ostream_create (ostream_t destination, bool pass_ownership)
 {
   noop_styled_ostream_t stream =
     XMALLOC (struct noop_styled_ostream_representation);
-
   stream->base.base.vtable = &noop_styled_ostream_vtable;
   stream->destination = destination;
   stream->own_destination = pass_ownership;
index a6690c39f73094702a8ad5ebea5dcc351eaf73c7..30f54368a2a3f37478ff945de668e921862ee118 100644 (file)
@@ -1,5 +1,5 @@
 /* Abstract output stream data type.
-   Copyright (C) 2006, 2019 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2019, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -41,11 +41,9 @@ ptrdiff_t
 ostream_printf (ostream_t stream, const char *format, ...)
 {
   va_list args;
-  char *temp_string;
-  ptrdiff_t ret;
-
   va_start (args, format);
-  ret = vasprintf (&temp_string, format, args);
+  char *temp_string;
+  ptrdiff_t ret = vasprintf (&temp_string, format, args);
   va_end (args);
   if (ret >= 0)
     {
index e296a4315f5c617581785cef58aa73f24ce1ff3b..626e72d2577f4abd85b8f7bcdfb90ad1909e0107 100644 (file)
@@ -196,18 +196,14 @@ color_distance (const hsv_t *color1, const hsv_t *color2)
 static unsigned int
 nearest_color (rgb_t given, const rgb_t *table, unsigned int table_size)
 {
-  hsv_t given_hsv;
-  unsigned int best_index;
-  float best_distance;
-  unsigned int i;
-
   assert (table_size > 0);
 
+  hsv_t given_hsv;
   rgb_to_hsv (given, &given_hsv);
 
-  best_index = 0;
-  best_distance = 1000000.0f;
-  for (i = 0; i < table_size; i++)
+  unsigned int best_index = 0;
+  float best_distance = 1000000.0f;
+  for (unsigned int i = 0; i < table_size; i++)
     {
       hsv_t i_hsv;
 
@@ -303,9 +299,9 @@ static inline term_color_t
 rgb_to_color_common8 (int r, int g, int b)
 {
   rgb_t color;
-  hsv_t hsv;
-
   color.red = r; color.green = g; color.blue = b;
+
+  hsv_t hsv;
   rgb_to_hsv (color, &hsv);
 
   if (hsv.saturation < 0.065f)
@@ -361,9 +357,9 @@ static inline term_color_t
 rgb_to_color_xterm8 (int r, int g, int b)
 {
   rgb_t color;
-  hsv_t hsv;
-
   color.red = r; color.green = g; color.blue = b;
+
+  hsv_t hsv;
   rgb_to_hsv (color, &hsv);
 
   if (hsv.saturation < 0.065f)
@@ -409,9 +405,9 @@ static inline term_color_t
 rgb_to_color_xterm16 (int r, int g, int b)
 {
   rgb_t color;
-  hsv_t hsv;
-
   color.red = r; color.green = g; color.blue = b;
+
+  hsv_t hsv;
   rgb_to_hsv (color, &hsv);
 
   if (hsv.saturation < 0.065f)
@@ -535,9 +531,9 @@ static inline term_color_t
 rgb_to_color_xterm88 (int r, int g, int b)
 {
   rgb_t color;
-  hsv_t hsv;
-
   color.red = r; color.green = g; color.blue = b;
+
+  hsv_t hsv;
   rgb_to_hsv (color, &hsv);
 
   if (hsv.saturation < 0.065f)
@@ -847,9 +843,9 @@ static inline term_color_t
 rgb_to_color_xterm256 (int r, int g, int b)
 {
   rgb_t color;
-  hsv_t hsv;
-
   color.red = r; color.green = g; color.blue = b;
+
+  hsv_t hsv;
   rgb_to_hsv (color, &hsv);
 
   if (hsv.saturation < 0.065f)
@@ -1164,12 +1160,10 @@ generate_hyperlink_id (term_ostream_t stream)
       stream->id_serial
     };
   char *p = id;
-  unsigned int i;
-  for (i = 0; i < 4; i++)
+  for (unsigned int i = 0; i < 4; i++)
     {
       uint32_t word = words[i];
-      unsigned int j;
-      for (j = 0; j < 32 / 4; j++)
+      for (unsigned int j = 0; j < 32 / 4; j++)
         *p++ = hexdigits[(word >> (32 - 4 * (j + 1))) & 0x0f];
     }
   *p = '\0';
@@ -1198,8 +1192,8 @@ static int
 out_char (int c)
 {
   char bytes[1];
-
   bytes[0] = (char)c;
+
   /* We have to write directly to the file descriptor, not to a buffer with
      the same destination, because of the padding and sleeping that tputs()
      does.  */
@@ -1223,8 +1217,8 @@ static _GL_ASYNC_SAFE int
 out_char_unchecked (int c)
 {
   char bytes[1];
-
   bytes[0] = (char)c;
+
   full_write (out_fd, bytes, 1);
   return 0;
 }
@@ -1312,11 +1306,10 @@ out_color_change (term_ostream_t stream, term_color_t new_color,
       assert (new_color >= 0 && new_color < 88);
       {
         char bytes[10];
-        char *p;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '5'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (new_color >= 10)
           *p++ = '0' + (new_color / 10);
         *p++ = '0' + (new_color % 10);
@@ -1330,11 +1323,10 @@ out_color_change (term_ostream_t stream, term_color_t new_color,
       assert (new_color >= 0 && new_color < 256);
       {
         char bytes[11];
-        char *p;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '5'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (new_color >= 100)
           *p++ = '0' + (new_color / 100);
         if (new_color >= 10)
@@ -1350,14 +1342,13 @@ out_color_change (term_ostream_t stream, term_color_t new_color,
       assert (new_color >= 0 && new_color < 0x1000000);
       {
         char bytes[19];
-        char *p;
         unsigned int r = (new_color >> 16) & 0xff;
         unsigned int g = (new_color >> 8) & 0xff;
         unsigned int b = new_color & 0xff;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '3'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '2'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (r >= 100)
           *p++ = '0' + (r / 100);
         if (r >= 10)
@@ -1463,11 +1454,10 @@ out_bgcolor_change (term_ostream_t stream, term_color_t new_bgcolor,
       assert (new_bgcolor >= 0 && new_bgcolor < 88);
       {
         char bytes[10];
-        char *p;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '5'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (new_bgcolor >= 10)
           *p++ = '0' + (new_bgcolor / 10);
         *p++ = '0' + (new_bgcolor % 10);
@@ -1481,11 +1471,10 @@ out_bgcolor_change (term_ostream_t stream, term_color_t new_bgcolor,
       assert (new_bgcolor >= 0 && new_bgcolor < 256);
       {
         char bytes[11];
-        char *p;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '5'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (new_bgcolor >= 100)
           *p++ = '0' + (new_bgcolor / 100);
         if (new_bgcolor >= 10)
@@ -1501,14 +1490,13 @@ out_bgcolor_change (term_ostream_t stream, term_color_t new_bgcolor,
       assert (new_bgcolor >= 0 && new_bgcolor < 0x1000000);
       {
         char bytes[19];
-        char *p;
         unsigned int r = (new_bgcolor >> 16) & 0xff;
         unsigned int g = (new_bgcolor >> 8) & 0xff;
         unsigned int b = new_bgcolor & 0xff;
         bytes[0] = 0x1B; bytes[1] = '[';
         bytes[2] = '4'; bytes[3] = '8'; bytes[4] = ';';
         bytes[5] = '2'; bytes[6] = ';';
-        p = bytes + 7;
+        char *p = bytes + 7;
         if (r >= 100)
           *p++ = '0' + (r / 100);
         if (r >= 10)
@@ -1664,8 +1652,6 @@ out_attr_change (term_ostream_t stream, attributes_t new_attr)
   else
   #endif
     {
-      bool cleared_attributes;
-
       /* For out_char to work.  */
       out_stream = stream;
       out_fd = stream->fd;
@@ -1702,7 +1688,7 @@ out_attr_change (term_ostream_t stream, attributes_t new_attr)
          The variable 'cleared_attributes' tells whether an escape sequence
          has been output that may have cleared all attributes and all color
          settings.  */
-      cleared_attributes = false;
+      bool cleared_attributes = false;
       if (old_attr.posture != POSTURE_NORMAL
           && new_attr.posture == POSTURE_NORMAL
           && stream->exit_italics_mode != NULL)
@@ -1899,35 +1885,33 @@ activate_default_attr (term_ostream_t stream)
 static void
 output_buffer (term_ostream_t stream, attributes_t goal_attr)
 {
-  const char *cp;
-  const attributes_t *ap;
-  size_t len;
-  size_t n;
-
-  cp = stream->buffer;
-  ap = stream->attrbuffer;
-  len = stream->buflen;
+  const char *cp = stream->buffer;
+  const attributes_t *ap = stream->attrbuffer;
+  size_t len = stream->buflen;
 
-  /* See how much we can output without blocking signals.  */
-  for (n = 0; n < len && equal_attributes (ap[n], stream->active_attr); n++)
-    ;
-  if (n > 0)
-    {
-      if (full_write (stream->fd, cp, n) < n)
-        {
-          int error_code = errno;
-          /* Do output to stderr only after we have switched back to the
-             default attributes.  Otherwise this output may come out with
-             the wrong text attributes.  */
-          if (!equal_attributes (stream->active_attr, stream->default_attr))
-            activate_default_attr (stream);
-          error (EXIT_FAILURE, error_code, _("error writing to %s"),
-                 stream->filename);
-        }
-      cp += n;
-      ap += n;
-      len -= n;
-    }
+  {
+    /* See how much we can output without blocking signals.  */
+    size_t n;
+    for (n = 0; n < len && equal_attributes (ap[n], stream->active_attr); n++)
+      ;
+    if (n > 0)
+      {
+        if (full_write (stream->fd, cp, n) < n)
+          {
+            int error_code = errno;
+            /* Do output to stderr only after we have switched back to the
+               default attributes.  Otherwise this output may come out with
+               the wrong text attributes.  */
+            if (!equal_attributes (stream->active_attr, stream->default_attr))
+              activate_default_attr (stream);
+            error (EXIT_FAILURE, error_code, _("error writing to %s"),
+                   stream->filename);
+          }
+        cp += n;
+        ap += n;
+        len -= n;
+      }
+  }
   if (len > 0)
     {
       if (!equal_attributes (*ap, stream->default_attr))
@@ -1939,6 +1923,7 @@ output_buffer (term_ostream_t stream, attributes_t goal_attr)
           out_attr_change (stream, *ap);
           /* See how many characters we can output without further attribute
              changes.  */
+          size_t n;
           for (n = 1; n < len && equal_attributes (ap[n], stream->active_attr); n++)
             ;
           if (full_write (stream->fd, cp, n) < n)
@@ -1976,8 +1961,7 @@ output_buffer (term_ostream_t stream, attributes_t goal_attr)
   {
     size_t count = stream->hyperlinks_count;
     size_t j = 0;
-    size_t i;
-    for (i = 0; i < count; i++)
+    for (size_t i = 0; i < count; i++)
       {
         /* Here 0 <= j <= i.  */
         hyperlink_t *hyperlink = stream->hyperlinks_array[i];
@@ -2132,8 +2116,7 @@ term_ostream::free (term_ostream_t stream)
   if (stream->hyperlinks_array != NULL)
     {
       size_t count = stream->hyperlinks_count;
-      size_t i;
-      for (i = 0; i < count; i++)
+      for (size_t i = 0; i < count; i++)
         free_hyperlink (stream->hyperlinks_array[i]);
       free (stream->hyperlinks_array);
     }
@@ -2233,7 +2216,6 @@ term_ostream::set_hyperlink (term_ostream_t stream,
     {
       /* Create a new hyperlink_t object.  */
       hyperlink_t *hyperlink = XMALLOC (hyperlink_t);
-
       hyperlink->ref = xstrdup (ref);
       if (id != NULL)
         {
@@ -2408,7 +2390,6 @@ term_ostream_t
 term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
 {
   term_ostream_t stream = XMALLOC (struct term_ostream_representation);
-
   stream->base.vtable = &term_ostream_vtable;
   stream->fd = fd;
   #if HAVE_WINDOWS_CONSOLES
@@ -2421,12 +2402,12 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
            <https://docs.microsoft.com/en-us/windows/console/getconsolemode>  */
         && GetConsoleMode (stream->handle, &mode) != 0)
       {
-        CONSOLE_SCREEN_BUFFER_INFO info;
         BOOL ok;
 
         /* GetConsoleScreenBufferInfo
            <https://docs.microsoft.com/en-us/windows/console/getconsolescreenbufferinfo>
            <https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str>  */
+        CONSOLE_SCREEN_BUFFER_INFO info;
         ok = GetConsoleScreenBufferInfo (stream->handle, &info);
         if (!ok)
           {
@@ -2527,10 +2508,8 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
   else
   #endif
     {
-      const char *term;
-
       /* Retrieve the terminal type.  */
-      term = getenv ("TERM");
+      const char *term = getenv ("TERM");
       if (term != NULL && term[0] != '\0')
         {
           /* When the terminfo function are available, we prefer them over the
@@ -2565,11 +2544,10 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
              bytes long.  <https://tldp.org/LDP/lpg/node91.html> suggests a
              buffer size of 2048 bytes.  */
           struct { char buf[2048]; char canary[4]; } termcapbuf;
-          int retval;
 
           /* Call tgetent, being defensive against buffer overflow.  */
           memcpy (termcapbuf.canary, "CnRy", 4);
-          retval = tgetent (termcapbuf.buf, term);
+          int retval = tgetent (termcapbuf.buf, term);
           if (memcmp (termcapbuf.canary, "CnRy", 4) != 0)
             /* Buffer overflow!  */
             abort ();
@@ -2748,8 +2726,7 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
         uint32_t h = 0;
         if (hostname != NULL)
           {
-            const char *p;
-            for (p = hostname; *p; p++)
+            for (const char *p = hostname; *p; p++)
               h = (unsigned char) *p + ((h << 9) | (h >> (32 - 9)));
           }
         stream->hostname_hash = h;
index c23ed773c99b5fa535d86abd99412e0d3ca83a7a..e487faaa8d3c1e3218efb3fa9cf5b4d090b1fbf3 100644 (file)
@@ -1,5 +1,5 @@
 /* Output stream for CSS styled text, producing ANSI escape sequences.
-   Copyright (C) 2006-2007, 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2006-2007, 2019-2020, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -152,14 +152,11 @@ typedef struct _CRXStyle
 static CRXStyle *
 crx_style_new (gboolean a_set_props_to_initial_values)
 {
-  CRStyle *base;
-  CRXStyle *result;
-
-  base = cr_style_new (a_set_props_to_initial_values);
+  CRStyle *base = cr_style_new (a_set_props_to_initial_values);
   if (base == NULL)
     return NULL;
 
-  result = XMALLOC (CRXStyle);
+  CRXStyle *result = XMALLOC (CRXStyle);
   result->base = base;
   if (a_set_props_to_initial_values)
     result->text_decoration = TEXT_DECORATION_NONE;
@@ -184,21 +181,19 @@ crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade,
                                CRXStyle * a_parent_style, CRXStyle ** a_style,
                                gboolean a_set_props_to_initial_values)
 {
-  enum CRStatus status;
-  CRPropList *props = NULL;
 
   if (!(a_this && a_cascade && a_node && a_style))
     return CR_BAD_PARAM_ERROR;
 
-  status = cr_sel_eng_get_matched_properties_from_cascade (a_this, a_cascade,
-                                                           a_node, &props);
+  CRPropList *props = NULL;
+  enum CRStatus status =
+    cr_sel_eng_get_matched_properties_from_cascade (a_this, a_cascade, a_node,
+                                                    &props);
   if (!(status == CR_OK))
     return status;
 
   if (props)
     {
-      CRXStyle *style;
-
       if (!*a_style)
         {
           *a_style = crx_style_new (a_set_props_to_initial_values);
@@ -218,52 +213,48 @@ crx_sel_eng_get_matched_style (CRSelEng * a_this, CRCascade * a_cascade,
               (*a_style)->text_decoration = TEXT_DECORATION_INHERIT;
             }
         }
-      style = *a_style;
+      CRXStyle *style = *a_style;
       style->parent_style = a_parent_style;
       style->base->parent_style =
         (a_parent_style != NULL ? a_parent_style->base : NULL);
 
-      {
-        CRPropList *cur;
-
-        for (cur = props; cur != NULL; cur = cr_prop_list_get_next (cur))
-          {
-            CRDeclaration *decl = NULL;
-
-            cr_prop_list_get_decl (cur, &decl);
-            cr_style_set_style_from_decl (style->base, decl);
-            if (decl != NULL
-                && decl->property != NULL
-                && decl->property->stryng != NULL
-                && decl->property->stryng->str != NULL)
-              {
-                if (strcmp (decl->property->stryng->str, "text-decoration") == 0
-                    && decl->value != NULL
-                    && decl->value->type == TERM_IDENT
-                    && decl->value->content.str != NULL)
-                  {
-                    const char *value =
-                      cr_string_peek_raw_str (decl->value->content.str);
-
-                    if (value != NULL)
-                      {
-                        if (strcmp (value, "none") == 0)
-                          style->text_decoration = TEXT_DECORATION_NONE;
-                        else if (strcmp (value, "underline") == 0)
-                          style->text_decoration = TEXT_DECORATION_UNDERLINE;
-                        else if (strcmp (value, "overline") == 0)
-                          style->text_decoration = TEXT_DECORATION_OVERLINE;
-                        else if (strcmp (value, "line-through") == 0)
-                          style->text_decoration = TEXT_DECORATION_LINE_THROUGH;
-                        else if (strcmp (value, "blink") == 0)
-                          style->text_decoration = TEXT_DECORATION_BLINK;
-                        else if (strcmp (value, "inherit") == 0)
-                          style->text_decoration = TEXT_DECORATION_INHERIT;
-                      }
-                  }
-              }
-          }
-      }
+      for (CRPropList *cur = props; cur != NULL; cur = cr_prop_list_get_next (cur))
+        {
+          CRDeclaration *decl = NULL;
+          cr_prop_list_get_decl (cur, &decl);
+
+          cr_style_set_style_from_decl (style->base, decl);
+          if (decl != NULL
+              && decl->property != NULL
+              && decl->property->stryng != NULL
+              && decl->property->stryng->str != NULL)
+            {
+              if (strcmp (decl->property->stryng->str, "text-decoration") == 0
+                  && decl->value != NULL
+                  && decl->value->type == TERM_IDENT
+                  && decl->value->content.str != NULL)
+                {
+                  const char *value =
+                    cr_string_peek_raw_str (decl->value->content.str);
+
+                  if (value != NULL)
+                    {
+                      if (strcmp (value, "none") == 0)
+                        style->text_decoration = TEXT_DECORATION_NONE;
+                      else if (strcmp (value, "underline") == 0)
+                        style->text_decoration = TEXT_DECORATION_UNDERLINE;
+                      else if (strcmp (value, "overline") == 0)
+                        style->text_decoration = TEXT_DECORATION_OVERLINE;
+                      else if (strcmp (value, "line-through") == 0)
+                        style->text_decoration = TEXT_DECORATION_LINE_THROUGH;
+                      else if (strcmp (value, "blink") == 0)
+                        style->text_decoration = TEXT_DECORATION_BLINK;
+                      else if (strcmp (value, "inherit") == 0)
+                        style->text_decoration = TEXT_DECORATION_INHERIT;
+                    }
+                }
+            }
+        }
 
       cr_prop_list_destroy (props);
     }
@@ -298,16 +289,12 @@ style_compute_color_value (CRStyle *style, enum CRRgbProp which,
       else
         {
           CRRgb rgb;
-          int r;
-          int g;
-          int b;
-
           cr_rgb_copy (&rgb, &style->rgb_props[which].sv);
           if (cr_rgb_compute_from_percentage (&rgb) != CR_OK)
             abort ();
-          r = rgb.red & 0xff;
-          g = rgb.green & 0xff;
-          b = rgb.blue & 0xff;
+          int r = rgb.red & 0xff;
+          int g = rgb.green & 0xff;
+          int b = rgb.blue & 0xff;
           return term_ostream_rgb_to_color (stream, r, g, b);
         }
     }
@@ -422,52 +409,45 @@ style_compute_text_underline_value (const CRXStyle *style)
 static attributes_t *
 match (term_styled_ostream_t stream)
 {
-  xmlNodePtr root;
-  xmlNodePtr curr;
-  char *p_end;
-  char *p_start;
-  CRXStyle *curr_style;
-  CRStyle *curr_style_base;
-  attributes_t *attr;
-
   /* Create a hierarchy of XML nodes.  */
-  root = xmlNewNode (NULL, (const xmlChar *) "__root__");
+  xmlNode *root = xmlNewNode (NULL, (const xmlChar *) "__root__");
   root->type = XML_ELEMENT_NODE;
-  curr = root;
-  p_end = &stream->curr_classes[stream->curr_classes_length];
-  p_start = stream->curr_classes;
-  while (p_start < p_end)
-    {
-      char *p;
-      xmlNodePtr child;
+  {
+    xmlNode *curr = root;
+    char *p_end = &stream->curr_classes[stream->curr_classes_length];
+    char *p_start = stream->curr_classes;
+    while (p_start < p_end)
+      {
+        if (!(*p_start == ' '))
+          abort ();
+        p_start++;
 
-      if (!(*p_start == ' '))
-        abort ();
-      p_start++;
-      for (p = p_start; p < p_end && *p != ' '; p++)
-        ;
+        char *p;
+        for (p = p_start; p < p_end && *p != ' '; p++)
+          ;
 
-      /* Temporarily replace the ' ' by '\0'.  */
-      *p = '\0';
-      child = xmlNewNode (NULL, (const xmlChar *) p_start);
-      child->type = XML_ELEMENT_NODE;
-      xmlSetProp (child, (const xmlChar *) "class", (const xmlChar *) p_start);
-      *p = ' ';
+        /* Temporarily replace the ' ' by '\0'.  */
+        *p = '\0';
+        xmlNode *child = xmlNewNode (NULL, (const xmlChar *) p_start);
+        child->type = XML_ELEMENT_NODE;
+        xmlSetProp (child, (const xmlChar *) "class", (const xmlChar *) p_start);
+        *p = ' ';
 
-      if (xmlAddChild (curr, child) == NULL)
-        /* Error! Shouldn't happen.  */
-        abort ();
+        if (xmlAddChild (curr, child) == NULL)
+          /* Error! Shouldn't happen.  */
+          abort ();
 
-      curr = child;
-      p_start = p;
-    }
+        curr = child;
+        p_start = p;
+      }
+  }
 
   /* Retrieve the matching CSS declarations.  */
   /* Not curr_style = crx_style_new (TRUE); because that assumes that the
      default foreground color is black and that the default background color
      is white, which is not necessarily true in a terminal context.  */
-  curr_style = NULL;
-  for (curr = root; curr != NULL; curr = curr->children)
+  CRXStyle *curr_style = NULL;
+  for (xmlNode *curr = root; curr != NULL; curr = curr->children)
     {
       CRXStyle *parent_style = curr_style;
       curr_style = NULL;
@@ -485,10 +465,10 @@ match (term_styled_ostream_t stream)
         /* curr_style is a new style, inheriting from parent_style.  */
         ;
     }
-  curr_style_base = (curr_style != NULL ? curr_style->base : NULL);
+  CRStyle *curr_style_base = (curr_style != NULL ? curr_style->base : NULL);
 
   /* Extract the CSS declarations that we can use.  */
-  attr = XMALLOC (attributes_t);
+  attributes_t *attr = XMALLOC (attributes_t);
   attr->color =
     style_compute_color_value (curr_style_base, RGB_PROP_COLOR,
                                stream->destination);
@@ -531,16 +511,12 @@ static void
 term_styled_ostream::begin_use_class (term_styled_ostream_t stream,
                                       const char *classname)
 {
-  size_t classname_len;
-  char *p;
-  void *found;
-
   if (classname[0] == '\0' || strchr (classname, ' ') != NULL)
     /* Invalid classname argument.  */
     abort ();
 
   /* Push the classname onto the classname list.  */
-  classname_len = strlen (classname);
+  size_t classname_len = strlen (classname);
   if (stream->curr_classes_length + 1 + classname_len + 1
       > stream->curr_classes_allocated)
     {
@@ -551,12 +527,13 @@ term_styled_ostream::begin_use_class (term_styled_ostream_t stream,
       stream->curr_classes = xrealloc (stream->curr_classes, new_allocated);
       stream->curr_classes_allocated = new_allocated;
     }
-  p = &stream->curr_classes[stream->curr_classes_length];
+  char *p = &stream->curr_classes[stream->curr_classes_length];
   *p++ = ' ';
   memcpy (p, classname, classname_len);
   stream->curr_classes_length += 1 + classname_len;
 
-  /* Uodate stream->curr_attr.  */
+  /* Update stream->curr_attr.  */
+  void *found;
   if (hash_find_entry (&stream->cache,
                        stream->curr_classes, stream->curr_classes_length,
                        &found) < 0)
@@ -569,21 +546,16 @@ static void
 term_styled_ostream::end_use_class (term_styled_ostream_t stream,
                                     const char *classname)
 {
-  char *p_end;
-  char *p_start;
-  char *p;
-  void *found;
-
   if (stream->curr_classes_length == 0)
     /* No matching call to begin_use_class.  */
     abort ();
 
   /* Remove the trailing classname.  */
-  p_end = &stream->curr_classes[stream->curr_classes_length];
-  p = p_end;
+  char *p_end = &stream->curr_classes[stream->curr_classes_length];
+  char *p = p_end;
   while (*--p != ' ')
     ;
-  p_start = p + 1;
+  char *p_start = p + 1;
   if (!(p_end - p_start == strlen (classname)
         && memcmp (p_start, classname, p_end - p_start) == 0))
     /* The match ing call to begin_use_class used a different classname.  */
@@ -591,6 +563,7 @@ term_styled_ostream::end_use_class (term_styled_ostream_t stream,
   stream->curr_classes_length = p - stream->curr_classes;
 
   /* Update stream->curr_attr.  */
+  void *found;
   if (hash_find_entry (&stream->cache,
                        stream->curr_classes, stream->curr_classes_length,
                        &found) < 0)
@@ -635,21 +608,18 @@ term_styled_ostream_t
 term_styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
                             const char *css_filename)
 {
-  term_styled_ostream_t stream;
-  CRStyleSheet *css_file_contents;
-
   /* If css_filename is NULL, no styling is desired.  The code below would end
      up returning NULL anyway.  But it's better to not rely on such details of
      libcroco behaviour.  */
   if (css_filename == NULL)
     return NULL;
 
-  stream = XMALLOC (struct term_styled_ostream_representation);
-
+  term_styled_ostream_t stream = XMALLOC (struct term_styled_ostream_representation);
   stream->base.base.vtable = &term_styled_ostream_vtable;
   stream->destination = term_ostream_create (fd, filename, tty_control);
   stream->css_filename = xstrdup (css_filename);
 
+  CRStyleSheet *css_file_contents;
   if (cr_om_parser_simply_parse_file ((const guchar *) css_filename,
                                       CR_UTF_8, /* CR_AUTO is not supported */
                                       &css_file_contents) != CR_OK)
index 32734b031005463712e2e546714604c9f3e4960a..9b2764ded099571bff659d3aedd4c9a23d2417e8 100644 (file)
@@ -94,18 +94,16 @@ print_color_test ()
       { "white",   -2, 255, 255, 255 },
       { "default", COLOR_DEFAULT, /* unused: */ -1, -1, -1 }
     };
-  term_ostream_t stream;
-  int i, row, col;
 
-  stream = term_ostream_create (1, "stdout", TTYCTL_AUTO);
+  term_ostream_t stream = term_ostream_create (1, "stdout", TTYCTL_AUTO);
 
-  for (i = 0; i < 8; i++)
+  for (int i = 0; i < 8; i++)
     colors[i].c =
       term_ostream_rgb_to_color (stream, colors[i].r, colors[i].g, colors[i].b);
 
   ostream_write_str (stream, "Colors (foreground/background):\n");
   ostream_write_str (stream, "       ");
-  for (col = 0; col <= 8; col++)
+  for (int col = 0; col <= 8; col++)
     {
       const char *name = colors[col].name;
       ostream_write_str (stream, "|");
@@ -113,12 +111,12 @@ print_color_test ()
       ostream_write_mem (stream, "        ", 7 - strlen (name));
     }
   ostream_write_str (stream, "\n");
-  for (row = 0; row <= 8; row++)
+  for (int row = 0; row <= 8; row++)
     {
       const char *name = colors[row].name;
       ostream_write_str (stream, name);
       ostream_write_mem (stream, "        ", 7 - strlen (name));
-      for (col = 0; col <= 8; col++)
+      for (int col = 0; col <= 8; col++)
         {
           term_color_t row_color = colors[row].c;
           term_color_t col_color = colors[col].c;
@@ -142,10 +140,10 @@ print_color_test ()
 
   ostream_write_str (stream, "Colors (hue/saturation):\n");
   /* Hue from 0 to 1.  */
-  for (row = 0; row <= 17; row++)
+  for (int row = 0; row <= 17; row++)
     {
       ostream_write_str (stream, row == 0 ? "red:     " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int r = 255;
           int b = (int) (255.0f / 64.0f * col + 0.5f);
@@ -158,10 +156,10 @@ print_color_test ()
       ostream_write_str (stream, "\n");
     }
   /* Hue from 1 to 2.  */
-  for (row = 17; row >= 0; row--)
+  for (int row = 17; row >= 0; row--)
     {
       ostream_write_str (stream, row == 17 ? "yellow:  " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int g = 255;
           int b = (int) (255.0f / 64.0f * col + 0.5f);
@@ -174,10 +172,10 @@ print_color_test ()
       ostream_write_str (stream, "\n");
     }
   /* Hue from 2 to 3.  */
-  for (row = 0; row <= 17; row++)
+  for (int row = 0; row <= 17; row++)
     {
       ostream_write_str (stream, row == 0 ? "green:   " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int g = 255;
           int r = (int) (255.0f / 64.0f * col + 0.5f);
@@ -190,10 +188,10 @@ print_color_test ()
       ostream_write_str (stream, "\n");
     }
   /* Hue from 3 to 4.  */
-  for (row = 17; row >= 0; row--)
+  for (int row = 17; row >= 0; row--)
     {
       ostream_write_str (stream, row == 17 ? "cyan:    " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int b = 255;
           int r = (int) (255.0f / 64.0f * col + 0.5f);
@@ -206,10 +204,10 @@ print_color_test ()
       ostream_write_str (stream, "\n");
     }
   /* Hue from 4 to 5.  */
-  for (row = 0; row <= 17; row++)
+  for (int row = 0; row <= 17; row++)
     {
       ostream_write_str (stream, row == 0 ? "blue:    " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int b = 255;
           int g = (int) (255.0f / 64.0f * col + 0.5f);
@@ -222,11 +220,11 @@ print_color_test ()
       ostream_write_str (stream, "\n");
     }
   /* Hue from 5 to 6.  */
-  for (row = 17; row >= 0; row--)
+  for (int row = 17; row >= 0; row--)
     {
       ostream_write_str (stream, row == 17 ? "magenta: " :
                                  row == 0 ? "red:     " : "         ");
-      for (col = 0; col <= 64; col++)
+      for (int col = 0; col <= 64; col++)
         {
           int r = 255;
           int g = (int) (255.0f / 64.0f * col + 0.5f);
@@ -286,7 +284,7 @@ print_color_test ()
   ostream_write_str (stream, "\n");
 
   ostream_write_str (stream, "Colors (foreground) mixed with attributes:\n");
-  for (row = 0; row <= 8; row++)
+  for (int row = 0; row <= 8; row++)
     {
       const char *name = colors[row].name;
       ostream_write_str (stream, name);
@@ -333,7 +331,7 @@ print_color_test ()
   ostream_write_str (stream, "\n");
 
   ostream_write_str (stream, "Colors (background) mixed with attributes:\n");
-  for (row = 0; row <= 8; row++)
+  for (int row = 0; row <= 8; row++)
     {
       const char *name = colors[row].name;
       ostream_write_str (stream, name);
@@ -421,18 +419,15 @@ style_file_prepare (const char *style_file_envvar,
   if (style_file_name == NULL)
     {
       const char *user_preference = getenv (style_file_envvar);
-
       if (user_preference != NULL && user_preference[0] != '\0')
         style_file_name =
           style_file_lookup (xstrdup (user_preference),
                              stylesdir_after_install);
       else
         {
-          const char *stylesdir;
-
           /* Make it possible to override the default style file location.  This
              is necessary for running the testsuite before "make install".  */
-          stylesdir = getenv (stylesdir_envvar);
+          const char *stylesdir = getenv (stylesdir_envvar);
           if (stylesdir == NULL || stylesdir[0] == '\0')
             stylesdir = stylesdir_after_install;
 
index 6b1f0eb389830bfdbf6e7b8bfd92cb7898584523..1575b4b1ca28d4d371ee937b7a1307c039fc270e 100644 (file)
@@ -1,5 +1,5 @@
 /* Miscellaneous public API.
-   Copyright (C) 2019, 2021 Free Software Foundation, Inc.
+   Copyright (C) 2019, 2021, 2025 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2019.
 
    This program is free software: you can redistribute it and/or modify
@@ -30,9 +30,8 @@ styled_ostream_t
 styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
                        const char *css_filename)
 {
-  styled_ostream_t stream;
-
-  stream = term_styled_ostream_create (fd, filename, tty_control, css_filename);
+  styled_ostream_t stream =
+    term_styled_ostream_create (fd, filename, tty_control, css_filename);
   if (stream == NULL)
     stream =
       noop_styled_ostream_create (fd_ostream_create (fd, filename, true), true);