]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Add plural form support to YCP scanner.
authorBruno Haible <bruno@clisp.org>
Mon, 5 Nov 2001 10:48:16 +0000 (10:48 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 20:51:47 +0000 (22:51 +0200)
src/ChangeLog
src/x-ycp.c

index 08b13cd212e3235ed5673aaf3e3094d086df9562..eefd361d5c573b32f3e5f78bc99556d10a7e9614 100644 (file)
@@ -1,3 +1,10 @@
+2001-11-03  Bruno Haible  <haible@clisp.cons.org>
+
+       Add YCP plural form support.
+       * x-ycp.c (enum token_type_ty): New value token_type_comma.
+       (x_ycp_lex): Recognize comma.
+       (extract_ycp): Also recognize the _("singular","plural" pattern.
+
 2001-11-01  Bruno Haible  <haible@clisp.cons.org>
 
        * msgfmt.c (check_plural_eval): Fix #if mistake.
index add21a1a8a11087965669d8d32dedd31762c38bd..1624ec8634e31974392d5429a36899adbb51d1b1 100644 (file)
@@ -47,6 +47,7 @@ enum token_type_ty
   token_type_eof,
   token_type_lparen,           /* ( */
   token_type_rparen,           /* ) */
+  token_type_comma,            /* , */
   token_type_i18n,             /* _( */
   token_type_string_literal,   /* "abc" */
   token_type_other             /* number, symbol, misc. operator */
@@ -508,6 +509,10 @@ x_ycp_lex (tp)
          tp->type = token_type_rparen;
          return;
 
+       case ',':
+         tp->type = token_type_comma;
+         return;
+
        default:
          /* We could carefully recognize each of the 2 and 3 character
             operators, but it is not necessary, as we only need to recognize
@@ -528,11 +533,17 @@ extract_ycp (f, real_filename, logical_filename, mdlp)
 {
   message_list_ty *mlp = mdlp->item[0]->messages;
   int state;
+  message_ty *plural_mp = NULL;        /* defined only when in states 1 and 2 */
 
-  /* The file is broken into tokens.  Look for
+  /* The file is broken into tokens.
+     Normal handling: Look for
        [A] _( [B] msgid ... )
+     Plural handling: Look for
+       [A] _( [B] msgid [C] , [D] msgid_plural ... )
      At point [A]: state == 0.
-     At point [B]: state == 1.  */
+     At point [B]: state == 1, plural_mp == NULL.
+     At point [C]: state == 2, plural_mp != NULL.
+     At point [D]: state == 1, plural_mp != NULL.  */
 
   fp = f;
   real_file_name = real_filename;
@@ -555,6 +566,7 @@ extract_ycp (f, real_filename, logical_filename, mdlp)
        {
        case token_type_i18n:
          state = 1;
+         plural_mp = NULL;
          continue;
 
        case token_type_string_literal:
@@ -564,11 +576,31 @@ extract_ycp (f, real_filename, logical_filename, mdlp)
              pos.file_name = logical_file_name;
              pos.line_number = token.line_number;
 
-             remember_a_message (mlp, token.string, &pos);
+             if (plural_mp == NULL)
+               {
+                 /* Seen an msgid.  */
+                 plural_mp = remember_a_message (mlp, token.string, &pos);
+                 state = 2;
+               }
+             else
+               {
+                 /* Seen an msgid_plural.  */
+                 remember_a_message_plural (plural_mp, token.string, &pos);
+                 state = 0;
+               }
            }
          else
-           free (token.string);
-         state = 0;
+           {
+             free (token.string);
+             state = 0;
+           }
+         continue;
+
+       case token_type_comma:
+         if (state == 2)
+           state = 1;
+         else
+           state = 0;
          continue;
 
        case token_type_eof: