diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1996-11-11 04:55:06 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1996-11-11 04:55:06 +0000 |
commit | 066a987bf16f54e03a964424714abf17c430d1fb (patch) | |
tree | c82c969f6f69136b422aed922ae40829a4dcf7ce /lib | |
parent | e1f3fe3d0e5692a676c8be1703f378fb580ae38f (diff) |
Move libcom_err out of Kerberos, change include location.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 8 | ||||
-rw-r--r-- | lib/libcom_err/Makefile | 14 | ||||
-rw-r--r-- | lib/libcom_err/com_err.3 | 95 | ||||
-rw-r--r-- | lib/libcom_err/com_err.c | 151 | ||||
-rw-r--r-- | lib/libcom_err/com_err.h | 27 | ||||
-rw-r--r-- | lib/libcom_err/error_message.c | 80 | ||||
-rw-r--r-- | lib/libcom_err/error_table.h | 41 | ||||
-rw-r--r-- | lib/libcom_err/et_name.c | 55 | ||||
-rw-r--r-- | lib/libcom_err/init_et.c | 63 |
9 files changed, 530 insertions, 4 deletions
diff --git a/lib/Makefile b/lib/Makefile index 5ed41eccc0f..1a4378a8752 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.11 1996/10/25 00:06:11 downsj Exp $ +# $OpenBSD: Makefile,v 1.12 1996/11/11 04:55:00 downsj Exp $ # $NetBSD: Makefile,v 1.20.4.1 1996/06/14 17:22:38 cgd Exp $ -SUBDIR= csu libarch libc libcompat libcrypt libcurses libedit libform \ - libl libm libmenu libocurses libpanel libpcap libresolv librpcsvc \ - libskey libtelnet libterm libtermlib libutil liby libz +SUBDIR= csu libarch libc libcom_err libcompat libcrypt libcurses libedit \ + libform libl libm libmenu libocurses libpanel libpcap libresolv \ + librpcsvc libskey libtelnet libterm libtermlib libutil liby libz # XXX Temporarely until all ports are able to use libkvm (leo) .if (${MACHINE} == "amiga") || \ diff --git a/lib/libcom_err/Makefile b/lib/libcom_err/Makefile new file mode 100644 index 00000000000..1dc2e96be56 --- /dev/null +++ b/lib/libcom_err/Makefile @@ -0,0 +1,14 @@ +# $OpenBSD: Makefile,v 1.1 1996/11/11 04:55:02 downsj Exp $ + +LIB= com_err +SRCS= com_err.c error_message.c et_name.c init_et.c +CFLAGS+=-I${.CURDIR} +MAN= com_err.3 + +includes: + -cd ${.CURDIR}; cmp -s com_err.h ${DESTDIR}/usr/include/com_err.h > \ + /dev/null 2>&1 || \ + install -c -o ${BINOWN} -g ${BINGRP} -m 444 com_err.h \ + ${DESTDIR}/usr/include/com_err.h + +.include <bsd.lib.mk> diff --git a/lib/libcom_err/com_err.3 b/lib/libcom_err/com_err.3 new file mode 100644 index 00000000000..ed8159fbfde --- /dev/null +++ b/lib/libcom_err/com_err.3 @@ -0,0 +1,95 @@ +.\" Copyright (c) 1988 Massachusetts Institute of Technology, +.\" Student Information Processing Board. All rights reserved. +.\" +.\" $OpenBSD: com_err.3,v 1.1 1996/11/11 04:55:02 downsj Exp $ +.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". diff --git a/lib/libcom_err/com_err.c b/lib/libcom_err/com_err.c new file mode 100644 index 00000000000..0f6ff80b622 --- /dev/null +++ b/lib/libcom_err/com_err.c @@ -0,0 +1,151 @@ +/* $OpenBSD: com_err.c,v 1.1 1996/11/11 04:55:03 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> + +#if __STDC__ +# undef VARARGS +# include <stdarg.h> +#else +# undef VARARGS +# define VARARGS 1 +# include <varargs.h> +#endif + +#include "kerberosIV/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 "kerberosIV/com_err.h" +#undef com_err +#endif + +#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.1 1996/11/11 04:55:03 downsj Exp $"; +#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); + } +#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); +} + +typedef void (*errf) __P((const char *, long, const char *, va_list)); + +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; +{ + 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, + 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; +} diff --git a/lib/libcom_err/com_err.h b/lib/libcom_err/com_err.h new file mode 100644 index 00000000000..0e09a54370b --- /dev/null +++ b/lib/libcom_err/com_err.h @@ -0,0 +1,27 @@ +/* $OpenBSD: com_err.h,v 1.1 1996/11/11 04:55:03 downsj Exp $ */ + +/*- + * 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 +#define __COM_ERR_H + +#include <stdarg.h> + +/* ANSI C -- use prototypes etc */ +void com_err __P((const char *, long, const char *, ...)); +char const *error_message __P((long)); +void (*com_err_hook) __P((const char *, long, const char *, va_list)); +void (*set_com_err_hook __P((void (*) (const char *, long, const char *, va_list)))) + __P((const char *, long, const char *, va_list)); +void (*reset_com_err_hook __P((void))) + __P((const char *, long, const char *, va_list)); + +#endif /* ! defined(__COM_ERR_H) */ diff --git a/lib/libcom_err/error_message.c b/lib/libcom_err/error_message.c new file mode 100644 index 00000000000..53e65732f51 --- /dev/null +++ b/lib/libcom_err/error_message.c @@ -0,0 +1,80 @@ +/* $OpenBSD: error_message.c,v 1.1 1996/11/11 04:55:03 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 <string.h> +#include <errno.h> +#include "error_table.h" + +static const char rcsid[] = + "$Id: error_message.c,v 1.1 1996/11/11 04:55:03 downsj Exp $"; +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); +} diff --git a/lib/libcom_err/error_table.h b/lib/libcom_err/error_table.h new file mode 100644 index 00000000000..e6b2462061a --- /dev/null +++ b/lib/libcom_err/error_table.h @@ -0,0 +1,41 @@ +/* $OpenBSD: error_table.h,v 1.1 1996/11/11 04:55:04 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. + */ + +#ifndef _ET_H +#define _ET_H + +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(); + +#endif diff --git a/lib/libcom_err/et_name.c b/lib/libcom_err/et_name.c new file mode 100644 index 00000000000..3fde10ad72c --- /dev/null +++ b/lib/libcom_err/et_name.c @@ -0,0 +1,55 @@ +/* $OpenBSD: et_name.c,v 1.1 1996/11/11 04:55:04 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 "error_table.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[] = + "$Id: et_name.c,v 1.1 1996/11/11 04:55:04 downsj Exp $"; +#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); +} diff --git a/lib/libcom_err/init_et.c b/lib/libcom_err/init_et.c new file mode 100644 index 00000000000..ba714189bab --- /dev/null +++ b/lib/libcom_err/init_et.c @@ -0,0 +1,63 @@ +/* $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; +} |