home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 332_02 / unctrl.c < prev    next >
C/C++ Source or Header  |  1990-01-06  |  2KB  |  59 lines

  1. /****************************************************************/
  2. /* Unctrl() routines of the PCcurses package            */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free to make it public domain.    */
  9. /*                Bjorn Larsson (bl@infovox.se)    */
  10. /****************************************************************/
  11. /*             IMPLEMENTATION NOTE            */
  12. /* The conversion from a control character to a two-character    */
  13. /* sequence is done by the unctrl() function. In the BSD ver-    */
  14. /* sion of curses it is done by a macro, which uses a publi-    */
  15. /* cally available translation table. Some ill-behaved appli-    */
  16. /* cation programs use the table directly, and since it does    */
  17. /* not exist in this curses version such application will link    */
  18. /* with an error message complainting about undefined symbols.    */
  19. /****************************************************************/
  20. /* 1.4:  Use of short wherever possible. Portability        */
  21. /*     improvements. Fix for character signed-ness        */
  22. /*     and 8-bit ASCII:                900114    */
  23. /* 1.3:     MSC -W3, Turbo'C' -w -w-pro checkes:        881005    */
  24. /* 1.2:     Rcsid[] string for maintenance:        881002    */
  25. /* 1.0:     Release:                    870515    */
  26. /****************************************************************/
  27.  
  28. #include <curses.h>
  29. #include <curspriv.h>
  30.  
  31. static char    strbuf[3] = {0,0,0};
  32.  
  33. char _curses_unctrl_rcsid[] = "@(#)unctrl.c     v.1.4  - 900114";
  34.  
  35. /****************************************************************/
  36. /* Unctrl() returns a char pointer to a string corresponding to    */
  37. /* argument character 'c'.                    */
  38. /****************************************************************/
  39.  
  40. char *unctrl(c)
  41.   char c;
  42.   {
  43.   short ic = c;
  44.   ic &= 0xff;
  45.   
  46.   if (((ic & 0xe0) != 0) && (ic != 0x7f))    /* normal characters */
  47.     {
  48.     strbuf[0] = (char) ic;
  49.     strbuf[1] = '\0';
  50.     return(strbuf);
  51.     } /* if */
  52.   strbuf[0] = '^';                /* '^' prefix */
  53.   if (c == 0x7f)                /* DEL */
  54.     strbuf[1] = '?';
  55.   else                        /* other control */
  56.     strbuf[1] = ((char) ic) + '@';
  57.   return(strbuf);
  58.   } /* unctrl */
  59.