summaryrefslogtreecommitdiffstats
path: root/usr.bin/compile_et
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>1999-09-04 09:52:36 +0000
committermarkm <markm@FreeBSD.org>1999-09-04 09:52:36 +0000
commit3f27ca11404bfee6ad95039f41fe9625062bf654 (patch)
tree0dfea1e6c3c821e4454301f7c4824fe1a7ae9bf6 /usr.bin/compile_et
parent444a62d6e11e4184062a6f4999c3986590ebbdfc (diff)
downloadFreeBSD-src-3f27ca11404bfee6ad95039f41fe9625062bf654.zip
FreeBSD-src-3f27ca11404bfee6ad95039f41fe9625062bf654.tar.gz
Build this from contrib/ now.
Diffstat (limited to 'usr.bin/compile_et')
-rw-r--r--usr.bin/compile_et/Makefile13
-rw-r--r--usr.bin/compile_et/compile_et.178
-rw-r--r--usr.bin/compile_et/compile_et.c268
-rw-r--r--usr.bin/compile_et/compiler.h19
-rw-r--r--usr.bin/compile_et/error_table.y237
-rw-r--r--usr.bin/compile_et/et_lex.lex.l26
-rw-r--r--usr.bin/compile_et/mit-sipb-copyright.h19
7 files changed, 3 insertions, 657 deletions
diff --git a/usr.bin/compile_et/Makefile b/usr.bin/compile_et/Makefile
index d8cd738..a84460a 100644
--- a/usr.bin/compile_et/Makefile
+++ b/usr.bin/compile_et/Makefile
@@ -1,16 +1,9 @@
# $FreeBSD$
PROG= compile_et
-SRCS= compile_et.c error_table.y
-CFLAGS+=-I. -I${.CURDIR}/../../lib/libcom_err
-LFLAGS+=-l
-YFLAGS=
-DPADD= ${LIBL}
-LDADD= -ll
-CLEANFILES= et_lex.lex.c
-
-error_table.o: et_lex.lex.c
+SRCS= compile_et.c parse.y lex.l getarg.c
+CFLAGS+=-I. -I${.CURDIR}/../../contrib/com_err
.include <bsd.prog.mk>
-${DEPENDFILE}: et_lex.lex.c
+.PATH: ${.CURDIR}/../../contrib/com_err
diff --git a/usr.bin/compile_et/compile_et.1 b/usr.bin/compile_et/compile_et.1
deleted file mode 100644
index 0910380..0000000
--- a/usr.bin/compile_et/compile_et.1
+++ /dev/null
@@ -1,78 +0,0 @@
-.\" Copyright (c) 1988 Massachusetts Institute of Technology,
-.\" Student Information Processing Board. All rights reserved.
-.\"
-.\" $FreeBSD$
-.\"
-.Dd November 22, 1988
-.Os
-.Dt COMPILE_ET 1
-.Sh NAME
-.Nm compile_et
-.Nd error table compiler
-.Sh SYNOPSIS
-.Nm compile_et
-.Ar file
-.Sh DESCRIPTION
-.Nm Compile_et
-converts a table listing error-code names and associated messages into
-a C source file suitable for use with the
-.Xr com_err 3
-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:
-
-.Em error_table name
-
-followed by up to 256 entries of the form:
-
-.Em error_code name ,
-"
-.Em string
-"
-
-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
-which must be called in order for the
-.Xr com_err 3
-library to recognize the error table.
-.Pp
-The various error codes defined are assigned sequentially increasing
-numbers (starting with a large number computed as a hash function of
-the name of the table); thus for compatibility it is suggested that
-new codes be added only to the end of an existing table, and that no
-codes be removed from tables.
-.Pp
-The names defined in the table are placed into a C header file with
-preprocessor directives defining them as integer constants of up to
-32 bits in magnitude.
-.Pp
-A C source file is also generated which should be compiled and linked
-with the object files which reference these error codes; it contains
-the text of the messages and the initialization subroutine. Both C
-files have names derived from that of the original source file, with
-the ``.et'' suffix replaced by ``.c'' and ``.h''.
-.Pp
-A ``#'' in the source file is treated as a comment character, and all
-remaining text to the end of the source line will be ignored.
-.Sh BUGS
-Since
-.Nm compile_et
-uses a very simple parser based on
-.Xr yacc 1 ,
-its error recovery leaves much to be desired.
-.Sh "SEE ALSO"
-.Xr yacc 1 ,
-.Xr com_err 3
-.Pp
-.Rs
-.%A Ken Raeburn
-.%T "A Common Error Description Library for UNIX"
-.Re
diff --git a/usr.bin/compile_et/compile_et.c b/usr.bin/compile_et/compile_et.c
deleted file mode 100644
index b0a9926..0000000
--- a/usr.bin/compile_et/compile_et.c
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- *
- * Copyright 1986, 1987, 1988
- * by MIT Student Information Processing Board.
- *
- * For copyright info, see "mit-sipb-copyright.h".
- *
- */
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/file.h>
-#include <sys/param.h>
-#include "mit-sipb-copyright.h"
-#include "compiler.h"
-
-#ifndef __STDC__
-#define const
-#endif
-
-#ifndef lint
-static const char copyright[] =
- "Copyright 1987,1988 by MIT Student Information Processing Board";
-
-static const char rcsid_compile_et_c[] =
- "$FreeBSD$";
-#endif
-
-extern char *gensym();
-extern char *current_token;
-extern int table_number, current;
-char buffer[BUFSIZ];
-char *table_name = (char *)NULL;
-FILE *hfile, *cfile;
-
-/* lex stuff */
-extern FILE *yyin;
-extern int yylineno;
-
-char * xmalloc (size) unsigned int size; {
- char * p = malloc (size);
- if (!p)
- err(1, NULL);
- 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;
- 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 noargs_def[] = {
- "#ifdef __STDC__\n",
- "#define NOARGS void\n",
- "#else\n",
- "#define NOARGS\n",
- "#define const\n",
- "#endif\n\n",
- 0,
-};
-
-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,
-};
-
-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 */
-
-static void usage () {
- fprintf (stderr, "usage: compile_et ERROR_TABLE\n");
- exit (1);
-}
-
-static void dup_err (type, one, two) char const *type, *one, *two; {
- warnx("multiple %s specified: `%s' and `%s'", type, one, two);
- usage ();
-}
-
-int main (argc, argv) int argc; char **argv; {
- char *p, *ename;
- int len;
- char const * const *cpp;
- int got_language = 0;
-
- /* argument parsing */
- debug = 0;
- filename = 0;
- 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 ("languages", 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 {
- errx(1, "unknown language name `%s'\n\tpick one of: C K&R-C", arg);
- }
- }
- else {
- warnx("unknown control argument -`%s'", arg);
- usage ();
- }
- }
- }
- if (!filename)
- usage ();
- if (!got_language)
- language = lang_KRC;
- else if (language == lang_CPP) {
- errx(1, "sorry, C++ support is not yet finished");
- }
-
- p = xmalloc (strlen (filename) + 5);
- strcpy (p, filename);
- filename = p;
- p = strrchr(filename, '/');
- if (p == (char *)NULL)
- p = filename;
- else
- 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 == (FILE *)NULL) {
- perror(h_file);
- exit(1);
- }
- fprintf (hfile, warning, h_file);
-
- cfile = fopen(c_file, "w");
- if (cfile == (FILE *)NULL) {
- perror(c_file);
- exit(1);
- }
- fprintf (cfile, warning, c_file);
-
- /* prologue */
- for (cpp = noargs_def; *cpp; cpp++) {
- fputs (*cpp, cfile);
- fputs (*cpp, hfile);
- }
-
- fputs("static const char * const text[] = {\n", cfile);
-
- /* parse it */
- 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, %dL, %d };\n\n",
- table_number, current);
- fputs("static struct et_list link = { 0, 0 };\n\n",
- cfile);
- fprintf(cfile, "void initialize_%s_error_table (NOARGS) {\n",
- table_name);
- 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 (NOARGS);\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 */
-
- return 0;
-}
-
-int yyerror(s) char *s; {
- fputs(s, stderr);
- fprintf(stderr, "\nLine number %d; last token was '%s'\n",
- yylineno, current_token);
- return 0;
-}
-
diff --git a/usr.bin/compile_et/compiler.h b/usr.bin/compile_et/compiler.h
deleted file mode 100644
index 3bf568d..0000000
--- a/usr.bin/compile_et/compiler.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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;
diff --git a/usr.bin/compile_et/error_table.y b/usr.bin/compile_et/error_table.y
deleted file mode 100644
index 0045df7..0000000
--- a/usr.bin/compile_et/error_table.y
+++ /dev/null
@@ -1,237 +0,0 @@
-%{
-#include <stdio.h>
-#include <stdlib.h>
-char *str_concat(), *ds(), *quote();
-char *current_token = (char *)NULL;
-extern char *table_name;
-%}
-%union {
- char *dynstr;
-}
-
-%token ERROR_TABLE ERROR_CODE_ENTRY END
-%token <dynstr> STRING QUOTED_STRING
-%type <dynstr> ec_name description table_id
-%{
-%}
-%start error_table
-%%
-
-error_table : ERROR_TABLE table_id error_codes END
- { table_name = ds($2);
- current_token = table_name;
- put_ecs(); }
- ;
-
-table_id : STRING
- { current_token = $1;
- set_table_num($1);
- $$ = $1; }
- ;
-
-error_codes : error_codes ec_entry
- | ec_entry
- ;
-
-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);
- }
- ;
-
-ec_name : STRING
- { $$ = ds($1);
- current_token = $$; }
- ;
-
-description : QUOTED_STRING
- { $$ = ds($1);
- current_token = $$; }
- ;
-
-%%
-/*
- *
- * Copyright 1986, 1987 by the MIT Student Information Processing Board
- *
- * For copyright info, see mit-sipb-copyright.h.
- */
-
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include "internal.h"
-#include "error_table.h"
-#include "mit-sipb-copyright.h"
-
-#ifndef lint
-static char const rcsid_error_table_y[] =
- "$FreeBSD$";
-#endif
-
-void *malloc(), *realloc();
-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 = malloc(32 * sizeof(char));
- gensym_n++;
- sprintf(symbol, "et%ld", gensym_n);
- return(symbol);
-}
-
-char *
-ds(string)
- char const *string;
-{
- char *rv;
- rv = malloc(strlen(string)+1);
- strcpy(rv, string);
- return(rv);
-}
-
-char *
-quote(string)
- char const *string;
-{
- char *rv;
- rv = malloc(strlen(string)+3);
- strcpy(rv, "\"");
- strcat(rv, string);
- strcat(rv, "\"");
- return(rv);
-}
-
-long 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()
-{
- int i;
- for (i = 0; i < current; i++) {
- if (error_codes[i] != (char *)NULL)
- fprintf(hfile, "#define %-40s (%ldL)\n",
- error_codes[i], table_number + i);
- }
-}
-
-/*
- * 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);
-}
-
-void
-set_table_num(string)
- char *string;
-{
- 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;
-}
-
-#include "et_lex.lex.c"
diff --git a/usr.bin/compile_et/et_lex.lex.l b/usr.bin/compile_et/et_lex.lex.l
deleted file mode 100644
index 57cbd04..0000000
--- a/usr.bin/compile_et/et_lex.lex.l
+++ /dev/null
@@ -1,26 +0,0 @@
-PC [^\"]
-AN [A-Z_a-z0-9]
-%%
-
-error_table return ERROR_TABLE;
-et return ERROR_TABLE;
-error_code return ERROR_CODE_ENTRY;
-ec return ERROR_CODE_ENTRY;
-end return END;
-
-[\t\n ] ;
-
-\"{PC}*\" { register char *p; yylval.dynstr = ds(yytext+1);
- if ( (p=rindex(yylval.dynstr, '"')) ) *p='\0';
- return QUOTED_STRING;
- }
-
-{AN}* { yylval.dynstr = ds(yytext); return STRING; }
-
-#.*\n ;
-
-. { return (*yytext); }
-%%
-#ifndef lint
-static char rcsid_et_lex_lex_l[] = "$FreeBSD$";
-#endif
diff --git a/usr.bin/compile_et/mit-sipb-copyright.h b/usr.bin/compile_et/mit-sipb-copyright.h
deleted file mode 100644
index 2f7eb29..0000000
--- a/usr.bin/compile_et/mit-sipb-copyright.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-
-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.
-
-*/
-
OpenPOWER on IntegriCloud