home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d352 / mg.lha / MG / src.LZH / mg / cinfo.c < prev    next >
C/C++ Source or Header  |  1990-05-23  |  4KB  |  154 lines

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