1 /* Expression parsing for plural form selection.
2 Copyright (C) 2000-2013 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
28 #include "plural-exp.h"
30 #if (defined __GNUC__ && !defined __APPLE_CC__) \
31 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
33 /* These structs are the constant expression for the germanic plural
34 form determination. It represents the expression "n != 1". */
35 static const struct expression plvar
=
40 static const struct expression plone
=
49 const struct expression GERMANIC_PLURAL
=
52 .operation
= not_equal
,
57 [0] = (struct expression
*) &plvar
,
58 [1] = (struct expression
*) &plone
63 # define INIT_GERMANIC_PLURAL()
67 /* For compilers without support for ISO C 99 struct/union initializers:
68 Initialization at run-time. */
70 static struct expression plvar
;
71 static struct expression plone
;
72 struct expression GERMANIC_PLURAL
;
75 init_germanic_plural ()
77 if (plone
.val
.num
== 0)
80 plvar
.operation
= var
;
83 plone
.operation
= num
;
86 GERMANIC_PLURAL
.nargs
= 2;
87 GERMANIC_PLURAL
.operation
= not_equal
;
88 GERMANIC_PLURAL
.val
.args
[0] = &plvar
;
89 GERMANIC_PLURAL
.val
.args
[1] = &plone
;
93 # define INIT_GERMANIC_PLURAL() init_germanic_plural ()
99 EXTRACT_PLURAL_EXPRESSION (nullentry
, pluralp
, npluralsp
)
100 const char *nullentry
;
101 const struct expression
**pluralp
;
102 unsigned long int *npluralsp
;
104 if (nullentry
!= NULL
)
107 const char *nplurals
;
109 plural
= strstr (nullentry
, "plural=");
110 nplurals
= strstr (nullentry
, "nplurals=");
111 if (plural
== NULL
|| nplurals
== NULL
)
117 struct parse_args args
;
119 /* First get the number. */
121 while (*nplurals
!= '\0' && isspace ((unsigned char) *nplurals
))
123 if (!(*nplurals
>= '0' && *nplurals
<= '9'))
125 #if defined HAVE_STRTOUL || defined _LIBC
126 n
= strtoul (nplurals
, &endp
, 10);
128 for (endp
= nplurals
, n
= 0; *endp
>= '0' && *endp
<= '9'; endp
++)
129 n
= n
* 10 + (*endp
- '0');
131 if (nplurals
== endp
)
135 /* Due to the restrictions bison imposes onto the interface of the
136 scanner function we have to put the input string and the result
137 passed up from the parser into the same structure which address
138 is passed down to the parser. */
141 if (PLURAL_PARSE (&args
) != 0)
148 /* By default we are using the Germanic form: singular form only
149 for `one', the plural form otherwise. Yes, this is also what
150 English is using since English is a Germanic language. */
152 INIT_GERMANIC_PLURAL ();
153 *pluralp
= &GERMANIC_PLURAL
;