]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Implement disambiguation of overloaded functions.
authorBruno Haible <bruno@clisp.org>
Wed, 19 Oct 2005 11:14:42 +0000 (11:14 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:55 +0000 (12:12 +0200)
21 files changed:
gettext-tools/doc/ChangeLog
gettext-tools/doc/xgettext.texi
gettext-tools/src/ChangeLog
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-csharp.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-java.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c
gettext-tools/src/x-python.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-tcl.c
gettext-tools/src/xgettext.c
gettext-tools/src/xgettext.h
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/xgettext-c-11 [new file with mode: 0755]

index 0255fd20ec8b2074e4bb84c03c0a08b31dc519a6..f45f76d0b0a9a1cae44ab2615654710f238e61fb 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-18  Bruno Haible  <bruno@clisp.org>
+
+       * xgettext.texi (--keyword): Document how to specify the total number
+       of arguments.
+
 2005-10-03  Bruno Haible  <bruno@clisp.org>
 
        Add support for contexts in xgettext.
index 1f9805d9f3c64c6bb7765d40bcde2b9a86ea2cfc..958db3dbbf61e9bb590e4263039df9c75925e890 100644 (file)
@@ -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},
index 2aaf7ad3e7482bed486875b98191cbb870a02252..0a5acfadfc5414cae7130e45986a8623fdab4aae 100644 (file)
@@ -1,3 +1,33 @@
+2005-10-18  Bruno Haible  <bruno@clisp.org>
+
+       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 (Часлав Илић) <caslav.ilic@gmx.net>.
+
 2005-10-09  Bruno Haible  <bruno@clisp.org>
 
        * msginit.c (catalogname_for_locale, language_of_locale): Drop support
index f961932d78b2d50e8a86d5644342165956dfff87..ac0347cba8b921d61f90886ef19fdbea7220eb5c 100644 (file)
@@ -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:
index d079276c57a5c792c13020adc73e5acca4699aee..60d2bcc96985a224b394ad1405b157382efe65ed 100644 (file)
@@ -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:
index 7f8b703f3812b4b8dc0408db137fbbb17b5a9396..cbdb199502f64d95d3740975964034cf11a43c6f 100644 (file)
@@ -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;
 
index bc605837e870f1fdbcda7e1fa93e821ef2fb99c4..c93854aa9b2b4030cd5df66bd56277132688b8df 100644 (file)
@@ -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;
index 6845db51c68aee2af13e39cb27e651e1068ec77f..c113928706d8dde2489ab4fbf30b049a7396a75e 100644 (file)
@@ -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;
 
index 56b78b61b76d10819b38cc58f97438be9afdd828..4e53665af0ae60168ebe9dab466af1c1523bdca9 100644 (file)
@@ -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;
index bcc5cf6e94df8c9d1bb5d99bb702663a897bb73e..19f3073618f8e6602745b25a79a6e39c007898e9 100644 (file)
@@ -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;
index 0e6880b6184d7fb0e33f09d1d5c779c342d87872..5981f6b96032808978c66b8194bf83eeaa397868 100644 (file)
@@ -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);
 
index b42d26982e72d9c18034d24fa8150bcc5f51aabf..7cabbce29396190b5513699f408a5071833021a6 100644 (file)
@@ -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:
index e56ac1aea574120406074251ab663f6cebed7585..b256a6d76403a3c17f9fe5feaa5202443c20e27e 100644 (file)
@@ -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;
 
index d831dfe3fffd4743d83f2b545e07bd6679a618b1..d678b1f43775c6d3ade2619f0ec956275baa8b17 100644 (file)
@@ -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;
index 625dd8870d72b25745c1feef8a3fa2f5f3a17c52..07e5d9d268d055cc2523f563980556c70b50d618 100644 (file)
@@ -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;
                }
index 58f90086e27ecaffb48e12967f275d31aaf4c8ee..3271fdcce67f8c4411bffe7affc453388790c047 100644 (file)
@@ -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;
          }
 
index bdfb7c9abdf120bb2b767183dbd9a4f565b1064c..36b4bf5f3f725298353f7ea00d2c1d0d8a170cf3 100644 (file)
@@ -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)
index 619a785ad724b928e55a70eede359429551ef375..fcbde3eefa360269bd22d97b94ce4c5e7cad268b 100644 (file)
@@ -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
index b1145362228ccbc5e58d206371775065334e658c..9872471575f7973d9ec2c91f31403a06e59cf8ea 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-18  Bruno Haible  <bruno@clisp.org>
+
+       * xgettext-c-11: New file.
+       * Makefile.am (TESTS): Add it.
+
 2005-10-05  Bruno Haible  <bruno@clisp.org>
 
        * msgfmt-15: New file.
index d4f609c594add51cf9c1a00fe3c3237f7865939a..328c19c37aa5d6d9ed6428c2e96ed3d37b7b4084 100644 (file)
@@ -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 (executable)
index 0000000..5115c46
--- /dev/null
@@ -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 <<EOF > 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