[BACK]Return to cinfo.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mg

Annotation of src/usr.bin/mg/cinfo.c, Revision 1.1

1.1     ! deraadt     1: /*
        !             2:  *             Character class tables.
        !             3:  * Do it yourself character classification
        !             4:  * macros, that understand the multinational character set,
        !             5:  * and let me ask some questions the standard macros (in
        !             6:  * ctype.h) don't let you ask.
        !             7:  */
        !             8: #include       "def.h"
        !             9:
        !            10: /*
        !            11:  * This table, indexed by a character drawn
        !            12:  * from the 256 member character set, is used by my
        !            13:  * own character type macros to answer questions about the
        !            14:  * type of a character. It handles the full multinational
        !            15:  * character set, and lets me ask some questions that the
        !            16:  * standard "ctype" macros cannot ask.
        !            17:  */
        !            18: char   cinfo[256] = {
        !            19:        _C,             _C,             _C,             _C,     /* 0x0X */
        !            20:        _C,             _C,             _C,             _C,
        !            21:        _C,             _C,             _C,             _C,
        !            22:        _C,             _C,             _C,             _C,
        !            23:        _C,             _C,             _C,             _C,     /* 0x1X */
        !            24:        _C,             _C,             _C,             _C,
        !            25:        _C,             _C,             _C,             _C,
        !            26:        _C,             _C,             _C,             _C,
        !            27:        0,              _P,             0,              0,      /* 0x2X */
        !            28:        _W,             _W,             0,              _W,
        !            29:        0,              0,              0,              0,
        !            30:        0,              0,              _P,             0,
        !            31:        _D|_W,          _D|_W,          _D|_W,          _D|_W,  /* 0x3X */
        !            32:        _D|_W,          _D|_W,          _D|_W,          _D|_W,
        !            33:        _D|_W,          _D|_W,          0,              0,
        !            34:        0,              0,              0,              _P,
        !            35:        0,              _U|_W,          _U|_W,          _U|_W,  /* 0x4X */
        !            36:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            37:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            38:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            39:        _U|_W,          _U|_W,          _U|_W,          _U|_W,  /* 0x5X */
        !            40:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            41:        _U|_W,          _U|_W,          _U|_W,          0,
        !            42:        0,              0,              0,              0,
        !            43:        0,              _L|_W,          _L|_W,          _L|_W,  /* 0x6X */
        !            44:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            45:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            46:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            47:        _L|_W,          _L|_W,          _L|_W,          _L|_W,  /* 0x7X */
        !            48:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            49:        _L|_W,          _L|_W,          _L|_W,          0,
        !            50:        0,              0,              0,              _C,
        !            51:        0,              0,              0,              0,      /* 0x8X */
        !            52:        0,              0,              0,              0,
        !            53:        0,              0,              0,              0,
        !            54:        0,              0,              0,              0,
        !            55:        0,              0,              0,              0,      /* 0x9X */
        !            56:        0,              0,              0,              0,
        !            57:        0,              0,              0,              0,
        !            58:        0,              0,              0,              0,
        !            59:        0,              0,              0,              0,      /* 0xAX */
        !            60:        0,              0,              0,              0,
        !            61:        0,              0,              0,              0,
        !            62:        0,              0,              0,              0,
        !            63:        0,              0,              0,              0,      /* 0xBX */
        !            64:        0,              0,              0,              0,
        !            65:        0,              0,              0,              0,
        !            66:        0,              0,              0,              0,
        !            67:        _U|_W,          _U|_W,          _U|_W,          _U|_W,  /* 0xCX */
        !            68:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            69:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            70:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            71:        0,              _U|_W,          _U|_W,          _U|_W,  /* 0xDX */
        !            72:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            73:        _U|_W,          _U|_W,          _U|_W,          _U|_W,
        !            74:        _U|_W,          _U|_W,          0,              _W,
        !            75:        _L|_W,          _L|_W,          _L|_W,          _L|_W,  /* 0xEX */
        !            76:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            77:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            78:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            79:        0,              _L|_W,          _L|_W,          _L|_W,  /* 0xFX */
        !            80:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            81:        _L|_W,          _L|_W,          _L|_W,          _L|_W,
        !            82:        _L|_W,          _L|_W,          0,              0
        !            83: };
        !            84:
        !            85: /*
        !            86:  * Find the name of a keystroke.  Needs to be changed to handle 8-bit printing
        !            87:  * characters and function keys better.         Returns a pointer to the terminating
        !            88:  * '\0'.
        !            89:  */
        !            90:
        !            91: char *keyname(cp, k)
        !            92: register char *cp;
        !            93: register int k;
        !            94: {
        !            95:     register char *np;
        !            96: #ifdef FKEYS
        !            97:     extern char *keystrings[];
        !            98: #endif
        !            99:
        !           100:     if(k < 0) k = CHARMASK(k);                 /* sign extended char */
        !           101:     switch(k) {
        !           102:        case CCHR('@'): np = "NUL"; break;
        !           103:        case CCHR('I'): np = "TAB"; break;
        !           104:        case CCHR('J'): np = "LFD"; break; /* yuck, but that's what GNU calls it */
        !           105:        case CCHR('M'): np = "RET"; break;
        !           106:        case CCHR('['): np = "ESC"; break;
        !           107:        case ' ':       np = "SPC"; break; /* yuck again */
        !           108:        case CCHR('?'): np = "DEL"; break;
        !           109:        default:
        !           110: #ifdef FKEYS
        !           111:            if(k >= KFIRST && k <= KLAST &&
        !           112:                    (np = keystrings[k - KFIRST]) != NULL)
        !           113:                break;
        !           114: #endif
        !           115:            if(k > CCHR('?')) {
        !           116:                *cp++ = '0';
        !           117:                *cp++ = ((k>>6)&7) + '0';
        !           118:                *cp++ = ((k>>3)&7) + '0';
        !           119:                *cp++ = (k&7) + '0';
        !           120:                *cp = '\0';
        !           121:                return cp;
        !           122:            }
        !           123:            if(k < ' ') {
        !           124:                *cp++ = 'C';
        !           125:                *cp++ = '-';
        !           126:                k = CCHR(k);
        !           127:                if(ISUPPER(k)) k = TOLOWER(k);
        !           128:            }
        !           129:            *cp++ = k;
        !           130:            *cp = '\0';
        !           131:            return cp;
        !           132:     }
        !           133:     (VOID) strcpy(cp, np);
        !           134:     return cp + strlen(cp);
        !           135: }