Bruno Haible f1459a89e2 xgettext: Allow inhibiting the warnings about URLs and email addresses.
Reported at <https://savannah.gnu.org/bugs/?67672>.

* gettext-tools/src/message.h (enum syntax_check_type): Add sc_url, sc_email.
(NSYNTAXCHECKS): Increase by 2.
* gettext-tools/src/message.c (syntax_check_name): Update.
* gettext-tools/src/xgettext.h (default_syntax_check): Add comment.
* gettext-tools/src/xgettext.c (default_syntax_check): Add initializer.
(main): Recognize --no-check option.
(usage): Document --no-check option.
* gettext-tools/src/xg-message.c (decide_syntax_check): Assume that
default_syntax_check[i] != undecided.
* gettext-tools/src/xg-check.c (syntax_check_function): Remove the second
argument.
(string_has_ascii_ellipsis): New function, extracted from
syntax_check_ellipsis_unicode.
(message_has_ascii_ellipsis): New function.
(syntax_check_ellipsis_unicode): Remove the second argument. Simplify. Emit only
a single error for both msgid and msgid_plural.
(string_has_space_ellipsis): New function, extracted from
syntax_check_space_ellipsis.
(message_has_space_ellipsis): New function.
(syntax_check_space_ellipsis): Remove the second argument. Simplify. Emit only
a single error for both msgid and msgid_plural.
(syntax_check_quote_unicode): Remove the second argument.
(syntax_check_bullet_unicode_string): New function, extracted from
syntax_check_bullet_unicode.
(syntax_check_bullet_unicode): Remove the second argument. Simplify.
(string_has_url): Don't recognize 'mailto:' URLs.
(syntax_check_url, syntax_check_email): New functions, extracted from
url_check_message.
(url_check_message): Remove function.
(sc_funcs): Add syntax_check_url, syntax_check_email.
(syntax_check_message): Simplify.
(xgettext_check_message_list): Don't invoke url_check_message.
* gettext-tools/tests/xgettext-14: Update after xg-check.c changesd.
* gettext-tools/tests/xgettext-20: Add more testcases.
* gettext-tools/doc/xgettext.texi: Document the --no-check option.
* gettext-tools/doc/gettext.texi: Bump copyright year.
* NEWS: Mention the change.
2026-01-10 20:16:46 +01:00

136 lines
4.1 KiB
Bash
Executable File

#!/bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
# Test for --check option.
# --check=ellipsis-unicode
cat <<\EOF > xg-ellipsis-u.c
gettext ("This is a sentence...");
ngettext ("This is a sentence", "These are sentences...", 2);
/* xgettext: no-ellipsis-unicode-check */
gettext ("This is another sentence...");
gettext ("This is a multi-sentence example. This is the first sentence. "
"This is the second..., no it's not, this is the second sentence...\n"
"This is the third sentence...? Perhaps.\n");
EOF
: ${XGETTEXT=xgettext}
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=ellipsis-unicode -d xg-ellipsis-u.tmp xg-ellipsis-u.c 2>xg-ellipsis-u.err
test `grep -c 'ASCII ellipsis' xg-ellipsis-u.err` = 3 || Exit 1
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=ellipsis-unicode --sentence-end=double-space -d xg-ellipsis-ud.tmp xg-ellipsis-u.c 2>xg-ellipsis-ud.err
test `grep -c 'ASCII ellipsis' xg-ellipsis-ud.err` = 3 || Exit 1
# --check=space-ellipsis
cat <<\EOF > xg-space-e.c
gettext ("This is a sentence ...");
/* xgettext: no-space-ellipsis-check, no-ellipsis-unicode-check */
gettext ("This is another sentence ...");
gettext ("This is a multi-sentence example. This is the first sentence. "
"This is the second..., no it's not, this is the second sentence ...\n"
"This is the third sentence \u2026? Perhaps.\n");
EOF
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=space-ellipsis -d xg-space-e.tmp xg-space-e.c 2>xg-space-e.err
test `grep -c 'space before ellipsis' xg-space-e.err` = 2 || Exit 1
# --check=quote-unicode
cat <<\EOF > xg-quote-u.c
gettext ("\"double quoted\"");
/* xgettext: no-quote-unicode-check */
gettext ("\"double quoted but ignored\"");
gettext ("double quoted but empty \"\"");
gettext ("\"\" double quoted but empty");
gettext ("\"foo\" \"bar\" \"baz\"");
gettext ("'single quoted'");
/* xgettext: no-quote-unicode-check */
gettext ("'single quoted but ignored'");
gettext ("'foo' 'bar' 'baz'");
gettext ("prefix'single quoted without surrounding spaces'suffix");
gettext ("prefix 'single quoted with surrounding spaces' suffix");
gettext ("single quoted with apostrophe, empty '' ");
gettext ("'single quoted at the beginning of string' ");
gettext (" 'single quoted at the end of string'");
gettext ("line 1\n"
"'single quoted at the beginning of line' \n"
"line 3");
gettext ("line 1\n"
" 'single quoted at the end of line'\n"
"line 3");
gettext ("`single quoted with grave'");
/* xgettext: no-quote-unicode-check */
gettext ("`single quoted with grave but ignored'");
gettext ("single quoted with grave, empty `'");
gettext ("`' single quoted with grave, empty");
gettext ("`double grave`");
EOF
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=quote-unicode -d xg-quote-u.tmp xg-quote-u.c 2>xg-quote-u.err
test `grep -c 'ASCII double quote' xg-quote-u.err` = 4 || Exit 1
test `grep -c 'ASCII single quote' xg-quote-u.err` = 12 || Exit 1
# --check=bullet-unicode
cat <<\EOF > xg-bullet-u1.c
gettext ("The following is a list of items:\n\
* item 1\n\
* item 2\n\
* item 3\n");
EOF
: ${XGETTEXT=xgettext}
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=bullet-unicode -d xg-bullet-u1.tmp xg-bullet-u1.c 2>xg-bullet-u1.err
test `grep -c 'ASCII bullet' xg-bullet-u1.err` = 1 || { cat xg-bullet-u1.err; Exit 1; }
cat <<\EOF > xg-bullet-u2.c
gettext ("The following is a list of items:\n\
* item 1\n\
- item 2\n\
* item 3\n");
EOF
: ${XGETTEXT=xgettext}
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=bullet-unicode -d xg-bullet-u2.tmp xg-bullet-u2.c 2>xg-bullet-u2.err
test `grep -c 'ASCII bullet' xg-bullet-u2.err` = 1 || { cat xg-bullet-u2.err; Exit 1; }
cat <<\EOF > xg-bullet-u3.c
gettext ("The following is NOT a list of items:\n\
* item 1\n\
- item 2\n\
* item 3\n");
EOF
: ${XGETTEXT=xgettext}
LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=bullet-unicode -d xg-bullet-u3.tmp xg-bullet-u3.c 2>xg-bullet-u3.err
test `grep -c 'ASCII bullet' xg-bullet-u3.err` = 0 || { cat xg-bullet-u3.err; Exit 1; }