freebsd-nq/usr.bin/compile_et/error_message.c
Geoff Rehmet 60643d379b Initial import of eBones.
(Including all changes for FreeBSD - importing the original eBones distribution
would be too complex at this stage, since I don't have access to Piero's 
CVS.)
(If you want to include eBones in your system, don't forget to include
MAKE_EBONES in /etc/make.conf.)
(This stuff is now also suppable from braae.ru.ac.za.)

Bones originally from MIT SIPB.
Original port to FreeBSD 1.x  by Piero Serini.
Moved to FreeBSD 2.0 by Doug Rabson and Geoff Rehmet.
Nice bug fixes from Doug Rabson.
1994-09-30 14:50:09 +00:00

78 lines
1.7 KiB
C

/*
* Copyright 1987 by the Student Information Processing Board
* of the Massachusetts Institute of Technology
* For copyright info, see "Copyright.SIPB".
*
* from: error_message.c,v 1.1 86/11/10 21:34:34 spook Exp $
* $Id: error_message.c,v 1.3 1994/09/09 21:43:22 g89r4222 Exp $
*/
#include <stdio.h>
#include "error_table.h"
extern int sys_nerr;
static char buffer[25];
char *
error_message(code)
int code;
{
register int offset;
register error_table **et;
register int table_num;
register int div;
register char *cp;
offset = code & ((1<<ERRCODE_RANGE)-1);
table_num = code - offset;
if ((_et_list == (error_table **)NULL) && table_num)
goto oops;
if (!table_num) {
if (offset < sys_nerr)
return(sys_errlist[offset]);
else
goto oops;
}
for (et = _et_list; *et != (error_table *)NULL; et++) {
if ((*et)->base == table_num) {
/* This is the right table */
if ((*et)->n_msgs <= offset)
goto oops;
return((*et)->msgs[offset]);
}
}
oops:
cp = buffer;
{
register char *cp1;
for (cp1 = "Unknown code "; *cp1; cp1++, cp++)
*cp = *cp1;
if (table_num) {
for (cp1 = error_table_name(table_num); *cp1; cp1++, cp++)
*cp = *cp1;
*cp++ = ' ';
*cp = '\0';
}
}
div = 1000000000;
if (offset == 0) {
*cp++ = '0';
*cp = '\0';
return(buffer);
}
while (div > offset)
div /= 10;
do {
register int n = offset / div;
*cp++ = '0' + n;
offset -= n * div;
div /= 10;
} while (offset && div);
while (div) {
*cp++ = '0';
div /= 10;
}
*cp = '\0';
return(buffer);
}