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