1 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
35 insert_char (struct linereader
*lr
, struct charset_t
*cs
, int bytes
,
36 unsigned int value
, const char *from
, const char *to
);
40 charset_new_char (struct linereader
*lr
, struct charset_t
*cs
, int bytes
,
41 unsigned int value
, const char *from
, const char *to
)
43 if (bytes
< cs
->mb_cur_min
)
44 lr_error (lr
, _("too few bytes in character encoding"));
45 else if (bytes
> cs
->mb_cur_max
)
46 lr_error (lr
, _("too many bytes in character encoding"));
48 insert_char (lr
, cs
, bytes
, value
, from
, to
);
53 charset_new_unicode (struct linereader
*lr
, struct charset_t
*cs
, int bytes
,
54 unsigned int value
, const char *from
, const char *to
)
56 /* For now: perhaps <Uxxxx> support will be removed again... */
57 insert_char (lr
, cs
, bytes
, value
, from
, to
);
62 charset_find_value (const struct charset_t
*cs
, const char *name
, size_t len
)
66 if (find_entry ((hash_table
*) &cs
->char_table
, name
, len
, &result
) < 0)
67 return ILLEGAL_CHAR_VALUE
;
69 return (unsigned int) ((unsigned long int) result
);
74 insert_char (struct linereader
*lr
, struct charset_t
*cs
, int bytes
,
75 unsigned int value
, const char *from
, const char *to
)
79 int prefix_len
, len1
, len2
;
80 unsigned int from_nr
, to_nr
, cnt
;
84 if (insert_entry (&cs
->char_table
, from
, strlen (from
),
85 (void *) (unsigned long int) value
)
87 lr_error (lr
, _("duplicate character name `%s'"), from
);
92 /* We have a range: the names must have names with equal prefixes
93 and an equal number of digits, where the second number is greater
94 or equal than the first. */
101 lr_error (lr
, _("illegal names for character range"));
105 cp
= &from
[len1
- 1];
106 while (isdigit (*cp
) && cp
>= from
)
109 prefix_len
= (cp
- from
) + 1;
111 if (cp
== &from
[len1
- 1] || strncmp (from
, to
, prefix_len
) != 0)
114 from_nr
= strtoul (&from
[prefix_len
], NULL
, 10);
115 to_nr
= strtoul (&to
[prefix_len
], NULL
, 10);
119 lr_error (lr
, _("upper limit in range is not smaller then lower limit"));
123 buf
= alloca (len1
+ 1);
124 memcpy (buf
, from
, prefix_len
);
126 for (cnt
= from_nr
; cnt
<= to_nr
; ++cnt
)
128 sprintf (&buf
[prefix_len
], "%0d", cnt
);
130 if (insert_entry (&cs
->char_table
, buf
, len1
,
131 (void *) (unsigned long int) cnt
) < 0)
132 lr_error (lr
, _("duplicate character name `%s'"), buf
);