1 /*
2  * Copyright 1987 by the Student Information Processing Board
3  * of the Massachusetts Institute of Technology
4  *
5  * For copyright info, see "mit-sipb-copyright.h".
6  */
7 
8 #include "error_table.h"
9 #include "com_err.h"
10 #include <sysdep.h>
11 
12 char *error_table_name_r __P((int, char *));
13 
14 struct et_list * _et_list = (struct et_list *) NULL;
15 
error_message(code)16 const char * error_message (code)
17 long	code;
18 {
19     static char buf[COM_ERR_BUF_LEN];
20 
21     return(error_message_r(code, buf));
22 }
23 
error_message_r(code,buf)24 const char * error_message_r (code, buf)
25 long	code;
26 char	*buf;
27 {
28     int offset;
29     struct et_list *et;
30     int table_num;
31     int started = 0;
32     char *cp, namebuf[6];
33 
34     offset = code & ((1<<ERRCODE_RANGE)-1);
35     table_num = code - offset;
36     if (!table_num)
37 	return strerror(offset);
38     for (et = _et_list; et; et = et->next) {
39 	if (et->table->base == table_num) {
40 	    /* This is the right table */
41 	    if (et->table->n_msgs <= offset)
42 		break;
43 	    return(et->table->msgs[offset]);
44 	}
45     }
46 
47     strcpy (buf, "Unknown code ");
48     if (table_num) {
49 	strcat (buf, error_table_name_r (table_num, namebuf));
50 	strcat (buf, " ");
51     }
52     for (cp = buf; *cp; cp++)
53 	;
54     if (offset >= 100) {
55 	*cp++ = '0' + offset / 100;
56 	offset %= 100;
57 	started++;
58     }
59     if (started || offset >= 10) {
60 	*cp++ = '0' + offset / 10;
61 	offset %= 10;
62     }
63     *cp++ = '0' + offset;
64     *cp = '\0';
65     return(buf);
66 }
67