diff options
author | 2000-02-19 12:07:17 +0000 | |
---|---|---|
committer | 2000-02-19 12:07:17 +0000 | |
commit | 99dba025ca46f1954b1e7325e8f39d81988bc5a4 (patch) | |
tree | 28aca827927c4fde56dbc5d898ce03a7176ab572 | |
parent | set interface fields to null when detaching substructures (diff) | |
download | wireguard-openbsd-99dba025ca46f1954b1e7325e8f39d81988bc5a4.tar.xz wireguard-openbsd-99dba025ca46f1954b1e7325e8f39d81988bc5a4.zip |
Update to a newer version from KTH-Kerberos.
(most work by art@)
-rw-r--r-- | lib/libcom_err/Makefile | 4 | ||||
-rw-r--r-- | lib/libcom_err/com_err.c | 251 | ||||
-rw-r--r-- | lib/libcom_err/com_err.h | 113 | ||||
-rw-r--r-- | lib/libcom_err/com_right.h | 59 | ||||
-rw-r--r-- | lib/libcom_err/error.c | 96 | ||||
-rw-r--r-- | lib/libcom_err/init_et.c | 63 | ||||
-rw-r--r-- | usr.bin/compile_et/Makefile | 9 | ||||
-rw-r--r-- | usr.bin/compile_et/compile_et.1 | 28 | ||||
-rw-r--r-- | usr.bin/compile_et/compile_et.c | 449 | ||||
-rw-r--r-- | usr.bin/compile_et/compile_et.h | 83 | ||||
-rw-r--r-- | usr.bin/compile_et/compiler.h | 22 | ||||
-rw-r--r-- | usr.bin/compile_et/error_table.y | 373 | ||||
-rw-r--r-- | usr.bin/compile_et/et_lex.lex.l | 138 |
13 files changed, 935 insertions, 753 deletions
diff --git a/lib/libcom_err/Makefile b/lib/libcom_err/Makefile index 7376055a47b..93644e3af57 100644 --- a/lib/libcom_err/Makefile +++ b/lib/libcom_err/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.3 1997/04/27 20:56:07 millert Exp $ +# $OpenBSD: Makefile,v 1.4 2000/02/19 12:10:27 hin Exp $ LIB= com_err -SRCS= com_err.c error_message.c et_name.c init_et.c +SRCS= com_err.c error.c CFLAGS+=-I${.CURDIR} MAN= com_err.3 diff --git a/lib/libcom_err/com_err.c b/lib/libcom_err/com_err.c index 841084c5c8b..b6ce80e026e 100644 --- a/lib/libcom_err/com_err.c +++ b/lib/libcom_err/com_err.c @@ -1,151 +1,156 @@ -/* $OpenBSD: com_err.c,v 1.4 1998/05/13 17:53:25 art Exp $ */ - -/*- - * Copyright 1987, 1988 by the Student Information Processing Board - * of the Massachusetts Institute of Technology +/* + * Copyright (c) 1997, 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice - * appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, - * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be - * used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * M.I.T. and the M.I.T. S.I.P.B. make no representations about - * the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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 <stdio.h> - -#ifdef __STDC__ -# undef VARARGS -# include <stdarg.h> -#else -# undef VARARGS -# define VARARGS 1 -# include <varargs.h> +#ifdef HAVE_CONFIG_H +#include <config.h> +/* RCSID("$KTH: com_err.c,v 1.13 1999/03/12 15:17:08 bg Exp $"); */ #endif - +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +/* #include <roken.h> */ #include "com_err.h" -#include "error_table.h" -/* - * Protect us from header version (externally visible) of com_err, so - * we can survive in a <varargs.h> environment. I think. - */ -#if VARARGS -#define com_err com_err_external -#include "com_err.h" -#undef com_err -#endif +struct et_list *_et_list; -#ifdef NPOSIX -#undef vfprintf -#define vfprintf(stream,fmt,args) _doprnt(fmt,args,stream) -#endif -#if !defined(lint) -static const char rcsid[] = - "$Id: com_err.c,v 1.4 1998/05/13 17:53:25 art Exp $"; -#endif /* ! lint */ +const char * +error_message (long code) +{ + static char msg[128]; + const char *p = com_right(_et_list, code); + if (p == NULL) + p = strerror(code); + if (p != NULL && *p != '\0') { + strncpy(msg, p, sizeof(msg) - 1); + msg[sizeof(msg) - 1] = 0; + } else + sprintf(msg, "Unknown error %ld", code); + return msg; +} -static void -#ifdef __STDC__ - default_com_err_proc (const char *whoami, errcode_t code, const char *fmt, va_list args) -#else - default_com_err_proc (whoami, code, fmt, args) - const char *whoami; - errcode_t code; - const char *fmt; - va_list args; -#endif +int +init_error_table(const char **msgs, long base, int count) { - if (whoami) { - fputs(whoami, stderr); - fputs(": ", stderr); - } -#ifdef SOLARIS - if (code) { - fputs(error_message(code), stderr); - fputs(" ", stderr); - } else { - vfprintf (stderr, fmt, args); - } -#else - if (code) { - fputs(error_message(code), stderr); - fputs(" ", stderr); - } - if (fmt) { - vfprintf (stderr, fmt, args); - } -#endif - putc('\n', stderr); - /* should do this only on a tty in raw mode */ - putc('\r', stderr); - fflush(stderr); + initialize_error_table_r(&_et_list, msgs, count, base); + return 0; } -typedef void (*errf) __P((const char *, errcode_t, const char *, va_list)); +static void +default_proc (const char *whoami, long code, const char *fmt, va_list args) +{ + if (whoami) + fprintf(stderr, "%s: ", whoami); + if (code) + fprintf(stderr, "%s ", error_message(code)); + if (fmt) + vfprintf(stderr, fmt, args); + fprintf(stderr, "\r\n"); /* ??? */ +} -errf com_err_hook = default_com_err_proc; +static errf com_err_hook = default_proc; -void com_err_va (whoami, code, fmt, args) - const char *whoami; - errcode_t code; - const char *fmt; - va_list args; +void +com_err_va (const char *whoami, + long code, + const char *fmt, + va_list args) { - if (! com_err_hook) - com_err_hook = default_com_err_proc; (*com_err_hook) (whoami, code, fmt, args); } -#if ! VARARGS -void com_err (const char *whoami, - errcode_t code, - const char *fmt, ...) -{ -#else -void com_err (va_alist) - va_dcl +void +com_err (const char *whoami, + long code, + const char *fmt, + ...) { - const char *whoami, *fmt; - errcode_t code; -#endif - va_list pvar; - - if (!com_err_hook) - com_err_hook = default_com_err_proc; -#if VARARGS - va_start (pvar); - whoami = va_arg (pvar, const char *); - code = va_arg (pvar, errcode_t); - fmt = va_arg (pvar, const char *); -#else - va_start(pvar, fmt); -#endif - com_err_va (whoami, code, fmt, pvar); - va_end(pvar); + va_list ap; + va_start(ap, fmt); + com_err_va (whoami, code, fmt, ap); + va_end(ap); } -errf set_com_err_hook (new_proc) - errf new_proc; +errf +set_com_err_hook (errf new) { - errf x = com_err_hook; + errf old = com_err_hook; - if (new_proc) - com_err_hook = new_proc; + if (new) + com_err_hook = new; else - com_err_hook = default_com_err_proc; + com_err_hook = default_proc; + + return old; +} - return x; +errf +reset_com_err_hook (void) +{ + return set_com_err_hook(NULL); } -errf reset_com_err_hook () { - errf x = com_err_hook; - com_err_hook = default_com_err_proc; - return x; +#define ERRCODE_RANGE 8 /* # of bits to shift table number */ +#define BITS_PER_CHAR 6 /* # bits to shift per character in name */ + +static const char char_set[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; + +static char buf[6]; + +const char * +error_table_name(int num) +{ + int ch; + int i; + char *p; + + /* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */ + p = buf; + num >>= ERRCODE_RANGE; + /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */ + num &= 077777777; + /* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */ + for (i = 4; i >= 0; i--) { + ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1); + if (ch != 0) + *p++ = char_set[ch-1]; + } + *p = '\0'; + return(buf); } diff --git a/lib/libcom_err/com_err.h b/lib/libcom_err/com_err.h index d58cefeedf1..642e51cdffe 100644 --- a/lib/libcom_err/com_err.h +++ b/lib/libcom_err/com_err.h @@ -1,30 +1,99 @@ -/* $OpenBSD: com_err.h,v 1.3 1998/05/13 17:53:26 art Exp $ */ - -/*- - * Header file for common error description library. +/* + * Copyright (c) 1997, 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. * - * Copyright 1988, Student Information Processing Board of the - * Massachusetts Institute of Technology. + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * For copyright and distribution info, see the documentation supplied - * with this package. + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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 __COM_ERR_H -#define __COM_ERR_H +/* $KTH: com_err.h,v 1.3 1998/05/02 20:13:28 assar Exp $ */ -typedef int errcode_t; /* XXX compatibilty with newer version */ +/* MIT compatible com_err library */ +#ifndef __COM_ERR_H__ +#define __COM_ERR_H__ + +#ifdef __STDC__ #include <stdarg.h> +#endif + +#ifndef __P +#ifdef __STDC__ +#define __P(X) X +#else +#define __P(X) () +#endif +#endif + + +/* + * For compatibility with MIT's com_err the com_right.h include + * file is inserted here. + */ +/* $KTH: com_right.h,v 1.8 1998/02/17 21:19:43 bg Exp $ */ + +#ifndef __COM_RIGHT_H__ +#define __COM_RIGHT_H__ + +struct error_table { + char const * const * msgs; + long base; + int n_msgs; +}; +struct et_list { + struct et_list *next; + struct error_table *table; +}; +extern struct et_list *_et_list; + +const char *com_right(struct et_list *list, long code); +void initialize_error_table_r(struct et_list **, const char **, int, long); +void free_error_table(struct et_list *); + +#endif /* __COM_RIGHT_H__ */ + + +typedef void (*errf) __P((const char *, long, const char *, va_list)); + +const char * error_message __P((long)); +int init_error_table __P((const char**, long, int)); + +void com_err_va __P((const char *, long, const char *, va_list)); +void com_err __P((const char *, long, const char *, ...)); + +errf set_com_err_hook __P((errf)); +errf reset_com_err_hook __P((void)); + +const char *error_table_name(int num); -/* ANSI C -- use prototypes etc */ -void com_err __P((const char *, errcode_t, const char *, ...)); -void com_err_va __P((const char *, errcode_t, const char *, va_list)); -char const *error_message __P((long)); -void (*com_err_hook) __P((const char *, errcode_t, const char *, va_list)); -void (*set_com_err_hook __P((void (*) (const char *, errcode_t, const char *, va_list)))) - __P((const char *, errcode_t, const char *, va_list)); -void (*reset_com_err_hook __P((void))) - __P((const char *, errcode_t, const char *, va_list)); - -#endif /* ! defined(__COM_ERR_H) */ +#endif /* __COM_ERR_H__ */ diff --git a/lib/libcom_err/com_right.h b/lib/libcom_err/com_right.h new file mode 100644 index 00000000000..6a6e557fb84 --- /dev/null +++ b/lib/libcom_err/com_right.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1997, 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $KTH: com_right.h,v 1.8 1998/02/17 21:19:43 bg Exp $ */ + +#ifndef __COM_RIGHT_H__ +#define __COM_RIGHT_H__ + +struct error_table { + char const * const * msgs; + long base; + int n_msgs; +}; +struct et_list { + struct et_list *next; + struct error_table *table; +}; +extern struct et_list *_et_list; + +const char *com_right(struct et_list *list, long code); +void initialize_error_table_r(struct et_list **, const char **, int, long); +void free_error_table(struct et_list *); + +#endif /* __COM_RIGHT_H__ */ diff --git a/lib/libcom_err/error.c b/lib/libcom_err/error.c new file mode 100644 index 00000000000..a3fdb2e7d65 --- /dev/null +++ b/lib/libcom_err/error.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 1997, 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +RCSID("$KTH: error.c,v 1.13 1998/02/17 21:19:44 bg Exp $"); +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <com_right.h> + +const char * +com_right(struct et_list *list, long code) +{ + struct et_list *p; + for (p = list; p; p = p->next) { + if (code >= p->table->base && code < p->table->base + p->table->n_msgs) + return p->table->msgs[code - p->table->base]; + } + return NULL; +} + +struct foobar { + struct et_list etl; + struct error_table et; +}; + +void +initialize_error_table_r(struct et_list **list, + const char **messages, + int num_errors, + long base) +{ + struct et_list *et; + struct foobar *f; + for (et = *list; et; et = et->next) + if (et->table->msgs == messages) + return; + f = malloc(sizeof(*f)); + if (f == NULL) + return; + et = &f->etl; + et->table = &f->et; + et->table->msgs = messages; + et->table->n_msgs = num_errors; + et->table->base = base; + et->next = *list; + *list = et; +} + + +void +free_error_table(struct et_list *et) +{ + while(et){ + struct et_list *p = et; + et = et->next; + free(p); + } +} diff --git a/lib/libcom_err/init_et.c b/lib/libcom_err/init_et.c deleted file mode 100644 index ba714189bab..00000000000 --- a/lib/libcom_err/init_et.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: init_et.c,v 1.1 1996/11/11 04:55:05 downsj Exp $ */ - -/*- - * Copyright 1987, 1988 by the Student Information Processing Board - * of the Massachusetts Institute of Technology - * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice - * appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, - * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be - * used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * M.I.T. and the M.I.T. S.I.P.B. make no representations about - * the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "error_table.h" - -#ifndef __STDC__ -#define const -#endif - -#ifndef lint -static const char rcsid_init_et_c[] = - "$Id: init_et.c,v 1.1 1996/11/11 04:55:05 downsj Exp $"; -#endif - -struct foobar { - struct et_list etl; - struct error_table et; -}; - -extern struct et_list * _et_list; - -int -init_error_table(msgs, base, count) - const char * const * msgs; - int base; - int count; -{ - struct foobar * new_et; - - if (!base || !count || !msgs) - return 0; - - new_et = (struct foobar *) malloc(sizeof(struct foobar)); - if (!new_et) - return errno; /* oops */ - new_et->etl.table = &new_et->et; - new_et->et.msgs = msgs; - new_et->et.base = base; - new_et->et.n_msgs= count; - - new_et->etl.next = _et_list; - _et_list = &new_et->etl; - return 0; -} diff --git a/usr.bin/compile_et/Makefile b/usr.bin/compile_et/Makefile index db4a7b14ee8..a2eff189709 100644 --- a/usr.bin/compile_et/Makefile +++ b/usr.bin/compile_et/Makefile @@ -1,11 +1,14 @@ -# $OpenBSD: Makefile,v 1.1 1996/11/11 05:06:33 downsj Exp $ +# $OpenBSD: Makefile,v 1.2 2000/02/19 12:07:17 hin Exp $ PROG= compile_et -SRCS= compile_et.c error_table.y #et_lex.lex.l +SRCS= compile_et.c error_table.c et_lex.lex.l CFLAGS+=-I. -I${.CURDIR} -I${.CURDIR}/../../lib/libcom_err DPADD= ${LIBL} LDADD= -ll -CLEANFILES=error_table.c y.tab.h et_lex.lex.c +CLEANFILES=error_table.h error_table.c y.tab.h et_lex.lex.c + +error_table.h error_table.c: error_table.y + ${YACC} -d -o error_table.c ${.CURDIR}/error_table.y beforedepend: et_lex.lex.c error_table.o: et_lex.lex.c diff --git a/usr.bin/compile_et/compile_et.1 b/usr.bin/compile_et/compile_et.1 index 7ab8e2acc2d..94b757fbcc0 100644 --- a/usr.bin/compile_et/compile_et.1 +++ b/usr.bin/compile_et/compile_et.1 @@ -1,8 +1,8 @@ .\" Copyright (c) 1988 Massachusetts Institute of Technology, .\" Student Information Processing Board. All rights reserved. .\" -.\" $OpenBSD: compile_et.1,v 1.7 2000/01/03 00:18:05 aaron Exp $ -.\" $Header: /home/cvs/src/usr.bin/compile_et/Attic/compile_et.1,v 1.7 2000/01/03 00:18:05 aaron Exp $ +.\" $OpenBSD: compile_et.1,v 1.8 2000/02/19 12:07:18 hin Exp $ +.\" $Header: /home/cvs/src/usr.bin/compile_et/Attic/compile_et.1,v 1.8 2000/02/19 12:07:18 hin Exp $ .\" .Dd November 22, 1988 .Dt COMPILE_ET 1 @@ -21,23 +21,41 @@ a C source file suitable for use with the library. .Pp The source file name must end with a suffix of ``.et''; the file -consists of a declaration supplying the name (up to four characters -long) of the error-code table: +consists of headers and declarations supplying the name (up to four characters +long) of the error-code table. + +The file may have these declarations: + +.Em id string + +where string is a revision control system tag. + +.Em prefix string + +where string is prepended to all error codes specified in the file. .Em error_table name -followed by up to 256 entries of the form: +which specifies the name of the error table. + +.Em index number + +sets the assigned error number for the next entry. .Em error_code name , " .Em string " +declares an error code called name with description name. Upto +256 error codes are allowed. + and a final .Em end to indicate the end of the table. + .Pp The name of the table is used to construct the name of a subroutine .Em initialize_XXXX_error_table diff --git a/usr.bin/compile_et/compile_et.c b/usr.bin/compile_et/compile_et.c index c8a08eb103b..d7954f6421f 100644 --- a/usr.bin/compile_et/compile_et.c +++ b/usr.bin/compile_et/compile_et.c @@ -1,291 +1,222 @@ -/* $OpenBSD: compile_et.c,v 1.4 1998/05/13 17:54:20 art Exp $ */ - +/* $OpenBSD: compile_et.c,v 1.5 2000/02/19 12:07:18 hin Exp $ */ /* - * Copyright 1986, 1987, 1988 - * by MIT Student Information Processing Board. + * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * For copyright info, see "mit-sipb-copyright.h". + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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 <stdio.h> -#include <sys/types.h> -#include <sys/file.h> -#include <string.h> -#include <sys/param.h> -#include "compiler.h" +#undef ROKEN_RENAME +#include "compile_et.h" -#ifndef __STDC__ -#define const -#endif +/* RCSID("$KTH: compile_et.c,v 1.12 1999/04/01 09:13:52 joda Exp $"); */ -#ifndef lint -static const char copyright[] = - "Copyright 1987,1988 by MIT Student Information Processing Board"; +#include <err.h> +#include "error_table.h" -static const char rcsid_compile_et_c[] = - "$Id: compile_et.c,v 1.4 1998/05/13 17:54:20 art Exp $"; -#endif +int numerror; +extern FILE *yyin; -extern char *gensym(); -extern char *current_token; -extern int table_number, current; -char buffer[BUFSIZ]; -char *table_name = NULL; -FILE *hfile, *cfile; +extern void yyparse(void); -/* C library */ -extern char *malloc(); -extern int errno; +long base; +int number; +char *prefix; +char *id_str; -/* lex stuff */ -extern FILE *yyin; -extern unsigned lineno; +char name[128]; +char Basename[128]; + +#ifdef YYDEBUG +extern int yydebug = 1; +#endif -char * xmalloc (size) unsigned int size; { - char * p = malloc (size); - if (!p) { - perror (whoami); - exit (1); +char *filename; +char hfn[128]; +char cfn[128]; + +struct error_code *codes = NULL; + +static int +generate_c(void) +{ + int n; + struct error_code *ec; + + FILE *c_file = fopen(cfn, "w"); + if(c_file == NULL) + return 1; + + fprintf(c_file, "/* Generated from %s */\n", filename); + if(id_str) + fprintf(c_file, "/* %s */\n", id_str); + fprintf(c_file, "\n"); + fprintf(c_file, "#include <stddef.h>\n"); + fprintf(c_file, "#include <com_err.h>\n"); + fprintf(c_file, "#include \"%s\"\n", hfn); + fprintf(c_file, "\n"); + + fprintf(c_file, "static const char *text[] = {\n"); + + for(ec = codes, n = 0; ec; ec = ec->next, n++) { + while(n < ec->number) { + fprintf(c_file, "\t/* %03d */ \"Reserved %s error (%d)\",\n", + n, name, n); + n++; + + } + fprintf(c_file, "\t/* %03d */ \"%s\",\n", ec->number, ec->string); } - return p; -} -static int check_arg (str_list, arg) char const *const *str_list, *arg; { - while (*str_list) - if (!strcmp(arg, *str_list++)) - return 1; + fprintf(c_file, "\tNULL\n"); + fprintf(c_file, "};\n"); + fprintf(c_file, "\n"); + fprintf(c_file, + "void initialize_%s_error_table_r(struct et_list **list)\n", + name); + fprintf(c_file, "{\n"); + fprintf(c_file, + " initialize_error_table_r(list, text, " + "%s_num_errors, ERROR_TABLE_BASE_%s);\n", name, name); + fprintf(c_file, "}\n"); + fprintf(c_file, "\n"); + fprintf(c_file, "void initialize_%s_error_table(void)\n", name); + fprintf(c_file, "{\n"); + fprintf(c_file, + " init_error_table(text, ERROR_TABLE_BASE_%s, " + "%s_num_errors);\n", name, name); + fprintf(c_file, "}\n"); + + fclose(c_file); return 0; } -static const char *const debug_args[] = { - "d", - "debug", - 0, -}; - -static const char *const lang_args[] = { - "lang", - "language", - 0, -}; - -static const char *const language_names[] = { - "C", - "K&R C", - "C++", - 0, -}; - -static const char * const c_src_prolog[] = { - "static const char * const text[] = {\n", - 0, -}; - -static const char * const krc_src_prolog[] = { - "#ifdef __STDC__\n", - "#define NOARGS void\n", - "#else\n", - "#define NOARGS\n", - "#define const\n", - "#endif\n\n", - "static const char * const text[] = {\n", - 0, -}; +static int +generate_h(void) +{ + struct error_code *ec; + char fn[128]; + FILE *h_file = fopen(hfn, "w"); + char *p; + + if(h_file == NULL) + return 1; + + snprintf(fn, sizeof(fn), "__%s__", hfn); + for(p = fn; *p; p++) + if(!isalnum((unsigned char)*p)) + *p = '_'; + + fprintf(h_file, "/* Generated from %s */\n", filename); + if(id_str) + fprintf(h_file, "/* %s */\n", id_str); + fprintf(h_file, "\n"); + fprintf(h_file, "#ifndef %s\n", fn); + fprintf(h_file, "#define %s\n", fn); + fprintf(h_file, "\n"); + fprintf(h_file, "#include <com_err.h>\n"); + fprintf(h_file, "\n"); + fprintf(h_file, + "void initialize_%s_error_table_r(struct et_list **);\n", + name); + fprintf(h_file, "\n"); + fprintf(h_file, "void initialize_%s_error_table(void);\n", name); + fprintf(h_file, "#define init_%s_err_tbl initialize_%s_error_table\n", + name, name); + fprintf(h_file, "\n"); + fprintf(h_file, "typedef enum %s_error_number{\n", name); + fprintf(h_file, "\tERROR_TABLE_BASE_%s = %ld,\n", name, base); + fprintf(h_file, "\t%s_err_base = %ld,\n", name, base); + + for(ec = codes; ec; ec = ec->next) { + fprintf(h_file, "\t%s = %ld,\n", ec->name, base + ec->number); + } -static const char *const struct_def[] = { - "struct error_table {\n", - " char const * const * msgs;\n", - " long base;\n", - " int n_msgs;\n", - "};\n", - "struct et_list {\n", - " struct et_list *next;\n", - " const struct error_table * table;\n", - "};\n", - "extern struct et_list *_et_list;\n", - "\n", 0, -}; + fprintf(h_file, "\t%s_num_errors = %d\n", name, number); + fprintf(h_file, "} %s_error_number;\n", name); + fprintf(h_file, "\n"); + fprintf(h_file, "#endif /* %s */\n", fn); -static const char warning[] = - "/*\n * %s:\n * This file is automatically generated; please do not edit it.\n */\n"; -/* pathnames */ -char c_file[MAXPATHLEN]; /* output file */ -char h_file[MAXPATHLEN]; /* output */ + fclose(h_file); + return 0; +} -static void usage () { - fprintf (stderr, "usage: %s ERROR_TABLE\n", - whoami); - exit (1); +static int +generate(void) +{ + return generate_c() || generate_h(); } -static void dup_err (type, one, two) char const *type, *one, *two; { - fprintf (stderr, "%s: multiple %s specified: `%s' and `%s'\n", - whoami, type, one, two); - usage (); +static void +usage(int code) +{ + extern char *__progname; + fprintf(stderr, "Usage: %s <file>\n", __progname); + exit(1); } -int main (argc, argv) int argc; char **argv; { - char *p, *ename; - int len; - char const * const *cpp; - int got_language = 0; +int +main(int argc, char **argv) +{ + char *p; - /* argument parsing */ - debug = 0; - filename = 0; - whoami = argv[0]; - p = strrchr (whoami, '/'); - if (p) - whoami = p+1; - while (argv++, --argc) { - char *arg = *argv; - if (arg[0] != '-') { - if (filename) - dup_err ("filenames", filename, arg); - filename = arg; - } - else { - arg++; - if (check_arg (debug_args, arg)) - debug++; - else if (check_arg (lang_args, arg)) { - got_language++; - arg = *++argv, argc--; - if (!arg) - usage (); - if (language) - dup_err ("languanges", language_names[(int)language], arg); -#define check_lang(x,v) else if (!strcasecmp(arg,x)) language = v - check_lang ("c", lang_C); - check_lang ("ansi_c", lang_C); - check_lang ("ansi-c", lang_C); - check_lang ("krc", lang_KRC); - check_lang ("kr_c", lang_KRC); - check_lang ("kr-c", lang_KRC); - check_lang ("k&r-c", lang_KRC); - check_lang ("k&r_c", lang_KRC); - check_lang ("c++", lang_CPP); - check_lang ("cplusplus", lang_CPP); - check_lang ("c-plus-plus", lang_CPP); -#undef check_lang - else { - fprintf (stderr, "%s: unknown language name `%s'\n", - whoami, arg); - fprintf (stderr, "\tpick one of: C K&R-C\n"); - exit (1); - } - } - else { - fprintf (stderr, "%s: unknown control argument -`%s'\n", - whoami, arg); - usage (); - } - } - } - if (!filename) - usage (); - if (!got_language) - language = lang_KRC; - else if (language == lang_CPP) { - fprintf (stderr, "%s: Sorry, C++ support is not yet finished.\n", - whoami); - exit (1); - } + if(argc != 2) + usage(1); - p = xmalloc (strlen (filename) + 5); - strcpy (p, filename); - filename = p; + filename = argv[1]; + yyin = fopen(filename, "r"); + if(yyin == NULL) + err(1, "%s", filename); + + p = strrchr(filename, '/'); - if (p == NULL) - p = filename; - else + if(p) p++; - ename = p; - len = strlen (ename); - p += len - 3; - if (strcmp (p, ".et")) - p += 3; - *p++ = '.'; - /* now p points to where "et" suffix should start */ - /* generate new filenames */ - strcpy (p, "c"); - strcpy (c_file, ename); - *p = 'h'; - strcpy (h_file, ename); - strcpy (p, "et"); - - yyin = fopen(filename, "r"); - if (!yyin) { - perror(filename); - exit(1); - } - - hfile = fopen(h_file, "w"); - if (hfile == NULL) { - perror(h_file); - exit(1); - } - fprintf (hfile, warning, h_file); - - cfile = fopen(c_file, "w"); - if (cfile == NULL) { - perror(c_file); - exit(1); - } - fprintf (cfile, warning, c_file); - - /* prologue */ - if (language == lang_C) - cpp = c_src_prolog; - else if (language == lang_KRC) - cpp = krc_src_prolog; else - abort (); - while (*cpp) - fputs (*cpp++, cfile); - - /* parse it */ + p = filename; + strncpy(Basename, p, sizeof(Basename)); + Basename[sizeof(Basename) - 1] = '\0'; + + Basename[strcspn(Basename, ".")] = '\0'; + + snprintf(hfn, sizeof(hfn), "%s.h", Basename); + snprintf(cfn, sizeof(cfn), "%s.c", Basename); + yyparse(); - fclose(yyin); /* bye bye input file */ - - fputs (" 0\n};\n\n", cfile); - for (cpp = struct_def; *cpp; cpp++) - fputs (*cpp, cfile); - fprintf(cfile, - "static const struct error_table et = { text, %d, %d };\n\n", - table_number, current); - fputs("static struct et_list link = { 0, 0 };\n\n", - cfile); - fprintf(cfile, "void initialize_%s_error_table (%s) {\n", - table_name, (language == lang_C) ? "void" : "NOARGS"); - fputs(" if (!link.table) {\n", cfile); - fputs(" link.next = _et_list;\n", cfile); - fputs(" link.table = &et;\n", cfile); - fputs(" _et_list = &link;\n", cfile); - fputs(" }\n", cfile); - fputs("}\n", cfile); - fclose(cfile); - - fprintf (hfile, "extern void initialize_%s_error_table ();\n", - table_name); - fprintf (hfile, "#define ERROR_TABLE_BASE_%s (%dL)\n", - table_name, table_number); - /* compatibility... */ - fprintf (hfile, "\n/* for compatibility with older versions... */\n"); - fprintf (hfile, "#define init_%s_err_tbl initialize_%s_error_table\n", - table_name, table_name); - fprintf (hfile, "#define %s_err_base ERROR_TABLE_BASE_%s\n", table_name, - table_name); - fclose(hfile); /* bye bye include file */ + if(numerror) + return 1; - return 0; -} - -int yyerror(s) char *s; { - fputs(s, stderr); - fprintf(stderr, "\nLine number %d; last token was '%s'\n", - lineno, current_token); - - return 0; + return generate(); } diff --git a/usr.bin/compile_et/compile_et.h b/usr.bin/compile_et/compile_et.h new file mode 100644 index 00000000000..332ce2f984d --- /dev/null +++ b/usr.bin/compile_et/compile_et.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ + +/* $KTH: compile_et.h,v 1.3 1998/11/22 09:39:46 assar Exp $ */ + +#ifndef __COMPILE_ET_H__ +#define __COMPILE_ET_H__ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdarg.h> +#include <ctype.h> + +extern long base; +extern int number; +extern char *prefix; +extern char name[128]; +extern char *id_str; +extern char *filename; +extern int numerror; + +struct error_code { + unsigned number; + char *name; + char *string; + struct error_code *next, **tail; +}; + +extern struct error_code *codes; + +#define APPEND(L, V) \ +do { \ + if((L) == NULL) { \ + (L) = (V); \ + (L)->tail = &(V)->next; \ + (L)->next = NULL; \ + }else{ \ + *(L)->tail = (V); \ + (L)->tail = &(V)->next; \ + } \ +}while(0) + +#endif /* __COMPILE_ET_H__ */ diff --git a/usr.bin/compile_et/compiler.h b/usr.bin/compile_et/compiler.h deleted file mode 100644 index d8bce211a1c..00000000000 --- a/usr.bin/compile_et/compiler.h +++ /dev/null @@ -1,22 +0,0 @@ -/* $OpenBSD: compiler.h,v 1.1 1996/11/11 05:06:34 downsj Exp $ */ - -/* - * definitions common to the source files of the error table compiler - */ - -#ifndef __STDC__ -/* loser */ -#undef const -#define const -#endif - -enum lang { - lang_C, /* ANSI C (default) */ - lang_KRC, /* C: ANSI + K&R */ - lang_CPP /* C++ */ -}; - -int debug; /* dump debugging info? */ -char *filename; /* error table source */ -enum lang language; -const char *whoami; diff --git a/usr.bin/compile_et/error_table.y b/usr.bin/compile_et/error_table.y index 2d32ca87e08..93ed55f7555 100644 --- a/usr.bin/compile_et/error_table.y +++ b/usr.bin/compile_et/error_table.y @@ -1,264 +1,171 @@ %{ -/* $OpenBSD: error_table.y,v 1.2 1998/05/13 17:54:21 art Exp $ */ - -/*- - * Copyright 1987, 1988 by the Student Information Processing Board - * of the Massachusetts Institute of Technology +/* + * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice - * appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, - * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be - * used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * M.I.T. and the M.I.T. S.I.P.B. make no representations about - * the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. + * 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 Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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 <stdio.h> -#include <stdlib.h> -char *str_concat(), *ds(), *quote(); -char *current_token = (char *)NULL; -extern char *table_name; +#include "compile_et.h" +/* RCSID("$KTH: parse.y,v 1.9 1999/07/04 14:54:58 assar Exp $"); */ + +void yyerror (char *s); +long name2number(const char *str); +void error_message(char *, ...); + +extern char *yytext; + +/* This is for bison */ + +#if !defined(alloca) && !defined(HAVE_ALLOCA) +#define alloca(x) malloc(x) +#endif + %} + %union { - char *dynstr; + char *string; + int number; } -%token ERROR_TABLE ERROR_CODE_ENTRY END -%token <dynstr> STRING QUOTED_STRING -%type <dynstr> ec_name description table_id -%{ -%} -%start error_table +%token ET INDEX PREFIX EC ID END +%token <string> STRING +%token <number> NUMBER + %% -error_table : ERROR_TABLE table_id error_codes END - { table_name = ds($2); - current_token = table_name; - put_ecs(); } +file : /* */ + | header statements ; -table_id : STRING - { current_token = $1; - set_table_num($1); - $$ = $1; } +header : id et + | et ; -error_codes : error_codes ec_entry - | ec_entry +id : ID STRING + { + id_str = $2; + } ; -ec_entry : ERROR_CODE_ENTRY ec_name ',' description - { add_ec($2, $4); - free($2); - free($4); } - | ERROR_CODE_ENTRY ec_name '=' STRING ',' description - { add_ec_val($2, $4, $6); - free($2); - free($4); - free($6); - } +et : ET STRING + { + base = name2number($2); + strncpy(name, $2, sizeof(name)); + name[sizeof(name) - 1] = '\0'; + free($2); + } + | ET STRING STRING + { + base = name2number($2); + strncpy(name, $3, sizeof(name)); + name[sizeof(name) - 1] = '\0'; + free($2); + free($3); + } ; -ec_name : STRING - { $$ = ds($1); - current_token = $$; } +statements : statement + | statements statement ; -description : QUOTED_STRING - { $$ = ds($1); - current_token = $$; } +statement : INDEX NUMBER + { + number = $2; + } + | PREFIX STRING + { + prefix = realloc(prefix, strlen($2) + 2); + strcpy(prefix, $2); + strcat(prefix, "_"); + free($2); + } + | PREFIX + { + prefix = realloc(prefix, 1); + *prefix = '\0'; + } + | EC STRING ',' STRING + { + struct error_code *ec = malloc(sizeof(*ec)); + + ec->next = NULL; + ec->number = number; + if(prefix && *prefix != '\0') { + asprintf (&ec->name, "%s%s", prefix, $2); + free($2); + } else + ec->name = $2; + ec->string = $4; + APPEND(codes, ec); + number++; + } + | END + { + YYACCEPT; + } ; %% -/* - * Copyright 1987, 1988 by the Student Information Processing Board - * of the Massachusetts Institute of Technology - * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice - * appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, - * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be - * used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * M.I.T. and the M.I.T. S.I.P.B. make no representations about - * the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - */ - -#include <string.h> -#include <assert.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/time.h> -#include "error_table.h" - -#ifndef lint -static char const rcsid_error_table_y[] = - "$Id: error_table.y,v 1.2 1998/05/13 17:54:21 art Exp $"; -#endif - -#include "et_lex.lex.c" - -extern FILE *hfile, *cfile; - -static long gensym_n = 0; -char * -gensym(x) - char const *x; -{ - char *symbol; - if (!gensym_n) { - struct timeval tv; - struct timezone tzp; - gettimeofday(&tv, &tzp); - gensym_n = (tv.tv_sec%10000)*100 + tv.tv_usec/10000; - } - symbol = (char *)malloc(32 * sizeof(char)); - gensym_n++; - snprintf(symbol, 32 * sizeof(char), "et%ld", gensym_n); - return(symbol); -} - -char * -ds(string) - char const *string; -{ - char *rv; - rv = (char *)malloc(strlen(string)+1); - strcpy(rv, string); - return(rv); -} - -char * -quote(string) - char const *string; -{ - char *rv; - rv = (char *)malloc(strlen(string)+3); - strcpy(rv, "\""); - strcat(rv, string); - strcat(rv, "\""); - return(rv); -} - -int table_number; -int current = 0; -char **error_codes = (char **)NULL; - -void -add_ec(name, description) - char const *name, *description; -{ - fprintf(cfile, "\t\"%s\",\n", description); - if (error_codes == (char **)NULL) { - error_codes = (char **)malloc(sizeof(char *)); - *error_codes = (char *)NULL; - } - error_codes = (char **)realloc((char *)error_codes, - (current + 2)*sizeof(char *)); - error_codes[current++] = ds(name); - error_codes[current] = (char *)NULL; -} - -void -add_ec_val(name, val, description) - char const *name, *val, *description; -{ - const int ncurrent = atoi(val); - if (ncurrent < current) { - printf("Error code %s (%d) out of order", name, - current); - return; - } - - while (ncurrent > current) - fputs("\t(char *)NULL,\n", cfile), current++; - - fprintf(cfile, "\t\"%s\",\n", description); - if (error_codes == (char **)NULL) { - error_codes = (char **)malloc(sizeof(char *)); - *error_codes = (char *)NULL; - } - error_codes = (char **)realloc((char *)error_codes, - (current + 2)*sizeof(char *)); - error_codes[current++] = ds(name); - error_codes[current] = (char *)NULL; -} -void -put_ecs() +long +name2number(const char *str) { - int i; - for (i = 0; i < current; i++) { - if (error_codes[i] != (char *)NULL) - fprintf(hfile, "#define %-40s (%d)\n", - error_codes[i], table_number + i); + const char *p; + long base = 0; + const char *x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789_"; + if(strlen(str) > 4) { + yyerror("table name too long"); + return 0; + } + for(p = str; *p; p++){ + char *q = strchr(x, *p); + if(q == NULL) { + yyerror("invalid character in table name"); + return 0; } -} - -/* - * char_to_num -- maps letters and numbers into a small numbering space - * uppercase -> 1-26 - * lowercase -> 27-52 - * digits -> 53-62 - * underscore-> 63 - */ - -static const char char_set[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; - -int char_to_num(c) - char c; -{ - const char *where; - int diff; - - where = strchr (char_set, c); - if (where) { - diff = where - char_set + 1; - assert (diff < (1 << ERRCODE_RANGE)); - return diff; - } - else if (isprint (c)) - fprintf (stderr, - "Illegal character `%c' in error table name\n", - c); - else - fprintf (stderr, - "Illegal character %03o in error table name\n", - c); - exit (1); + base = (base << 6) + (q - x) + 1; + } + base <<= 8; + if(base > 0x7fffffff) + base = -(0xffffffff - base + 1); + return base; } void -set_table_num(string) - char *string; +yyerror (char *s) { - if (char_to_num (string[0]) > char_to_num ('z')) { - fprintf (stderr, "%s%s%s%s", - "First character of error table name must be ", - "a letter; name ``", - string, "'' rejected\n"); - exit (1); - } - if (strlen(string) > 4) { - fprintf(stderr, "Table name %s too long, truncated ", - string); - string[4] = '\0'; - fprintf(stderr, "to %s\n", string); - } - while (*string != '\0') { - table_number = (table_number << BITS_PER_CHAR) - + char_to_num(*string); - string++; - } - table_number = table_number << ERRCODE_RANGE; + error_message ("%s\n", s); } - diff --git a/usr.bin/compile_et/et_lex.lex.l b/usr.bin/compile_et/et_lex.lex.l index e25e18328a1..b2f0a95d315 100644 --- a/usr.bin/compile_et/et_lex.lex.l +++ b/usr.bin/compile_et/et_lex.lex.l @@ -1,31 +1,127 @@ %{ - unsigned lineno = 1; -%} +/* + * Copyright (c) 1998 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE 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. + */ -PC [^\"] -AN [A-Z_a-z0-9] -%% +/* + * This is to handle the definition of this symbol in some AIX + * headers, which will conflict with the definition that lex will + * generate for it. It's only a problem for AIX lex. + */ -error_table return ERROR_TABLE; -et return ERROR_TABLE; -error_code return ERROR_CODE_ENTRY; -ec return ERROR_CODE_ENTRY; -end return END; +#undef ECHO -[\t ] ; -\n ++lineno; +#include "compile_et.h" +#include "error_table.h" -\"{PC}*\" { register char *p; yylval.dynstr = ds(yytext+1); - if ((p = strrchr(yylval.dynstr, '"')) != NULL) *p = '\0'; - return QUOTED_STRING; - } +/* RCSID("$KTH: lex.l,v 1.4 1998/11/20 05:58:52 assar Exp $"); */ -{AN}* { yylval.dynstr = ds(yytext); return STRING; } +static unsigned lineno = 1; +void error_message(char *, ...); +int getstring(void); -#.*\n ++lineno; +%} -. { return (*yytext); } + +%% +et { return ET; } +error_table { return ET; } +ec { return EC; } +error_code { return EC; } +prefix { return PREFIX; } +index { return INDEX; } +id { return ID; } +end { return END; } +[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } +#[^\n]* ; +[ \t] ; +\n { lineno++; } +\" { return getstring(); } +[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return STRING; } +. { return *yytext; } %% -#ifndef lint -static char rcsid_et_lex_lex_l[] = "$Id: et_lex.lex.l,v 1.2 1998/05/13 17:54:22 art Exp $"; + +#ifndef yywrap /* XXX */ +int +yywrap () +{ + return 1; +} #endif + +int +getstring(void) +{ + char x[128]; + int i = 0; + int c; + int quote = 0; + while((c = input()) != EOF){ + if(quote) { + x[i++] = c; + quote = 0; + continue; + } + if(c == '\n'){ + error_message("unterminated string"); + lineno++; + break; + } + if(c == '\\'){ + quote++; + continue; + } + if(c == '\"') + break; + x[i++] = c; + } + x[i] = '\0'; + yylval.string = strdup(x); + return STRING; +} + +void +error_message (char *format, ...) +{ + va_list args; + + va_start (args, format); + fprintf (stderr, "%s:%d:", filename, lineno); + vfprintf (stderr, format, args); + va_end (args); + numerror++; +} |