et_name.c revision e0ed7404719a9ddd2ba427a80db5365c8bad18c0
1/*
2 * Copyright 1987 by MIT Student Information Processing Board
3 *
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose is hereby granted, provided that
6 * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7 * advertising or publicity pertaining to distribution of the software
8 * without specific, written prior permission.  M.I.T. and the
9 * M.I.T. S.I.P.B. make no representations about the suitability of
10 * this software for any purpose.  It is provided "as is" without
11 * express or implied warranty.
12 */
13
14#include "com_err.h"
15#include "error_table.h"
16#include "internal.h"
17
18static const char char_set[] =
19	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
20
21static char buf[6];
22
23const char * error_table_name(errcode_t num)
24{
25    int ch;
26    int i;
27    char *p;
28
29    /* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */
30    p = buf;
31    num >>= ERRCODE_RANGE;
32    /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
33    num &= 077777777L;
34    /* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
35    for (i = 4; i >= 0; i--) {
36	ch = (int)((num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1));
37	if (ch != 0)
38	    *p++ = char_set[ch-1];
39    }
40    *p = '\0';
41    return(buf);
42}
43