From: Bruno Haible Date: Mon, 5 Nov 2001 10:48:16 +0000 (+0000) Subject: Add plural form support to YCP scanner. X-Git-Tag: v0.11~333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17bd65d934b8c83028ecf3607d3f7d854784ac86;p=thirdparty%2Fgettext.git Add plural form support to YCP scanner. --- diff --git a/src/ChangeLog b/src/ChangeLog index 08b13cd21..eefd361d5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2001-11-03 Bruno Haible + + 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 * msgfmt.c (check_plural_eval): Fix #if mistake. diff --git a/src/x-ycp.c b/src/x-ycp.c index add21a1a8..1624ec863 100644 --- a/src/x-ycp.c +++ b/src/x-ycp.c @@ -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: