[23095] | 1 | /* |
---|
[23740] | 2 | * $Header: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/util/et/error_message.c,v 1.2 1998-02-05 22:13:07 danw Exp $ |
---|
| 3 | * $Source: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/util/et/error_message.c,v $ |
---|
| 4 | * $Locker: $ |
---|
[23095] | 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 <stdio.h> |
---|
| 13 | #include <string.h> |
---|
| 14 | #include "error_table.h" |
---|
| 15 | #include "mit-sipb-copyright.h" |
---|
| 16 | |
---|
[23740] | 17 | static const char rcsid[] = "$Id: error_message.c,v 1.2 1998-02-05 22:13:07 danw Exp $"; |
---|
[23095] | 18 | static const char copyright[] = |
---|
| 19 | "Copyright 1986, 1987, 1988 by the Student Information Processing Board\nand the department of Information Systems\nof the Massachusetts Institute of Technology"; |
---|
| 20 | |
---|
| 21 | static char buffer[25]; |
---|
| 22 | |
---|
| 23 | struct et_list *_et_list = NULL; |
---|
| 24 | |
---|
| 25 | const char *error_message(long code) |
---|
| 26 | { |
---|
| 27 | int offset; |
---|
| 28 | struct et_list *et; |
---|
| 29 | int table_num; |
---|
| 30 | int started = 0; |
---|
| 31 | char *cp; |
---|
| 32 | |
---|
| 33 | offset = code & ((1<<ERRCODE_RANGE)-1); |
---|
| 34 | table_num = code - offset; |
---|
| 35 | if (!table_num) |
---|
| 36 | return strerror(offset); |
---|
| 37 | for (et = _et_list; et; et = et->next) { |
---|
| 38 | if (et->table->base == table_num) { |
---|
| 39 | /* This is the right table */ |
---|
| 40 | if (et->table->n_msgs <= offset) |
---|
| 41 | goto oops; |
---|
| 42 | return(et->table->msgs[offset]); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | oops: |
---|
| 46 | strcpy (buffer, "Unknown code "); |
---|
| 47 | if (table_num) { |
---|
| 48 | strcat (buffer, error_table_name (table_num)); |
---|
| 49 | strcat (buffer, " "); |
---|
| 50 | } |
---|
| 51 | for (cp = buffer; *cp; cp++) |
---|
| 52 | ; |
---|
| 53 | if (offset >= 100) { |
---|
| 54 | *cp++ = '0' + offset / 100; |
---|
| 55 | offset %= 100; |
---|
| 56 | started++; |
---|
| 57 | } |
---|
| 58 | if (started || offset >= 10) { |
---|
| 59 | *cp++ = '0' + offset / 10; |
---|
| 60 | offset %= 10; |
---|
| 61 | } |
---|
| 62 | *cp++ = '0' + offset; |
---|
| 63 | *cp = '\0'; |
---|
| 64 | return(buffer); |
---|
| 65 | } |
---|