obsolete mkstr(1) and xstr(1)
These were only used on PDP-11 for two programs we don't ship, and have been obsolete since the VAX days. xstr never worked in the build.sh cross-build environment (22 years), or parallel make environment (nearly 28 years), didn't work in the orignal 386bsd import, and has never been needed in NetBSD as we don't have the older BSD programs (pascal, pre-nvi ex) that needed mkstr/xstr on PDP-11. PR toolchain/35964
This commit is contained in:
parent
7a543a5f74
commit
8e5c6bed5f
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: ramdiskbin.conf,v 1.10 2017/04/12 17:29:49 christos Exp $
|
||||
# $NetBSD: ramdiskbin.conf,v 1.11 2023/05/24 13:00:14 lukem Exp $
|
||||
|
||||
srcdirs bin sbin libexec usr.bin usr.sbin
|
||||
|
||||
|
@ -39,7 +39,7 @@ progs compress crontab ctags cut dirname du env file find finger from fsplit
|
|||
progs fstat ftp gencat getopt head hexdump id
|
||||
progs indent ipcrm ipcs join jot kdump ktrace lam last lastcomm leave less
|
||||
progs lex lock logger login logname look m4 mail man menuc mesg mkdep
|
||||
progs mkfifo mkstr mktemp msgc msgs netgroup netstat newsyslog nfsstat
|
||||
progs mkfifo mktemp msgc msgs netgroup netstat newsyslog nfsstat
|
||||
progs nice nl nohup paste patch pr printenv printf quota renice rev rpcgen
|
||||
progs rpcinfo rs sed showmount shuffle skey skeyinfo skeyinit soelim
|
||||
progs su systat tail tee tftp time touch tset tsort tty uname
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: mi,v 1.2428 2023/05/12 11:13:09 riastradh Exp $
|
||||
# $NetBSD: mi,v 1.2429 2023/05/24 13:00:15 lukem Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
./etc/mtree/set.comp comp-sys-root
|
||||
|
@ -58,7 +58,7 @@
|
|||
./usr/bin/lto-dump comp-c-bin gcccmds,gcc=10
|
||||
./usr/bin/luac comp-util-bin
|
||||
./usr/bin/menuc comp-c-bin
|
||||
./usr/bin/mkstr comp-c-bin
|
||||
./usr/bin/mkstr comp-obsolete obsolete
|
||||
./usr/bin/mkubootimage comp-util-bin
|
||||
./usr/bin/msgattrib comp-c-bin
|
||||
./usr/bin/msgc comp-c-bin
|
||||
|
@ -93,7 +93,7 @@
|
|||
./usr/bin/unifdefall comp-util-bin
|
||||
./usr/bin/unprotoize comp-obsolete obsolete
|
||||
./usr/bin/xgettext comp-c-bin
|
||||
./usr/bin/xstr comp-c-bin
|
||||
./usr/bin/xstr comp-obsolete obsolete
|
||||
./usr/bin/yacc comp-c-bin
|
||||
./usr/include/a.out.h comp-c-include
|
||||
./usr/include/adosfs/adosfs.h comp-c-include
|
||||
|
@ -4613,7 +4613,7 @@
|
|||
./usr/share/man/cat1/lto-dump.0 comp-c-catman gcccmds,.cat,gcc=10
|
||||
./usr/share/man/cat1/luac.0 comp-util-catman .cat
|
||||
./usr/share/man/cat1/menuc.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/mkstr.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/mkstr.0 comp-obsolete obsolete
|
||||
./usr/share/man/cat1/msg_clear.0 comp-obsolete obsolete
|
||||
./usr/share/man/cat1/msg_display.0 comp-obsolete obsolete
|
||||
./usr/share/man/cat1/msg_display_add.0 comp-obsolete obsolete
|
||||
|
@ -4649,7 +4649,7 @@
|
|||
./usr/share/man/cat1/tsort.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/unifdef.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/unifdefall.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/xstr.0 comp-c-catman .cat
|
||||
./usr/share/man/cat1/xstr.0 comp-obsolete obsolete
|
||||
./usr/share/man/cat1/yacc.0 comp-c-catman .cat
|
||||
./usr/share/man/cat2/EV_SET.0 comp-c-catman .cat
|
||||
./usr/share/man/cat2/_Exit.0 comp-c-catman .cat
|
||||
|
@ -13119,7 +13119,7 @@
|
|||
./usr/share/man/html1/lto-dump.html comp-c-htmlman gcccmds,html,gcc=10
|
||||
./usr/share/man/html1/luac.html comp-util-htmlman html
|
||||
./usr/share/man/html1/menuc.html comp-c-htmlman html
|
||||
./usr/share/man/html1/mkstr.html comp-c-htmlman html
|
||||
./usr/share/man/html1/mkstr.html comp-obsolete obsolete
|
||||
./usr/share/man/html1/msgc.html comp-c-htmlman html
|
||||
./usr/share/man/html1/nbperf.html comp-util-htmlman html
|
||||
./usr/share/man/html1/nm.html comp-util-htmlman binutils,html
|
||||
|
@ -13144,7 +13144,7 @@
|
|||
./usr/share/man/html1/tsort.html comp-c-htmlman html
|
||||
./usr/share/man/html1/unifdef.html comp-c-htmlman html
|
||||
./usr/share/man/html1/unifdefall.html comp-c-htmlman html
|
||||
./usr/share/man/html1/xstr.html comp-c-htmlman html
|
||||
./usr/share/man/html1/xstr.html comp-obsolete obsolete
|
||||
./usr/share/man/html1/yacc.html comp-c-htmlman html
|
||||
./usr/share/man/html2/EV_SET.html comp-c-htmlman html
|
||||
./usr/share/man/html2/_Exit.html comp-c-htmlman html
|
||||
|
@ -21415,7 +21415,7 @@
|
|||
./usr/share/man/man1/lto-dump.1 comp-c-man gcccmds,.man,gcc=10
|
||||
./usr/share/man/man1/luac.1 comp-util-man .man
|
||||
./usr/share/man/man1/menuc.1 comp-c-man .man
|
||||
./usr/share/man/man1/mkstr.1 comp-c-man .man
|
||||
./usr/share/man/man1/mkstr.1 comp-obsolete obsolete
|
||||
./usr/share/man/man1/msg_clear.1 comp-obsolete obsolete
|
||||
./usr/share/man/man1/msg_display.1 comp-obsolete obsolete
|
||||
./usr/share/man/man1/msg_display_add.1 comp-obsolete obsolete
|
||||
|
@ -21452,7 +21452,7 @@
|
|||
./usr/share/man/man1/tsort.1 comp-util-man .man
|
||||
./usr/share/man/man1/unifdef.1 comp-util-man .man
|
||||
./usr/share/man/man1/unifdefall.1 comp-util-man .man
|
||||
./usr/share/man/man1/xstr.1 comp-c-man .man
|
||||
./usr/share/man/man1/xstr.1 comp-obsolete obsolete
|
||||
./usr/share/man/man1/yacc.1 comp-c-man .man
|
||||
./usr/share/man/man2/EV_SET.2 comp-c-man .man
|
||||
./usr/share/man/man2/_Exit.2 comp-c-man .man
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: mi,v 1.398 2023/05/10 15:52:07 christos Exp $
|
||||
# $NetBSD: mi,v 1.399 2023/05/24 13:00:15 lukem Exp $
|
||||
./etc/mtree/set.debug comp-sys-root
|
||||
./usr/lib comp-sys-usr compatdir
|
||||
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
|
||||
|
@ -689,7 +689,7 @@
|
|||
./usr/libdata/debug/usr/bin/mkesdb.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/mkfifo.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/mklocale.debug comp-locale-debug debug
|
||||
./usr/libdata/debug/usr/bin/mkstr.debug comp-c-debug debug
|
||||
./usr/libdata/debug/usr/bin/mkstr.debug comp-obsolete obsolete
|
||||
./usr/libdata/debug/usr/bin/mktemp.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/mkubootimage.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/modstat.debug comp-obsolete obsolete
|
||||
|
@ -896,7 +896,7 @@
|
|||
./usr/libdata/debug/usr/bin/xargs.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/xgettext.debug comp-c-debug debug
|
||||
./usr/libdata/debug/usr/bin/xmlwf.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/xstr.debug comp-c-debug debug
|
||||
./usr/libdata/debug/usr/bin/xstr.debug comp-obsolete obsolete
|
||||
./usr/libdata/debug/usr/bin/xz.debug comp-util-debug debug
|
||||
./usr/libdata/debug/usr/bin/yacc.debug comp-c-debug debug
|
||||
./usr/libdata/debug/usr/bin/yes.debug comp-util-debug debug
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.238 2022/06/06 10:56:29 nia Exp $
|
||||
# $NetBSD: Makefile,v 1.239 2023/05/24 13:00:15 lukem Exp $
|
||||
# from: @(#)Makefile 8.3 (Berkeley) 1/7/94
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
@ -17,7 +17,7 @@ SUBDIR= aiomixer apply asa at audio audiocfg \
|
|||
kdump ktrace ktruss lam last lastcomm ldd leave \
|
||||
locale locate lock logger login logname look lorder m4 \
|
||||
machine mail make man menuc mesg midiplay midirecord mixerctl \
|
||||
mkcsmapper mkdep mkesdb mkfifo mklocale mkstr mktemp mkubootimage \
|
||||
mkcsmapper mkdep mkesdb mkfifo mklocale mktemp mkubootimage \
|
||||
moduli msgc msgs \
|
||||
nbperf nc netgroup netstat newgrp newsyslog nfsstat nice nl nohup \
|
||||
pagesize passwd paste patch pathchk pkill pmap pr \
|
||||
|
@ -34,7 +34,7 @@ SUBDIR= aiomixer apply asa at audio audiocfg \
|
|||
uudecode uuencode uuidgen vacation vgrind videoctl vis \
|
||||
vmstat vndcompress w \
|
||||
wall wc what whereis who whois \
|
||||
write xargs xinstall xlint xstr yes
|
||||
write xargs xinstall xlint yes
|
||||
|
||||
SUBDIR+= ../external/zlib/pigz/bin/pigz
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: really-big.conf,v 1.5 2012/04/21 12:27:29 roy Exp $
|
||||
# $NetBSD: really-big.conf,v 1.6 2023/05/24 13:00:15 lukem Exp $
|
||||
#
|
||||
# really-big.conf - just about everything, just for testing.
|
||||
# This ends up having some good examples of the use of specials for
|
||||
|
@ -43,14 +43,14 @@ progs dirname du env error expand false file find finger fmt fold fpr from
|
|||
progs fsplit fstat ftp getconf getopt gprof head hexdump id indent ipcrm
|
||||
progs ipcs join kdump ktrace last lastcomm leave lex lock logger locate
|
||||
progs login logname look m4 machine mail make man mesg mkfifo
|
||||
progs mkstr modstat more msgs netstat newsyslog nfsstat nice nm nohup
|
||||
progs modstat more msgs netstat newsyslog nfsstat nice nm nohup
|
||||
progs pagesize passwd paste patch pr printenv printf quota ranlib
|
||||
progs renice rev rlogin rpcgen rpcinfo rsh rup ruptime rusers rwall rwho
|
||||
progs script sed showmount size soelim split strings strip su tail talk
|
||||
progs tcopy tee telnet tftp time tip tn3270 touch tput tr true tset tsort
|
||||
progs tty ul uname unexpand unifdef uniq units unvis users uudecode uuencode
|
||||
progs vacation vgrind vi vis vmstat w wall wc what whatis whereis who
|
||||
progs whois window write xargs xinstall xstr yacc yes ypcat ypmatch ypwhich
|
||||
progs whois window write xargs xinstall yacc yes ypcat ypmatch ypwhich
|
||||
|
||||
# shell scripts: lorder mkdep shar which
|
||||
# problems: rdist uses libcompat.a(regex.o), which conflicts with
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.3 1995/09/28 06:22:18 tls Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= mkstr
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -1,131 +0,0 @@
|
|||
.\" $NetBSD: mkstr.1,v 1.14 2022/08/28 10:48:16 hgutch Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. 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.
|
||||
.\"
|
||||
.\" @(#)mkstr.1 8.1 (Berkeley) 6/6/93
|
||||
.\"
|
||||
.Dd June 6, 1993
|
||||
.Dt MKSTR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm mkstr
|
||||
.Nd create an error message file by massaging C source
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl
|
||||
.Ar messagefile
|
||||
.Ar prefix file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
creates files containing error messages extracted from C source,
|
||||
and restructures the same C source, to use the created error message
|
||||
file.
|
||||
The intent of
|
||||
.Nm
|
||||
was to reduce the size of large programs and
|
||||
reduce swapping (see
|
||||
.Sx BUGS
|
||||
section below).
|
||||
.Pp
|
||||
.Nm
|
||||
processes each of the specified
|
||||
.Ar files ,
|
||||
placing a restructured version of the input in a file whose name
|
||||
consists of the specified
|
||||
.Ar prefix
|
||||
and the original name.
|
||||
A typical usage of
|
||||
.Nm
|
||||
is
|
||||
.Bd -literal -offset indent
|
||||
mkstr pistrings xx *.c
|
||||
.Ed
|
||||
.Pp
|
||||
This command causes all the error messages from the C source
|
||||
files in the current directory to be placed in the file
|
||||
.Ar pistrings
|
||||
and restructured copies of the sources to be placed in
|
||||
files whose names are prefixed with
|
||||
.Ar \&xx .
|
||||
.Pp
|
||||
Options:
|
||||
.Bl -tag -width indent
|
||||
.It Fl
|
||||
Error messages are placed at the end of the specified
|
||||
message file for recompiling part of a large
|
||||
.Nm
|
||||
ed
|
||||
program.
|
||||
.El
|
||||
.Pp
|
||||
.Nm
|
||||
finds error messages in the source by
|
||||
searching for the string
|
||||
.Li \&`error("'
|
||||
in the input stream.
|
||||
Each time it occurs, the C string starting at the
|
||||
.Sq \&"\&
|
||||
is stored
|
||||
in the message file followed by a null character and a new-line character;
|
||||
The new source is restructured with
|
||||
.Xr lseek 2
|
||||
pointers into the error message file for retrieval.
|
||||
.Bd -literal -offset indent
|
||||
char efilname = "/usr/lib/pi_strings";
|
||||
int efil = -1;
|
||||
|
||||
error(a1, a2, a3, a4)
|
||||
\&{
|
||||
char buf[256];
|
||||
|
||||
if (efil < 0) {
|
||||
efil = open(efilname, 0);
|
||||
if (efil < 0) {
|
||||
oops:
|
||||
perror(efilname);
|
||||
exit 1 ;
|
||||
}
|
||||
}
|
||||
if (lseek(efil, a1, 0) < 0 || read(efil, buf, 256) <= 0)
|
||||
goto oops;
|
||||
printf(buf, a2, a3, a4);
|
||||
}
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr xstr 1 ,
|
||||
.Xr lseek 2
|
||||
.Sh HISTORY
|
||||
.Nm
|
||||
appeared in
|
||||
.Bx 1 .
|
||||
.Sh BUGS
|
||||
.Nm
|
||||
was intended for the limited architecture of the PDP-11 family.
|
||||
Very few programs actually use it.
|
||||
It is not an efficient method, the error messages
|
||||
should be stored in the program text.
|
|
@ -1,320 +0,0 @@
|
|||
/* $NetBSD: mkstr.c,v 1.17 2016/09/05 00:40:29 sevan Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: mkstr.c,v 1.17 2016/09/05 00:40:29 sevan Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ungetchar(c) ungetc(c, stdin)
|
||||
|
||||
/*
|
||||
* mkstr - create a string error message file by massaging C source
|
||||
*
|
||||
* Bill Joy UCB August 1977
|
||||
*
|
||||
* Modified March 1978 to hash old messages to be able to recompile
|
||||
* without addding messages to the message file (usually)
|
||||
*
|
||||
* Based on an earlier program conceived by Bill Joy and Chuck Haley
|
||||
*
|
||||
* Program to create a string error message file
|
||||
* from a group of C programs. Arguments are the name
|
||||
* of the file where the strings are to be placed, the
|
||||
* prefix of the new files where the processed source text
|
||||
* is to be placed, and the files to be processed.
|
||||
*
|
||||
* The program looks for 'error("' in the source stream.
|
||||
* Whenever it finds this, the following characters from the '"'
|
||||
* to a '"' are replaced by 'seekpt' where seekpt is a
|
||||
* pointer into the error message file.
|
||||
* If the '(' is not immediately followed by a '"' no change occurs.
|
||||
*
|
||||
* The optional '-' causes strings to be added at the end of the
|
||||
* existing error message file for recompilation of single routines.
|
||||
*/
|
||||
|
||||
|
||||
FILE *mesgread, *mesgwrite;
|
||||
char *progname;
|
||||
const char usagestr[] = "usage: %s [ - ] mesgfile prefix file ...\n";
|
||||
char name[100], *np;
|
||||
|
||||
void process(void);
|
||||
int match(const char *);
|
||||
int octdigit(char);
|
||||
void inithash(void);
|
||||
long hashit(const char *, char, long);
|
||||
void copystr(void);
|
||||
int fgetNUL(char *, int, FILE *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char addon = 0;
|
||||
|
||||
argc--, progname = *argv++;
|
||||
if (argc > 1 && argv[0][0] == '-')
|
||||
addon++, argc--, argv++;
|
||||
if (argc < 3)
|
||||
fprintf(stderr, usagestr, progname), exit(1);
|
||||
mesgwrite = fopen(argv[0], addon ? "a" : "w");
|
||||
if (mesgwrite == NULL)
|
||||
perror(argv[0]), exit(1);
|
||||
mesgread = fopen(argv[0], "r");
|
||||
if (mesgread == NULL)
|
||||
perror(argv[0]), exit(1);
|
||||
inithash();
|
||||
argc--, argv++;
|
||||
strlcpy(name, argv[0], sizeof(name));
|
||||
np = name + strlen(name);
|
||||
argc--, argv++;
|
||||
do {
|
||||
strlcpy(np, argv[0], sizeof(name) - (np - name));
|
||||
if (freopen(name, "w", stdout) == NULL)
|
||||
perror(name), exit(1);
|
||||
if (freopen(argv[0], "r", stdin) == NULL)
|
||||
perror(argv[0]), exit(1);
|
||||
process();
|
||||
argc--, argv++;
|
||||
} while (argc > 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
process(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
for (;;) {
|
||||
c = getchar();
|
||||
if (c == EOF)
|
||||
return;
|
||||
if (c != 'e') {
|
||||
putchar(c);
|
||||
continue;
|
||||
}
|
||||
if (match("error(")) {
|
||||
printf("error(");
|
||||
c = getchar();
|
||||
if (c != '"')
|
||||
putchar(c);
|
||||
else
|
||||
copystr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
match(const char *ocp)
|
||||
{
|
||||
const char *cp;
|
||||
int c;
|
||||
|
||||
for (cp = ocp + 1; *cp; cp++) {
|
||||
c = getchar();
|
||||
if (c != *cp) {
|
||||
while (ocp < cp)
|
||||
putchar(*ocp++);
|
||||
ungetchar(c);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
copystr(void)
|
||||
{
|
||||
int c, ch;
|
||||
char buf[512];
|
||||
char *cp = buf;
|
||||
|
||||
for (;;) {
|
||||
c = getchar();
|
||||
if (c == EOF)
|
||||
break;
|
||||
switch (c) {
|
||||
|
||||
case '"':
|
||||
*cp++ = 0;
|
||||
goto out;
|
||||
case '\\':
|
||||
c = getchar();
|
||||
switch (c) {
|
||||
|
||||
case 'b':
|
||||
c = '\b';
|
||||
break;
|
||||
case 't':
|
||||
c = '\t';
|
||||
break;
|
||||
case 'r':
|
||||
c = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
c = '\n';
|
||||
break;
|
||||
case '\n':
|
||||
continue;
|
||||
case 'f':
|
||||
c = '\f';
|
||||
break;
|
||||
case '0':
|
||||
c = 0;
|
||||
break;
|
||||
case '\\':
|
||||
break;
|
||||
default:
|
||||
if (!octdigit(c))
|
||||
break;
|
||||
c -= '0';
|
||||
ch = getchar();
|
||||
if (!octdigit(ch))
|
||||
break;
|
||||
c <<= 7, c += ch - '0';
|
||||
ch = getchar();
|
||||
if (!octdigit(ch))
|
||||
break;
|
||||
c <<= 3, c+= ch - '0', ch = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*cp++ = c;
|
||||
}
|
||||
out:
|
||||
*cp = 0;
|
||||
printf("%ld", hashit(buf, 1, 0));
|
||||
}
|
||||
|
||||
int
|
||||
octdigit(char c)
|
||||
{
|
||||
|
||||
return (c >= '0' && c <= '7');
|
||||
}
|
||||
|
||||
void
|
||||
inithash(void)
|
||||
{
|
||||
char buf[512];
|
||||
long mesgpt = 0;
|
||||
|
||||
rewind(mesgread);
|
||||
while (fgetNUL(buf, sizeof buf, mesgread) != 0) {
|
||||
hashit(buf, 0, mesgpt);
|
||||
mesgpt += strlen(buf) + 2;
|
||||
}
|
||||
}
|
||||
|
||||
#define NBUCKETS 511
|
||||
|
||||
struct hash {
|
||||
long hval;
|
||||
long hpt;
|
||||
struct hash *hnext;
|
||||
} *bucket[NBUCKETS];
|
||||
|
||||
long
|
||||
hashit(const char *str, char really, long fakept)
|
||||
{
|
||||
int i;
|
||||
struct hash *hp;
|
||||
char buf[512];
|
||||
long hashval = 0;
|
||||
const char *cp;
|
||||
|
||||
#ifdef __GNUC__
|
||||
hp = NULL; /* XXX gcc */
|
||||
#endif
|
||||
if (really)
|
||||
fflush(mesgwrite);
|
||||
for (cp = str; *cp;)
|
||||
hashval = (hashval << 1) + *cp++;
|
||||
i = hashval % NBUCKETS;
|
||||
if (i < 0)
|
||||
i += NBUCKETS;
|
||||
if (really != 0)
|
||||
for (hp = bucket[i]; hp != 0; hp = hp->hnext)
|
||||
if (hp->hval == hashval) {
|
||||
fseek(mesgread, hp->hpt, 0);
|
||||
fgetNUL(buf, sizeof buf, mesgread);
|
||||
/*
|
||||
fprintf(stderr, "Got (from %ld) %s\n", hp->hpt, buf);
|
||||
*/
|
||||
if (strcmp(buf, str) == 0)
|
||||
break;
|
||||
}
|
||||
if (!really || hp == 0) {
|
||||
hp = (struct hash *) calloc(1, sizeof *hp);
|
||||
hp->hnext = bucket[i];
|
||||
hp->hval = hashval;
|
||||
hp->hpt = really ? ftell(mesgwrite) : fakept;
|
||||
if (really) {
|
||||
fwrite(str, sizeof (char), strlen(str) + 1, mesgwrite);
|
||||
fwrite("\n", sizeof (char), 1, mesgwrite);
|
||||
}
|
||||
bucket[i] = hp;
|
||||
}
|
||||
/*
|
||||
fprintf(stderr, "%s hashed to %ld at %ld\n", str, hp->hval, hp->hpt);
|
||||
*/
|
||||
return (hp->hpt);
|
||||
}
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
fgetNUL(char *obuf, int rmdr, FILE *file)
|
||||
{
|
||||
int c;
|
||||
char *buf = obuf;
|
||||
|
||||
while (--rmdr > 0 && (c = getc(file)) != 0 && c != EOF)
|
||||
*buf++ = c;
|
||||
*buf++ = 0;
|
||||
getc(file);
|
||||
return ((feof(file) || ferror(file)) ? 0 : 1);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
# $NetBSD: Makefile,v 1.3 1994/11/14 04:56:21 jtc Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/9/93
|
||||
|
||||
PROG= xstr
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -1,35 +0,0 @@
|
|||
/* $NetBSD: pathnames.h,v 1.4 2003/08/07 11:17:51 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. 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.
|
||||
*
|
||||
* @(#)pathnames.h 8.1 (Berkeley) 6/9/93
|
||||
* $NetBSD: pathnames.h,v 1.4 2003/08/07 11:17:51 agc Exp $
|
||||
*/
|
||||
|
||||
#define _PATH_TMP "/tmp/xstrXXXXXX"
|
|
@ -1,210 +0,0 @@
|
|||
.\" $NetBSD: xstr.1,v 1.20 2019/01/13 16:48:51 uwe Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. 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.
|
||||
.\" 3. 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.
|
||||
.\"
|
||||
.\" @(#)xstr.1 8.2 (Berkeley) 12/30/93
|
||||
.\"
|
||||
.Dd July 23, 2004
|
||||
.Dt XSTR 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm xstr
|
||||
.Nd "extract strings from C programs to implement shared strings"
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl cv
|
||||
.Op Fl l Ar array
|
||||
.Op Fl
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
maintains a file
|
||||
.Pa strings
|
||||
into which strings in component parts of a large program are hashed.
|
||||
These strings are replaced with references to this common area.
|
||||
This serves to implement shared constant strings, most useful if they
|
||||
are also read-only.
|
||||
.Pp
|
||||
Available options:
|
||||
.Bl -tag -width XXlXarrayXX
|
||||
.It Fl
|
||||
.Nm
|
||||
reads from the standard input.
|
||||
.It Fl c
|
||||
.Nm
|
||||
will extract the strings from the C source
|
||||
.Ar file
|
||||
or the standard input
|
||||
.Pq Fl ,
|
||||
replacing
|
||||
string references by expressions of the form (&xstr[number])
|
||||
for some number.
|
||||
An appropriate declaration of
|
||||
.Nm
|
||||
is prepended to the file.
|
||||
The resulting C text is placed in the file
|
||||
.Pa x.c ,
|
||||
to then be compiled.
|
||||
The strings from this file are placed in the
|
||||
.Pa strings
|
||||
data base if they are not there already.
|
||||
Repeated strings and strings which are suffixes of existing strings
|
||||
do not cause changes to the data base.
|
||||
.It Fl l Ar array
|
||||
Specify the named array in program references to abstracted
|
||||
strings.
|
||||
The default array name is xstr.
|
||||
.It Fl v
|
||||
Be verbose.
|
||||
.El
|
||||
.Pp
|
||||
After all components of a large program have been compiled, a file
|
||||
.Pa xs.c
|
||||
declaring the common
|
||||
.Nm
|
||||
space can be created by a command of the form:
|
||||
.Pp
|
||||
.Dl $ xstr
|
||||
.Pp
|
||||
The file
|
||||
.Pa xs.c
|
||||
should then be compiled and loaded with the rest
|
||||
of the program.
|
||||
If possible, the array can be made read-only (shared) saving
|
||||
space and swap overhead.
|
||||
.Pp
|
||||
.Nm
|
||||
can also be used on a single file.
|
||||
The following command creates files
|
||||
.Pa x.c
|
||||
and
|
||||
.Pa xs.c
|
||||
as before, without using or affecting any
|
||||
.Pa strings
|
||||
file in the same directory:
|
||||
.Pp
|
||||
.Dl $ xstr name
|
||||
.Pp
|
||||
It may be useful to run
|
||||
.Nm
|
||||
after the C preprocessor if any macro definitions yield strings
|
||||
or if there is conditional code which contains strings
|
||||
which may not, in fact, be needed.
|
||||
An appropriate command sequence for running
|
||||
.Nm
|
||||
after the C preprocessor is:
|
||||
.Bd -literal -offset indent
|
||||
$ cc \-E name.c | xstr \-c \-
|
||||
$ cc \-c x.c
|
||||
$ mv x.o name.o
|
||||
.Ed
|
||||
.Pp
|
||||
.Nm
|
||||
does not touch the file
|
||||
.Pa strings
|
||||
unless new items are added, thus
|
||||
.Xr make 1
|
||||
can avoid remaking
|
||||
.Pa xs.o
|
||||
unless truly necessary.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /tmp/xsxx* -compact
|
||||
.It Pa strings
|
||||
Data base of strings
|
||||
.It Pa x.c
|
||||
Massaged C source
|
||||
.It Pa xs.c
|
||||
C source for definition of array `xstr'
|
||||
.It Pa /tmp/xs*
|
||||
Temp file when `xstr name' doesn't touch
|
||||
.Pa strings
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr mkstr 1
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Bx 3.0 .
|
||||
.Sh BUGS
|
||||
If a string is a suffix of another string in the data base,
|
||||
but the shorter string is seen first by
|
||||
.Nm
|
||||
both strings will be placed in the data base, when just
|
||||
placing the longer one there will do.
|
||||
.Pp
|
||||
.Nm
|
||||
does not parse the file properly so it does not know not to process:
|
||||
.Bd -literal
|
||||
char var[] = "const";
|
||||
.Ed
|
||||
into:
|
||||
.Bd -literal
|
||||
char var[] = (&xstr[N]);
|
||||
.Ed
|
||||
.Pp
|
||||
These must be changed manually into an appropriate initialization for
|
||||
the string, or use the following ugly hack.
|
||||
.Pp
|
||||
Also,
|
||||
.Nm
|
||||
cannot initialize structures and unions that contain strings.
|
||||
Those can be fixed by changing from:
|
||||
.Bd -literal
|
||||
struct foo {
|
||||
int i;
|
||||
char buf[10];
|
||||
} = {
|
||||
1, "foo"
|
||||
};
|
||||
.Ed
|
||||
to:
|
||||
.Bd -literal
|
||||
struct foo {
|
||||
int i;
|
||||
char buf[10];
|
||||
} = {
|
||||
1, { 'f', 'o', 'o', '\e0' }
|
||||
};
|
||||
.Ed
|
||||
.Pp
|
||||
The real problem in both cases above is that the compiler knows the size
|
||||
of the literal constant so that it can perform the initialization required,
|
||||
but when
|
||||
.Nm
|
||||
changes the literal string to a pointer reference, the size information is
|
||||
lost.
|
||||
It would require a real parser to do this right, so the obvious solution is
|
||||
to fix the program manually to compile, or even better rely on the compiler
|
||||
and the linker to merge strings appropriately.
|
||||
.Pp
|
||||
Finally,
|
||||
.Nm
|
||||
is not very useful these days because most of the string merging is done
|
||||
automatically by the compiler and the linker, provided that the strings
|
||||
are identical and read-only.
|
|
@ -1,569 +0,0 @@
|
|||
/* $NetBSD: xstr.c,v 1.26 2016/03/11 18:39:03 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1980, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 3. 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
|
||||
The Regents of the University of California. All rights reserved.");
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)xstr.c 8.1 (Berkeley) 6/9/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: xstr.c,v 1.26 2016/03/11 18:39:03 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include "pathnames.h"
|
||||
|
||||
/*
|
||||
* xstr - extract and hash strings in a C program
|
||||
*
|
||||
* Bill Joy UCB
|
||||
* November, 1978
|
||||
*/
|
||||
|
||||
static off_t hashit(const char *, int);
|
||||
__dead static void onintr(int);
|
||||
static off_t yankstr(char **);
|
||||
static int octdigit(char);
|
||||
static void inithash(void);
|
||||
static int fgetNUL(char *, int, FILE *);
|
||||
static int xgetc(FILE *);
|
||||
static void flushsh(void);
|
||||
static void found(int, off_t, const char *);
|
||||
static void prstr(const char *);
|
||||
static void xsdotc(void);
|
||||
static char lastchr(const char *);
|
||||
static int istail(const char *, const char *);
|
||||
static void process(const char *);
|
||||
__dead static void usage(void);
|
||||
|
||||
static off_t tellpt;
|
||||
static off_t mesgpt;
|
||||
static char stringtmpfile[MAXPATHLEN];
|
||||
static const char *strings = "strings";
|
||||
static const char *array = 0;
|
||||
static int cflg;
|
||||
static int vflg;
|
||||
static int readstd;
|
||||
static char linebuf[8192];
|
||||
|
||||
#define BUCKETS 128
|
||||
|
||||
static struct hash {
|
||||
off_t hpt;
|
||||
char *hstr;
|
||||
struct hash *hnext;
|
||||
short hnew;
|
||||
} bucket[BUCKETS];
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "-cvl:")) != -1)
|
||||
switch (c) {
|
||||
case '-':
|
||||
readstd++;
|
||||
break;
|
||||
case 'c':
|
||||
cflg++;
|
||||
break;
|
||||
case 'v':
|
||||
vflg++;
|
||||
break;
|
||||
case 'l':
|
||||
array = optarg;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (array == 0)
|
||||
array = "xstr";
|
||||
|
||||
if (signal(SIGINT, SIG_IGN) == SIG_DFL)
|
||||
(void)signal(SIGINT, onintr);
|
||||
if (cflg || (argc == 0 && !readstd))
|
||||
inithash();
|
||||
else {
|
||||
int fd;
|
||||
|
||||
snprintf(stringtmpfile, sizeof(stringtmpfile),
|
||||
"%s%s.XXXXXX", _PATH_TMP, "xstr");
|
||||
strings = stringtmpfile;
|
||||
fd = mkstemp(stringtmpfile);
|
||||
if (fd == -1)
|
||||
err(1, "mkstemp failed");
|
||||
close(fd);
|
||||
}
|
||||
while (readstd || argc > 0) {
|
||||
if (freopen("x.c", "w", stdout) == NULL)
|
||||
err(1, "Cannot open `%s'", "x.c");
|
||||
if (!readstd && freopen(argv[0], "r", stdin) == NULL)
|
||||
err(1, "Cannot open `%s'", argv[0]);
|
||||
process("x.c");
|
||||
if (readstd == 0)
|
||||
argc--, argv++;
|
||||
else
|
||||
readstd = 0;
|
||||
};
|
||||
flushsh();
|
||||
if (cflg == 0)
|
||||
xsdotc();
|
||||
if (strings[0] == '/')
|
||||
(void)unlink(strings);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
process(const char *name)
|
||||
{
|
||||
char *cp;
|
||||
int c;
|
||||
int incomm = 0;
|
||||
int inasm = 0;
|
||||
int asmparnest = 0;
|
||||
int ret;
|
||||
|
||||
printf("extern char\t%s[];\n", array);
|
||||
for (;;) {
|
||||
if (fgets(linebuf, sizeof linebuf, stdin) == NULL) {
|
||||
if (ferror(stdin))
|
||||
err(1, "Error reading `%s'", name);
|
||||
break;
|
||||
}
|
||||
if (linebuf[0] == '#') {
|
||||
printf("%s", linebuf);
|
||||
continue;
|
||||
}
|
||||
for (cp = linebuf; (c = *cp++);)
|
||||
switch (c) {
|
||||
|
||||
case '"':
|
||||
if (incomm || inasm)
|
||||
goto def;
|
||||
if ((ret = (int) yankstr(&cp)) == -1)
|
||||
goto out;
|
||||
printf("(&%s[%d])", array, ret);
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
if (incomm || inasm)
|
||||
goto def;
|
||||
putchar(c);
|
||||
if (*cp)
|
||||
putchar(*cp++);
|
||||
break;
|
||||
|
||||
case '/':
|
||||
if (incomm || *cp != '*')
|
||||
goto def;
|
||||
incomm = 1;
|
||||
cp++;
|
||||
printf("/*");
|
||||
continue;
|
||||
|
||||
case '*':
|
||||
if (incomm && *cp == '/') {
|
||||
incomm = 0;
|
||||
cp++;
|
||||
printf("*/");
|
||||
continue;
|
||||
}
|
||||
goto def;
|
||||
|
||||
case '(':
|
||||
if (!incomm && inasm)
|
||||
asmparnest++;
|
||||
goto def;
|
||||
|
||||
case ')':
|
||||
if (!incomm && inasm && !--asmparnest)
|
||||
inasm = 0;
|
||||
goto def;
|
||||
|
||||
case '_':
|
||||
if (incomm || inasm)
|
||||
goto def;
|
||||
if (!strncmp(cp, "_asm", 4)) {
|
||||
cp += 4;
|
||||
printf("__asm");
|
||||
if (!strncmp(cp, "__", 2)) {
|
||||
cp += 2;
|
||||
printf("__");
|
||||
}
|
||||
if (isalnum((unsigned char)*cp) ||
|
||||
*cp == '_')
|
||||
goto def;
|
||||
asmparnest = 0;
|
||||
inasm = 1;
|
||||
} else
|
||||
goto def;
|
||||
break;
|
||||
def:
|
||||
default:
|
||||
putchar(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (ferror(stdout)) {
|
||||
warn("Error reading `%s'", "x.c");
|
||||
onintr(1);
|
||||
}
|
||||
}
|
||||
|
||||
static off_t
|
||||
yankstr(char **cpp)
|
||||
{
|
||||
char *cp = *cpp;
|
||||
int c, ch;
|
||||
char *dbuf, *dp, *edp;
|
||||
const char *tp;
|
||||
off_t hash;
|
||||
size_t bsiz = BUFSIZ;
|
||||
|
||||
if ((dp = dbuf = malloc(bsiz)) == NULL)
|
||||
err(1, "malloc");
|
||||
edp = dbuf + bsiz;
|
||||
|
||||
while ((c = *cp++) != '\0') {
|
||||
switch (c) {
|
||||
|
||||
case '"':
|
||||
/* Look for a concatenated string */
|
||||
for (;;) {
|
||||
while (isspace((unsigned char)*cp))
|
||||
cp++;
|
||||
if (*cp == '\0') {
|
||||
if (fgets(linebuf,
|
||||
sizeof linebuf, stdin) == NULL) {
|
||||
if (ferror(stdin))
|
||||
err(1,
|
||||
"Error reading `x.c'");
|
||||
goto out;
|
||||
}
|
||||
cp = linebuf;
|
||||
} else {
|
||||
if (*cp == '"') {
|
||||
cp++;
|
||||
if (*cp == '"') {
|
||||
cp++;
|
||||
continue;
|
||||
} else {
|
||||
c = *cp++;
|
||||
goto gotc;
|
||||
}
|
||||
} else {
|
||||
cp++;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
case '\\':
|
||||
c = *cp++;
|
||||
if (c == 0)
|
||||
break;
|
||||
if (c == '\n') {
|
||||
if (fgets(linebuf, sizeof linebuf, stdin)
|
||||
== NULL) {
|
||||
if (ferror(stdin))
|
||||
err(1, "Error reading `x.c'");
|
||||
return(-1);
|
||||
}
|
||||
cp = linebuf;
|
||||
continue;
|
||||
}
|
||||
for (tp = "b\bt\tr\rn\nf\f\\\\\"\""; (ch = *tp++); tp++)
|
||||
if (c == ch) {
|
||||
c = *tp;
|
||||
goto gotc;
|
||||
}
|
||||
if (!octdigit(c)) {
|
||||
*dp++ = '\\';
|
||||
break;
|
||||
}
|
||||
c -= '0';
|
||||
if (!octdigit(*cp))
|
||||
break;
|
||||
c <<= 3, c += *cp++ - '0';
|
||||
if (!octdigit(*cp))
|
||||
break;
|
||||
c <<= 3, c += *cp++ - '0';
|
||||
break;
|
||||
}
|
||||
gotc:
|
||||
if (dp >= edp - 1) {
|
||||
char *nbuf;
|
||||
bsiz += BUFSIZ;
|
||||
if ((nbuf = realloc(dbuf, bsiz)) == NULL) {
|
||||
free(dbuf);
|
||||
err(1, "realloc");
|
||||
}
|
||||
dp = nbuf + (dp - dbuf);
|
||||
edp = nbuf + bsiz;
|
||||
dbuf = nbuf;
|
||||
}
|
||||
*dp++ = c;
|
||||
}
|
||||
out:
|
||||
*cpp = --cp;
|
||||
*dp = '\0';
|
||||
hash = hashit(dbuf, 1);
|
||||
free(dbuf);
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int
|
||||
octdigit(char c)
|
||||
{
|
||||
|
||||
return (isdigit((unsigned char)c) && c != '8' && c != '9');
|
||||
}
|
||||
|
||||
static void
|
||||
inithash(void)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
FILE *mesgread = fopen(strings, "r");
|
||||
|
||||
if (mesgread == NULL)
|
||||
return;
|
||||
for (;;) {
|
||||
mesgpt = tellpt;
|
||||
if (fgetNUL(buf, sizeof buf, mesgread) == 0)
|
||||
break;
|
||||
(void)hashit(buf, 0);
|
||||
}
|
||||
(void)fclose(mesgread);
|
||||
}
|
||||
|
||||
static int
|
||||
fgetNUL(char *obuf, int rmdr, FILE *file)
|
||||
{
|
||||
int c;
|
||||
char *buf = obuf;
|
||||
|
||||
c = 0; /* XXXGCC -Wuninitialized */
|
||||
|
||||
while (--rmdr > 0 && (c = xgetc(file)) != 0 && c != EOF)
|
||||
*buf++ = c;
|
||||
*buf++ = 0;
|
||||
return (feof(file) || ferror(file)) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int
|
||||
xgetc(FILE *file)
|
||||
{
|
||||
|
||||
tellpt++;
|
||||
return getc(file);
|
||||
}
|
||||
|
||||
|
||||
static off_t
|
||||
hashit(const char *str, int new)
|
||||
{
|
||||
int i;
|
||||
struct hash *hp, *hp0;
|
||||
|
||||
hp = hp0 = &bucket[lastchr(str) & 0177];
|
||||
while (hp->hnext) {
|
||||
hp = hp->hnext;
|
||||
i = istail(str, hp->hstr);
|
||||
if (i >= 0)
|
||||
return (hp->hpt + i);
|
||||
}
|
||||
if ((hp = calloc(1, sizeof (*hp))) == NULL)
|
||||
err(1, NULL);
|
||||
hp->hpt = mesgpt;
|
||||
if ((hp->hstr = strdup(str)) == NULL)
|
||||
err(1, NULL);
|
||||
mesgpt += strlen(hp->hstr) + 1;
|
||||
hp->hnext = hp0->hnext;
|
||||
hp->hnew = new;
|
||||
hp0->hnext = hp;
|
||||
return (hp->hpt);
|
||||
}
|
||||
|
||||
static void
|
||||
flushsh(void)
|
||||
{
|
||||
int i;
|
||||
struct hash *hp;
|
||||
FILE *mesgwrit;
|
||||
int old = 0, new = 0;
|
||||
|
||||
for (i = 0; i < BUCKETS; i++)
|
||||
for (hp = bucket[i].hnext; hp != NULL; hp = hp->hnext)
|
||||
if (hp->hnew)
|
||||
new++;
|
||||
else
|
||||
old++;
|
||||
if (new == 0 && old != 0)
|
||||
return;
|
||||
mesgwrit = fopen(strings, old ? "r+" : "w");
|
||||
if (mesgwrit == NULL)
|
||||
err(1, "Cannot open `%s'", strings);
|
||||
for (i = 0; i < BUCKETS; i++)
|
||||
for (hp = bucket[i].hnext; hp != NULL; hp = hp->hnext) {
|
||||
found(hp->hnew, hp->hpt, hp->hstr);
|
||||
if (hp->hnew) {
|
||||
(void)fseek(mesgwrit, hp->hpt, 0);
|
||||
(void)fwrite(hp->hstr, strlen(hp->hstr) + 1, 1,
|
||||
mesgwrit);
|
||||
if (ferror(mesgwrit))
|
||||
err(1, "Error writing `%s'", strings);
|
||||
}
|
||||
}
|
||||
if (fclose(mesgwrit) == EOF)
|
||||
err(1, "Error closing `%s'", strings);
|
||||
}
|
||||
|
||||
static void
|
||||
found(int new, off_t off, const char *str)
|
||||
{
|
||||
if (vflg == 0)
|
||||
return;
|
||||
if (!new)
|
||||
(void)fprintf(stderr, "found at %d:", (int) off);
|
||||
else
|
||||
(void)fprintf(stderr, "new at %d:", (int) off);
|
||||
prstr(str);
|
||||
(void)fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static void
|
||||
prstr(const char *cp)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = (*cp++ & 0377)) != '\0')
|
||||
if (c < ' ')
|
||||
(void)fprintf(stderr, "^%c", c + '`');
|
||||
else if (c == 0177)
|
||||
(void)fprintf(stderr, "^?");
|
||||
else if (c > 0200)
|
||||
(void)fprintf(stderr, "\\%03o", c);
|
||||
else
|
||||
(void)fprintf(stderr, "%c", c);
|
||||
}
|
||||
|
||||
static void
|
||||
xsdotc(void)
|
||||
{
|
||||
FILE *strf = fopen(strings, "r");
|
||||
FILE *xdotcf;
|
||||
|
||||
if (strf == NULL)
|
||||
err(1, "Cannot open `%s'", strings);
|
||||
xdotcf = fopen("xs.c", "w");
|
||||
if (xdotcf == NULL)
|
||||
err(1, "Cannot open `%s'", "xs.c");
|
||||
(void)fprintf(xdotcf, "char\t%s[] = {\n", array);
|
||||
for (;;) {
|
||||
int i, c;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
c = getc(strf);
|
||||
if (ferror(strf)) {
|
||||
warn("Error reading `%s'", strings);
|
||||
onintr(1);
|
||||
}
|
||||
if (feof(strf)) {
|
||||
(void)fprintf(xdotcf, "\n");
|
||||
goto out;
|
||||
}
|
||||
(void)fprintf(xdotcf, "0x%02x,", c);
|
||||
}
|
||||
(void)fprintf(xdotcf, "\n");
|
||||
}
|
||||
out:
|
||||
(void)fprintf(xdotcf, "};\n");
|
||||
(void)fclose(xdotcf);
|
||||
(void)fclose(strf);
|
||||
}
|
||||
|
||||
static char
|
||||
lastchr(const char *cp)
|
||||
{
|
||||
|
||||
while (cp[0] && cp[1])
|
||||
cp++;
|
||||
return (*cp);
|
||||
}
|
||||
|
||||
static int
|
||||
istail(const char *str, const char *of)
|
||||
{
|
||||
int d = strlen(of) - strlen(str);
|
||||
|
||||
if (d < 0 || strcmp(&of[d], str) != 0)
|
||||
return (-1);
|
||||
return (d);
|
||||
}
|
||||
|
||||
static void
|
||||
onintr(int dummy)
|
||||
{
|
||||
|
||||
(void)signal(SIGINT, SIG_IGN);
|
||||
if (strings[0] == '/')
|
||||
(void)unlink(strings);
|
||||
(void)unlink("x.c");
|
||||
(void)unlink("xs.c");
|
||||
exit(dummy);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: %s [-cv] [-l array] [-] [<name> ...]\n",
|
||||
getprogname());
|
||||
exit(1);
|
||||
}
|
|
@ -2469,7 +2469,6 @@ mkostemps
|
|||
mkquery
|
||||
mkstemp
|
||||
mkstemps
|
||||
mkstr
|
||||
mktemp
|
||||
mktime
|
||||
mkubootimage
|
||||
|
@ -4781,7 +4780,6 @@ xname
|
|||
xpci
|
||||
xprt
|
||||
xsh
|
||||
xstr
|
||||
xsurf
|
||||
xt
|
||||
xvif
|
||||
|
|
Loading…
Reference in New Issue