mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
Build this from contrib/ now.
This commit is contained in:
parent
f9ce010afd
commit
d8f5c86825
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=50881
|
@ -1,14 +1,18 @@
|
||||||
# $FreeBSD$
|
# $FreeBSD$
|
||||||
|
|
||||||
LIB= com_err
|
LIB= com_err
|
||||||
SRCS= com_err.c error_message.c et_name.c init_et.c
|
SRCS= com_err.c error.c
|
||||||
MAN3= com_err.3
|
MAN3= com_err.3
|
||||||
|
COM_ERRDIR= ${.CURDIR}/../../contrib/com_err
|
||||||
|
CFLAGS+= -I${COM_ERRDIR}
|
||||||
|
|
||||||
SUBDIR= doc
|
SUBDIR= doc
|
||||||
|
|
||||||
beforeinstall:
|
beforeinstall:
|
||||||
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/com_err.h \
|
${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \
|
||||||
${DESTDIR}/usr/include
|
${COM_ERRDIR}/com_err.h ${COM_ERRDIR}/com_right.h \
|
||||||
|
${DESTDIR}/usr/include
|
||||||
|
|
||||||
.include <bsd.lib.mk>
|
.include <bsd.lib.mk>
|
||||||
|
|
||||||
|
.PATH: ${COM_ERRDIR}
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
.\" Copyright (c) 1988 Massachusetts Institute of Technology,
|
|
||||||
.\" Student Information Processing Board. All rights reserved.
|
|
||||||
.\"
|
|
||||||
.\" $FreeBSD$
|
|
||||||
.\"
|
|
||||||
.TH COM_ERR 3 "22 Nov 1988" SIPB
|
|
||||||
.SH NAME
|
|
||||||
com_err \- common error display routine
|
|
||||||
.SH SYNOPSIS
|
|
||||||
.nf
|
|
||||||
#include <com_err.h>
|
|
||||||
.PP
|
|
||||||
void com_err (whoami, code, format, ...);
|
|
||||||
const char *whoami;
|
|
||||||
long code;
|
|
||||||
const char *format;
|
|
||||||
.PP
|
|
||||||
proc = set_com_err_hook (proc);
|
|
||||||
.fi
|
|
||||||
void (*
|
|
||||||
.I proc
|
|
||||||
) (const char *, long, const char *, va_list);
|
|
||||||
.nf
|
|
||||||
.PP
|
|
||||||
proc = reset_com_err_hook ();
|
|
||||||
.PP
|
|
||||||
void initialize_XXXX_error_table ();
|
|
||||||
.fi
|
|
||||||
.SH DESCRIPTION
|
|
||||||
.I Com_err
|
|
||||||
displays an error message on the standard error stream
|
|
||||||
.I stderr
|
|
||||||
(see
|
|
||||||
.IR stdio (3S))
|
|
||||||
composed of the
|
|
||||||
.I whoami
|
|
||||||
string, which should specify the program name or some subportion of
|
|
||||||
a program, followed by an error message generated from the
|
|
||||||
.I code
|
|
||||||
value (derived from
|
|
||||||
.IR compile_et (1)),
|
|
||||||
and a string produced using the
|
|
||||||
.I format
|
|
||||||
string and any following arguments, in the same style as
|
|
||||||
.IR fprintf (3).
|
|
||||||
|
|
||||||
The behavior of
|
|
||||||
.I com_err
|
|
||||||
can be modified using
|
|
||||||
.I set_com_err_hook;
|
|
||||||
this defines a procedure which is called with the arguments passed to
|
|
||||||
.I com_err,
|
|
||||||
instead of the default internal procedure which sends the formatted
|
|
||||||
text to error output. Thus the error messages from a program can all
|
|
||||||
easily be diverted to another form of diagnostic logging, such as
|
|
||||||
.IR syslog (3).
|
|
||||||
.I Reset_com_err_hook
|
|
||||||
may be used to restore the behavior of
|
|
||||||
.I com_err
|
|
||||||
to its default form. Both procedures return the previous ``hook''
|
|
||||||
value. These ``hook'' procedures must have the declaration given for
|
|
||||||
.I proc
|
|
||||||
above in the synopsis.
|
|
||||||
|
|
||||||
The
|
|
||||||
.I initialize_XXXX_error_table
|
|
||||||
routine is generated mechanically by
|
|
||||||
.IR compile_et (1)
|
|
||||||
from a source file containing names and associated strings. Each
|
|
||||||
table has a name of up to four characters, which is used in place of
|
|
||||||
the
|
|
||||||
.B XXXX
|
|
||||||
in the name of the routine. These routines should be called before
|
|
||||||
any of the corresponding error codes are used, so that the
|
|
||||||
.I com_err
|
|
||||||
library will recognize error codes from these tables when they are
|
|
||||||
used.
|
|
||||||
|
|
||||||
The
|
|
||||||
.B com_err.h
|
|
||||||
header file should be included in any source file that uses routines
|
|
||||||
from the
|
|
||||||
.I com_err
|
|
||||||
library; executable files must be linked using
|
|
||||||
.I ``-lcom_err''
|
|
||||||
in order to cause the
|
|
||||||
.I com_err
|
|
||||||
library to be included.
|
|
||||||
|
|
||||||
.\" .IR for manual entries
|
|
||||||
.\" .PP for paragraph breaks
|
|
||||||
|
|
||||||
.SH "SEE ALSO"
|
|
||||||
compile_et (1), syslog (3).
|
|
||||||
|
|
||||||
Ken Raeburn, "A Common Error Description Library for UNIX".
|
|
|
@ -1,111 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 1987, 1988 by MIT Student Information Processing Board.
|
|
||||||
*
|
|
||||||
* For copyright info, see mit-sipb-copyright.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "mit-sipb-copyright.h"
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "error_table.h"
|
|
||||||
#include "internal.h"
|
|
||||||
#include "com_err.h"
|
|
||||||
|
|
||||||
#if ! lint
|
|
||||||
static const char rcsid[] =
|
|
||||||
"$FreeBSD$";
|
|
||||||
#endif /* ! lint */
|
|
||||||
|
|
||||||
static void
|
|
||||||
#ifdef __STDC__
|
|
||||||
default_com_err_proc (const char *whoami, long code, const char *fmt, va_list args)
|
|
||||||
#else
|
|
||||||
default_com_err_proc (whoami, code, fmt, args)
|
|
||||||
const char *whoami;
|
|
||||||
long code;
|
|
||||||
const char *fmt;
|
|
||||||
va_list args;
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if (whoami) {
|
|
||||||
fputs(whoami, stderr);
|
|
||||||
fputs(": ", stderr);
|
|
||||||
}
|
|
||||||
if (code) {
|
|
||||||
fputs(error_message(code), stderr);
|
|
||||||
fputs(" ", stderr);
|
|
||||||
}
|
|
||||||
if (fmt) {
|
|
||||||
vfprintf (stderr, fmt, args);
|
|
||||||
}
|
|
||||||
putc('\n', stderr);
|
|
||||||
/* should do this only on a tty in raw mode */
|
|
||||||
putc('\r', stderr);
|
|
||||||
fflush(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __STDC__
|
|
||||||
typedef void (*errf) (const char *, long, const char *, va_list);
|
|
||||||
#else
|
|
||||||
typedef void (*errf) ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
errf com_err_hook = default_com_err_proc;
|
|
||||||
|
|
||||||
void com_err_va (whoami, code, fmt, args)
|
|
||||||
const char *whoami;
|
|
||||||
long code;
|
|
||||||
const char *fmt;
|
|
||||||
va_list args;
|
|
||||||
{
|
|
||||||
(*com_err_hook) (whoami, code, fmt, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ! VARARGS
|
|
||||||
void com_err (const char *whoami,
|
|
||||||
long code,
|
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
|
||||||
#else
|
|
||||||
void com_err (va_alist)
|
|
||||||
va_dcl
|
|
||||||
{
|
|
||||||
const char *whoami, *fmt;
|
|
||||||
long 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, long);
|
|
||||||
fmt = va_arg (pvar, const char *);
|
|
||||||
#else
|
|
||||||
va_start(pvar, fmt);
|
|
||||||
#endif
|
|
||||||
com_err_va (whoami, code, fmt, pvar);
|
|
||||||
va_end(pvar);
|
|
||||||
}
|
|
||||||
|
|
||||||
errf set_com_err_hook (new_proc)
|
|
||||||
errf new_proc;
|
|
||||||
{
|
|
||||||
errf x = com_err_hook;
|
|
||||||
|
|
||||||
if (new_proc)
|
|
||||||
com_err_hook = new_proc;
|
|
||||||
else
|
|
||||||
com_err_hook = default_com_err_proc;
|
|
||||||
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
errf reset_com_err_hook () {
|
|
||||||
errf x = com_err_hook;
|
|
||||||
com_err_hook = default_com_err_proc;
|
|
||||||
return x;
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Header file for common error description library.
|
|
||||||
*
|
|
||||||
* Copyright 1988, Student Information Processing Board of the
|
|
||||||
* Massachusetts Institute of Technology.
|
|
||||||
*
|
|
||||||
* For copyright and distribution info, see the documentation supplied
|
|
||||||
* with this package.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __COM_ERR_H
|
|
||||||
|
|
||||||
#ifdef __STDC__
|
|
||||||
#ifndef __HIGHC__ /* gives us STDC but not stdarg */
|
|
||||||
#include <stdarg.h>
|
|
||||||
#else
|
|
||||||
#include <varargs.h>
|
|
||||||
#endif
|
|
||||||
/* ANSI C -- use prototypes etc */
|
|
||||||
void com_err (const char *, long, const char *, ...);
|
|
||||||
char const *error_message (long);
|
|
||||||
void (*com_err_hook) (const char *, long, const char *, va_list);
|
|
||||||
void (*set_com_err_hook (void (*) (const char *, long, const char *, va_list)))
|
|
||||||
(const char *, long, const char *, va_list);
|
|
||||||
void (*reset_com_err_hook ()) (const char *, long, const char *, va_list);
|
|
||||||
#else
|
|
||||||
/* no prototypes */
|
|
||||||
void com_err ();
|
|
||||||
char *error_message ();
|
|
||||||
void (*com_err_hook) ();
|
|
||||||
void (*set_com_err_hook ()) ();
|
|
||||||
void (*reset_com_err_hook ()) ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define __COM_ERR_H
|
|
||||||
#endif /* ! defined(__COM_ERR_H) */
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* $FreeBSD$
|
|
||||||
* $Source: /home/ncvs/src/lib/libcom_err/error_message.c,v $
|
|
||||||
* $Locker: $
|
|
||||||
*
|
|
||||||
* Copyright 1987 by the Student Information Processing Board
|
|
||||||
* of the Massachusetts Institute of Technology
|
|
||||||
*
|
|
||||||
* For copyright info, see "mit-sipb-copyright.h".
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include "error_table.h"
|
|
||||||
#include "mit-sipb-copyright.h"
|
|
||||||
#include "internal.h"
|
|
||||||
|
|
||||||
static const char rcsid[] =
|
|
||||||
"$FreeBSD$";
|
|
||||||
static const char copyright[] =
|
|
||||||
"Copyright 1986, 1987, 1988 by the Student Information Processing Board\nand the department of Information Systems\nof the Massachusetts Institute of Technology";
|
|
||||||
|
|
||||||
static char buffer[25];
|
|
||||||
|
|
||||||
struct et_list * _et_list = (struct et_list *) NULL;
|
|
||||||
|
|
||||||
const char * error_message (code)
|
|
||||||
long code;
|
|
||||||
{
|
|
||||||
int offset;
|
|
||||||
struct et_list *et;
|
|
||||||
int table_num;
|
|
||||||
int started = 0;
|
|
||||||
char *cp;
|
|
||||||
|
|
||||||
offset = code & ((1<<ERRCODE_RANGE)-1);
|
|
||||||
table_num = code - offset;
|
|
||||||
if (!table_num) {
|
|
||||||
if (offset < sys_nerr)
|
|
||||||
return(sys_errlist[offset]);
|
|
||||||
else
|
|
||||||
goto oops;
|
|
||||||
}
|
|
||||||
for (et = _et_list; et; et = et->next) {
|
|
||||||
if (et->table->base == table_num) {
|
|
||||||
/* This is the right table */
|
|
||||||
if (et->table->n_msgs <= offset)
|
|
||||||
goto oops;
|
|
||||||
return(et->table->msgs[offset]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
oops:
|
|
||||||
strcpy (buffer, "Unknown code ");
|
|
||||||
if (table_num) {
|
|
||||||
strcat (buffer, error_table_name (table_num));
|
|
||||||
strcat (buffer, " ");
|
|
||||||
}
|
|
||||||
for (cp = buffer; *cp; cp++)
|
|
||||||
;
|
|
||||||
if (offset >= 100) {
|
|
||||||
*cp++ = '0' + offset / 100;
|
|
||||||
offset %= 100;
|
|
||||||
started++;
|
|
||||||
}
|
|
||||||
if (started || offset >= 10) {
|
|
||||||
*cp++ = '0' + offset / 10;
|
|
||||||
offset %= 10;
|
|
||||||
}
|
|
||||||
*cp++ = '0' + offset;
|
|
||||||
*cp = '\0';
|
|
||||||
return(buffer);
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 1988 by the Student Information Processing Board of the
|
|
||||||
* Massachusetts Institute of Technology.
|
|
||||||
*
|
|
||||||
* For copyright info, see mit-sipb-copyright.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ET_H
|
|
||||||
/* Are we using ANSI C? */
|
|
||||||
#ifndef __STDC__
|
|
||||||
#define const
|
|
||||||
#endif
|
|
||||||
extern int errno;
|
|
||||||
struct error_table {
|
|
||||||
char const * const * msgs;
|
|
||||||
long base;
|
|
||||||
int n_msgs;
|
|
||||||
};
|
|
||||||
struct et_list {
|
|
||||||
struct et_list *next;
|
|
||||||
const struct error_table *table;
|
|
||||||
};
|
|
||||||
extern struct et_list * _et_list;
|
|
||||||
|
|
||||||
#define ERRCODE_RANGE 8 /* # of bits to shift table number */
|
|
||||||
#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
|
|
||||||
|
|
||||||
extern const char *error_table_name();
|
|
||||||
#define _ET_H
|
|
||||||
#endif
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 1987 by MIT Student Information Processing Board
|
|
||||||
*
|
|
||||||
* For copyright info, see mit-sipb-copyright.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "error_table.h"
|
|
||||||
#include "mit-sipb-copyright.h"
|
|
||||||
#include "internal.h"
|
|
||||||
|
|
||||||
#ifndef lint
|
|
||||||
static const char copyright[] =
|
|
||||||
"Copyright 1987,1988 by Student Information Processing Board, Massachusetts Institute of Technology";
|
|
||||||
static const char rcsid_et_name_c[] =
|
|
||||||
"$FreeBSD$";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static const char char_set[] =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
|
|
||||||
|
|
||||||
static char buf[6];
|
|
||||||
|
|
||||||
const char * error_table_name(num)
|
|
||||||
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);
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* $FreeBSD$
|
|
||||||
* $Source: /home/ncvs/src/lib/libcom_err/init_et.c,v $
|
|
||||||
* $Locker: $
|
|
||||||
*
|
|
||||||
* Copyright 1986, 1987, 1988 by MIT Information Systems and
|
|
||||||
* the MIT Student Information Processing Board.
|
|
||||||
*
|
|
||||||
* For copyright info, see mit-sipb-copyright.h.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "error_table.h"
|
|
||||||
#include "mit-sipb-copyright.h"
|
|
||||||
|
|
||||||
#ifndef __STDC__
|
|
||||||
#define const
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef lint
|
|
||||||
static const char rcsid_init_et_c[] =
|
|
||||||
"$FreeBSD$";
|
|
||||||
#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;
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
/*
|
|
||||||
* internal include file for com_err package
|
|
||||||
*/
|
|
||||||
#include "mit-sipb-copyright.h"
|
|
||||||
#ifndef __STDC__
|
|
||||||
#undef const
|
|
||||||
#define const
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int errno;
|
|
||||||
extern char const * const sys_errlist[];
|
|
||||||
extern /* const */ int sys_nerr;
|
|
||||||
|
|
||||||
#ifdef __STDC__
|
|
||||||
void perror (const char *);
|
|
||||||
#else
|
|
||||||
int perror ();
|
|
||||||
#endif
|
|
|
@ -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.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "com_err.h"
|
|
||||||
#include "test1.h"
|
|
||||||
#include "test2.h"
|
|
||||||
|
|
||||||
extern int sys_nerr, errno;
|
|
||||||
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
printf("Before initiating error table:\n\n");
|
|
||||||
printf("Table name '%s'\n", error_table_name(KRB_MK_AP_TGTEXP));
|
|
||||||
printf("UNIX name '%s'\n", error_table_name(EPERM));
|
|
||||||
printf("Msg TGT-expired is '%s'\n", error_message(KRB_MK_AP_TGTEXP));
|
|
||||||
printf("Msg EPERM is '%s'\n", error_message(EPERM));
|
|
||||||
printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
|
|
||||||
printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
|
|
||||||
printf("Msg {sys_nerr} is '%s'\n", error_message(sys_nerr));
|
|
||||||
|
|
||||||
printf("With 0: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP));
|
|
||||||
|
|
||||||
initialize_krb_error_table();
|
|
||||||
printf("KRB error table initialized: base %d (%s), name %s\n",
|
|
||||||
ERROR_TABLE_BASE_krb, error_message(ERROR_TABLE_BASE_krb),
|
|
||||||
error_table_name(ERROR_TABLE_BASE_krb));
|
|
||||||
initialize_krb_error_table();
|
|
||||||
printf("With krb: tgt-expired -> %s\n",
|
|
||||||
error_message(KRB_MK_AP_TGTEXP));
|
|
||||||
|
|
||||||
initialize_quux_error_table();
|
|
||||||
printf("QUUX error table initialized: base %d (%s), name %s\n",
|
|
||||||
ERROR_TABLE_BASE_quux, error_message(ERROR_TABLE_BASE_quux),
|
|
||||||
error_table_name(ERROR_TABLE_BASE_quux));
|
|
||||||
|
|
||||||
printf("Msg for TGT-expired is '%s'\n",
|
|
||||||
error_message(KRB_MK_AP_TGTEXP));
|
|
||||||
printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1));
|
|
||||||
printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR));
|
|
||||||
printf("Msg KRB_SKDC_CANT is '%s'\n",
|
|
||||||
error_message(KRB_SKDC_CANT));
|
|
||||||
printf("Msg 1e6 (8B 64) is '%s'\n", error_message(1000000));
|
|
||||||
printf("\n\nCOM_ERR tests:\n");
|
|
||||||
com_err("whoami", FOO_ERR, (char *)NULL);
|
|
||||||
com_err("whoami", FOO_ERR, " -- message goes %s", "here");
|
|
||||||
com_err("whoami", 0, (char *)0);
|
|
||||||
com_err("whoami", 0, "error number %d\n", 0);
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
error_table krb
|
|
||||||
|
|
||||||
error_code KRB_MK_AP_TKFIL,
|
|
||||||
"Can't read ticket file"
|
|
||||||
|
|
||||||
ec KRB_MK_AP_NOTKT,
|
|
||||||
"Can't find ticket or TGT"
|
|
||||||
|
|
||||||
ec KRB_MK_AP_TGTEXP,
|
|
||||||
"TGT expired"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_UNDEC,
|
|
||||||
"Can't decode authenticator"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_EXP,
|
|
||||||
"Ticket expired"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_REPEAT,
|
|
||||||
"Repeated request"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_NOT_US,
|
|
||||||
"The ticket isn't for us"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_INCON,
|
|
||||||
"Request is inconsistent"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_TIME,
|
|
||||||
"Delta-T too big"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_BADD,
|
|
||||||
"Incorrect net address"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_VERSION,
|
|
||||||
"Protocol version mismatch"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_MSG_TYPE,
|
|
||||||
"Invalid message type"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_MODIFIED,
|
|
||||||
"Message stream modified"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_ORDER,
|
|
||||||
"Message out of order"
|
|
||||||
|
|
||||||
ec KRB_RD_AP_UNAUTHOR,
|
|
||||||
"Unauthorized request"
|
|
||||||
|
|
||||||
ec KRB_GT_PW_NULL,
|
|
||||||
"Current password is null"
|
|
||||||
|
|
||||||
ec KRB_GT_PW_BADPW,
|
|
||||||
"Incorrect current password"
|
|
||||||
|
|
||||||
ec KRB_GT_PW_PROT,
|
|
||||||
"Protocol error"
|
|
||||||
|
|
||||||
ec KRB_GT_PW_KDCERR,
|
|
||||||
"Error returned by KDC"
|
|
||||||
|
|
||||||
ec KRB_GT_PW_NULLTKT,
|
|
||||||
"Null ticket returned by KDC"
|
|
||||||
|
|
||||||
ec KRB_SKDC_RETRY,
|
|
||||||
"Retry count exceeded"
|
|
||||||
|
|
||||||
ec KRB_SKDC_CANT,
|
|
||||||
"Can't send request"
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,9 +0,0 @@
|
||||||
error_table quux
|
|
||||||
|
|
||||||
ec FOO_ERR, "foo"
|
|
||||||
|
|
||||||
ec BAR_ERR, "bar"
|
|
||||||
|
|
||||||
ec BAZ_ERR, "meow"
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,16 +1,9 @@
|
||||||
# $FreeBSD$
|
# $FreeBSD$
|
||||||
|
|
||||||
PROG= compile_et
|
PROG= compile_et
|
||||||
SRCS= compile_et.c error_table.y
|
SRCS= compile_et.c parse.y lex.l getarg.c
|
||||||
CFLAGS+=-I. -I${.CURDIR}/../../lib/libcom_err
|
CFLAGS+=-I. -I${.CURDIR}/../../contrib/com_err
|
||||||
LFLAGS+=-l
|
|
||||||
YFLAGS=
|
|
||||||
DPADD= ${LIBL}
|
|
||||||
LDADD= -ll
|
|
||||||
CLEANFILES= et_lex.lex.c
|
|
||||||
|
|
||||||
error_table.o: et_lex.lex.c
|
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
|
||||||
${DEPENDFILE}: et_lex.lex.c
|
.PATH: ${.CURDIR}/../../contrib/com_err
|
||||||
|
|
|
@ -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
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -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;
|
|
|
@ -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"
|
|
|
@ -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
|
|
|
@ -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.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue