* 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.
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
==================
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]);
/* 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[] =
};
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)
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 == '_')
{
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 == '}')
/* 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);
}
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;
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. */
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);
static void
subst_from_stdin ()
{
- int c;
-
for (;;)
{
+ int c;
+
c = do_getc ();
if (c == EOF)
break;
}
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
{
while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
|| (c >= '0' && c <= '9') || c == '_');
+ bool valid;
if (opening_brace)
{
if (c == '}')
/* 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
++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;
}
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]);
/* 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[] =
};
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)
error (EXIT_FAILURE, 0, _("missing arguments"));
}
- msgid = argv[optind++];
+ const char *msgid = argv[optind++];
/* Expand escape sequences if enabled. */
if (do_expand)
/* 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)
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]);
/* 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[] =
};
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)
}
/* 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;
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];
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
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';
}
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;
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;
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]);
/* 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
};
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. */
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. */
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]);
/* 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
};
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. */
(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. */
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)
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
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;
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
{
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)
}
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)
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);
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);
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)
}
/* 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;
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++;
/* 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,
&& 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;
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,
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. */
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]);
/* 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[] =
};
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)
/* 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);
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);
}
else
{
- error (1, 0, _("extra operand %s"), argv[optind]);
+ error (EXIT_FAILURE, 0, _("extra operand %s"), argv[optind]);
}
return 0;
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
_("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. */
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;
}
/* Large enough. */
+ struct result result;
result.output = XNMALLOC (input_len - quote_count
+ (bold ? 7 : 3) * quote_count + 1,
char);
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;
/* Parse width. */
if (*format == '*')
{
- size_t width_number = 0;
-
format++;
+ size_t width_number = 0;
if (c_isdigit (*format))
{
const char *f = format;
if (*format == '*')
{
- size_t precision_number = 0;
-
format++;
+ size_t precision_number = 0;
if (c_isdigit (*format))
{
const char *f = format;
}
}
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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;
/* 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)
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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. */
{
/* 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))
unnumbered_arg_count++;
}
- type = FAT_ANY;
- presentation = 0;
+ unsigned int type = FAT_ANY;
+ unsigned int presentation = 0;
if (*format == ':')
{
format++;
/* Parse sign. */
+ bool have_sign = false;
if (*format == '+' || *format == '-' || *format == ' ')
{
format++;
}
/* Parse '#' flag. */
+ bool have_hash_flag = false;
if (*format == '#')
{
format++;
}
/* Parse '0' flag. */
+ bool have_zero_flag = false;
if (*format == '0')
{
format++;
}
/* Parse precision. */
+ bool have_precision = false;
if (*format == '.')
{
format++;
}
/* Parse 'L' flag. */
+ bool have_L_flag = false;
if (*format == 'L')
{
format++;
}
/* Parse type. */
- type_spec = '\0';
+ char type_spec = '\0';
if (*format != '\0' && *format != '}')
{
type_spec = *format;
/* 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)
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
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 (")");
{
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");
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;
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;
}
}
+ format_arg_type_t type;
+
if (!SYSDEP_SEGMENTS_PROCESSED && *format == '<')
{
spec.sysdep_directives =
}
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;
/* 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
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);
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;
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)
{
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
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)
{
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
{
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");
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;
else
{
/* A directive. */
- size_t number;
-
spec.directives++;
+ size_t number;
if (!c_isdigit (*format))
{
*invalid_reason =
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
{
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");
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. */
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);
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);
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;
}
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],
}
/* 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)
}
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];
{
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],
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);
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;
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;
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;
}
{
/* 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;
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++;
}
/* 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]);
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)
}
/* 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++)
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;
initial_splitelement (list, n);
initial_splitelement (list, n + 1);
*/
- size_t s;
- size_t t;
VERIFY_LIST (list);
}
/* 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++)
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)
}
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]);
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);
/* 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. */
/* 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. */
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
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;
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);
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;
/* 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);
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)
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,
VERIFY_LIST (list);
return list;
-
}
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 ();
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;
}
/* Parse width. */
+ size_t width_number = 0;
+ bool width_from_arg = false;
if (c_isdigit (*format))
{
do format++; while (c_isdigit (*format));
}
/* Parse precision. */
+ size_t precision_number = 0;
+ bool precision_from_arg = false;
if (*format == '.')
{
format++;
}
/* Parse separator. */
+ bool separator_digits_from_arg = false;
+ bool separator_char_from_arg = false;
if (*format == ',')
{
format++;
char **invalid_reason)
{
struct spec spec;
- struct spec *result;
-
spec.directives = 0;
spec.likely_intentional_directives = 0;
spec.list = make_unconstrained_list ();
/* Normalize the result. */
normalize_list (spec.list);
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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 (" ");
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]);
{
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");
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))
{
}
}
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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. */
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;
}
/* 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)
}
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')
}
else if (*format == '*')
{
- size_t precision_number = 0;
-
format++;
+ size_t precision_number = 0;
if (c_isdigit (*format))
{
const char *f = format;
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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. */
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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++ == '%')
if (*format != '%')
{
- format_arg_type_t type;
-
if (c_isdigit (*format))
{
const char *f = format;
}
}
+ format_arg_type_t type;
if (*format == 'C')
{
type = FAT_VOID;
/* 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
/* 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;
}
}
free (numbered);
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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
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)
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
{
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");
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 == '-'
parse_specifier:
/* Parse the specifier. */
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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. */
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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)
}
}
- flags = 0;
-
/* Parse flags. */
+ unsigned int flags = 0;
for (;;)
{
if (*format == '#')
}
/* Parse conversion. */
+ format_arg_type_t type;
+ unsigned int invalid_flags;
switch (*format)
{
case '%':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
{
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");
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 =
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))
{
freea (element_alloced);
return false;
}
- number = 0;
+ size_t number = 0;
do
{
number = 10 * number + (*element - '0');
}
while (c_isdigit (*element));
- type = FAT_OBJECT;
+ enum format_arg_type type = FAT_OBJECT;
if (*element == '\0')
;
else if (str_startswith (element, ",time")
{
/* 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")
}
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);
char **invalid_reason)
{
struct spec spec;
- struct spec *result;
-
spec.directives = 0;
spec.numbered_arg_count = 0;
spec.allocated = 0;
/* 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)
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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;
{
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");
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;
do format++; while (c_isdigit (*format));
}
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
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
{
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");
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 == '&');
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 == ';';
}
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, '&');
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) ? "&" : "&");
- str = amp + 1;
- }
- stpcpy (bp, "</gt:kuit>");
+ bp = stpcpy (bp, is_reference (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 ();
#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 =
if (spec.base == NULL)
return NULL;
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- struct kde_spec *kspec;
- size_t last;
- size_t i;
if (spec == NULL)
{
return;
}
- kspec = (struct kde_spec *) spec->base;
+ struct kde_spec *kspec = (struct kde_spec *) spec->base;
if (kspec == NULL)
{
}
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;
{
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");
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++ == '%')
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');
/* 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)
;
{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;
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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 :
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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))
{
}
}
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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. */
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);
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);
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;
}
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],
}
/* 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)
}
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];
{
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],
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);
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;
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;
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;
}
{
/* 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;
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++;
}
/* 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]);
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)
}
/* 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++)
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;
initial_splitelement (list, n);
initial_splitelement (list, n + 1);
*/
- size_t s;
- size_t t;
VERIFY_LIST (list);
}
/* 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++)
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)
}
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]);
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;
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);
/* 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. */
/* 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. */
/* 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. */
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;
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;
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;
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;
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. */
{
/* 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;
{
/* 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;
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
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;
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);
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;
/* 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);
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);
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);
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;
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. */
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).
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;
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;
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;
}
/* Parse modifiers. */
+ bool colon_p = false;
+ bool atsign_p = false;
for (;;)
{
if (*format == ':')
}
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))
{
*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 ();
}
/* Second alternative: use sub-format. */
+ struct format_arg_list *union_list;
{
int sub_position = position;
struct format_arg_list *sub_list =
}
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))
{
*formatp = format;
*escapep = escape;
- union_position = -2;
- union_list = NULL;
+ int union_position = -2;
+ struct format_arg_list *union_list = NULL;
/* First alternative. */
{
}
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))
{
}
/* 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)
{
*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. */
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;
}
{
/* 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~{~^~}
/* ~{ catches ~^. */
sub_list = union (sub_list, sub_escape);
+ struct format_arg_list *looplist;
if (sub_list == NULL)
looplist = make_empty_list ();
else
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,
/* Normalize the result. */
normalize_list (spec.list);
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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 (" ");
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]);
{
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");
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';)
{
if (*fatstr != '%')
{
- enum format_arg_type type;
-
/* Parse width. */
if (c_isdigit (*fatstr))
{
}
}
+ enum format_arg_type type;
switch (*fatstr)
{
case 'c':
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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])
{
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (" ");
{
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");
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';)
{
if (*format != '%')
{
- enum format_arg_type type;
-
/* Parse flags. */
if (*format == '-')
format++;
while (c_isdigit (*format))
format++;
+ enum format_arg_type type;
switch (*format)
{
case 's':
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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])
{
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
printf ("(");
- for (i = 0; i < spec->arg_count; i++)
+ for (size_t i = 0; i < spec->arg_count; i++)
{
if (i > 0)
printf (" ");
{
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");
{
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)
{
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;
/* Parse width. */
if (*format == '*')
{
- size_t width_number = 0;
-
format++;
+ size_t width_number = 0;
if (translated && c_isdigit (*format))
{
const char *f = format;
if (*format == '*')
{
- size_t precision_number = 0;
-
format++;
+ size_t precision_number = 0;
if (translated && c_isdigit (*format))
{
const char *f = format;
format++;
}
+ format_arg_type_t type;
+ char *signature = NULL;
switch (*format)
{
case 'd':
/* 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,
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;
}
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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
{
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++ == '%')
/* 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;
}
}
+ enum format_arg_type type;
switch (c_tolower (*format))
{
case 'd': case 'u': case 'x':
/* 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
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;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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;
{
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");
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++ == '{')
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';
/* 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);
spec.named_arg_count = j;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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);
}
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;
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 :
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (", ");
{
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");
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;
}
/* Parse vector. */
+ bool vectorize = false;
if (*format == 'v')
{
format++;
/* Parse width. */
if (*format == '*')
{
- size_t width_number = 0;
-
format++;
+ size_t width_number = 0;
if (c_isnonzerodigit (*format))
{
const char *f = format;
if (*format == '*')
{
- size_t precision_number = 0;
-
format++;
+ size_t precision_number = 0;
if (c_isnonzerodigit (*format))
{
const char *f = format;
}
/* Parse size. */
- size = 0;
+ format_arg_type_t size = 0;
if (*format == 'h')
{
size = FAT_SIZE_SHORT;
}
}
+ format_arg_type_t type;
switch (*format)
{
case '%':
/* 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
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;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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;
if (*format == 'l')
format++;
+ enum format_arg_type type;
switch (*format)
{
case 'b': case 'd': case 'u': case 'o': case 'x': case 'X':
/* 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
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;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
{
const char *format = *formatp;
const char *const format_start = format;
- const char *name_start;
- const char *name_end;
+
char c;
c = *++format;
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))
{
return false;
}
}
- name_end = format;
+ const char *name_end = format;
if (*format == ':')
{
[[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 =
return false;
}
- c2 = format[1];
+ int c2 = format[1];
if (c2 == '<' || c2 == '>' || c2 == '=' || c2 == '^')
format += 2;
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)
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))
/* 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);
spec.named_arg_count = j;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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 :
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (", ");
{
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");
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';
do format++; while (c_isdigit (*format));
}
+ bool zero_precision = false;
if (*format == '.')
{
format++;
if (*format == 'h' || *format == 'l' || *format == 'L')
format++;
+ enum format_arg_type type;
switch (*format)
{
case '%':
/* 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)
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);
}
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);
}
{
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)
{
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
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
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 (", ");
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 (" ");
{
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");
char **invalid_reason)
{
const char *const format_start = format;
- struct spec spec;
- struct spec *result;
+ struct spec spec;
spec.directives = 0;
for (; *format != '\0';)
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
{
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");
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;
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');
}
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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)
{
}
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]);
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
printf ("(");
- for (i = 0; i < spec->arg_count; i++)
+ for (size_t i = 0; i < spec->arg_count; i++)
{
if (i > 0)
printf (" ");
{
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");
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;
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 == ' '
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
goto bad_format;
}
- name_start = ++format;
+ const char *name_start = ++format;
for (; *format != '\0'; format++)
if (*format == '>')
break;
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';
break;
}
+ enum format_arg_type type;
switch (*format)
{
case '%':
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
goto bad_format;
}
- name_start = ++format;
+ const char *name_start = ++format;
for (; *format != '\0'; format++)
if (*format == '}')
break;
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';
/* 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
/* 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
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);
}
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);
}
{
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)
{
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)
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
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 (", ");
}
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;
{
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");
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';)
{
{
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. */
[[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 =
goto bad_format;
}
- c2 = format[1];
+ int c2 = format[1];
if (c2 == '<' || c2 == '>' || c2 == '^')
format += 2;
/* 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)
;
/* 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);
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);
}
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);
}
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 :
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 :
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i, j;
if (spec == NULL)
{
}
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;
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 (" ");
{
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");
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. */
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);
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);
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;
}
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],
}
/* 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)
}
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];
{
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],
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);
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;
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;
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;
}
{
/* 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;
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++;
}
/* 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]);
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)
}
/* 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++)
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;
initial_splitelement (list, n);
initial_splitelement (list, n + 1);
*/
- size_t s;
- size_t t;
VERIFY_LIST (list);
}
/* 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++)
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)
}
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]);
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;
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);
/* 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. */
/* 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. */
/* 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. */
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;
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;
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;
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;
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. */
{
/* 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;
{
/* 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;
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
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;
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);
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;
/* 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);
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);
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);
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;
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. */
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).
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;
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;
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;
}
/* Parse modifiers. */
+ bool colon_p = false;
+ bool atsign_p = false;
for (;;)
{
if (*format == ':')
}
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))
{
*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 ();
}
/* Second alternative: use sub-format. */
+ struct format_arg_list *union_list;
{
int sub_position = position;
struct format_arg_list *sub_list =
}
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))
{
*formatp = format;
*escapep = escape;
- union_position = -2;
- union_list = NULL;
+ int union_position = -2;
+ struct format_arg_list *union_list = NULL;
/* First alternative. */
{
}
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))
{
}
/* 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)
{
*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. */
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;
}
{
/* 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~{~^~}
/* ~{ catches ~^. */
sub_list = union (sub_list, sub_escape);
+ struct format_arg_list *looplist;
if (sub_list == NULL)
looplist = make_empty_list ();
else
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,
/* Normalize the result. */
normalize_list (spec.list);
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
}
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 (" ");
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]);
{
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");
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;
format++;
}
+ enum format_arg_type type;
switch (*format)
{
case 'c':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
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 == '}')
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 ();
}
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';
/* 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);
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);
}
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);
}
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 :
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
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 (", ");
{
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");
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;
FDI_SET (format - 1, FMTDIR_END);
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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]);
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t i;
if (spec == NULL)
{
}
printf ("(");
- for (i = 0; i < spec->arg_count; i++)
+ for (size_t i = 0; i < spec->arg_count; i++)
{
if (i > 0)
printf (" ");
{
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");
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;
}
/* 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':
/* 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
goto bad_format;
}
- result = XMALLOC (struct spec);
+ struct spec *result = XMALLOC (struct spec);
*result = spec;
return result;
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;
format_print (void *descr)
{
struct spec *spec = (struct spec *) descr;
- size_t last;
- size_t i;
if (spec == NULL)
{
}
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 *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");
{
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)
{
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
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,
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;
/* 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. */
};
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)
#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
}
static void
print_hostname ()
{
- char *hostname;
- char *dot;
-
- hostname = xgethostname ();
+ char *hostname = xgethostname ();
switch (format)
{
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;
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. */
#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
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. */
&& 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);
#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)
bool multiline, const char *format, ...)
{
va_list args;
-
va_start (args, format);
if_verror (severity, filename, lineno, column, multiline, format, args);
va_end (args);
generic_error (void *data, const char *message, ...)
{
va_list args;
-
va_start (args, message);
vfprintf (stderr, message, args);
va_end (args);
const char *value)
{
struct its_value_ty _value;
-
_value.name = xstrdup (name);
_value.value = xstrdup (value);
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)
const char *value)
{
size_t i;
-
for (i = 0; i < values->nitems; i++)
{
struct its_value_ty *_value = &values->items[i];
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];
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);
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;
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;
}
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);
}
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);
}
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);
}
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"));
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);
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
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;
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. */
{
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')
{
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)
{
}
}
- 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, "&");
- break;
- case '<':
- p = stpcpy (p, "<");
- break;
- case '>':
- p = stpcpy (p, ">");
- break;
- case '"':
- if (is_attribute)
- p = stpcpy (p, """);
- 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, "&");
+ break;
+ case '<':
+ p = stpcpy (p, "<");
+ break;
+ case '>':
+ p = stpcpy (p, ">");
+ break;
+ case '"':
+ if (is_attribute)
+ p = stpcpy (p, """);
+ else
+ *p++ = '"';
+ break;
+ default:
+ *p++ = *str;
+ break;
+ }
+ }
+ *p = '\0';
+ }
return result;
}
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;
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,
/* 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 =
{
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)
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);
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");
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 *
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)
{
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);
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);
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");
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
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)
{
}
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);
}
- 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);
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);
}
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);
}
}
/* 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
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);
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");
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 *
- 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;
/* 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;
/* 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;
}
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");
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 *
- 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;
}
/* 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)
}
/* 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);
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");
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);
}
- 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;
}
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");
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);
}
- 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)
{
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))
}
/* 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);
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);
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;
}
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]);
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)))
{
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)
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 ();
return false;
}
+ bool result;
if (setjmp (xml_error_exit) == 0)
{
xmlSetStructuredErrorFunc (NULL, structured_error);
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 ();
return false;
}
+ bool result;
if (setjmp (xml_error_exit) == 0)
{
xmlSetStructuredErrorFunc (NULL, structured_error);
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);
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);
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);
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)
{
{
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))
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);
}
}
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);
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,
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
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;
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);
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);
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 ();
&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,
#else
copy = xmlNewNode (node->ns, node->name);
- xmlAttr *attributes;
- for (attributes = node->properties;
+ for (xmlAttr *attributes = node->properties;
attributes != NULL;
attributes = attributes->next)
{
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 ("&");
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, "&");
- else if (*str == '<')
- p = stpcpy (p, "<");
- else if (*str == '>')
- p = stpcpy (p, ">");
- 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, "&");
+ else if (*str == '<')
+ p = stpcpy (p, "<");
+ else if (*str == '>')
+ p = stpcpy (p, ">");
+ else
+ *p++ = *str;
+ }
+ *p = '\0';
+ }
return result;
}
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;
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')
|| 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)
{
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 =
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')
if (c == '\0')
return false;
}
+
+ bool slash_after_tag = false;
if (!slash_before_tag)
{
/* Parse a sequence of attributes.
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)))
{
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
<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);
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,
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 ();
return NULL;
}
+ struct its_merge_context_ty *result;
if (setjmp (xml_error_exit) == 0)
{
xmlSetStructuredErrorFunc (NULL, structured_error);
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;
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"));
}
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;
/* 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 ();
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);
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;
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"))
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);
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"));
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");
}
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"))
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);
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;
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;
}
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);
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;
}
void
message_free (message_ty *mp)
{
- size_t j;
-
free ((char *) mp->msgid);
if (mp->msgid_plural != NULL)
free ((char *) mp->msgid_plural);
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);
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;
}
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);
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;
}
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);
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. */
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);
{
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;
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++;
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)
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--;
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)
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];
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];
char *alloced_key;
const char *key;
size_t keylen;
-
if (msgctxt != NULL)
{
/* Concatenate the msgctxt and msgid, to form the hash table key. */
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)
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;
}
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')
{
}
}
}
+
return best_mp;
}
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);
}
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;
}
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);
{
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;
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]);
}
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);
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;
}
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;
}
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;
mdlp->item[0] = msgdomain_alloc (MESSAGE_DOMAIN_DEFAULT, use_hashtable);
mdlp->use_hashtable = use_hashtable;
mdlp->encoding = NULL;
+
return mdlp;
}
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);
{
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;
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
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;
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);
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;
}
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;
}
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;
/* 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
};
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)
"--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);
/* 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];
&& 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;
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,
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;
/* 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
};
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)
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);
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;
/* 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
};
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)
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;
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')
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;
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;
/* 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;
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;
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';
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);
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;
/* 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];
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;
/* 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
};
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)
"--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. */
/* 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);
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;
/* 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
};
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)
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)
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)
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;
/* 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
};
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)
"--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. */
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;
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];
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;
/* 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
/* 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)
/* 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)
{
strings must continue nevertheless. */
{
sigset_t sigpipe_set;
-
sigemptyset (&sigpipe_set);
sigaddset (&sigpipe_set, SIGPIPE);
+
sigprocmask (SIG_UNBLOCK, &sigpipe_set, NULL);
}
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
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
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]);
/* 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;
{
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);
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]);
}
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);
}
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;
/* 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
/* 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)
/* 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)
_("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";
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)
{
char *result;
size_t length;
-
filter (str, len, &result, &length);
/* Remove NUL bytes from result. */
for (; p < pend; p++)
if (*p == '\0')
{
- char *q;
-
- q = p;
+ char *q = p;
for (; p < pend; p++)
if (*p != '\0')
*q++ = *p;
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);
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
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
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;
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]);
}
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;
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. */
/* 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[] =
};
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)
{
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);
}
}
}
+ exit_status = EXIT_SUCCESS;
+
if (desktop_mode)
{
/* Ensure that desktop_keywords is initialized. */
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;
}
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);
: 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. */
/* 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
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)
{
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;
}
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;
}
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;
{
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;
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)
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++;
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. */
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);
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;
* operands->nitems_max);
}
- operand = &operands->items[operands->nitems++];
+ msgfmt_operand_ty *operand = &operands->items[operands->nitems++];
operand->language = xstrdup (language);
operand->mlp = messages;
}
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);
/* 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;
/* 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
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
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);
}
/* 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);
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;
/* 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
};
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)
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)
"--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];
}
/* 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
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;
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);
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;
|| (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);
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)
{
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);
&& 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);
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;
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;
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;
/* 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. */
};
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)
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)
{
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;
"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;
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';
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 = "";
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;
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);
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"),
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);
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"),
{
/* Assume the translator will modify the PO file now. */
time_t now;
-
time (&now);
+
return po_strftime (&now);
}
}
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)
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';
#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] = _("\
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);
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"),
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;
#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);
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
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"),
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;
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);
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"),
}
return line;
- }
- failed:
- free (prog);
+ failed:
+ free (prog);
+ }
return NULL;
}
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';
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;
}
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;
}
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;
/* 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. */
{
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)
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);
}
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;
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];
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];
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] =
/* 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";
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);
}
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
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;
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;
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;
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;
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;
{
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;
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
}
/* 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;
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);
if (cp < endp)
{
size_t len = endp - cp;
+
project_id = XNMALLOC (len + 1, char);
memcpy (project_id, cp, len);
project_id[len] = '\0';
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))
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;
}
/* 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;
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;
/* 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
}
/* Determine the target encoding for the remaining messages. */
+ const char *canon_to_code;
if (to_code != NULL)
{
/* Canonicalize target encoding. */
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)
/* 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
}
/* 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. */
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;
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
/* 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
}
}
}
- {
- 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;
}
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;
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';
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;
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 =
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);
/* 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)
/* 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);
}
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)
{
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];
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];
&& !(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;
}
}
+ 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 =
}
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)
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,
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)
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++;
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 =
#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] == ':')
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;
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];
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];
{
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;
}
{
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)
}
/* Search for the occurrence of field in msgstr2. */
+ const char *ptr2;
for (ptr2 = msgstr2;;)
{
if (msgstr2_end - ptr2 < fieldlen)
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;
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))
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;
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;
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;
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. */
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);
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. */
}
/* 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);
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];
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)
{
/* 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)
{
/* 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];
}
/* 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];
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);
}
/* 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)
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)
{
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];
}
/* 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 ();
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);
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;
}
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];
{
/* 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)
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];
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);
}
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)
{
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;
_("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];
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."),
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);
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;
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)
{
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;
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;
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)
{
#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];
{
/* 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]);
}
const char *msgctxt, const char *msgid)
{
message_ty *mp1;
-
if (false)
{
/* Old, slow code. */
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);
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
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 -
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;
}
}
/* Compare with any of the known fields. */
+ size_t cnt;
for (cnt = 0;
cnt < sizeof (known_fields) / sizeof (known_fields[0]);
++cnt)
/* 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. */
}
{
- 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;
}
}
{
- 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;
}
/* 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);
}
}
- 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
: 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
/* 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);
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);
/* 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
#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;
}
}
- for (j = 0; j < refmlp->nitems; j++)
+ for (size_t j = 0; j < refmlp->nitems; j++)
{
message_ty *refmsg = refmlp->item[j];
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,
#: 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);
}
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)
{
/* 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)
: NULL);
}
- for (j = 0; j < resultmlp->nitems; j++)
+ for (size_t j = 0; j < resultmlp->nitems; j++)
{
message_ty *mp = resultmlp->item[j];
{
/* 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;
/* 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 *
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__ };
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;
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;
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);
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;
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';
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))
{
{
/* 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],
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;
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';
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],
/* 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;
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;
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';
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);
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;
/* 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];
{
/* 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)
{
/* 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);
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;
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;
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;
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. */
/* 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
};
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)
#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)
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");
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);
}
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);
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;
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];
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;
/* 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[] =
};
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)
{
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);
}
}
/* Read the given .mo file. */
+ msgdomain_list_ty *result;
if (java_mode)
{
result = msgdomain_read_java (java_resource_name, java_locale_name);
}
else
{
- message_list_ty *mlp;
-
- mlp = message_list_alloc (false);
+ message_list_ty *mlp = message_list_alloc (false);
if (optind < argc)
{
do
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;
/* 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
};
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)
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)
"--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);
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);
{
/* 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);
{
const struct expression *plural;
unsigned long int nplurals;
-
extract_plural_expression (header, &plural, &nplurals);
return nplurals;
"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;
"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;
"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;
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,
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;
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++)
{
/* 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';
/* 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';
{
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';
/* 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';
&& s[5] == ':')
{
const char *string_start;
- const char *string_end;
{
const char *p = s + 6;
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;
{
/* 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';
{
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);
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)
/* 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;
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)
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;
}
/* 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;
}
/* 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;
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)
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;
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;
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)
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);
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;
static void
default_reset_comment_state (default_catalog_reader_ty *dcatr)
{
- size_t j, i;
-
if (dcatr->handle_comments)
{
if (dcatr->comment != NULL)
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;
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;
}
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))
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;
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;
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;
}
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"));
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"),
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)
}
/* Prepare arguments. */
+ const char *args[4];
args[0] = directory_converted;
args[1] = resource_name;
args[2] = culture_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,
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);
static int
phase1_getc ()
{
- int c;
-
- c = getc (fp);
+ int c = getc (fp);
if (c == EOF)
{
case '[':
{
- bool non_blank = false;
- size_t non_blank_lineno = 0;
-
for (;;)
{
c = phase2_getc ();
APPEND (c);
}
/* Skip until newline. */
+ bool non_blank = false;
+ size_t non_blank_lineno = 0;
while (c != '\n' && c != EOF)
{
c = phase2_getc ();
{
size_t locale_start;
bool found_locale = false;
- size_t value_start;
for (;;)
{
APPEND (c);
}
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 ();
{
struct token_ty token;
desktop_lex (&token);
+
switch (token.type)
{
case token_type_eof:
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;
}
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;
}
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"));
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"),
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);
resource_name = "Messages";
/* Prepare arguments. */
+ const char *args[3];
args[0] = resource_name;
if (locale_name != NULL)
{
/* 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,
char *buf = NULL;
size_t alloc = 0;
size_t size = 0;
- size_t count;
-
while (!feof (fp))
{
const size_t increment = 4096;
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))
size += count;
}
buf = (char *) xrealloc (buf, size);
+
bfp->filename = filename;
bfp->data = buf;
bfp->size = size;
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
/* 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"),
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;
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'))
_("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;
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;
}
/* 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. */
{
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
/* 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,
/* 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."),
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);
/* 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,
}
}
- 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);
}
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 =
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"));
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"));
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
}
else
{
- const char *envval;
-
ps->po_lex_charset = canon_charset;
if (strcmp (canon_charset, "UTF-8") == 0)
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
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\
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);
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);
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)
{
mbf->bufcount++;
}
+ size_t bytes;
+
#if HAVE_ICONV
if (ps->po_lex_iconv != (iconv_t)(-1))
{
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'))
if (mb_iseq (mbc, '\\'))
{
mbchar_t mbc2;
-
mbfile_getc_normalized (ps, mbc2, ps->mbf);
if (mb_iseof (mbc2))
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])
{
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. */
}
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))
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;
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. */
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)
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;
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;
}
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');
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);
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 ();
&& (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),
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),
{
/* 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;
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 == '!')
{
/* A comment line. */
struct string_buffer buffer;
-
sb_init (&buffer);
for (;;)
{
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,
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"));
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"),
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,
/* 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]);
}
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)
{
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);
encoding = enc_ucs2le;
else
{
- int c2;
-
- c2 = phase1_getc (catr);
+ int c2 = phase1_getc (catr);
if (c2 == EOF)
{
phase1_ungetc (c1);
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;
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);
{
unsigned char buf[6];
unsigned int count;
+
int c;
- ucs4_t uc;
c = phase1_getc (catr);
if (c == EOF)
}
}
+ ucs4_t uc;
u8_mbtouc (&uc, buf, count);
+
return uc;
}
/* Read an ISO-8859-1 encoded character. */
{
int c = phase1_getc (catr);
-
if (c == EOF)
return UEOF;
return 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;
}
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;
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)
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;
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
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)
{
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 (;;)
{
static int *buffer;
static size_t bufmax;
static size_t buflen;
+
int c;
/* Skip whitespace before the string. */
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)
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')
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;
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);
{
/* "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,
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,
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;
}
/* 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)
{
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;
}
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]);
/* 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[] =
};
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)
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
size_t last_backconv_line_len;
#endif
- init_linebuffer (&lb);
-
/* Initialize the conversion descriptors. */
if (need_code_conversion)
{
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 ();
#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
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
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
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;
/* 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);
}
/* 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);
}
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;
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;
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);
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);
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;
}
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;
}
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;
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;
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];
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;
/* 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
};
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)
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)
{
/* 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;
{
/* 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;
}
if (wget_present)
{
const char *argv[10];
- int exitstatus;
-
argv[0] = "wget";
argv[1] = "--quiet";
argv[2] = "--output-document"; argv[3] = "-";
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)
{
/* 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;
}
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)
{
/* 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;
}
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)
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;
{
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];
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];
}
}
- 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
&& 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,
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);
else
#endif
{
- FILE *fp;
- file_ostream_t stream;
-
/* Open the output file. */
+ FILE *fp;
if (!to_stdout)
{
fp = fopen (filename, "wb");
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)
{
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);
}
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;
{
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;
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];
{
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;
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;
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 == '_')
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)
{
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);
{
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
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");
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 ");
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++;
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]);
{
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(");
/* 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);
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,
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;
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)
{
/* 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
/* 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);
/* 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);
/* 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))
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;
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;
}
}
- template_file = fopen (template_file_name, "r");
+ FILE *template_file = fopen (template_file_name, "r");
if (template_file == NULL)
{
desktop_reader_free (reader);
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);
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;
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);
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
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;
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;
{
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);
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;
hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]);
}
}
+
fprintf (stream, "\"");
}
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);
{
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
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]);
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];
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 ");
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
/* 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");
}
{
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(");
/* 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);
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,
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;
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);
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;
/* 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)
{
}
}
- 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);
/* 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))
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);
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);
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;
/* 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)
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;
}
}
- 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;
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 */
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] == '>')
{
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)
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]);
}
}
/* 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);
/* 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
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)
/* 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;
/* 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;
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. */
/* 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,
/* 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 =
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);
/* 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;
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);
/* 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;
/* 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);
/* 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. */
}
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);
}
{
- 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)
}
/* 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);
/* 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. */
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);
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];
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);
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);
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;
{
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);
{
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, "#.");
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;
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);
}
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. */
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#:");
|| mp->do_wrap == no)
{
bool first_flag = true;
- size_t i;
begin_css_class (stream, class_flag_comment);
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);
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);
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
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;
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)
{
}
/* 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. */
|| (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;
}
}
}
- 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;
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;
/* 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);
/* 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)
{
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)
{
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
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);
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);
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;
|| mp->do_wrap == no)
{
bool first_flag = true;
- size_t i;
ostream_write_str (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;
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);
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);
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
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;
}
/* 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. */
}
/* 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,
}
/* 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,
/* 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);
}
}
- result = XNMALLOC (length + 1, char);
+ char *result = XNMALLOC (length + 1, char);
{
char *newstr = result;
{
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;
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];
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);
}
write_u16 (FILE *output_file, unsigned short value)
{
unsigned char data[2];
-
data[0] = (value >> 8) & 0xff;
data[1] = value & 0xff;
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;
append_u8 (struct obstack *mempool, unsigned char value)
{
unsigned char data[1];
-
data[0] = value;
obstack_grow (mempool, data, 1);
append_u16 (struct obstack *mempool, unsigned short value)
{
unsigned char data[2];
-
data[0] = (value >> 8) & 0xff;
data[1] = value & 0xff;
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;
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;
}
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;
}
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;
}
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];
/* 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];
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];
}
/* 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;
== 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;
/* 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))
/* 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 (""),
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;
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];
/* 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"),
{
/* 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 (""),
/* 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 (""),
/* 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,
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);
}
}
/* 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];
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);
/* 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];
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);
/* 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);
}
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");
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);
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];
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);
}
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'. */
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'. */
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;
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];
/* 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 (""),
/* 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 (""),
/* 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"),
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
}
}
- 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,
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);
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;
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);
}
static int
phase2_getc ()
{
- int lineno;
int c;
c = phase1_getc ();
{
struct string_buffer buffer;
sb_init (&buffer);
- lineno = line_number;
+ int lineno = line_number;
for (;;)
{
c = phase1_getc ();
static void
phase3_get (token_ty *tp)
{
- int c;
-
if (phase3_pushback_length)
{
*tp = phase3_pushback[--phase3_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase2_getc ();
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);
}
for (;;)
{
token_ty token;
-
phase4_get (&token);
if (next_is_argument && token.type != token_type_lparen)
case token_type_symbol:
{
void *keyword_value;
-
if (hash_find_entry (&keywords, token.string, strlen (token.string),
&keyword_value)
== 0)
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);
}
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;
phase4_getc ()
{
int c;
- bool last_was_star;
c = phase3_getc ();
if (c != '/')
case '*':
/* C comment. */
comment_start ();
- last_was_star = false;
+ bool last_was_star = false;
for (;;)
{
c = phase3_getc ();
static int
get_string_element (int context)
{
- int c, j;
+ int c;
/* Use phase 3, because phase 4 elides comments. */
c = phase3_getc ();
- 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)
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 ();
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 ();
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;
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 ();
}
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 ')'. */
if (tp->type == token_type_white_space)
{
token_ty next;
-
phase5_get (&next);
+
if (next.type == token_type_hash)
*tp = next;
else
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
/* 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);
}
/* 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. */
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;
for (;;)
{
token_ty tmp;
-
phase8c_get (&tmp);
+
if (tmp.type != token_type_string_literal)
{
phase8c_unget (&tmp);
for (;;)
{
token_ty token;
- void *keyword_value;
-
phase8_get (&token);
+
switch (token.type)
{
case token_type_eof:
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;
for (;;)
{
xgettext_token_ty token;
-
x_c_lex (&token);
+
switch (token.type)
{
case xgettext_token_type_keyword:
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);
}
else if (errno == EINVAL)
{
/* An incomplete multibyte character. */
- int c;
-
if (bufcount == MAX_PHASE1_PUSHBACK)
{
/* An overlong incomplete multibyte sequence was
}
/* Read one more byte and retry iconv. */
- c = phase1_getc ();
+ int c = phase1_getc ();
if (c == EOF)
{
multiline_error (xstrdup (""),
{
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)
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
unsigned char buf[6];
unsigned int count;
int c;
- ucs4_t uc;
c = phase1_getc ();
if (c == EOF)
count = 6;
}
+ ucs4_t uc;
u8_mbtouc (&uc, buf, count);
return uc;
}
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 ();
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. */
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;
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 ();
do_getc_escaped ()
{
int c;
- int n;
- int i;
/* Use phase 3, because phase 4 elides comments. */
c = phase3_getc ();
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);
static void
phase6_get (token_ty *tp)
{
- int c;
-
if (phase6_pushback_length)
{
*tp = phase6_pushback[--phase6_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
tp->logical_line_number = logical_line_number;
c = phase5_getc ();
/* 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;
/* 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 == '{')
{
/* 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);
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 (;;)
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;
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);
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;
break;
}
- for (dottedname = sum;;)
+ for (const char *dottedname = sum;;)
{
void *keyword_value;
-
if (hash_find_entry (&keywords, dottedname, strlen (dottedname),
&keyword_value)
== 0)
dottedname++;
}
- for (dottedname = sum;;)
+ flag_context_list_ty *context_list;
+ for (const char *dottedname = sum;;)
{
context_list =
flag_context_list_table_lookup (
case token_type_template:
{
lex_pos_ty pos;
-
pos.file_name = logical_file_name;
pos.line_number = token.line_number;
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] == '!')
{
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
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 =
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)));
}
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);
/* 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;
|| (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;
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')
/* 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))
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))
}
}
- 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);
/* 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))
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))
}
}
- 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);
/* 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))
/* 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))
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))
/* 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);
/* 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);
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)));
}
}
{
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);
}
/* 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);
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)
{
{
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)
{
desktop_parse (reader, f, real_filename, logical_filename);
desktop_reader_free (reader);
-
- reader = NULL;
}
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);
}
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')
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;
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;
}
for (;; arg++)
{
- struct object inner;
flag_region_ty *inner_region;
-
if (arg == 0)
inner_region = null_context_region ();
else
&context_iter));
++nesting_depth;
+ struct object inner;
read_object (&inner, arg == 0, new_backquote_flag,
inner_region);
nesting_depth--;
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)
{
for (;;)
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, false, new_backquote_flag,
null_context_region ());
nesting_depth--;
case '\'':
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, false, new_backquote_flag,
null_context_region ());
nesting_depth--;
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--;
do_ungetc (c);
}
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, false, false, null_context_region ());
nesting_depth--;
case ';':
{
- bool all_semicolons = true;
-
last_comment_line = line_number;
comment_start ();
+ bool all_semicolons = true;
for (;;)
{
int c = do_getc ();
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);
/* 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--;
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--;
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--;
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--;
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;
{
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;
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;
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;
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, ", ");
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);
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);
default_keywords = false;
else
{
- const char *end;
- struct callshape shape;
- const char *colon;
-
if (keywords.table == NULL)
{
hash_init (&keywords, 100);
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
|| 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);
/* 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;
|| (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;
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)
/* 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)
&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;
}
}
/* 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)
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)
{
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)
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)
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)
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)
{
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)
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
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)
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;
&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;
}
}
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))
{
{
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))
}
{
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))
{
{
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))
}
{
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))
{
/* 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;
}
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. */
{
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);
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]);
}
}
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;
}
/* "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)
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)
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)
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)
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)
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)
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)
{
/* 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
{
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)
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)
/* "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)
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)
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)
{
/* 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)
{
/* 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)
{
/* 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)
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;
}
/* 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);
/* 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);
/* 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))
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)));
}
}
|| (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);
}
/* 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);
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);
}
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;
if (c == 'u')
{
unsigned int u_count = 1;
- unsigned char buf[4];
- unsigned int n;
- int i;
-
for (;;)
{
c = phase1_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 ();
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 ();
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. */
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)
{
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];
{
/* 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 =
/* 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')
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
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
static void
phase5_get (token_ty *tp)
{
- int c;
-
if (phase5_pushback_length)
{
*tp = phase5_pushback[--phase5_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase4_getc ();
{
/* 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 (;;)
}
/* 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 ();
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);
/* String literal. */
{
struct mixed_string_buffer literal;
-
mixed_string_buffer_init (&literal, lc_string,
logical_file_name, line_number);
accumulate_escaped (&literal, '"');
/* Character literal. */
{
struct mixed_string_buffer literal;
-
mixed_string_buffer_init (&literal, lc_outside,
logical_file_name, line_number);
accumulate_escaped (&literal, '\'');
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);
for (;;)
{
token_ty token;
-
x_java_lex (&token);
+
switch (token.type)
{
case token_type_symbol:
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;
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)
dottedname++;
}
- for (dottedname = sum;;)
+ flag_context_list_ty *context_list;
+ for (const char *dottedname = sum;;)
{
context_list =
flag_context_list_table_lookup (
case token_type_string_literal:
{
lex_pos_ty pos;
-
pos.file_name = logical_file_name;
pos.line_number = token.line_number;
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);
}
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)
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;
else if (errno == EINVAL)
{
/* An incomplete multibyte character. */
- int c;
-
if (bufcount == MAX_PHASE1_PUSHBACK)
{
/* An overlong incomplete multibyte sequence was
}
/* Read one more byte and retry iconv. */
- c = phase1_getc ();
+ int c = phase1_getc ();
if (c == EOF)
{
multiline_error (xstrdup (""),
{
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)
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
unsigned char buf[6];
unsigned int count;
int c;
- ucs4_t uc;
c = phase1_getc ();
if (c == EOF)
count = 6;
}
+ ucs4_t uc;
u8_mbtouc (&uc, buf, count);
return uc;
}
static int
phase3_getc ()
{
- int c;
-
for (;;)
{
+ int c;
+
c = phase2_getc ();
if (c == '\\')
{
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 ();
static int
phase7_getuc (int quote_char)
{
- int c;
-
for (;;)
{
+ int c;
+
/* Use phase 2, because phase 3 elides comments. */
c = phase2_getc ();
case 'x':
{
int c1 = phase2_getc ();
- int n1;
+ int n1;
if (c1 >= '0' && c1 <= '9')
n1 = c1 - '0';
else if (c1 >= 'A' && c1 <= 'F')
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')
{
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 ();
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 ();
{ "![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;
/* 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])
/* 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])
if (end[j] == '\0')
{
- c = phase2_getc ();
+ int c = phase2_getc ();
if (c == UEOF)
goto eof;
if (c != '>')
static void
phase5_get (token_ty *tp)
{
- int c;
-
if (phase5_pushback_length)
{
*tp = phase5_pushback[--phase5_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase3_getc ();
/* Symbol, or part of a number. */
{
struct string_buffer buffer;
-
sb_init (&buffer);
for (;;)
{
{
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,
/* Template literals. */
{
struct mixed_string_buffer msb;
-
lexical_context = lc_string;
/* Start accumulating the string. */
mixed_string_buffer_init (&msb, lexical_context,
{
/* 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,
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)
{
else if (tp->type == token_type_symbol)
{
token_ty token2;
-
phase5_get (&token2);
+
if (token2.type == token_type_template
|| token2.type == token_type_ltemplate)
{
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)
case token_type_rtemplate:
{
lex_pos_ty pos;
-
pos.file_name = logical_file_name;
pos.line_number = token.line_number;
&& 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 ();
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);
}
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;
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)
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;
}
for (;; arg++)
{
- struct object inner;
flag_region_ty *inner_region;
-
if (arg == 0)
inner_region = null_context_region ();
else
&context_iter));
++nesting_depth;
+ struct object inner;
read_object (&inner, inner_region);
nesting_depth--;
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)
{
for (;;)
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, null_context_region ());
nesting_depth--;
case '\'':
case '`':
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, null_context_region ());
nesting_depth--;
case ';':
{
- bool all_semicolons = true;
-
last_comment_line = line_number;
comment_start ();
+ bool all_semicolons = true;
for (;;)
{
int c = do_getc ();
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);
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.
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.
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);
}
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);
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;
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;
}
/* 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]);
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
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;
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;
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;
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)
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;
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;
- 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++;
{
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)
{
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;
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;
static void
case_convert_token (struct token *tp)
{
- int n = tp->charcount;
- int i;
-
switch (readtable_case)
{
case case_upcase:
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;
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;
}
for (;;)
{
struct char_syntax curr;
-
read_char_syntax (&curr);
switch (curr.scode)
/* Number. */
{
int base = read_base;
-
if (is_number (op->token, &base) != n_none)
{
free_token (op->token);
for (;; arg++)
{
- struct object inner;
flag_region_ty *inner_region;
-
if (arg == 0)
inner_region = null_context_region ();
else
&context_iter));
++nesting_depth;
+ struct object inner;
read_object (&inner, inner_region);
nesting_depth--;
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),
case '\'':
case '`':
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, null_context_region ());
nesting_depth--;
case ';':
{
- bool all_semicolons = true;
-
last_comment_line = line_number;
comment_start ();
+ bool all_semicolons = true;
for (;;)
{
int c = do_getc ();
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);
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.
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.
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);
}
phase2_getc ()
{
int c;
- int lineno;
c = phase1_getc ();
bool end = false;
int esigns2 = 0;
- lineno = line_number;
+ int lineno = line_number;
comment_start ();
while (!end)
{
else
{
/* One line (short) comment, starting with '--[=...='. */
- lineno = last_comment_line;
+ int lineno = last_comment_line;
comment_start ();
comment_add ('[');
while (esigns--)
else
{
/* One line (short) comment. */
- lineno = line_number;
+ int lineno = line_number;
comment_start ();
phase1_ungetc (c);
eat_comment_line ();
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 (;;)
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;
case '"':
case '\'':
{
- c_start = c;
+ int c_start = c;
struct string_buffer buffer;
sb_init (&buffer);
case 'x':
{
int num = 0;
- int i = 0;
+ int i;
for (i = 0; i < 2; i++)
{
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 ();
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;
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;
for (;;)
{
token_ty token;
-
x_lua_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)
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);
}
static int
phase2_getc ()
{
- int c;
-
if (phase2_pushback_length)
return phase2_pushback[--phase2_pushback_length];
+ int c;
+
c = phase1_getc ();
if (c == '(')
{
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 ();
static void
phase3_get (token_ty *tp)
{
- int c;
-
if (phase3_pushback_length)
{
*tp = phase3_pushback[--phase3_pushback_length];
}
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase2_getc ();
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);
for (;;)
{
token_ty token;
-
x_modula2_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)
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);
}
{
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)
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)
#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)
{
/* 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;
{
/* 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;
{
/* 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;
{
/* 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;
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)
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)
/* 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);
/* 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);
{
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);
}
/* 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);
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);
}
/* 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))
++(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)
}
/* 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;
static int
phase2_getc (struct perl_extractor *xp)
{
- int lineno;
int c;
c = phase1_getc (xp);
{
struct string_buffer buffer;
sb_init (&buffer);
- lineno = xp->line_number;
+ int lineno = xp->line_number;
/* Skip leading whitespace. */
for (;;)
{
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 '(':
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')
for (i = 0; i < len; i++)
{
char c = string[i];
- int number;
+ int number;
if (c >= '0' && c <= '7')
number = c - '0';
else
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 == '[')
{
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).
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)
{
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)
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
continue;
case 'x':
{
- unsigned int hex_number = 0;
-
crs += 2;
+
+ unsigned int hex_number = 0;
if (*crs == '{')
{
const char *end = strchr (crs, '}');
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
}
/* No escape sequence, go on. */
+ bool backslashed;
if (*crs == '\\')
{
++crs;
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;
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
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);
/* 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)
{
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;
for (;;)
{
int c = phase2_getc (xp);
- int c2;
switch (c)
{
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:
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
* 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;
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)
case '-':
{
string_desc_t contents = sb_contents (&buffer);
+ void *keyword_value;
if (hash_find_entry (&keywords,
sd_data (contents),
sd_length (contents),
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),
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;
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;
}
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;
}
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;
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));
{
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;
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);
}
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);
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);
for (;;)
{
/* The current token. */
- token_ty *tp;
-
- tp = x_perl_lex (xp);
+ token_ty *tp = x_perl_lex (xp);
if (first)
{
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];
{
void *keyword_value;
-
if (hash_find_entry (&keywords, tp->string, strlen (tp->string),
&keyword_value) == 0)
{
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);
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];
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);
}
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)
{
static int
phase3_getc (struct php_extractor *xp)
{
- int lineno;
int c;
if (xp->phase3_pushback_length)
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);
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);
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);
}
if (c == '\\')
{
- int n, j;
-
c = phase1_getc (xp);
switch (c)
{
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':
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)];
for (;;)
{
+ int c;
+
tp->line_number = xp->line_number;
c = phase3_getc (xp);
switch (c)
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;
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;
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)
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';
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);
}
else if (errno == EINVAL)
{
/* An incomplete multibyte character. */
- int c;
-
if (bufcount == MAX_PHASE1_PUSHBACK)
{
/* An overlong incomplete multibyte sequence was
}
/* Read one more byte and retry iconv. */
- c = phase1_getc ();
+ int c = phase1_getc ();
if (c == EOF)
goto incomplete_at_eof;
if (c == '\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)
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
{
/* 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';
static int
phase3_getc ()
{
- int c;
-
for (;;)
{
+ int c;
+
c = phase2_getc ();
if (c == '\\')
{
else if (c == '#')
{
/* Eat a comment. */
- const char *comment;
-
last_comment_line = line_number;
comment_start ();
for (;;)
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;
bool f_string,
unsigned int *backslash_counter)
{
- int c;
-
for (;;)
{
+ int c;
+
/* Use phase 2, because phase 3 elides comments. */
c = phase2_getc ();
case 'x':
{
int c1 = phase2_getc ();
- int n1;
+ int n1;
if (c1 >= '0' && c1 <= '9')
n1 = c1 - '0';
else if (c1 >= 'A' && c1 <= 'F')
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')
{
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 ();
{
unsigned char buf[UNINAME_MAX + 1];
int i;
- unsigned int n;
for (i = 0; i < UNINAME_MAX; i++)
{
}
buf[i] = '\0';
- n = unicode_name_character ((char *) buf);
+ unsigned int n = unicode_name_character ((char *) buf);
if (n != UNINAME_INVALID)
{
*backslash_counter = 0;
static void
phase5_get (token_ty *tp)
{
- int c;
-
if (phase5_pushback_length)
{
*tp = phase5_pushback[--phase5_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase3_getc ();
/* Symbol, or part of a number. */
{
struct string_buffer buffer;
-
sb_init (&buffer);
for (;;)
{
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,
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)
{
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)
case token_type_498:
{
lex_pos_ty pos;
-
pos.file_name = logical_file_name;
pos.line_number = token.line_number;
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)
}
/* Read ModuleName.ConstName. */
+ char *location;
{
struct string_buffer buffer;
sb_init (&buffer);
}
/* Read StringExpression. */
+ char *msgid;
{
struct string_buffer buffer;
sb_init (&buffer);
}
else if (c == '#')
{
- int n;
c = getc (f);
if (c == EOF && ferror (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);
msgid = sb_xdupfree_c (&buffer);
}
+ lex_pos_ty pos;
pos.file_name = location;
pos.line_number = (size_t)(-1);
parse_integer ()
_GL_ATTRIBUTE_ACQUIRE_CAPABILITY (buffer.data)
{
+ sb_init (&buffer);
+
int c;
- sb_init (&buffer);
c = phase2_getc ();
for (;;)
{
phase2_ungetc (c);
return pr_none;
}
+
mixed_string_buffer_init (&stringbuf, lc_string,
logical_file_name, line_number);
for (;;)
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 ();
msgdomain_list_ty *mdlp)
{
message_list_ty *mlp = mdlp->item[0]->messages;
- int c;
fp = f;
real_file_name = real_filename;
/* 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;
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)
{
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"));
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"),
{
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];
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];
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];
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];
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 (¯o_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] == '!')
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)
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. */
&& 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')
/* 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);
/* 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);
/* 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 =
#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
/* 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);
/* 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);
/* 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))
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,
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)));
}
}
{
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)));
}
}
|| 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);
}
/* 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);
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;
{
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:
*/
if (p == p_end)
return false;
+
/* Parse leading sign. */
- seen_sign = false;
+ bool seen_sign = false;
if (*p == '+' || *p == '-')
{
p++;
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;
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)
{
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])
break;
}
{
- unsigned int n;
- bool overflow;
-
- n = 0;
- overflow = false;
-
+ unsigned int n = 0;
+ bool overflow = false;
for (;;)
{
switch (c)
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 ();
case ';':
{
- bool all_semicolons = true;
-
last_comment_line = line_number;
comment_start ();
+ bool all_semicolons = true;
for (;;)
{
int c = phase1_getc ();
for (;; arg++)
{
- struct object inner;
flag_region_ty *inner_region;
-
if (arg == 0)
inner_region = null_context_region ();
else
&context_iter));
++nesting_depth;
+ struct object inner;
read_object (&inner, inner_region);
nesting_depth--;
}
void *keyword_value;
-
if (hash_find_entry (&keywords,
symbol_name, strlen (symbol_name),
&keyword_value)
case '\'':
case '`':
{
- struct object inner;
-
++nesting_depth;
+ struct object inner;
read_object (&inner, null_context_region ());
nesting_depth--;
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.
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'
#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.
case 'E': case 'e':
case 'I': case 'i':
{
- struct token token;
phase1_ungetc (dmc);
+ struct token token;
read_token (&token, '#');
if (is_number (&token))
{
#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.
/* 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--;
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);
case '\\':
/* Character. */
{
- struct token token;
int c = phase1_getc ();
if (c != EOF)
{
+ struct token token;
read_token (&token, c);
free_token (&token);
}
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.
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);
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);
}
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 '\\';
read_word (struct word *wp, int looking_for, flag_region_ty *region)
{
int c;
- bool all_unquoted_digits;
- bool all_unquoted_name_characters;
do
{
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 ())
{
if (c == '$')
{
- int c2;
-
/* An unquoted dollar indicates we are not inside '...'. */
if (open_singlequote)
abort ();
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
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
|| (c >= 'a' && c <= 'f'))
{
int n;
-
if (c >= '0' && c <= '9')
n = c - '0';
else if (c >= 'A' && c <= 'F')
{
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 ();
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 (;;)
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). */
for (;;)
{
- struct word inner;
flag_region_ty *inner_region;
-
if (arg == 0)
inner_region = null_context_region ();
else
flag_context_list_iterator_advance (
&context_iter));
+ struct word inner;
read_word (&inner, looking_for, inner_region);
/* Recognize end of command. */
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)),
else
{
void *keyword_value;
-
if (hash_find_entry (&keywords,
function_name,
strlen (function_name),
_("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;
}
static void
phase2_get (token_ty *tp)
{
- int c;
-
if (phase2_pushback_length)
{
*tp = phase2_pushback[--phase2_pushback_length];
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase1_getc ();
switch (c)
case '"':
{
/* Comment. */
- int lineno;
-
comment_start ();
- lineno = line_number;
+ int lineno = line_number;
for (;;)
{
c = phase1_getc ();
case '%':
case '\\':
{
- char *name;
int c2 = phase1_getc ();
switch (c2)
{
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;
if (tp->type == token_type_uniq)
{
token_ty token2;
-
phase2_get (&token2);
+
if (token2.type == token_type_symbol
|| token2.type == token_type_string_literal)
{
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);
for (;;)
{
token_ty token;
-
phase4_get (&token);
switch (token.type)
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 =
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
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;
}
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)
else
{
bool nonempty = false;
-
for (; c != EOF && c != CL_BRACE; c = phase2_getc ())
{
if (c_isalnum ((unsigned char) c) || (c == '_'))
}
break;
}
+
if (c == '(')
{
/* $varname(index) */
{
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];
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)
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);
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)
{
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;
}
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);
}
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 ();
'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
|| 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);
/* 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;
|| (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;
&& 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')
/* 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);
/* 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);
/* 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))
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)));
}
}
{
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);
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);
}
phase2_getc ()
{
int c;
- bool last_was_star;
c = phase1_getc ();
if (c != '/')
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 ' ';
static int
get_string_element ()
{
- int c, j;
+ int c;
/* Use phase 1, because phase 2 elides comments. */
c = phase1_getc ();
break;
}
{
- int n;
- bool overflow;
-
- n = 0;
- overflow = false;
-
+ int n = 0;
+ bool overflow = false;
for (;;)
{
switch (c)
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 ();
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 ();
for (;;)
{
- bool template;
- bool verbatim;
int c;
tp->line_number = line_number;
}
last_non_comment_line = tp->line_number;
- template = false;
- verbatim = false;
+ bool template = false;
+ bool verbatim = false;
switch (c)
{
struct mixed_string_buffer msb;
{
int c2 = phase1_getc ();
-
if (c2 == '"')
{
int c3 = phase1_getc ();
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);
for (;;)
{
token_ty token;
-
x_vala_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)
case token_type_string_literal:
{
lex_pos_ty pos;
-
pos.file_name = logical_file_name;
pos.line_number = token.line_number;
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. */
/* sh comment. */
struct string_buffer buffer;
sb_init (&buffer);
- lineno = line_number;
+ int lineno = line_number;
for (;;)
{
c = phase1_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 ();
{
struct string_buffer buffer;
sb_init (&buffer);
- lineno = line_number;
+ int lineno = line_number;
for (;;)
{
c = phase1_getc ();
static int
get_string_element ()
{
- int c;
-
for (;;)
{
+ int c;
+
/* Use phase 1, because phase 2 elides comments. */
c = phase1_getc ();
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 ();
static void
phase5_get (token_ty *tp)
{
- int c;
-
if (phase5_pushback_length)
{
*tp = phase5_pushback[--phase5_pushback_length];
}
for (;;)
{
+ int c;
+
tp->line_number = line_number;
c = phase2_getc ();
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);
for (;;)
{
token_ty token;
-
if (in_i18n)
phase8_get (&token);
else
{
/* Seen an msgid. */
token_ty token2;
-
if (in_i18n)
phase8_get (&token2);
else
if (multiline_p)
{
bool old_error_with_progname = error_with_progname;
- char *prefix;
+ char *prefix;
if (filename != NULL)
{
if (lineno != (size_t)(-1))
split_keywordspec (const char *spec,
const char **endp, struct callshape *shapep)
{
- const char *p;
int argnum1 = 0;
int argnum2 = 0;
int argnumc = 0;
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])
}
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
p--;
if (*p == ':')
{
- size_t i;
-
if (argnum1 == 0 && argnum2 == 0)
/* At least one non-context argument must be given. */
break;
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;
/* 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
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);
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;
}
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
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;
}
list->argnum = argnum;
memset (&list->flags, '\0', sizeof (list->flags));
set_flags_for_formatstring_type (&list->flags, fi, value, pass);
+
list->next = copy;
}
}
{
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;
flag_context_ty modifier_context)
{
flag_region_ty *region = XMALLOC (flag_region_ty);
-
region->refcount = 1;
for (size_t fi = 0; fi < NXFORMATS; fi++)
{
{
/* Create the new region. */
flag_region_ty *region = XMALLOC (flag_region_ty);
-
region->refcount = 1;
for (size_t fi = 0; fi < NXFORMATS; fi++)
{
/* 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;
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,
}
/* 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
struct arglist_parser *ap =
(struct arglist_parser *)
xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative, 0));
-
ap->mlp = mlp;
ap->keyword = NULL;
ap->keyword_len = 0;
(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;
(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 = ©->alternative[i];
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];
{
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;
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
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];
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];
/* 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];
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];
}
/* 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];
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];
{
/* 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
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
{
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
}
}
- 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,
{
/* 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);
}
}
}
- 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);
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;
}
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;
}
syntax_check_quote_unicode (const message_ty *mp, const char *msgid)
{
struct callback_arg arg;
-
arg.mp = mp;
arg.seen_errors = 0;
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;
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)
{
{
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,
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];
"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)
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, '@');
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];
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:
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:
{
#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;
{
#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;
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])
/* 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])
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;
}
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)
{
savable_comment_to_xgettext_comment (comment);
+ struct argument_range range;
range.min = -1;
range.max = -1;
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)
{
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
/* 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;
/* 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;
}
}
- 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
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)
{
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;
}
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);
/* 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 =
}
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
/* 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. */
int line_number)
{
struct mixed_string *ms = XMALLOC (struct mixed_string);
-
if (*string == '\0')
{
/* An empty string. */
int line_number)
{
struct mixed_string *ms = XMALLOC (struct mixed_string);
-
if (*string == '\0')
{
/* An empty 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;
}
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;
}
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;
}
}
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);
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);
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);
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 ();
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);
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
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;
/* 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 =
};
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)
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);
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 : ".");
}
/* Determine list of files we have to process. */
+ string_list_ty *file_list;
if (files_from != NULL)
{
if (strcmp (files_from, "-") != 0)
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
}
/* 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. */
/* 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);
}
/* 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)
}
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 == '.')
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,
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 =
{
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);
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);
}
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
/* 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]);
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);
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
/* 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;
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;
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)
{
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);
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]);
}
}
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);
new_name = xconcatenated_filename (dir, fn, NULL);
+ struct stat statbuf;
if (stat (new_name, &statbuf) == 0)
{
found_in_dir = dir;
else
{
new_name = xstrdup (fn);
+ struct stat statbuf;
if (stat (fn, &statbuf) != 0)
error (EXIT_FAILURE, errno,
_("error while opening \"%s\" for reading"), 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)
{
}
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);
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);
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)
{
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)
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\
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\
/* 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];
&& 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,
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;
/* 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;
/* 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
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. */
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);
#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);
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;
}
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])
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);
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);
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;
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))
{
return false;
}
}
+
return true;
}
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;
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;
* for < etc. this is obvious, for  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;
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
|| (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;
else
{
const char *reason;
- char *error_text;
-
if (*from == ';')
reason = _("empty");
else
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;
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;
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;
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.
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,
}
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.
assert (context->cur_attr >= 0);
+ bool is_ascii;
if (unescape_string_inplace (context, context->partial_chunk,
&is_ascii)
&& (is_ascii
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
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 != '>')
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;
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);
context->parsing = true;
+ const char *location = NULL;
switch (context->state)
{
case STATE_START:
/* 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;
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')
{
/* 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
file_ostream_create (FILE *fp)
{
file_ostream_t stream = XMALLOC (struct file_ostream_representation);
-
stream->base.vtable = &file_ostream_vtable;
stream->fp = fp;
/* 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
{
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);
}
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)
{
#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 (;;)
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')
{
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;
/* 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
{
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);
/* 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"),
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\""),
/* 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
{
#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 (;;)
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);
/* 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
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);
/* 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
{
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;
/* 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
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)
{
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;
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)
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)
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)
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)
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)
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';
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. */
out_char_unchecked (int c)
{
char bytes[1];
-
bytes[0] = (char)c;
+
full_write (out_fd, bytes, 1);
return 0;
}
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);
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)
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)
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);
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)
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)
else
#endif
{
- bool cleared_attributes;
-
/* For out_char to work. */
out_stream = stream;
out_fd = stream->fd;
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)
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))
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)
{
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];
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);
}
{
/* Create a new hyperlink_t object. */
hyperlink_t *hyperlink = XMALLOC (hyperlink_t);
-
hyperlink->ref = xstrdup (ref);
if (id != NULL)
{
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
<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)
{
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
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 ();
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;
/* 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
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;
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);
(*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);
}
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);
}
}
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;
/* 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);
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)
{
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)
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. */
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)
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)
{ "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, "|");
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;
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);
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);
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);
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);
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);
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);
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);
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);
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;
/* 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
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);