annotate intl/plural-exp.c @ 1860:5edb4f242bf6 trunk

[svn] - cleanup some skin textures
author nenolod
date Wed, 11 Oct 2006 19:44:00 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Expression parsing for plural form selection.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 License along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 # include <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <ctype.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "plural-exp.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #if (defined __GNUC__ && !defined __APPLE_CC__) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 /* These structs are the constant expression for the germanic plural
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 form determination. It represents the expression "n != 1". */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 static const struct expression plvar =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 .nargs = 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 .operation = var,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 static const struct expression plone =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 .nargs = 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 .operation = num,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 .val =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 .num = 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 struct expression GERMANIC_PLURAL =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 .nargs = 2,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 .operation = not_equal,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 .val =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 .args =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 [0] = (struct expression *) &plvar,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 [1] = (struct expression *) &plone
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 # define INIT_GERMANIC_PLURAL()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 /* For compilers without support for ISO C 99 struct/union initializers:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 Initialization at run-time. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 static struct expression plvar;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 static struct expression plone;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 struct expression GERMANIC_PLURAL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 init_germanic_plural ()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 if (plone.val.num == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 plvar.nargs = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 plvar.operation = var;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 plone.nargs = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 plone.operation = num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 plone.val.num = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 GERMANIC_PLURAL.nargs = 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 GERMANIC_PLURAL.operation = not_equal;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 GERMANIC_PLURAL.val.args[0] = &plvar;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 GERMANIC_PLURAL.val.args[1] = &plone;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 # define INIT_GERMANIC_PLURAL() init_germanic_plural ()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 internal_function
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 EXTRACT_PLURAL_EXPRESSION (nullentry, pluralp, npluralsp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 const char *nullentry;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 struct expression **pluralp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 unsigned long int *npluralsp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 if (nullentry != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 const char *plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 const char *nplurals;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 plural = strstr (nullentry, "plural=");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 nplurals = strstr (nullentry, "nplurals=");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 if (plural == NULL || nplurals == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 goto no_plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 char *endp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 unsigned long int n;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 struct parse_args args;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 /* First get the number. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 nplurals += 9;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 while (*nplurals != '\0' && isspace ((unsigned char) *nplurals))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 ++nplurals;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 if (!(*nplurals >= '0' && *nplurals <= '9'))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 goto no_plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 #if defined HAVE_STRTOUL || defined _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 n = strtoul (nplurals, &endp, 10);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 n = n * 10 + (*endp - '0');
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 if (nplurals == endp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 goto no_plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 *npluralsp = n;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 /* Due to the restrictions bison imposes onto the interface of the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 scanner function we have to put the input string and the result
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 passed up from the parser into the same structure which address
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 is passed down to the parser. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 plural += 7;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 args.cp = plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 if (PLURAL_PARSE (&args) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 goto no_plural;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 *pluralp = args.res;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 /* By default we are using the Germanic form: singular form only
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 for `one', the plural form otherwise. Yes, this is also what
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 English is using since English is a Germanic language. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 no_plural:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 INIT_GERMANIC_PLURAL ();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 *pluralp = &GERMANIC_PLURAL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 *npluralsp = 2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 }