diff options
author | Daiki Ueno <ueno@gnu.org> | 2014-03-24 18:43:01 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2014-03-25 17:05:41 +0900 |
commit | 90c76fda268779b80c2fa969b8efddbb4aa5da1e (patch) | |
tree | 35736c9950945b19fad8244a89907d20d29c2b5b /gettext-tools/src | |
parent | 0c94b1c6d7a118b64e50644242cd498b60bfa518 (diff) | |
download | external_gettext-90c76fda268779b80c2fa969b8efddbb4aa5da1e.zip external_gettext-90c76fda268779b80c2fa969b8efddbb4aa5da1e.tar.gz external_gettext-90c76fda268779b80c2fa969b8efddbb4aa5da1e.tar.bz2 |
Extend --add-location option to suppress line number output
The --add-location option of msgattrib, msgcat, msgcomm, msgconv,
msgen, msgfilter, msggrep, msgmerge, msguniq, and xgettext
commands now takes an optional argument 'never', 'full', or
'file', to control the format of "#: ..." comments.
The default catalog reader changed to always remember file
positions so the line number part can be suppressed in output
phase rather than input phase.
Diffstat (limited to 'gettext-tools/src')
-rw-r--r-- | gettext-tools/src/ChangeLog | 42 | ||||
-rw-r--r-- | gettext-tools/src/msgattrib.c | 15 | ||||
-rw-r--r-- | gettext-tools/src/msgcat.c | 15 | ||||
-rw-r--r-- | gettext-tools/src/msgcomm.c | 15 | ||||
-rw-r--r-- | gettext-tools/src/msgconv.c | 21 | ||||
-rw-r--r-- | gettext-tools/src/msgen.c | 24 | ||||
-rw-r--r-- | gettext-tools/src/msgfilter.c | 21 | ||||
-rw-r--r-- | gettext-tools/src/msgfmt.c | 4 | ||||
-rw-r--r-- | gettext-tools/src/msggrep.c | 21 | ||||
-rw-r--r-- | gettext-tools/src/msgmerge.c | 21 | ||||
-rw-r--r-- | gettext-tools/src/msguniq.c | 15 | ||||
-rw-r--r-- | gettext-tools/src/read-catalog.c | 69 | ||||
-rw-r--r-- | gettext-tools/src/read-catalog.h | 8 | ||||
-rw-r--r-- | gettext-tools/src/write-po.c | 86 | ||||
-rw-r--r-- | gettext-tools/src/write-po.h | 13 | ||||
-rw-r--r-- | gettext-tools/src/x-po.c | 1 | ||||
-rw-r--r-- | gettext-tools/src/xgettext.c | 18 |
17 files changed, 268 insertions, 141 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 06a59bd..8db3725 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,45 @@ +2014-03-25 Daiki Ueno <ueno@gnu.org> + + Extend --add-location option to suppress line number output + The --add-location option of msgattrib, msgcat, msgcomm, msgconv, + msgen, msgfilter, msggrep, msgmerge, msguniq, and xgettext + commands now got new semantics. It takes an optional argument + 'never', 'full', or 'file', to control the format of "#: ..." + comments. + The default catalog reader changed to always remember file + positions so the line number part can be suppressed in output + phase rather than input phase. + Feature requested in: + <https://lists.gnu.org/archive/html/bug-gettext/2013-08/msg00039.html>. + * read-catalog.h (line_comment): Abolish. + (DEFAULT_CATALOG_READER_TY): Remove handle_filepos_comments field. + * read-catalog.c (line_comment): Abolish. + (default_destructor, default_copy_comment_state) + (default_reset_comment_state, default_comment_filepos): Always + remember filepos. + (default_parse_brief, read_catalog_stream): Adjust to the change. + * write-po.h (enum filepos_comment_type): New enum. + (message_print_style_filepos): New function declaration. + (handle_filepos_comment_option): New function declaration. + * write-po.c (message_print_style_filepos): New function + (handle_filepos_comment_option): New function. + (message_print_comment_filepos): Uniquify mp->filepos elements + ignoring line number if filepos_comment_type is + filepos_comment_file. + * msgfmt.c: Adjust to the change. + * msgattrib.c (long_options, main): Allow --add-location option to + take an optional format specifier. + * msgcat.c (long_options, main): Likewise. + * msgcomm.c (long_options, main): Likewise. + * msguniq.c (long_options, main): Likewise. + * xgettext.c (long_options, main): Likewise. + * msgconv.c (long_options, main): Likewise; add a new option -n as + an alias of --add-location. + * msgen.c (long_options, main): Likewise. + * msgfilter.c (long_options, main): Likewise. + * msggrep.c (long_options, main): Likewise. + * msgmerge.c (long_options, main): Likewise. + 2014-03-12 Daiki Ueno <ueno@gnu.org> xgettext: Fix infloop on loading Glade files with non-DL expat diff --git a/gettext-tools/src/msgattrib.c b/gettext-tools/src/msgattrib.c index 7732315..01b6f97 100644 --- a/gettext-tools/src/msgattrib.c +++ b/gettext-tools/src/msgattrib.c @@ -80,7 +80,7 @@ static int to_change; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "clear-fuzzy", no_argument, NULL, CHAR_MAX + 8 }, { "clear-obsolete", no_argument, NULL, CHAR_MAX + 10 }, { "clear-previous", no_argument, NULL, CHAR_MAX + 18 }, @@ -94,7 +94,7 @@ static const struct option long_options[] = { "indent", no_argument, NULL, 'i' }, { "no-escape", no_argument, NULL, 'e' }, { "no-fuzzy", no_argument, NULL, CHAR_MAX + 3 }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 22 }, { "no-obsolete", no_argument, NULL, CHAR_MAX + 5 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 13 }, { "obsolete", no_argument, NULL, CHAR_MAX + 12 }, @@ -207,7 +207,8 @@ main (int argc, char **argv) break; case 'n': - line_comment = 1; + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); break; case 'o': @@ -331,6 +332,10 @@ main (int argc, char **argv) to_change |= ADD_PREV; break; + case CHAR_MAX + 22: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -367,10 +372,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); diff --git a/gettext-tools/src/msgcat.c b/gettext-tools/src/msgcat.c index 7c36730..0cc432c 100644 --- a/gettext-tools/src/msgcat.c +++ b/gettext-tools/src/msgcat.c @@ -62,7 +62,7 @@ static const char *to_code; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 5 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -72,7 +72,7 @@ static const struct option long_options[] = { "indent", no_argument, NULL, 'i' }, { "lang", required_argument, NULL, CHAR_MAX + 7 }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 8 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 2 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -202,7 +202,8 @@ main (int argc, char **argv) break; case 'n': - line_comment = 1; + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); break; case 'o': @@ -276,6 +277,10 @@ main (int argc, char **argv) catalogname = optarg; break; + case CHAR_MAX + 8: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -307,10 +312,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); diff --git a/gettext-tools/src/msgcomm.c b/gettext-tools/src/msgcomm.c index e965dba..daddf2b 100644 --- a/gettext-tools/src/msgcomm.c +++ b/gettext-tools/src/msgcomm.c @@ -63,7 +63,7 @@ static const char *to_code; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 5 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -72,7 +72,7 @@ static const struct option long_options[] = { "help", no_argument, NULL, 'h' }, { "indent", no_argument, NULL, 'i' }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 7 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 2 }, { "omit-header", no_argument, NULL, CHAR_MAX + 1 }, { "output", required_argument, NULL, 'o' }, /* for backward compatibility */ @@ -197,7 +197,8 @@ main (int argc, char *argv[]) break; case 'n': - line_comment = 1; + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); break; case 'o': @@ -267,6 +268,10 @@ main (int argc, char *argv[]) handle_style_option (optarg); break; + case CHAR_MAX + 7: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -292,10 +297,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ usage (EXIT_SUCCESS); /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); diff --git a/gettext-tools/src/msgconv.c b/gettext-tools/src/msgconv.c index af1361a..5c9f7ea 100644 --- a/gettext-tools/src/msgconv.c +++ b/gettext-tools/src/msgconv.c @@ -60,7 +60,7 @@ static const char *to_code; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 4 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -68,7 +68,7 @@ static const struct option long_options[] = { "help", no_argument, NULL, 'h' }, { "indent", no_argument, NULL, 'i' }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 6 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 1 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -131,7 +131,7 @@ main (int argc, char **argv) output_file = NULL; input_file = NULL; - while ((opt = getopt_long (argc, argv, "D:eEFhio:pPst:Vw:", long_options, + while ((opt = getopt_long (argc, argv, "D:eEFhin:o:pPst:Vw:", long_options, NULL)) != EOF) switch (opt) @@ -163,6 +163,11 @@ main (int argc, char **argv) message_print_style_indent (); break; + case 'n': + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); + break; + case 'o': output_file = optarg; break; @@ -222,6 +227,10 @@ main (int argc, char **argv) handle_style_option (optarg); break; + case CHAR_MAX + 6: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); break; @@ -258,10 +267,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -360,7 +365,7 @@ Output details:\n")); printf (_("\ --no-location suppress '#: filename:line' lines\n")); printf (_("\ - --add-location preserve '#: filename:line' lines (default)\n")); + -n, --add-location preserve '#: filename:line' lines (default)\n")); printf (_("\ --strict strict Uniforum output style\n")); printf (_("\ diff --git a/gettext-tools/src/msgen.c b/gettext-tools/src/msgen.c index 2ec3d5e..e33c61a 100644 --- a/gettext-tools/src/msgen.c +++ b/gettext-tools/src/msgen.c @@ -57,7 +57,7 @@ static int force_po; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 5 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -66,7 +66,7 @@ static const struct option long_options[] = { "indent", no_argument, NULL, 'i' }, { "lang", required_argument, NULL, CHAR_MAX + 4 }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 7 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 1 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -128,8 +128,9 @@ main (int argc, char **argv) do_version = false; output_file = NULL; - while ((opt = getopt_long (argc, argv, "D:eEFhio:pPsVw:", long_options, NULL)) - != EOF) + while ((opt = getopt_long (argc, argv, + "D:eEFhin:o:pPsVw:", + long_options, NULL)) != EOF) switch (opt) { case '\0': /* Long option. */ @@ -159,6 +160,11 @@ main (int argc, char **argv) message_print_style_indent (); break; + case 'n': + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); + break; + case 'o': output_file = optarg; break; @@ -218,6 +224,10 @@ main (int argc, char **argv) handle_style_option (optarg); break; + case CHAR_MAX + 7: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); break; @@ -255,10 +265,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -355,7 +361,7 @@ Output details:\n")); printf (_("\ --no-location suppress '#: filename:line' lines\n")); printf (_("\ - --add-location preserve '#: filename:line' lines (default)\n")); + -n, --add-location preserve '#: filename:line' lines (default)\n")); printf (_("\ --strict strict Uniforum output style\n")); printf (_("\ diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index c414140..b92eef0 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -87,7 +87,7 @@ static void (*filter) (const char *str, size_t len, char **resultp, size_t *leng /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 6 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -97,7 +97,7 @@ static const struct option long_options[] = { "input", required_argument, NULL, 'i' }, { "keep-header", no_argument, &keep_header, 1 }, { "no-escape", no_argument, NULL, CHAR_MAX + 2 }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 8 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 3 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -164,7 +164,7 @@ main (int argc, char **argv) /* The '+' in the options string causes option parsing to terminate when the first non-option, i.e. the subprogram name, is encountered. */ - while ((opt = getopt_long (argc, argv, "+D:EFhi:o:pPsVw:", long_options, + while ((opt = getopt_long (argc, argv, "+D:EFhi:n:o:pPsVw:", long_options, NULL)) != EOF) switch (opt) @@ -197,6 +197,11 @@ main (int argc, char **argv) input_file = optarg; break; + case 'n': + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); + break; + case 'o': output_file = optarg; break; @@ -260,6 +265,10 @@ main (int argc, char **argv) handle_style_option (optarg); break; + case CHAR_MAX + 8: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); break; @@ -290,10 +299,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ sub_name = argv[optind]; /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -456,7 +461,7 @@ Output details:\n")); printf (_("\ --no-location suppress '#: filename:line' lines\n")); printf (_("\ - --add-location preserve '#: filename:line' lines (default)\n")); + -n, --add-location preserve '#: filename:line' lines (default)\n")); printf (_("\ --strict strict Uniforum output style\n")); printf (_("\ diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 4da999a..e51319d 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -846,8 +846,7 @@ is_nonobsolete (const message_ty *mp) default_catalog_reader_ty. Its particularities are: - The header entry check is performed on-the-fly. - Comments are not stored, they are discarded right away. - (This is achieved by setting handle_comments = false and - handle_filepos_comments = false.) + (This is achieved by setting handle_comments = false.) - The multi-domain handling is adapted to our domain_list. */ @@ -1107,7 +1106,6 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax) pop = default_catalog_reader_alloc (&msgfmt_methods); pop->handle_comments = false; - pop->handle_filepos_comments = false; pop->allow_domain_directives = true; pop->allow_duplicates = false; pop->allow_duplicates_if_same_msgstr = false; diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index 3b12e93..73ccb94 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -91,7 +91,7 @@ static struct grep_task grep_task[5]; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 9 }, { "comment", no_argument, NULL, 'C' }, { "directory", required_argument, NULL, 'D' }, @@ -111,7 +111,7 @@ static const struct option long_options[] = { "msgid", no_argument, NULL, 'K' }, { "msgstr", no_argument, NULL, 'T' }, { "no-escape", no_argument, NULL, CHAR_MAX + 3 }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 11 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 6 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -196,7 +196,7 @@ main (int argc, char **argv) gt->case_insensitive = false; } - while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:N:o:pPTvVw:X", + while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiJKM:n:N:o:pPTvVw:X", long_options, NULL)) != EOF) switch (opt) @@ -310,6 +310,11 @@ error while reading \"%s\""), optarg); string_list_append (domain_names, optarg); break; + case 'n': + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); + break; + case 'N': string_list_append (location_files, optarg); break; @@ -397,6 +402,10 @@ error while reading \"%s\""), optarg); handle_style_option (optarg); break; + case CHAR_MAX + 11: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); break; @@ -433,10 +442,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -603,7 +608,7 @@ Output details:\n")); printf (_("\ --no-location suppress '#: filename:line' lines\n")); printf (_("\ - --add-location preserve '#: filename:line' lines (default)\n")); + -n, --add-location preserve '#: filename:line' lines (default)\n")); printf (_("\ --strict strict Uniforum output style\n")); printf (_("\ diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index 3f96d3e..7c7add9 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -107,7 +107,7 @@ static const char *backup_suffix_string; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "backup", required_argument, NULL, CHAR_MAX + 1 }, { "color", optional_argument, NULL, CHAR_MAX + 9 }, { "compendium", required_argument, NULL, 'C', }, @@ -120,7 +120,7 @@ static const struct option long_options[] = { "multi-domain", no_argument, NULL, 'm' }, { "no-escape", no_argument, NULL, 'e' }, { "no-fuzzy-matching", no_argument, NULL, 'N' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 11 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 4 }, { "output-file", required_argument, NULL, 'o' }, { "previous", no_argument, NULL, CHAR_MAX + 7 }, @@ -204,7 +204,7 @@ main (int argc, char **argv) do_version = false; output_file = NULL; - while ((opt = getopt_long (argc, argv, "C:D:eEFhimNo:pPqsUvVw:", + while ((opt = getopt_long (argc, argv, "C:D:eEFhimn:No:pPqsUvVw:", long_options, NULL)) != EOF) switch (opt) @@ -244,6 +244,11 @@ main (int argc, char **argv) multi_domain_mode = true; break; + case 'n': + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); + break; + case 'N': use_fuzzy_matching = false; break; @@ -331,6 +336,10 @@ main (int argc, char **argv) handle_style_option (optarg); break; + case CHAR_MAX + 11: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); break; @@ -392,10 +401,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } } - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -581,7 +586,7 @@ Output details:\n")); printf (_("\ --no-location suppress '#: filename:line' lines\n")); printf (_("\ - --add-location preserve '#: filename:line' lines (default)\n")); + -n, --add-location preserve '#: filename:line' lines (default)\n")); printf (_("\ --strict strict Uniforum output style\n")); printf (_("\ diff --git a/gettext-tools/src/msguniq.c b/gettext-tools/src/msguniq.c index 9f1add6..24f4c31 100644 --- a/gettext-tools/src/msguniq.c +++ b/gettext-tools/src/msguniq.c @@ -60,7 +60,7 @@ static const char *to_code; /* Long options. */ static const struct option long_options[] = { - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "color", optional_argument, NULL, CHAR_MAX + 5 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -68,7 +68,7 @@ static const struct option long_options[] = { "help", no_argument, NULL, 'h' }, { "indent", no_argument, NULL, 'i' }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 7 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 2 }, { "output-file", required_argument, NULL, 'o' }, { "properties-input", no_argument, NULL, 'P' }, @@ -175,7 +175,8 @@ main (int argc, char **argv) break; case 'n': - line_comment = 1; + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); break; case 'o': @@ -246,6 +247,10 @@ main (int argc, char **argv) handle_style_option (optarg); break; + case CHAR_MAX + 7: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -282,10 +287,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index 51e96e8..4642249 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -112,6 +112,7 @@ void default_destructor (abstract_catalog_reader_ty *that) { default_catalog_reader_ty *this = (default_catalog_reader_ty *) that; + size_t j; /* Do not free this->mdlp and this->mlp. */ if (this->handle_comments) @@ -121,24 +122,19 @@ default_destructor (abstract_catalog_reader_ty *that) if (this->comment_dot != NULL) string_list_free (this->comment_dot); } - if (this->handle_filepos_comments) - { - size_t j; - for (j = 0; j < this->filepos_count; ++j) - free (this->filepos[j].file_name); - if (this->filepos != NULL) - free (this->filepos); - } + for (j = 0; j < this->filepos_count; ++j) + free (this->filepos[j].file_name); + if (this->filepos != NULL) + free (this->filepos); } void default_parse_brief (abstract_catalog_reader_ty *that) { - /* We need to parse comments, because even if this->handle_comments and - this->handle_filepos_comments are false, we need to know which messages - are fuzzy. */ + /* We need to parse comments, because even if this->handle_comments + is false, we need to know which messages are fuzzy. */ po_lex_pass_comments (true); } @@ -164,15 +160,12 @@ default_copy_comment_state (default_catalog_reader_ty *this, message_ty *mp) for (j = 0; j < this->comment_dot->nitems; ++j) message_comment_dot_append (mp, this->comment_dot->item[j]); } - if (this->handle_filepos_comments) + for (j = 0; j < this->filepos_count; ++j) { - for (j = 0; j < this->filepos_count; ++j) - { - lex_pos_ty *pp; + lex_pos_ty *pp; - pp = &this->filepos[j]; - message_comment_filepos (mp, pp->file_name, pp->line_number); - } + pp = &this->filepos[j]; + message_comment_filepos (mp, pp->file_name, pp->line_number); } mp->is_fuzzy = this->is_fuzzy; for (i = 0; i < NFORMATS; i++) @@ -200,15 +193,12 @@ default_reset_comment_state (default_catalog_reader_ty *this) this->comment_dot = NULL; } } - if (this->handle_filepos_comments) - { - for (j = 0; j < this->filepos_count; ++j) - free (this->filepos[j].file_name); - if (this->filepos != NULL) - free (this->filepos); - this->filepos_count = 0; - this->filepos = NULL; - } + for (j = 0; j < this->filepos_count; ++j) + free (this->filepos[j].file_name); + if (this->filepos != NULL) + free (this->filepos); + this->filepos_count = 0; + this->filepos = NULL; this->is_fuzzy = false; for (i = 0; i < NFORMATS; i++) this->is_format[i] = undecided; @@ -291,18 +281,14 @@ default_comment_filepos (abstract_catalog_reader_ty *that, const char *name, size_t line) { default_catalog_reader_ty *this = (default_catalog_reader_ty *) that; - - if (this->handle_filepos_comments) - { - size_t nbytes; - lex_pos_ty *pp; - - nbytes = (this->filepos_count + 1) * sizeof (this->filepos[0]); - this->filepos = xrealloc (this->filepos, nbytes); - pp = &this->filepos[this->filepos_count++]; - pp->file_name = xstrdup (name); - pp->line_number = line; - } + size_t nbytes; + lex_pos_ty *pp; + + nbytes = (this->filepos_count + 1) * sizeof (this->filepos[0]); + this->filepos = xrealloc (this->filepos, nbytes); + pp = &this->filepos[this->filepos_count++]; + pp->file_name = xstrdup (name); + pp->line_number = line; } @@ -458,10 +444,6 @@ default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table) /* Exported functions. */ -/* If nonzero, remember comments for file name and line number for each - msgid, if present in the reference input. Defaults to true. */ -int line_comment = 1; - /* If false, duplicate msgids in the same domain and file generate an error. If true, such msgids are allowed; the caller should treat them appropriately. Defaults to false. */ @@ -478,7 +460,6 @@ read_catalog_stream (FILE *fp, const char *real_filename, pop = default_catalog_reader_alloc (&default_methods); pop->handle_comments = true; - pop->handle_filepos_comments = (line_comment != 0); pop->allow_domain_directives = true; pop->allow_duplicates = allow_duplicates; pop->allow_duplicates_if_same_msgstr = false; diff --git a/gettext-tools/src/read-catalog.h b/gettext-tools/src/read-catalog.h index 8b77014..f567d78 100644 --- a/gettext-tools/src/read-catalog.h +++ b/gettext-tools/src/read-catalog.h @@ -77,10 +77,6 @@ struct default_catalog_reader_class_ty /* If true, pay attention to comments and filepos comments. */ \ bool handle_comments; \ \ - /* If true, remember comments for file name and line number for each \ - msgid, if present in the reference input. */ \ - bool handle_filepos_comments; \ - \ /* If false, domain directives lead to an error messsage. */ \ bool allow_domain_directives; \ \ @@ -167,10 +163,6 @@ extern default_catalog_reader_ty * default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table); -/* If nonzero, remember comments for file name and line number for each - msgid, if present in the reference input. Defaults to true. */ -extern DLL_VARIABLE int line_comment; - /* If false, duplicate msgids in the same domain and file generate an error. If true, such msgids are allowed; the caller should treat them appropriately. Defaults to false. */ diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 8cfd7c4..1534a3b 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -306,21 +306,57 @@ message_print_comment_dot (const message_ty *mp, ostream_t stream) /* Output mp->filepos as a set of comment lines. */ +static enum filepos_comment_type filepos_comment_type = filepos_comment_full; + void message_print_comment_filepos (const message_ty *mp, ostream_t stream, bool uniforum, size_t page_width) { - if (mp->filepos_count != 0) + 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); + 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) + { + lex_pos_ty *pp = &mp->filepos[i]; + size_t j; + + for (j = 0; j < filepos_count; j++) + if (strcmp (filepos[j].file_name, pp->file_name) == 0) + break; + + if (j == filepos_count) + { + filepos[filepos_count].file_name = pp->file_name; + filepos[filepos_count].line_number = (size_t)-1; + filepos_count++; + } + } + } + else + { + filepos = mp->filepos; + filepos_count = mp->filepos_count; + } + if (uniforum) { size_t j; - for (j = 0; j < mp->filepos_count; ++j) + for (j = 0; j < filepos_count; ++j) { - lex_pos_ty *pp = &mp->filepos[j]; + lex_pos_ty *pp = &filepos[j]; const char *cp = pp->file_name; char *str; @@ -345,19 +381,21 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream, ostream_write_str (stream, "#:"); column = 2; - for (j = 0; j < mp->filepos_count; ++j) + for (j = 0; j < filepos_count; ++j) { lex_pos_ty *pp; char buffer[21]; const char *cp; size_t len; - pp = &mp->filepos[j]; + pp = &filepos[j]; cp = pp->file_name; while (cp[0] == '.' && cp[1] == '/') cp += 2; - /* Some xgettext input formats, like RST, lack line numbers. */ - if (pp->line_number == (size_t)(-1)) + if (filepos_comment_type == filepos_comment_file + /* Some xgettext input formats, like RST, lack line + numbers. */ + || pp->line_number == (size_t)(-1)) buffer[0] = '\0'; else sprintf (buffer, ":%ld", (long) pp->line_number); @@ -377,6 +415,9 @@ message_print_comment_filepos (const message_ty *mp, ostream_t stream, ostream_write_str (stream, "\n"); } + if (filepos != mp->filepos) + free (filepos); + end_css_class (stream, class_reference_comment); } } @@ -505,6 +546,37 @@ message_print_style_escape (bool flag) escape = flag; } +void +message_print_style_filepos (enum filepos_comment_type type) +{ + filepos_comment_type = type; +} + + +/* --add-location argument handling. Return an error indicator. */ +bool +handle_filepos_comment_option (const char *option) +{ + if (option != NULL) + { + if (strcmp (option, "never") == 0 || strcmp (option, "no") == 0) + message_print_style_filepos (filepos_comment_none); + else if (strcmp (option, "full") == 0 || strcmp (option, "yes") == 0) + message_print_style_filepos (filepos_comment_full); + else if (strcmp (option, "file") == 0) + message_print_style_filepos (filepos_comment_file); + else + { + fprintf (stderr, "invalid --add-location argument: %s\n", option); + return true; + } + } + else + /* --add-location is equivalent to --add-location=full. */ + message_print_style_filepos (filepos_comment_full); + return false; +} + /* =============== msgdomain_list_print_po() and subroutines. =============== */ diff --git a/gettext-tools/src/write-po.h b/gettext-tools/src/write-po.h index 01875a5..9a243bf 100644 --- a/gettext-tools/src/write-po.h +++ b/gettext-tools/src/write-po.h @@ -30,6 +30,13 @@ extern "C" { #endif +enum filepos_comment_type + { + filepos_comment_none, + filepos_comment_full, + filepos_comment_file + }; + /* These functions are used to output a #, flags line. */ extern const char * make_format_description_string (enum is_format is_format, @@ -61,6 +68,12 @@ extern void message_print_style_uniforum (void); extern void message_print_style_escape (bool flag); +extern void + message_print_style_filepos (enum filepos_comment_type type); + +/* --add-location argument handling. Return an error indicator. */ +extern bool handle_filepos_comment_option (const char *option); + /* Describes a PO file in .po syntax. */ extern DLL_VARIABLE const struct catalog_output_format output_format_po; diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index aecf595..89824e2 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -155,7 +155,6 @@ extract (FILE *fp, pop = default_catalog_reader_alloc (&extract_methods); pop->handle_comments = true; - pop->handle_filepos_comments = (line_comment != 0); pop->allow_domain_directives = false; pop->allow_duplicates = false; pop->allow_duplicates_if_same_msgstr = true; diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index 8e89a33..8f14b93 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -199,7 +199,7 @@ iconv_t xgettext_current_source_iconv; static const struct option long_options[] = { { "add-comments", optional_argument, NULL, 'c' }, - { "add-location", no_argument, &line_comment, 1 }, + { "add-location", optional_argument, NULL, 'n' }, { "boost", no_argument, NULL, CHAR_MAX + 11 }, { "c++", no_argument, NULL, 'C' }, { "color", optional_argument, NULL, CHAR_MAX + 14 }, @@ -225,7 +225,7 @@ static const struct option long_options[] = { "msgstr-prefix", optional_argument, NULL, 'm' }, { "msgstr-suffix", optional_argument, NULL, 'M' }, { "no-escape", no_argument, NULL, 'e' }, - { "no-location", no_argument, &line_comment, 0 }, + { "no-location", no_argument, NULL, CHAR_MAX + 16 }, { "no-wrap", no_argument, NULL, CHAR_MAX + 4 }, { "omit-header", no_argument, &xgettext_omit_header, 1 }, { "output", required_argument, NULL, 'o' }, @@ -473,7 +473,8 @@ main (int argc, char *argv[]) break; case 'n': - line_comment = 1; + if (handle_filepos_comment_option (optarg)) + usage (EXIT_FAILURE); break; case 'o': @@ -587,6 +588,10 @@ main (int argc, char *argv[]) handle_style_option (optarg); break; + case CHAR_MAX + 16: /* --no-location */ + message_print_style_filepos (filepos_comment_none); + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -612,10 +617,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\ usage (EXIT_SUCCESS); /* Verify selected options. */ - if (!line_comment && sort_by_filepos) - error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), - "--no-location", "--sort-by-file"); - if (sort_by_msgid && sort_by_filepos) error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"), "--sort-output", "--sort-by-file"); @@ -2474,8 +2475,7 @@ meta information, not the empty string.\n"))); warn_format_string (is_format, mp->msgid, pos, "msgid"); /* Remember where we saw this msgid. */ - if (line_comment) - message_comment_filepos (mp, pos->file_name, pos->line_number); + message_comment_filepos (mp, pos->file_name, pos->line_number); /* Tell the lexer to reset its comment buffer, so that the next message gets the correct comments. */ |