1 /* Expression parsing for plural form selection.
2 Copyright (C) 2000, 2001, 2005, 2007 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 #include "plural-exp.h"
31 #if (defined __GNUC__ && !defined __APPLE_CC__) \
32 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
34 /* These structs are the constant expression for the germanic plural
35 form determination. It represents the expression "n != 1". */
36 static const struct expression plvar
=
41 static const struct expression plone
=
50 const struct expression GERMANIC_PLURAL
=
53 .operation
= not_equal
,
58 [0] = (struct expression
*) &plvar
,
59 [1] = (struct expression
*) &plone
64 # define INIT_GERMANIC_PLURAL()
68 /* For compilers without support for ISO C 99 struct/union initializers:
69 Initialization at run-time. */
71 static struct expression plvar
;
72 static struct expression plone
;
73 struct expression GERMANIC_PLURAL
;
76 init_germanic_plural ()
78 if (plone
.val
.num
== 0)
81 plvar
.operation
= var
;
84 plone
.operation
= num
;
87 GERMANIC_PLURAL
.nargs
= 2;
88 GERMANIC_PLURAL
.operation
= not_equal
;
89 GERMANIC_PLURAL
.val
.args
[0] = &plvar
;
90 GERMANIC_PLURAL
.val
.args
[1] = &plone
;
94 # define INIT_GERMANIC_PLURAL() init_germanic_plural ()
100 EXTRACT_PLURAL_EXPRESSION (nullentry
, pluralp
, npluralsp
)
101 const char *nullentry
;
102 const struct expression
**pluralp
;
103 unsigned long int *npluralsp
;
105 if (nullentry
!= NULL
)
108 const char *nplurals
;
110 plural
= strstr (nullentry
, "plural=");
111 nplurals
= strstr (nullentry
, "nplurals=");
112 if (plural
== NULL
|| nplurals
== NULL
)
118 struct parse_args args
;
120 /* First get the number. */
122 while (*nplurals
!= '\0' && isspace ((unsigned char) *nplurals
))
124 if (!(*nplurals
>= '0' && *nplurals
<= '9'))
126 #if defined HAVE_STRTOUL || defined _LIBC
127 n
= strtoul (nplurals
, &endp
, 10);
129 for (endp
= nplurals
, n
= 0; *endp
>= '0' && *endp
<= '9'; endp
++)
130 n
= n
* 10 + (*endp
- '0');
132 if (nplurals
== endp
)
136 /* Due to the restrictions bison imposes onto the interface of the
137 scanner function we have to put the input string and the result
138 passed up from the parser into the same structure which address
139 is passed down to the parser. */
142 if (PLURAL_PARSE (&args
) != 0)
149 /* By default we are using the Germanic form: singular form only
150 for `one', the plural form otherwise. Yes, this is also what
151 English is using since English is a Germanic language. */
153 INIT_GERMANIC_PLURAL ();
154 *pluralp
= &GERMANIC_PLURAL
;