/*	$NetBSD: et_name.c,v 1.4 1999/05/27 21:04:19 christos Exp $	*/

/*
 * Copyright 1987, 1988 by the Student Information Processing Board
 *	of the Massachusetts Institute of Technology
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purpose and without fee is
 * hereby granted, provided that the above copyright notice
 * appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation,
 * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
 * used in advertising or publicity pertaining to distribution
 * of the software without specific, written prior permission.
 * M.I.T. and the M.I.T. S.I.P.B. make no representations about
 * the suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 */

#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("Copyright 1987,1988 by Student Information Processing Board, Massachusetts Institute of Technology");
__RCSID("$NetBSD: et_name.c,v 1.4 1999/05/27 21:04:19 christos Exp $");
#endif

#include "error_table.h"
#include "internal.h"

static const char char_set[] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";

static char buf[6];

const char *
error_table_name(num)
    int num;
{
    int ch;
    int i;
    char *p;
    unsigned int unum = num;

    /* unum = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */
    p = buf;
    unum >>= ERRCODE_RANGE;
    /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
    unum &= 077777777;
    /* unum = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
    for (i = 4; i >= 0; i--) {
	ch = (unum >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
	if (ch != 0)
	    *p++ = char_set[ch-1];
    }
    *p = '\0';
    return(buf);
}
