1994-05-27 12:33:43 +00:00
|
|
|
%{
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Paul Borman at Krystal Technologies.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2002-04-28 12:34:54 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
static char sccsid[] = "@(#)yacc.y 8.1 (Berkeley) 6/6/93";
|
2002-04-28 12:34:54 +00:00
|
|
|
#endif /* 0 */
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-02-18 20:35:27 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <ctype.h>
|
2002-12-21 11:37:05 +00:00
|
|
|
#include <err.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <rune.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-02-20 04:48:37 +00:00
|
|
|
#include <string.h>
|
2002-04-28 12:34:54 +00:00
|
|
|
#include <unistd.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "ldef.h"
|
2002-04-28 12:34:54 +00:00
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
static void *xmalloc(unsigned int sz);
|
|
|
|
static unsigned long *xlalloc(unsigned int sz);
|
2002-10-20 19:56:15 +00:00
|
|
|
void yyerror(const char *s);
|
2002-04-28 12:34:54 +00:00
|
|
|
static unsigned long *xrelalloc(unsigned long *old, unsigned int sz);
|
|
|
|
static void dump_tables(void);
|
2002-10-20 19:56:15 +00:00
|
|
|
static void cleanout(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
const char *locale_file = "<stdout>";
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
rune_map maplower = { { 0 }, NULL };
|
|
|
|
rune_map mapupper = { { 0 }, NULL };
|
|
|
|
rune_map types = { { 0 }, NULL };
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
_RuneLocale new_locale = { "", "", NULL, NULL, 0, {}, {}, {},
|
|
|
|
{0, NULL}, {0, NULL}, {0, NULL}, NULL, 0 };
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-07-14 18:16:06 +00:00
|
|
|
void set_map(rune_map *, rune_list *, unsigned long);
|
|
|
|
void set_digitmap(rune_map *, rune_list *);
|
|
|
|
void add_map(rune_map *, rune_list *, unsigned long);
|
2003-06-17 19:58:33 +00:00
|
|
|
static void usage(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
rune_t rune;
|
|
|
|
int i;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
rune_list *list;
|
|
|
|
}
|
|
|
|
|
|
|
|
%token <rune> RUNE
|
|
|
|
%token LBRK
|
|
|
|
%token RBRK
|
|
|
|
%token THRU
|
|
|
|
%token MAPLOWER
|
|
|
|
%token MAPUPPER
|
|
|
|
%token DIGITMAP
|
|
|
|
%token <i> LIST
|
|
|
|
%token <str> VARIABLE
|
|
|
|
%token ENCODING
|
|
|
|
%token INVALID
|
|
|
|
%token <str> STRING
|
|
|
|
|
|
|
|
%type <list> list
|
|
|
|
%type <list> map
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
locale : /* empty */
|
|
|
|
| table
|
|
|
|
{ dump_tables(); }
|
|
|
|
;
|
|
|
|
|
|
|
|
table : entry
|
|
|
|
| table entry
|
|
|
|
;
|
|
|
|
|
|
|
|
entry : ENCODING STRING
|
2003-06-02 19:54:29 +00:00
|
|
|
{ if (strcmp($2, "NONE") &&
|
|
|
|
strcmp($2, "UTF2") &&
|
|
|
|
strcmp($2, "UTF-8") &&
|
|
|
|
strcmp($2, "EUC") &&
|
|
|
|
strcmp($2, "GBK") &&
|
|
|
|
strcmp($2, "BIG5") &&
|
2003-06-03 16:58:31 +00:00
|
|
|
strcmp($2, "MSKanji"))
|
|
|
|
warnx("ENCODING %s is not supported by libc", $2);
|
2003-06-02 19:54:29 +00:00
|
|
|
strncpy(new_locale.encoding, $2, sizeof(new_locale.encoding)); }
|
1994-05-27 12:33:43 +00:00
|
|
|
| VARIABLE
|
|
|
|
{ new_locale.variable_len = strlen($1) + 1;
|
2003-06-17 19:58:33 +00:00
|
|
|
new_locale.variable = xmalloc(new_locale.variable_len);
|
1994-05-27 12:33:43 +00:00
|
|
|
strcpy((char *)new_locale.variable, $1);
|
|
|
|
}
|
|
|
|
| INVALID RUNE
|
2002-12-21 11:37:05 +00:00
|
|
|
{ warnx("the INVALID keyword is deprecated");
|
|
|
|
new_locale.invalid_rune = $2;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
| LIST list
|
|
|
|
{ set_map(&types, $2, $1); }
|
|
|
|
| MAPLOWER map
|
|
|
|
{ set_map(&maplower, $2, 0); }
|
|
|
|
| MAPUPPER map
|
|
|
|
{ set_map(&mapupper, $2, 0); }
|
|
|
|
| DIGITMAP map
|
|
|
|
{ set_digitmap(&types, $2); }
|
|
|
|
;
|
|
|
|
|
|
|
|
list : RUNE
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $1;
|
|
|
|
$$->max = $1;
|
|
|
|
$$->next = 0;
|
|
|
|
}
|
|
|
|
| RUNE THRU RUNE
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $1;
|
|
|
|
$$->max = $3;
|
|
|
|
$$->next = 0;
|
|
|
|
}
|
|
|
|
| list RUNE
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $2;
|
|
|
|
$$->max = $2;
|
|
|
|
$$->next = $1;
|
|
|
|
}
|
|
|
|
| list RUNE THRU RUNE
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $2;
|
|
|
|
$$->max = $4;
|
|
|
|
$$->next = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
map : LBRK RUNE RUNE RBRK
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $2;
|
|
|
|
$$->max = $2;
|
|
|
|
$$->map = $3;
|
|
|
|
$$->next = 0;
|
|
|
|
}
|
|
|
|
| map LBRK RUNE RUNE RBRK
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $3;
|
|
|
|
$$->max = $3;
|
|
|
|
$$->map = $4;
|
|
|
|
$$->next = $1;
|
|
|
|
}
|
|
|
|
| LBRK RUNE THRU RUNE ':' RUNE RBRK
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $2;
|
|
|
|
$$->max = $4;
|
|
|
|
$$->map = $6;
|
|
|
|
$$->next = 0;
|
|
|
|
}
|
|
|
|
| map LBRK RUNE THRU RUNE ':' RUNE RBRK
|
|
|
|
{
|
2003-06-17 19:58:33 +00:00
|
|
|
$$ = (rune_list *)xmalloc(sizeof(rune_list));
|
1994-05-27 12:33:43 +00:00
|
|
|
$$->min = $3;
|
|
|
|
$$->max = $5;
|
|
|
|
$$->map = $7;
|
|
|
|
$$->next = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
%%
|
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
int debug;
|
2001-08-13 21:57:12 +00:00
|
|
|
FILE *fp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
static void
|
|
|
|
cleanout(void)
|
|
|
|
{
|
|
|
|
if (fp != NULL)
|
|
|
|
unlink(locale_file);
|
|
|
|
}
|
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
int
|
2002-07-14 18:23:22 +00:00
|
|
|
main(int ac, char *av[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
2001-08-13 21:57:12 +00:00
|
|
|
fp = stdout;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
while ((x = getopt(ac, av, "do:")) != EOF) {
|
|
|
|
switch(x) {
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
locale_file = optarg;
|
2003-06-17 19:58:33 +00:00
|
|
|
if ((fp = fopen(locale_file, "w")) == 0)
|
|
|
|
err(1, "%s", locale_file);
|
2002-10-20 19:56:15 +00:00
|
|
|
atexit(cleanout);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-06-17 19:58:33 +00:00
|
|
|
usage();
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ac - optind) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
2003-06-17 19:58:33 +00:00
|
|
|
if (freopen(av[optind], "r", stdin) == 0)
|
|
|
|
err(1, "%s", av[optind]);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-06-17 19:58:33 +00:00
|
|
|
usage();
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
|
|
|
mapupper.map[x] = x;
|
|
|
|
maplower.map[x] = x;
|
|
|
|
}
|
|
|
|
new_locale.invalid_rune = _INVALID_RUNE;
|
|
|
|
memcpy(new_locale.magic, _RUNE_MAGIC_1, sizeof(new_locale.magic));
|
|
|
|
|
|
|
|
yyparse();
|
2002-04-28 12:34:54 +00:00
|
|
|
|
|
|
|
return(0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2003-06-17 19:58:33 +00:00
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: mklocale [-d] [-o output] [source]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-04-28 12:34:54 +00:00
|
|
|
void
|
1994-05-27 12:33:43 +00:00
|
|
|
yyerror(s)
|
2002-04-28 12:34:54 +00:00
|
|
|
const char *s;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", s);
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
static void *
|
1994-05-27 12:33:43 +00:00
|
|
|
xmalloc(sz)
|
|
|
|
unsigned int sz;
|
|
|
|
{
|
|
|
|
void *r = malloc(sz);
|
2003-06-17 19:58:33 +00:00
|
|
|
if (!r)
|
|
|
|
errx(1, "xmalloc");
|
1994-05-27 12:33:43 +00:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
static unsigned long *
|
1994-05-27 12:33:43 +00:00
|
|
|
xlalloc(sz)
|
|
|
|
unsigned int sz;
|
|
|
|
{
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long *r = (unsigned long *)malloc(sz * sizeof(unsigned long));
|
2003-06-17 19:58:33 +00:00
|
|
|
if (!r)
|
|
|
|
errx(1, "xlalloc");
|
1994-05-27 12:33:43 +00:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
static unsigned long *
|
1994-05-27 12:33:43 +00:00
|
|
|
xrelalloc(old, sz)
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long *old;
|
1994-05-27 12:33:43 +00:00
|
|
|
unsigned int sz;
|
|
|
|
{
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long *r = (unsigned long *)realloc((char *)old,
|
|
|
|
sz * sizeof(unsigned long));
|
2003-06-17 19:58:33 +00:00
|
|
|
if (!r)
|
|
|
|
errx(1, "xrelalloc");
|
1994-05-27 12:33:43 +00:00
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_map(map, list, flag)
|
|
|
|
rune_map *map;
|
|
|
|
rune_list *list;
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long flag;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
while (list) {
|
|
|
|
rune_list *nlist = list->next;
|
|
|
|
add_map(map, list, flag);
|
|
|
|
list = nlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_digitmap(map, list)
|
|
|
|
rune_map *map;
|
|
|
|
rune_list *list;
|
|
|
|
{
|
|
|
|
rune_t i;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
rune_list *nlist = list->next;
|
|
|
|
for (i = list->min; i <= list->max; ++i) {
|
|
|
|
if (list->map + (i - list->min)) {
|
|
|
|
rune_list *tmp = (rune_list *)xmalloc(sizeof(rune_list));
|
|
|
|
tmp->min = i;
|
|
|
|
tmp->max = i;
|
|
|
|
add_map(map, tmp, list->map + (i - list->min));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
list = nlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_map(map, list, flag)
|
|
|
|
rune_map *map;
|
|
|
|
rune_list *list;
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long flag;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
rune_t i;
|
|
|
|
rune_list *lr = 0;
|
|
|
|
rune_list *r;
|
|
|
|
rune_t run;
|
|
|
|
|
|
|
|
while (list->min < _CACHED_RUNES && list->min <= list->max) {
|
|
|
|
if (flag)
|
|
|
|
map->map[list->min++] |= flag;
|
|
|
|
else
|
|
|
|
map->map[list->min++] = list->map++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list->min > list->max) {
|
|
|
|
free(list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
run = list->max - list->min + 1;
|
|
|
|
|
|
|
|
if (!(r = map->root) || (list->max < r->min - 1)
|
|
|
|
|| (!flag && list->max == r->min - 1)) {
|
|
|
|
if (flag) {
|
|
|
|
list->types = xlalloc(run);
|
|
|
|
for (i = 0; i < run; ++i)
|
|
|
|
list->types[i] = flag;
|
|
|
|
}
|
|
|
|
list->next = map->root;
|
|
|
|
map->root = list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (r = map->root; r && r->max + 1 < list->min; r = r->next)
|
|
|
|
lr = r;
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
/*
|
|
|
|
* We are off the end.
|
|
|
|
*/
|
|
|
|
if (flag) {
|
|
|
|
list->types = xlalloc(run);
|
|
|
|
for (i = 0; i < run; ++i)
|
|
|
|
list->types[i] = flag;
|
|
|
|
}
|
|
|
|
list->next = 0;
|
|
|
|
lr->next = list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list->max < r->min - 1) {
|
|
|
|
/*
|
|
|
|
* We come before this range and we do not intersect it.
|
|
|
|
* We are not before the root node, it was checked before the loop
|
|
|
|
*/
|
|
|
|
if (flag) {
|
|
|
|
list->types = xlalloc(run);
|
|
|
|
for (i = 0; i < run; ++i)
|
|
|
|
list->types[i] = flag;
|
|
|
|
}
|
|
|
|
list->next = lr->next;
|
|
|
|
lr->next = list;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point we have found that we at least intersect with
|
|
|
|
* the range pointed to by `r', we might intersect with one or
|
|
|
|
* more ranges beyond `r' as well.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!flag && list->map - list->min != r->map - r->min) {
|
|
|
|
/*
|
|
|
|
* There are only two cases when we are doing case maps and
|
|
|
|
* our maps needn't have the same offset. When we are adjoining
|
|
|
|
* but not intersecting.
|
|
|
|
*/
|
|
|
|
if (list->max + 1 == r->min) {
|
|
|
|
lr->next = list;
|
|
|
|
list->next = r;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (list->min - 1 == r->max) {
|
|
|
|
list->next = r->next;
|
|
|
|
r->next = list;
|
|
|
|
return;
|
|
|
|
}
|
2003-06-17 19:58:33 +00:00
|
|
|
errx(1, "error: conflicting map entries");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (list->min >= r->min && list->max <= r->max) {
|
|
|
|
/*
|
|
|
|
* Subset case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
for (i = list->min; i <= list->max; ++i)
|
|
|
|
r->types[i - r->min] |= flag;
|
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (list->min <= r->min && list->max >= r->max) {
|
|
|
|
/*
|
|
|
|
* Superset case. Make him big enough to hold us.
|
|
|
|
* We might need to merge with the guy after him.
|
|
|
|
*/
|
|
|
|
if (flag) {
|
|
|
|
list->types = xlalloc(list->max - list->min + 1);
|
|
|
|
|
|
|
|
for (i = list->min; i <= list->max; ++i)
|
|
|
|
list->types[i - list->min] = flag;
|
|
|
|
|
|
|
|
for (i = r->min; i <= r->max; ++i)
|
|
|
|
list->types[i - list->min] |= r->types[i - r->min];
|
|
|
|
|
|
|
|
free(r->types);
|
|
|
|
r->types = list->types;
|
|
|
|
} else {
|
|
|
|
r->map = list->map;
|
|
|
|
}
|
|
|
|
r->min = list->min;
|
|
|
|
r->max = list->max;
|
|
|
|
free(list);
|
|
|
|
} else if (list->min < r->min) {
|
|
|
|
/*
|
|
|
|
* Our tail intersects his head.
|
|
|
|
*/
|
|
|
|
if (flag) {
|
|
|
|
list->types = xlalloc(r->max - list->min + 1);
|
|
|
|
|
|
|
|
for (i = r->min; i <= r->max; ++i)
|
|
|
|
list->types[i - list->min] = r->types[i - r->min];
|
|
|
|
|
|
|
|
for (i = list->min; i < r->min; ++i)
|
|
|
|
list->types[i - list->min] = flag;
|
|
|
|
|
|
|
|
for (i = r->min; i <= list->max; ++i)
|
|
|
|
list->types[i - list->min] |= flag;
|
|
|
|
|
|
|
|
free(r->types);
|
|
|
|
r->types = list->types;
|
|
|
|
} else {
|
|
|
|
r->map = list->map;
|
|
|
|
}
|
|
|
|
r->min = list->min;
|
|
|
|
free(list);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Our head intersects his tail.
|
|
|
|
* We might need to merge with the guy after him.
|
|
|
|
*/
|
|
|
|
if (flag) {
|
|
|
|
r->types = xrelalloc(r->types, list->max - r->min + 1);
|
|
|
|
|
|
|
|
for (i = list->min; i <= r->max; ++i)
|
|
|
|
r->types[i - r->min] |= flag;
|
|
|
|
|
|
|
|
for (i = r->max+1; i <= list->max; ++i)
|
|
|
|
r->types[i - r->min] = flag;
|
|
|
|
}
|
1997-01-07 09:58:32 +00:00
|
|
|
r->max = list->max;
|
1994-05-27 12:33:43 +00:00
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay, check to see if we grew into the next guy(s)
|
|
|
|
*/
|
|
|
|
while ((lr = r->next) && r->max >= lr->min) {
|
|
|
|
if (flag) {
|
|
|
|
if (r->max >= lr->max) {
|
|
|
|
/*
|
|
|
|
* Good, we consumed all of him.
|
|
|
|
*/
|
|
|
|
for (i = lr->min; i <= lr->max; ++i)
|
|
|
|
r->types[i - r->min] |= lr->types[i - lr->min];
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* "append" him on to the end of us.
|
|
|
|
*/
|
|
|
|
r->types = xrelalloc(r->types, lr->max - r->min + 1);
|
|
|
|
|
|
|
|
for (i = lr->min; i <= r->max; ++i)
|
|
|
|
r->types[i - r->min] |= lr->types[i - lr->min];
|
|
|
|
|
|
|
|
for (i = r->max+1; i <= lr->max; ++i)
|
|
|
|
r->types[i - r->min] = lr->types[i - lr->min];
|
|
|
|
|
|
|
|
r->max = lr->max;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lr->max > r->max)
|
|
|
|
r->max = lr->max;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->next = lr->next;
|
|
|
|
|
|
|
|
if (flag)
|
|
|
|
free(lr->types);
|
|
|
|
free(lr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-20 19:56:15 +00:00
|
|
|
static void
|
1994-05-27 12:33:43 +00:00
|
|
|
dump_tables()
|
|
|
|
{
|
2002-10-20 19:56:15 +00:00
|
|
|
int x, first_d, curr_d;
|
1994-05-27 12:33:43 +00:00
|
|
|
rune_list *list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if we can compress some of the istype arrays
|
|
|
|
*/
|
|
|
|
for(list = types.root; list; list = list->next) {
|
|
|
|
list->map = list->types[0];
|
|
|
|
for (x = 1; x < list->max - list->min + 1; ++x) {
|
2002-04-28 12:34:54 +00:00
|
|
|
if ((rune_t)list->types[x] != list->map) {
|
1994-05-27 12:33:43 +00:00
|
|
|
list->map = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-17 19:58:33 +00:00
|
|
|
first_d = curr_d = -1;
|
2002-10-20 19:56:15 +00:00
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
|
|
|
unsigned long r = types.map[x];
|
|
|
|
|
|
|
|
if (r & _CTYPE_D) {
|
|
|
|
if (first_d < 0)
|
|
|
|
first_d = curr_d = x;
|
2003-06-17 19:58:33 +00:00
|
|
|
else if (x != curr_d + 1)
|
|
|
|
errx(1, "error: DIGIT range is not contiguous");
|
|
|
|
else if (x - first_d > 9)
|
|
|
|
errx(1, "error: DIGIT range is too big");
|
|
|
|
else
|
2002-10-20 19:56:15 +00:00
|
|
|
curr_d++;
|
2003-06-17 19:58:33 +00:00
|
|
|
if (!(r & _CTYPE_X))
|
|
|
|
errx(1,
|
|
|
|
"error: DIGIT range is not a subset of XDIGIT range");
|
2002-10-20 19:56:15 +00:00
|
|
|
}
|
|
|
|
}
|
2003-06-17 19:58:33 +00:00
|
|
|
if (first_d < 0)
|
|
|
|
errx(1, "error: no DIGIT range defined in the single byte area");
|
|
|
|
else if (curr_d - first_d < 9)
|
|
|
|
errx(1, "error: DIGIT range is too small in the single byte area");
|
2002-10-20 19:56:15 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
new_locale.invalid_rune = htonl(new_locale.invalid_rune);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in our tables. Do this in network order so that
|
|
|
|
* diverse machines have a chance of sharing data.
|
|
|
|
* (Machines like Crays cannot share with little machines due to
|
|
|
|
* word size. Sigh. We tried.)
|
|
|
|
*/
|
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
|
|
|
new_locale.runetype[x] = htonl(types.map[x]);
|
|
|
|
new_locale.maplower[x] = htonl(maplower.map[x]);
|
|
|
|
new_locale.mapupper[x] = htonl(mapupper.map[x]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count up how many ranges we will need for each of the extents.
|
|
|
|
*/
|
|
|
|
list = types.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
new_locale.runetype_ext.nranges++;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
new_locale.runetype_ext.nranges = htonl(new_locale.runetype_ext.nranges);
|
|
|
|
|
|
|
|
list = maplower.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
new_locale.maplower_ext.nranges++;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
new_locale.maplower_ext.nranges = htonl(new_locale.maplower_ext.nranges);
|
|
|
|
|
|
|
|
list = mapupper.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
new_locale.mapupper_ext.nranges++;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
new_locale.mapupper_ext.nranges = htonl(new_locale.mapupper_ext.nranges);
|
|
|
|
|
|
|
|
new_locale.variable_len = htonl(new_locale.variable_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay, we are now ready to write the new locale file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PART 1: The _RuneLocale structure
|
|
|
|
*/
|
|
|
|
if (fwrite((char *)&new_locale, sizeof(new_locale), 1, fp) != 1) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* PART 2: The runetype_ext structures (not the actual tables)
|
|
|
|
*/
|
|
|
|
list = types.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
_RuneEntry re;
|
|
|
|
|
|
|
|
re.min = htonl(list->min);
|
|
|
|
re.max = htonl(list->max);
|
|
|
|
re.map = htonl(list->map);
|
|
|
|
|
|
|
|
if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* PART 3: The maplower_ext structures
|
|
|
|
*/
|
|
|
|
list = maplower.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
_RuneEntry re;
|
|
|
|
|
|
|
|
re.min = htonl(list->min);
|
|
|
|
re.max = htonl(list->max);
|
|
|
|
re.map = htonl(list->map);
|
|
|
|
|
|
|
|
if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* PART 4: The mapupper_ext structures
|
|
|
|
*/
|
|
|
|
list = mapupper.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
_RuneEntry re;
|
|
|
|
|
|
|
|
re.min = htonl(list->min);
|
|
|
|
re.max = htonl(list->max);
|
|
|
|
re.map = htonl(list->map);
|
|
|
|
|
|
|
|
if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* PART 5: The runetype_ext tables
|
|
|
|
*/
|
|
|
|
list = types.root;
|
|
|
|
|
|
|
|
while (list) {
|
|
|
|
for (x = 0; x < list->max - list->min + 1; ++x)
|
|
|
|
list->types[x] = htonl(list->types[x]);
|
|
|
|
|
|
|
|
if (!list->map) {
|
1997-01-07 09:58:32 +00:00
|
|
|
if (fwrite((char *)list->types,
|
1994-09-05 14:02:42 +00:00
|
|
|
(list->max - list->min + 1) * sizeof(unsigned long),
|
|
|
|
1, fp) != 1) {
|
1994-05-27 12:33:43 +00:00
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* PART 5: And finally the variable data
|
|
|
|
*/
|
|
|
|
if (fwrite((char *)new_locale.variable,
|
|
|
|
ntohl(new_locale.variable_len), 1, fp) != 1) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-10-20 19:56:15 +00:00
|
|
|
if (fclose(fp) != 0) {
|
|
|
|
perror(locale_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fp = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (!debug)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (new_locale.encoding[0])
|
|
|
|
fprintf(stderr, "ENCODING %s\n", new_locale.encoding);
|
|
|
|
if (new_locale.variable)
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "VARIABLE %s\n", (char *)new_locale.variable);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "\nMAPLOWER:\n\n");
|
|
|
|
|
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
|
|
|
if (isprint(maplower.map[x]))
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, " '%c'", (int)maplower.map[x]);
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (maplower.map[x])
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04lx", maplower.map[x]);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
|
|
|
fprintf(stderr, "%4x", 0);
|
|
|
|
if ((x & 0xf) == 0xf)
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
for (list = maplower.root; list; list = list->next)
|
|
|
|
fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
|
|
|
|
|
|
|
|
fprintf(stderr, "\nMAPUPPER:\n\n");
|
|
|
|
|
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
|
|
|
if (isprint(mapupper.map[x]))
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, " '%c'", (int)mapupper.map[x]);
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (mapupper.map[x])
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04lx", mapupper.map[x]);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
|
|
|
fprintf(stderr, "%4x", 0);
|
|
|
|
if ((x & 0xf) == 0xf)
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
else
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
for (list = mapupper.root; list; list = list->next)
|
|
|
|
fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\nTYPES:\n\n");
|
|
|
|
|
|
|
|
for (x = 0; x < _CACHED_RUNES; ++x) {
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long r = types.map[x];
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (r) {
|
|
|
|
if (isprint(x))
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, " '%c': %2d", x, (int)(r & 0xff));
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-02-08 07:43:26 +00:00
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = types.root; list; list = list->next) {
|
|
|
|
if (list->map && list->min + 3 < list->max) {
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long r = list->map;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04lx: %2d",
|
|
|
|
(unsigned long)list->min, (int)(r & 0xff));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-02-08 07:43:26 +00:00
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\n...\n");
|
|
|
|
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04lx: %2d",
|
|
|
|
(unsigned long)list->max, (int)(r & 0xff));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-02-08 07:43:26 +00:00
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
} else
|
|
|
|
for (x = list->min; x <= list->max; ++x) {
|
1994-09-05 14:02:42 +00:00
|
|
|
unsigned long r = ntohl(list->types[x - list->min]);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (r) {
|
1998-08-02 15:18:45 +00:00
|
|
|
fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2000-02-08 07:43:26 +00:00
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
|
|
|
|
fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|