* sysdeps/unix/sysv/linux/fcntlbits.h: Moved from linux/i386.
[glibc.git] / locale / collate.c
blobf06964efcb66f1d2939e2082047f7f847547d119
1 /* Copyright (C) 1995 Free Software Foundation, Inc.
3 The GNU C Library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
8 The GNU C Library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with the GNU C Library; see the file COPYING.LIB. If
15 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 Cambridge, MA 02139, USA. */
18 #include <langinfo.h>
19 #include <libintl.h>
21 #include "localedef.h"
22 #include "token.h"
25 /* defined in locfile-lex.c: flag to indicate that unknown element names
26 are allowed. */
27 extern int reject_new_char;
30 #define SYNTAX_ERROR \
31 error (0, 0, gettext ("%s:%Zd: syntax error in locale definition file"), \
32 locfile_data.filename, locfile_data.line_no);
34 void
35 collate_input (int token)
37 int read_order_start = 0;
39 while (1)
41 char *ptr;
42 int len;
44 if (token == TOK_END)
45 /* This is the end of the category. */
47 token = xlocfile_lex (&ptr, &len);
49 if (token != _NL_NUM_LC_COLLATE)
51 error (0, 0, gettext ("%s:%Zd: category `%s' does not end "
52 "with `END %s'"), locfile_data.filename,
53 locfile_data.line_no, "LC_COLLATE", "LC_COLLATE");
54 ignore_to_eol (0, 0);
56 else
57 ignore_to_eol (0, 1);
59 /* Start next category. */
60 break;
63 #if 0
64 /* Process line. */
65 if (read_order_start == 0)
66 /* We're still in the preambel. */
68 switch (token)
70 case TOK_COLLATING_ELEMENT:
71 reject_new_char = 0;
72 token = xlocfile_lex (&ptr, &len);
73 reject_new_char = 1;
74 if (token == TOK_CHAR)
76 error (0, 0, gettext ("%s:%Zd: symbolic name must not be "
77 "duplicate name in charmap"),
78 locfile_data.filename, locfile_data.line_no);
79 ignore_to_eol (0, 0);
80 break;
82 else if (token != TOK_ILL_CHAR)
84 SYNTAX_ERROR;
85 ignore_to_eol (0, 0);
86 break;
88 else
90 char elem_name[len + 1];
91 memcpy (elem_name, ptr, len);
92 elem_name[len] = '\0';
94 /* Test whether defined in symbol table. */
96 token = xlocfile_lex (&ptr, &len);
97 if (token != TOK_FROM)
99 SYNTAX_ERROR;
100 ignore_to_eol (0, 0);
101 break;
104 token = xlocfile_lex (&ptr, &len);
105 if (token != TOK_STRING)
107 SYNTAX_ERROR;
108 ignore_to_eol (0, 0);
109 break;
112 /* Insert collating element into table. */
114 /* Rest of the line should be empty. */
115 ignore_to_eol (0, 1);
117 break;
118 case TOK_COLLATING_SYMBOL:
119 reject_new_char = 0;
120 token = xlocfile_lex (&ptr, &len);
121 reject_new_char = 1;
122 if (token == TOK_CHAR)
124 error (0, 0, gettext ("%s:%Zd: symbolic name must not "
125 "duplicate name in charmap"),
126 locfile_data.filename, locfile_data.line_no);
127 ignore_to_eol (0, 0);
128 break;
130 else if (token != TOK_ILL_CHAR)
132 SYNTAX_ERROR;
133 ignore_to_eol (0, 0);
134 break;
136 else
138 /* Test whether defined in element table. */
140 /* Insert collating symbol into table. */
142 ignore_to_eol (0, 1);
144 case TOK_ORDER_START:
145 nsort_rules = 0;
149 token = xlocfile_lex (&ptr, &len);
151 if (nsort_rules == 0 && token == ENDOFLINE)
152 break;
154 if (token != TOK_BACKWARD && token != TOK_FORWARD
155 && token != TOK_POSITION)
157 SYNTAX_ERROR;
158 break;
161 switch (token)
163 case TOK_BACKWARD:
164 if ((sort_rule[nsort_rules] & FORWARD_BIT) != 0)
165 error (0, 0, gettext ("%s:%Zd: directives `forward' "
166 "and `backward' are mutually "
167 "exclusive"),
168 locfile_data.filename, locfile_data.lineno);
169 else
170 sort_rule[nsort_rules] |= BACKWARD_BIT;
171 break;
172 case TOK_FORWARD:
173 if ((sort_rule[nsort_rules] & BACKWARD_BIT) != 0)
174 error (0, 0, gettext ("%s:%Zd: directives `forward' "
175 "and `backward' are mutually "
176 "exclusive"),
177 locfile_data.filename, locfile_data.lineno);
178 else
179 sort_rule[nsort_rules] |= FORWARD_BIT;
180 break;
181 case TOK_POSITION:
182 sort_rule[nsort_rules] |= POSITION_BIT;
183 break;
186 ++nsort_rules;
190 break;
191 default:
192 SYNTAX_ERROR;
193 ignore_to_eol (token, 0);
196 else
199 #endif
201 ignore_to_eol(token,0);
202 /* Get next token. */
203 token = xlocfile_lex (&ptr, &len);
208 * Local Variables:
209 * mode:c
210 * c-basic-offset:2
211 * End: