Remove chrtbl(8). Since NetBSD 1.6, the rune type based file format for
LC_CTYPE has been used.
This commit is contained in:
parent
353ac4a525
commit
080ec811b2
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.925 2011/03/10 13:16:57 jmmv Exp $
|
||||
# $NetBSD: mi,v 1.926 2011/03/17 02:35:27 joerg Exp $
|
||||
#
|
||||
# Note: Don't delete entries from here - mark them as "obsolete" instead,
|
||||
# unless otherwise stated below.
|
||||
@ -1130,7 +1130,7 @@
|
||||
./usr/sbin/chat base-ppp-bin
|
||||
./usr/sbin/chown base-sysutil-bin
|
||||
./usr/sbin/chroot base-sysutil-bin
|
||||
./usr/sbin/chrtbl base-sysutil-bin
|
||||
./usr/sbin/chrtbl base-obsolete obsolete
|
||||
./usr/sbin/cnwctl base-netutil-bin
|
||||
./usr/sbin/cpuctl base-sysutil-bin
|
||||
./usr/sbin/crash base-sysutil-bin
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.1599 2011/03/14 13:53:55 njoly Exp $
|
||||
# $NetBSD: mi,v 1.1600 2011/03/17 02:35:27 joerg Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
@ -3640,7 +3640,7 @@
|
||||
./usr/libdata/debug/usr/sbin/chat.debug comp-ppp-debug debug
|
||||
./usr/libdata/debug/usr/sbin/chown.debug comp-obsolete obsolete
|
||||
./usr/libdata/debug/usr/sbin/chroot.debug comp-sysutil-debug debug
|
||||
./usr/libdata/debug/usr/sbin/chrtbl.debug comp-sysutil-debug debug
|
||||
./usr/libdata/debug/usr/sbin/chrtbl.debug comp-obsolete obsolete
|
||||
./usr/libdata/debug/usr/sbin/cnwctl.debug comp-netutil-debug debug
|
||||
./usr/libdata/debug/usr/sbin/cpuctl.debug comp-sysutil-debug debug
|
||||
./usr/libdata/debug/usr/sbin/crash.debug comp-sysutil-debug debug
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.1301 2011/03/10 13:16:57 jmmv Exp $
|
||||
# $NetBSD: mi,v 1.1302 2011/03/17 02:35:28 joerg Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
#
|
||||
@ -2133,7 +2133,7 @@
|
||||
./usr/share/man/cat8/chat.0 man-ppp-catman .cat
|
||||
./usr/share/man/cat8/chown.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/chroot.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/chrtbl.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/chrtbl.0 man-obsolete obsolete
|
||||
./usr/share/man/cat8/cleanup.0 man-postfix-catman postfix,.cat
|
||||
./usr/share/man/cat8/clri.0 man-sysutil-catman .cat
|
||||
./usr/share/man/cat8/cnwctl.0 man-sysutil-catman .cat
|
||||
@ -4770,7 +4770,7 @@
|
||||
./usr/share/man/html8/chat.html man-ppp-htmlman html
|
||||
./usr/share/man/html8/chown.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/chroot.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/chrtbl.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/chrtbl.html man-obsolete obsolete
|
||||
./usr/share/man/html8/cleanup.html man-postfix-htmlman postfix,html
|
||||
./usr/share/man/html8/clri.html man-sysutil-htmlman html
|
||||
./usr/share/man/html8/cnwctl.html man-sysutil-htmlman html
|
||||
@ -7457,7 +7457,7 @@
|
||||
./usr/share/man/man8/chat.8 man-ppp-man .man
|
||||
./usr/share/man/man8/chown.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/chroot.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/chrtbl.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/chrtbl.8 man-obsolete obsolete
|
||||
./usr/share/man/man8/cleanup.8 man-postfix-man postfix,.man
|
||||
./usr/share/man/man8/clri.8 man-sysutil-man .man
|
||||
./usr/share/man/man8/cnwctl.8 man-sysutil-man .man
|
||||
|
@ -1,11 +1,11 @@
|
||||
# $NetBSD: Makefile,v 1.253 2011/03/06 17:08:42 bouyer Exp $
|
||||
# $NetBSD: Makefile,v 1.254 2011/03/17 02:35:28 joerg Exp $
|
||||
# from: @(#)Makefile 5.20 (Berkeley) 6/12/93
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
SUBDIR= ac accton acpitools altq apm apmd arp bad144 bootp \
|
||||
btattach btconfig btdevctl bthcid btpand catman \
|
||||
chroot chrtbl cnwctl cpuctl crash dev_mkdb \
|
||||
chroot cnwctl cpuctl crash dev_mkdb \
|
||||
dhcp diskpart dumpfs dumplfs edquota eeprom \
|
||||
envstat eshconfig etcupdate extattrctl flashctl fssconfig fusermount \
|
||||
fwctl gpioctl grfconfig gspa hdaudioctl ifwatchd inetd \
|
||||
|
@ -1,16 +0,0 @@
|
||||
# $NetBSD: Makefile,v 1.9 2010/05/22 06:38:15 tnozaki Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= chrtbl
|
||||
MAN= chrtbl.8
|
||||
|
||||
SRCS= chrtbl.c ctypeio.c
|
||||
|
||||
CPPFLAGS+= -I${NETBSDSRCDIR}/lib/libc/locale
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
.if (defined(HAVE_GCC) && ${HAVE_GCC} == 4) || defined(HAVE_PCC)
|
||||
COPTS.chrtbl.c+= -Wno-pointer-sign
|
||||
.endif
|
@ -1,87 +0,0 @@
|
||||
.\" $NetBSD: chrtbl.8,v 1.9 2010/12/16 17:42:29 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997 Christos Zoulas
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.\"
|
||||
.Dd May 12, 1997
|
||||
.Dt CHRTBL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm chrtbl
|
||||
.Nd create character classification and upper \*[Lt]-\*[Gt] lower conversion tables
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl o Ar ofile
|
||||
.Ar ifile
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
creates character classification and upper \*[Lt]-\*[Gt] lower conversion tables for
|
||||
single byte files. The
|
||||
.Nm
|
||||
command is modelled after the Solaris/SVR4 command. The input file is similar
|
||||
and contains a keyword per line followed by characters or ranges. Valid
|
||||
keywords are:
|
||||
.Bl -tag -width indent
|
||||
.It Nm LC_CTYPE Ar filename
|
||||
Set the filename for the character classification output.
|
||||
.It Nm LC_NUMERIC Ar filename
|
||||
Set the filename for the numeric formatting output.
|
||||
.It Nm isupper Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be upper case.
|
||||
.It Nm islower Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be lower case.
|
||||
.It Nm isdigit Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be numeric.
|
||||
.It Nm isspace Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be space.
|
||||
.It Nm ispunct Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be punctuation.
|
||||
.It Nm iscntrl Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be control.
|
||||
.It Nm isxdigit Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be hexadecimal digits.
|
||||
.It Nm isblank Ar begin-char Op - Ar end-char
|
||||
Set the attribute of the specified characters range(s) to be blank.
|
||||
.It Nm ul Ar \*[Lt]upper-char lower-char\*[Gt] ...
|
||||
Specify a case correspondence between upper and lower char.
|
||||
.It Nm cswidth Ar n1,s1:n2,s2:n3,s3
|
||||
Specify the character set byte width (n1,n2,n3) and the screen width(s1,s2,s3)
|
||||
for the 3 character sets.
|
||||
.It Nm decimal_point Ar char
|
||||
Specify the decimal point numeric formatting character.
|
||||
.It Nm thousands_sep Ar char
|
||||
Specify the thousands separator numeric formatting character.
|
||||
.El
|
||||
.Ss Available options
|
||||
.Bl -tag -width indent
|
||||
.It Fl o Ar ofile
|
||||
Print the conversion tables in a human readable (C source) form.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr setlocale 3
|
||||
.Sh BUGS
|
||||
Preliminary support of LC_NUMERIC is present, but not currently fully
|
||||
implemented.
|
||||
No support for wide-character locales.
|
||||
Support for alternate
|
||||
localized character sets and numeric formatting is currently not implemented.
|
@ -1,515 +0,0 @@
|
||||
/* $NetBSD: chrtbl.c,v 1.13 2010/12/14 02:28:58 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ctypeio.h"
|
||||
|
||||
struct chartbl {
|
||||
size_t maxchar;
|
||||
char *ctypefilename;
|
||||
unsigned char *ctype;
|
||||
unsigned short *uptab;
|
||||
unsigned short *lotab;
|
||||
char *numericfilename;
|
||||
unsigned char decimal_point;
|
||||
unsigned char thousands_sep;
|
||||
};
|
||||
|
||||
static void usage __P((void));
|
||||
static int numeric __P((struct chartbl *, const char *, int, char *, size_t));
|
||||
static int cswidth __P((struct chartbl *, const char *, int, char *, size_t));
|
||||
static int setfilename __P((struct chartbl *, const char *, int, char *,
|
||||
size_t));
|
||||
static int addattr __P((struct chartbl *, const char *, int, char *, size_t));
|
||||
static int uplow __P((struct chartbl *, const char *, int, char *, size_t));
|
||||
static void printctype __P((FILE *, unsigned int));
|
||||
static int output_ascii __P((const char *, const struct chartbl *));
|
||||
static int output_binary __P((const struct chartbl *));
|
||||
|
||||
int main __P((int, char *[]));
|
||||
|
||||
static const struct toklist {
|
||||
const char *name;
|
||||
int (*func) __P((struct chartbl *, const char *, int arg,
|
||||
char *, size_t lno));
|
||||
int arg;
|
||||
} tokens[] = {
|
||||
{ "LC_CTYPE", setfilename, 0 },
|
||||
{ "isupper", addattr, _CTYPE_U },
|
||||
{ "islower", addattr, _CTYPE_L },
|
||||
{ "isdigit", addattr, _CTYPE_N },
|
||||
{ "isspace", addattr, _CTYPE_S },
|
||||
{ "ispunct", addattr, _CTYPE_P },
|
||||
{ "iscntrl", addattr, _CTYPE_C },
|
||||
{ "isblank", addattr, _CTYPE_B },
|
||||
{ "isxdigit", addattr, _CTYPE_X },
|
||||
{ "ul", uplow, 0 },
|
||||
{ "cswidth", cswidth, 0 },
|
||||
{ "LC_NUMERIC", setfilename, 1 },
|
||||
{ "decimal_point", numeric, 0 },
|
||||
{ "thousands_sep", numeric, 0 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
/* usage():
|
||||
* Print a usage message and exit
|
||||
*/
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void) fprintf(stderr, "usage: %s [-o <filename>] <description>\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* numeric():
|
||||
* Parse a decimal_point or thousands_sep line
|
||||
*/
|
||||
static int
|
||||
numeric(cs, token, arg, line, lnum)
|
||||
struct chartbl *cs;
|
||||
const char *token;
|
||||
int arg;
|
||||
char *line;
|
||||
size_t lnum;
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* cswidth():
|
||||
* Parse a cswidth line. This is of the form:
|
||||
* cswidth: <n1>:<s1>,<n2>:<s2>,<n3>:<s3>
|
||||
* Where:
|
||||
* n1,n2,n3: byte widths of the supplementary codes 1,2,3
|
||||
* s1,s2,s3: screen widths " " "
|
||||
*/
|
||||
static int
|
||||
cswidth(cs, token, arg, line, lnum)
|
||||
struct chartbl *cs;
|
||||
const char *token;
|
||||
int arg;
|
||||
char *line;
|
||||
size_t lnum;
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* setfilename():
|
||||
* Set the output file name for LC_CTYPE or LC_NUMERIC
|
||||
*/
|
||||
static int
|
||||
setfilename(cs, token, arg, line, lnum)
|
||||
struct chartbl *cs;
|
||||
const char *token;
|
||||
int arg;
|
||||
char *line;
|
||||
size_t lnum;
|
||||
{
|
||||
char *p = strtok(line, " \t");
|
||||
|
||||
if (p == NULL || *p == '\0')
|
||||
return 0;
|
||||
|
||||
if ((p = strdup(p)) == NULL)
|
||||
err(1, "Out of memory at line %lu", (u_long)lnum);
|
||||
|
||||
switch (arg) {
|
||||
case 0:
|
||||
cs->ctypefilename = p;
|
||||
return 0;
|
||||
case 1:
|
||||
cs->numericfilename = p;
|
||||
return 0;
|
||||
default:
|
||||
warn("%s: Bad filename argument %d at line %lu", token, arg,
|
||||
(u_long)lnum);
|
||||
free(p);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* addattr():
|
||||
* Parse a character attribute line
|
||||
* The line is of the form <attribute>: <char> | <char> - <char>
|
||||
*/
|
||||
static int
|
||||
addattr(cs, token, arg, line, lnum)
|
||||
struct chartbl *cs;
|
||||
const char *token;
|
||||
int arg;
|
||||
char *line;
|
||||
size_t lnum;
|
||||
{
|
||||
static const char sep[] = "\t ";
|
||||
size_t b = 0, e = 0, n;
|
||||
int st = 0;
|
||||
char *ptr, *ep;
|
||||
|
||||
for (ptr = strtok(line, sep); ptr; ptr = strtok(NULL, sep)) {
|
||||
if (strcmp(ptr, "-") == 0) {
|
||||
if (st++ == 0)
|
||||
goto badrange;
|
||||
continue;
|
||||
}
|
||||
|
||||
n = (size_t) strtoul(ptr, &ep, 0);
|
||||
if (ptr == ep || *ep) {
|
||||
warnx("%s: Bad number `%s' at line %lu", token,
|
||||
ptr, (u_long)lnum);
|
||||
return 1;
|
||||
}
|
||||
switch (++st) {
|
||||
case 1:
|
||||
b = n;
|
||||
continue;
|
||||
case 2:
|
||||
if (b > cs->maxchar) {
|
||||
n = b;
|
||||
goto oorange;
|
||||
}
|
||||
cs->ctype[b+1] |= arg;
|
||||
st = 1;
|
||||
b = n;
|
||||
continue;
|
||||
case 3:
|
||||
e = n;
|
||||
if (e > cs->maxchar) {
|
||||
n = e;
|
||||
goto oorange;
|
||||
}
|
||||
for (n = b; n <= e; n++)
|
||||
cs->ctype[n+1] |= arg;
|
||||
st = 0;
|
||||
continue;
|
||||
default:
|
||||
goto badstate;
|
||||
}
|
||||
}
|
||||
switch (st) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
if (b > cs->maxchar) {
|
||||
n = b;
|
||||
goto oorange;
|
||||
}
|
||||
cs->ctype[b+1] |= arg;
|
||||
return 0;
|
||||
case 2:
|
||||
goto badrange;
|
||||
default:
|
||||
goto badstate;
|
||||
}
|
||||
|
||||
oorange:
|
||||
warnx("%s: Character %lu out of range at line %lu", token, (u_long)n,
|
||||
(u_long)lnum);
|
||||
return 1;
|
||||
badstate:
|
||||
warnx("%s: Unexpected state %d at line %lu", token, st,
|
||||
(u_long)lnum);
|
||||
return 1;
|
||||
badrange:
|
||||
warnx("%s: Missing %s range at line %lu", token,
|
||||
st == 1 ? "begin" : "end", (u_long)lnum);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* uplow():
|
||||
* Parse an upper<->lower case transformation. The format of the line
|
||||
* is ul <upper lower> ...
|
||||
*/
|
||||
static int
|
||||
uplow(cs, token, arg, line, lnum)
|
||||
struct chartbl *cs;
|
||||
const char *token;
|
||||
int arg;
|
||||
char *line;
|
||||
size_t lnum;
|
||||
{
|
||||
size_t lo, up;
|
||||
char *p, *ep;
|
||||
|
||||
for (p = line;;) {
|
||||
while (*p && isspace((u_char) *p))
|
||||
p++;
|
||||
switch (*p) {
|
||||
case '\0':
|
||||
return 0;
|
||||
case '<':
|
||||
p++;
|
||||
break;
|
||||
default:
|
||||
goto badtoken;
|
||||
}
|
||||
while (*p && isspace((u_char) *p))
|
||||
p++;
|
||||
if (*p == '\0')
|
||||
goto badtoken;
|
||||
lo = (size_t) strtol(p, &ep, 0);
|
||||
if (p == ep || !isspace((u_char) *ep))
|
||||
goto badtoken;
|
||||
p = ep + 1;
|
||||
while (*p && isspace((u_char) *p))
|
||||
p++;
|
||||
up = (size_t) strtol(p, &ep, 0);
|
||||
if (p == ep)
|
||||
goto badtoken;
|
||||
if (lo > cs->maxchar)
|
||||
goto oorange;
|
||||
if (up > cs->maxchar) {
|
||||
lo = up;
|
||||
goto oorange;
|
||||
}
|
||||
cs->lotab[up + 1] = lo;
|
||||
cs->uptab[lo + 1] = up;
|
||||
p = ep;
|
||||
switch (*ep) {
|
||||
case '\0':
|
||||
return 0;
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '>':
|
||||
p++;
|
||||
break;
|
||||
default:
|
||||
goto badtoken;
|
||||
}
|
||||
}
|
||||
|
||||
badtoken:
|
||||
warnx("%s: Bad token `%s' at line %lu", token, p, (u_long)lnum);
|
||||
return 1;
|
||||
oorange:
|
||||
warnx("%s: Out of range character %lx at line %lu", token, (u_long)lo,
|
||||
(u_long)lnum);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* printctype():
|
||||
* Symbolically print an ascii character.
|
||||
*/
|
||||
static void
|
||||
printctype(fp, ct)
|
||||
FILE *fp;
|
||||
unsigned int ct;
|
||||
{
|
||||
int did = 0;
|
||||
|
||||
#define DO(a) if (__CONCAT(_CTYPE_,a) & ct) { \
|
||||
if (did) \
|
||||
(void) fputc('|', fp); \
|
||||
did = 1; \
|
||||
(void) fputc('_', fp); \
|
||||
(void) fputs(__STRING(a), fp); \
|
||||
}
|
||||
DO(U)
|
||||
DO(L)
|
||||
DO(N)
|
||||
DO(S)
|
||||
DO(P)
|
||||
DO(C)
|
||||
DO(B)
|
||||
DO(X)
|
||||
if (!did)
|
||||
(void) fputc('0', fp);
|
||||
}
|
||||
|
||||
|
||||
/* output_ascii():
|
||||
* Print a `c' symbolic description of the character set
|
||||
*/
|
||||
static int
|
||||
output_ascii(fn, ct)
|
||||
const char *fn;
|
||||
const struct chartbl *ct;
|
||||
{
|
||||
size_t i;
|
||||
FILE *fp;
|
||||
|
||||
if ((fp = fopen(fn, "w")) == NULL) {
|
||||
warn("Cannot open `%s'", fn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
(void) fprintf(fp, "/* Automatically generated file; do not edit */\n");
|
||||
(void) fprintf(fp, "#include <ctype.h>\n");
|
||||
(void) fprintf(fp, "unsigned char _ctype_[] = { 0");
|
||||
for (i = 1; i <= ct->maxchar; i++) {
|
||||
if (((i - 1) & 7) == 0)
|
||||
(void) fputs(",\n\t", fp);
|
||||
printctype(fp, ct->ctype[i]);
|
||||
if ((i & 7) != 0)
|
||||
(void) fputs(",\t", fp);
|
||||
}
|
||||
(void) fprintf(fp, "\n};\n");
|
||||
|
||||
(void) fprintf(fp, "short _tolower_tab_[] = { -1");
|
||||
for (i = 1; i <= ct->maxchar; i++) {
|
||||
if (((i - 1) & 7) == 0)
|
||||
(void) fputs(",\n\t", fp);
|
||||
(void) fprintf(fp, "0x%x", ct->lotab[i]);
|
||||
if ((i & 7) != 0)
|
||||
(void) fputs(",\t", fp);
|
||||
}
|
||||
(void) fprintf(fp, "\n};\n");
|
||||
|
||||
(void) fprintf(fp, "short _toupper_tab_[] = { -1");
|
||||
for (i = 1; i <= ct->maxchar; i++) {
|
||||
if (((i - 1) & 7) == 0)
|
||||
(void) fputs(",\n\t", fp);
|
||||
(void) fprintf(fp, "0x%x", ct->uptab[i]);
|
||||
if ((i & 7) != 0)
|
||||
(void) fputs(",\t", fp);
|
||||
}
|
||||
(void) fprintf(fp, "\n};\n");
|
||||
(void) fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* output_binary():
|
||||
* Print a binary description of the requested character set.
|
||||
*/
|
||||
static int
|
||||
output_binary(ct)
|
||||
const struct chartbl *ct;
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (ct->ctypefilename != NULL) {
|
||||
if (!__savectype(ct->ctypefilename, ct->ctype, ct->lotab,
|
||||
ct->uptab))
|
||||
err(1, "Cannot creating/writing `%s'",
|
||||
ct->ctypefilename);
|
||||
}
|
||||
else {
|
||||
warnx("No output file for LC_CTYPE specified");
|
||||
error |= 1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
size_t lnum, size;
|
||||
FILE *fp;
|
||||
char *line, *token, *p;
|
||||
const struct toklist *t;
|
||||
struct chartbl ct;
|
||||
int c;
|
||||
size_t i;
|
||||
char *ifname, *ofname = NULL;
|
||||
int error = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "o:")) != -1)
|
||||
switch (c) {
|
||||
case 'o':
|
||||
ofname = optarg;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc - 1 != optind)
|
||||
usage();
|
||||
|
||||
ifname = argv[optind];
|
||||
|
||||
if ((fp = fopen(ifname, "r")) == NULL)
|
||||
err(1, "Cannot open `%s'", ifname);
|
||||
|
||||
ct.maxchar = 256;
|
||||
ct.ctype = malloc(sizeof(ct.ctype[0]) * (ct.maxchar + 1));
|
||||
ct.uptab = malloc(sizeof(ct.uptab[0]) * (ct.maxchar + 1));
|
||||
ct.lotab = malloc(sizeof(ct.lotab[0]) * (ct.maxchar + 1));
|
||||
ct.ctypefilename = NULL;
|
||||
ct.numericfilename = NULL;
|
||||
ct.decimal_point = '.';
|
||||
ct.thousands_sep = ',';
|
||||
|
||||
if (ct.ctype == NULL || ct.uptab == NULL || ct.lotab == NULL)
|
||||
err(1, "Out of memory");
|
||||
|
||||
(void) memset(ct.ctype, 0, sizeof(ct.ctype[0]) * (ct.maxchar * 1));
|
||||
(void) memset(ct.uptab, 0, sizeof(ct.uptab[0]) * (ct.maxchar * 1));
|
||||
(void) memset(ct.lotab, 0, sizeof(ct.lotab[0]) * (ct.maxchar * 1));
|
||||
|
||||
for (lnum = 1; (line = fparseln(fp, &size, &lnum, NULL, 0)) != NULL;
|
||||
free(line)) {
|
||||
for (token = line; *token && isspace((u_char) *token); token++)
|
||||
continue;
|
||||
if (*token == '\0')
|
||||
continue;
|
||||
for (p = token; *p && !isspace((u_char) *p); p++)
|
||||
continue;
|
||||
if (*p == '\0')
|
||||
continue;
|
||||
*p = '\0';
|
||||
for (p++; *p && isspace((u_char) *p); p++)
|
||||
continue;
|
||||
for (t = tokens; t->name != NULL; t++)
|
||||
if (strcmp(t->name, token) == 0)
|
||||
break;
|
||||
if (t->name == NULL) {
|
||||
warnx("Unknown token %s at line %lu", token,
|
||||
(u_long)lnum);
|
||||
error |= 1;
|
||||
continue;
|
||||
}
|
||||
error |= (*t->func)(&ct, token, t->arg, p, lnum);
|
||||
}
|
||||
(void) fclose(fp);
|
||||
|
||||
for (i = 1; i <= ct.maxchar; i++) {
|
||||
if (ct.uptab[i] == 0)
|
||||
ct.uptab[i] = i - 1;
|
||||
if (ct.lotab[i] == 0)
|
||||
ct.lotab[i] = i - 1;
|
||||
}
|
||||
|
||||
if (ofname != NULL)
|
||||
error |= output_ascii(ofname, &ct);
|
||||
error |= output_binary(&ct);
|
||||
return error;
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/* $NetBSD: ctypeio.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: ctypeio.c,v 1.5 2010/06/13 04:14:57 tnozaki Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "bsdctype_local.h"
|
||||
#include "ctypeio.h"
|
||||
|
||||
int
|
||||
__savectype(const char *name, unsigned char *new_ctype,
|
||||
short *new_toupper, short *new_tolower)
|
||||
{
|
||||
FILE *fp;
|
||||
uint32_t i, len = _CTYPE_CACHE_SIZE;
|
||||
|
||||
_DIAGASSERT(name != NULL);
|
||||
_DIAGASSERT(new_ctype != NULL);
|
||||
_DIAGASSERT(new_toupper != NULL);
|
||||
_DIAGASSERT(new_tolower != NULL);
|
||||
|
||||
if ((fp = fopen(name, "w")) == NULL)
|
||||
return 0;
|
||||
|
||||
if (fwrite(_CTYPE_ID, sizeof(_CTYPE_ID) - 1, 1, fp) != 1)
|
||||
goto bad;
|
||||
|
||||
i = htonl(_CTYPE_REV);
|
||||
if (fwrite(&i, sizeof(uint32_t), 1, fp) != 1)
|
||||
goto bad;
|
||||
|
||||
i = htonl(len);
|
||||
if (fwrite(&i, sizeof(uint32_t), 1, fp) != 1)
|
||||
goto bad;
|
||||
|
||||
if (fwrite(&new_ctype[1], sizeof(uint8_t), len, fp) != len)
|
||||
goto bad;
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
for (i = 1; i <= len; i++) {
|
||||
new_toupper[i] = htons(new_toupper[i]);
|
||||
new_tolower[i] = htons(new_tolower[i]);
|
||||
}
|
||||
#endif
|
||||
if (fwrite(&new_toupper[1], sizeof(int16_t), len, fp) != len)
|
||||
goto bad;
|
||||
|
||||
if (fwrite(&new_tolower[1], sizeof(int16_t), len, fp) != len)
|
||||
goto bad;
|
||||
|
||||
|
||||
(void)fclose(fp);
|
||||
return 1;
|
||||
bad:
|
||||
(void)fclose(fp);
|
||||
return 0;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/* $NetBSD: ctypeio.h,v 1.2 2009/10/21 01:07:47 snj Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
__BEGIN_DECLS
|
||||
int __savectype(const char *, unsigned char *, short *, short *);
|
||||
__END_DECLS
|
Loading…
Reference in New Issue
Block a user