From: Bruno Haible Date: Wed, 19 Oct 2005 11:14:42 +0000 (+0000) Subject: Implement disambiguation of overloaded functions. X-Git-Tag: v0.15~359 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1d6b988b0ee71b010b8e9900e1d72ef9715d359;p=thirdparty%2Fgettext.git Implement disambiguation of overloaded functions. --- diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 0255fd20e..f45f76d0b 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,8 @@ +2005-10-18 Bruno Haible + + * xgettext.texi (--keyword): Document how to specify the total number + of arguments. + 2005-10-03 Bruno Haible Add support for contexts in xgettext. diff --git a/gettext-tools/doc/xgettext.texi b/gettext-tools/doc/xgettext.texi index 1f9805d9f..958db3dbb 100644 --- a/gettext-tools/doc/xgettext.texi +++ b/gettext-tools/doc/xgettext.texi @@ -160,6 +160,12 @@ with plural handling. Also, if @var{keywordspec} is of the form @samp{@var{id}:@var{argnum},@var{contextargnum}c}, @code{xgettext} treats strings in the @var{contextargnum}th argument as a context specifier. @* +Furthermore, if @var{keywordspec} is of the form +@samp{@var{id}:@dots{},@var{totalnumargs}t}, @code{xgettext} recognizes this +argument specification only if the number of actual arguments is equal to +@var{totalnumargs}. This is useful for disambiguating overloaded function +calls in C++. +@* The default keyword specifications, which are always looked for if not explicitly disabled, are @code{gettext}, @code{dgettext:2}, @code{dcgettext:2}, @code{ngettext:1,2}, @code{dngettext:2,3}, diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 2aaf7ad3e..0a5acfadf 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,33 @@ +2005-10-18 Bruno Haible + + Disambiguate overloaded function calls according to argument count. + * xgettext.h (struct callshape): Add field 'argtotal'. + (struct partial_call): Likewise. + (arglist_parser_done): Add argnum argument. + * xgettext.c (split_keywordspec): Recognize NNt syntax and fill + argtotal. + (insert_keyword_callshape, arglist_parser_alloc, arglist_parser_clone): + Update. + (arglist_parser_decidedp): Compare also the argtotal if given. + (arglist_parser_done): Add argnum argument. + * x-awk.c (extract_parenthesized): Pass arg count to + arglist_parser_done. + * x-c.c (extract_parenthesized): Likewise. + * x-csharp.c (extract_parenthesized): Likewise. + * x-elisp.c (read_object): Likewise. + * x-java.c (extract_parenthesized): Likewise. + * x-librep.c (read_object): Likewise. + * x-lisp.c (read_object): Likewise. + * x-perl.c (extract_variable): Update. + (extract_balanced): Pass arg count to arglist_parser_done. + * x-php.c (extract_parenthesized): Likewise. + * x-python.c (extract_parenthesized): Likewise. + * x-scheme.c (read_object): Likewise. + * x-sh.c (read_command): Likewise. + * x-tcl.c (read_command): Likewise. + Stimulated by a patch from + Chusslove Illich (Часлав Илић) . + 2005-10-09 Bruno Haible * msginit.c (catalogname_for_locale, language_of_locale): Drop support diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index f961932d7..ac0347cba 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -758,7 +758,7 @@ extract_parenthesized (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; } next_is_argument = false; @@ -767,7 +767,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case token_type_rparen: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return false; case token_type_comma: @@ -834,7 +834,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case token_type_eof: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; case token_type_other: diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index d079276c5..60d2bcc96 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -1752,7 +1752,7 @@ extract_parenthesized (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; } next_context_iter = null_context_list_iterator; @@ -1761,7 +1761,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case xgettext_token_type_rparen: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return false; case xgettext_token_type_comma: @@ -1816,7 +1816,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case xgettext_token_type_eof: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; default: diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 7f8b703f3..cbdb19950 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -1982,7 +1982,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, state ? next_shapes : NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } @@ -1994,7 +1994,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, if (terminator == token_type_rparen) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } @@ -2016,7 +2016,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, arglist_parser_alloc (mlp, NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } @@ -2028,7 +2028,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, if (terminator == token_type_rbrace) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } @@ -2078,7 +2078,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_eof: xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index bc605837e..c93854aa9 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -666,7 +666,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, /* Don't bother converting "()" to "NIL". */ last_non_comment_line = line_number; if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return; } @@ -720,7 +720,7 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag, } if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); } op->type = t_other; last_non_comment_line = line_number; diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index 6845db51c..c11392870 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -1294,7 +1294,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, state ? next_shapes : NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } @@ -1306,7 +1306,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, if (terminator == token_type_rparen) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } @@ -1328,7 +1328,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, arglist_parser_alloc (mlp, NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; } @@ -1340,7 +1340,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, if (terminator == token_type_rbrace) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return false; } @@ -1390,7 +1390,7 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator, case token_type_eof: xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; return true; diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 56b78b61b..4e53665af 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -640,7 +640,7 @@ read_object (struct object *op, flag_context_ty outer_context) /* Don't bother converting "()" to "NIL". */ last_non_comment_line = line_number; if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return; } @@ -694,7 +694,7 @@ read_object (struct object *op, flag_context_ty outer_context) } if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); } op->type = t_other; last_non_comment_line = line_number; diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index bcc5cf6e9..19f307361 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -1033,7 +1033,7 @@ read_object (struct object *op, flag_context_ty outer_context) /* Don't bother converting "()" to "NIL". */ last_non_comment_line = line_number; if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return; } @@ -1098,7 +1098,7 @@ read_object (struct object *op, flag_context_ty outer_context) } if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); } op->type = t_other; last_non_comment_line = line_number; diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 0e6880b61..5981f6b96 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -1505,6 +1505,7 @@ extract_variable (message_list_ty *mlp, token_ty *tp, int first) shapes.shapes[0].argnum1 = 1; shapes.shapes[0].argnum2 = 0; shapes.shapes[0].argnumc = 0; + shapes.shapes[0].argtotal = 0; /* Extract a possible string from the key. Before proceeding we check whether the open curly is followed by a symbol and @@ -2855,7 +2856,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, if (delim == tp->type) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; #if DEBUG_PERL fprintf (stderr, "%s:%d: extract_balanced finished (%d)\n", @@ -2895,7 +2896,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, (const struct callshapes *) keyword_value; xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, shapes); arg = 1; @@ -2935,7 +2936,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, arg, arglist_parser_clone (argparser))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; free_token (tp); return true; @@ -2943,7 +2944,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, if (my_last_token == token_type_keyword_symbol) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); } @@ -2971,7 +2972,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, { /* We have missed the argument. */ xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); arg = 0; @@ -3022,7 +3023,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, if (arglist_parser_decidedp (argparser, arg)) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); state = 0; @@ -3038,7 +3039,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, logical_file_name, tp->line_number, nesting_level); #endif xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; free_token (tp); return true; @@ -3053,7 +3054,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, 1, arglist_parser_alloc (mlp, NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; free_token (tp); return true; @@ -3082,7 +3083,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, 1, arglist_parser_alloc (mlp, NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; free_token (tp); return true; @@ -3110,7 +3111,7 @@ extract_balanced (message_list_ty *mlp, int state, token_type_ty delim, /* The ultimate sign. */ xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_global_source_encoding; argparser = arglist_parser_alloc (mlp, NULL); diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index b42d26982..7cabbce29 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -1268,7 +1268,7 @@ extract_parenthesized (message_list_ty *mlp, arglist_parser_alloc (mlp, state ? next_shapes : NULL))) { - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; } next_context_iter = null_context_list_iterator; @@ -1276,7 +1276,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case token_type_rparen: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return false; case token_type_comma: @@ -1314,7 +1314,7 @@ extract_parenthesized (message_list_ty *mlp, continue; case token_type_eof: - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return true; default: diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index e56ac1aea..b256a6d76 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -1701,7 +1701,7 @@ extract_parenthesized (message_list_ty *mlp, state ? next_shapes : NULL))) { xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; } @@ -1711,7 +1711,7 @@ extract_parenthesized (message_list_ty *mlp, case token_type_rparen: xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_current_file_source_encoding; return false; @@ -1749,7 +1749,7 @@ extract_parenthesized (message_list_ty *mlp, case token_type_eof: xgettext_current_source_encoding = po_charset_utf8; - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); xgettext_current_source_encoding = xgettext_current_file_source_encoding; return true; diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index d831dfe3f..d678b1f43 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -750,7 +750,7 @@ read_object (struct object *op, flag_context_ty outer_context) op->type = t_other; last_non_comment_line = line_number; if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return; } @@ -804,7 +804,7 @@ read_object (struct object *op, flag_context_ty outer_context) free_object (&inner); } if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); } op->type = t_other; last_non_comment_line = line_number; diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 625dd8870..07e5d9d26 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -1150,7 +1150,7 @@ read_command (int looking_for, flag_context_ty outer_context) || inner.type == t_eof) { if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return inner.type; } @@ -1222,7 +1222,7 @@ read_command (int looking_for, flag_context_ty outer_context) { /* Stop looking for arguments of the last function_name. */ /* FIXME: What about context_iter? */ - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); shapes = NULL; argparser = NULL; } diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index 58f90086e..3271fdcce 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -872,7 +872,7 @@ read_command (int looking_for, flag_context_ty outer_context) || inner.type == t_brace || inner.type == t_eof) { if (argparser != NULL) - arglist_parser_done (argparser); + arglist_parser_done (argparser, arg); return inner.type; } diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index bdfb7c9ab..36b4bf5f3 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -961,15 +961,18 @@ split_keywordspec (const char *spec, int argnum1 = 0; int argnum2 = 0; int argnumc = 0; + int argtotal = 0; /* Start parsing from the end. */ p = spec + strlen (spec); while (p > spec) { if (isdigit ((unsigned char) p[-1]) - || (p[-1] == 'c' && p - 1 > spec && isdigit ((unsigned char) p[-2]))) + || ((p[-1] == 'c' || p[-1] == 't') + && p - 1 > spec && isdigit ((unsigned char) p[-2]))) { bool contextp = (p[-1] == 'c'); + bool totalp = (p[-1] == 't'); do p--; @@ -987,6 +990,13 @@ split_keywordspec (const char *spec, break; argnumc = arg; } + else if (totalp) + { + if (argtotal != 0) + /* Only one total number of arguments can be given. */ + break; + argtotal = arg; + } else { if (argnum2 != 0) @@ -1006,6 +1016,7 @@ split_keywordspec (const char *spec, shapep->argnum1 = (argnum1 > 0 ? argnum1 : 1); shapep->argnum2 = argnum2; shapep->argnumc = argnumc; + shapep->argtotal = argtotal; return; } } @@ -1021,6 +1032,7 @@ split_keywordspec (const char *spec, shapep->argnum1 = 1; shapep->argnum2 = 0; shapep->argnumc = 0; + shapep->argtotal = 0; } @@ -1057,7 +1069,8 @@ insert_keyword_callshape (hash_table *table, for (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) + && old_shapes->shapes[i].argnumc == shape->argnumc + && old_shapes->shapes[i].argtotal == shape->argtotal) { found = true; break; @@ -2193,6 +2206,7 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes) ap->alternative[i].argnumc = shapes->shapes[i].argnumc; ap->alternative[i].argnum1 = shapes->shapes[i].argnum1; ap->alternative[i].argnum2 = shapes->shapes[i].argnum2; + ap->alternative[i].argtotal = shapes->shapes[i].argtotal; ap->alternative[i].msgctxt = NULL; ap->alternative[i].msgctxt_pos.file_name = NULL; ap->alternative[i].msgctxt_pos.line_number = (size_t)(-1); @@ -2233,6 +2247,7 @@ arglist_parser_clone (struct arglist_parser *ap) ccp->argnumc = cp->argnumc; ccp->argnum1 = cp->argnum1; ccp->argnum2 = cp->argnum2; + ccp->argtotal = cp->argtotal; ccp->msgctxt = (cp->msgctxt != NULL ? xstrdup (cp->msgctxt) : NULL); ccp->msgctxt_pos = cp->msgctxt_pos; ccp->msgid = (cp->msgid != NULL ? xstrdup (cp->msgid) : NULL); @@ -2312,17 +2327,21 @@ arglist_parser_decidedp (struct arglist_parser *ap, int argnum) /* Test whether all alternatives are decided. Note: A decided alternative can be complete cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && cp->argtotal == 0 or it can be failed if no literal strings were found at the specified argument positions: cp->argnumc <= argnum && cp->argnum1 <= argnum && cp->argnum2 <= argnum + or it can be failed if the number of arguments is exceeded: + cp->argtotal > 0 && cp->argtotal < argnum */ for (i = 0; i < ap->nalternatives; i++) { struct partial_call *cp = &ap->alternative[i]; - if (!(cp->argnumc <= argnum - && cp->argnum1 <= argnum - && cp->argnum2 <= argnum)) + if (!((cp->argnumc <= argnum + && cp->argnum1 <= argnum + && cp->argnum2 <= argnum) + || (cp->argtotal > 0 && cp->argtotal < argnum))) /* cp is still undecided. */ return false; } @@ -2331,7 +2350,7 @@ arglist_parser_decidedp (struct arglist_parser *ap, int argnum) void -arglist_parser_done (struct arglist_parser *ap) +arglist_parser_done (struct arglist_parser *ap, int argnum) { size_t ncomplete; size_t i; @@ -2342,7 +2361,8 @@ arglist_parser_done (struct arglist_parser *ap) { struct partial_call *cp = &ap->alternative[i]; - if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0) + if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum)) ncomplete++; } @@ -2358,6 +2378,7 @@ arglist_parser_done (struct arglist_parser *ap) struct partial_call *cp = &ap->alternative[i]; if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) && cp->msgctxt != NULL && cp->msgid != NULL && cp->msgid_plural != NULL) @@ -2382,6 +2403,7 @@ arglist_parser_done (struct arglist_parser *ap) struct partial_call *cp = &ap->alternative[i]; if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) && cp->msgctxt != NULL && cp->msgid != NULL) { @@ -2400,6 +2422,7 @@ arglist_parser_done (struct arglist_parser *ap) struct partial_call *cp = &ap->alternative[i]; if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) && cp->msgid != NULL && cp->msgid_plural != NULL) { @@ -2431,6 +2454,7 @@ arglist_parser_done (struct arglist_parser *ap) struct partial_call *cp = &ap->alternative[i]; if (cp->argnumc == 0 && cp->argnum1 == 0 && cp->argnum2 == 0 + && (cp->argtotal == 0 || cp->argtotal == argnum) && cp->msgid != NULL) { if (best_cp != NULL) diff --git a/gettext-tools/src/xgettext.h b/gettext-tools/src/xgettext.h index 619a785ad..fcbde3eef 100644 --- a/gettext-tools/src/xgettext.h +++ b/gettext-tools/src/xgettext.h @@ -54,6 +54,7 @@ struct callshape int argnum1; /* argument number to use for msgid */ int argnum2; /* argument number to use for msgid_plural */ int argnumc; /* argument number to use for msgctxt */ + int argtotal; /* total number of arguments */ }; /* Split keyword spec into keyword, argnum1, argnum2, argnumc. */ @@ -250,6 +251,7 @@ struct partial_call int argnumc; /* number of context argument, 0 when seen */ int argnum1; /* number of singular argument, 0 when seen */ int argnum2; /* number of plural argument, 0 when seen */ + int argtotal; /* total number of arguments, 0 if unspecified */ char *msgctxt; /* context - owned string, or NULL */ lex_pos_ty msgctxt_pos; char *msgid; /* msgid - owned string, or NULL */ @@ -292,8 +294,9 @@ extern void arglist_parser_remember (struct arglist_parser *ap, /* Tests whether an arglist_parser has is not waiting for more arguments after argument ARGNUM. */ extern bool arglist_parser_decidedp (struct arglist_parser *ap, int argnum); -/* Terminates the processing of an arglist_parser and deletes it. */ -extern void arglist_parser_done (struct arglist_parser *ap); +/* Terminates the processing of an arglist_parser after argument ARGNUM and + deletes it. */ +extern void arglist_parser_done (struct arglist_parser *ap, int argnum); #ifdef __cplusplus diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index b11453622..987247157 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2005-10-18 Bruno Haible + + * xgettext-c-11: New file. + * Makefile.am (TESTS): Add it. + 2005-10-05 Bruno Haible * msgfmt-15: New file. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index d4f609c59..328c19c37 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -64,6 +64,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ xgettext-awk-1 \ xgettext-c-1 xgettext-c-2 xgettext-c-3 xgettext-c-4 xgettext-c-5 \ xgettext-c-6 xgettext-c-7 xgettext-c-8 xgettext-c-9 xgettext-c-10 \ + xgettext-c-11 \ xgettext-csharp-1 xgettext-csharp-2 xgettext-csharp-3 \ xgettext-csharp-4 xgettext-csharp-5 \ xgettext-elisp-1 \ diff --git a/gettext-tools/tests/xgettext-c-11 b/gettext-tools/tests/xgettext-c-11 new file mode 100755 index 000000000..5115c46ac --- /dev/null +++ b/gettext-tools/tests/xgettext-c-11 @@ -0,0 +1,47 @@ +#! /bin/sh + +# Test C support: extraction of contexts, disambiguating according to the +# argument count. + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles xg-c-11.c" +cat <<\EOF > xg-c-11.c +// (KDE) The 1-argument i18n macro is a simple gettext without context. +print (i18n ("help")); +// (KDE) The 2-argument i18n macro has the context first. +print (i18n ("Help", "about")); +// (KDE) The 3-argument i18n macro is an ngettext without context. +print (i18n ("error", "errors", 7)); +EOF + +tmpfiles="$tmpfiles xg-c-11.po" +: ${XGETTEXT=xgettext} +${XGETTEXT} --omit-header --no-location \ + --keyword=i18n:1 --keyword=i18n:1c,2,2t --keyword=i18n:1,2,3t \ + xg-c-11.c -d xg-c-11 +test $? = 0 || { rm -fr $tmpfiles; exit 1; } + +tmpfiles="$tmpfiles xg-c-11.ok" +cat < xg-c-11.ok +msgid "help" +msgstr "" + +msgctxt "Help" +msgid "about" +msgstr "" + +msgid "error" +msgid_plural "errors" +msgstr[0] "" +msgstr[1] "" +EOF + +: ${DIFF=diff} +${DIFF} xg-c-11.ok xg-c-11.po +result=$? + +rm -fr $tmpfiles + +exit $result