home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / or / or_ps2asc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.8 KB  |  115 lines

  1. /* or_ps2asc.c: convert printable string to ascii */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/or/RCS/or_ps2asc.c,v 6.0 1991/12/18 20:23:08 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/or/RCS/or_ps2asc.c,v 6.0 1991/12/18 20:23:08 jpo Rel $
  9.  *
  10.  * $Log: or_ps2asc.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:08  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19.  
  20.  
  21. /*
  22. Map printable string to ASCII
  23. */
  24.  
  25. void or_ps2asc (ps, ascii)
  26. char    *ps;
  27. char    *ascii;
  28. {
  29.     register char       *p, *q;
  30.     int                 i;
  31.  
  32.     PP_DBG (("Lib/or_ps2asc('%s')", ps));
  33.  
  34.     p = ps;
  35.     q = ascii;
  36.     for (;*p != '\0';) {
  37.  
  38.     if (*p != '(')
  39.         *q++ = *p++;
  40.     else {
  41.         if (*(p + 2) == ')') {
  42.             switch (*(p + 1)) {
  43.                 case 'a':
  44.                 case 'A':
  45.                 *q++ = '@';
  46.                 break;
  47.                 case 'p':
  48.                 case 'P':
  49.                 *q++ = '%';
  50.                 break;
  51.                 case 'b':
  52.                 case 'B':
  53.                 *q++ = '!';
  54.                 break;
  55.                 case 'q':
  56.                 case 'Q':
  57.                 *q++ = '"';
  58.                 break;
  59.                 case 'u':
  60.                 case 'U':
  61.                 *q++ = '_';
  62.                 break;
  63.                 case 'l':
  64.                 case 'L':
  65.                 *q++ = '(';
  66.                 break;
  67.                 case 'r':
  68.                 case 'R':
  69.                 *q++ = ')';
  70.                 break;
  71.  
  72.                 default:
  73.                 PP_LOG (LLOG_EXCEPTIONS, 
  74.                     ("Unknown Printable Char '%s'", ps));
  75.                 (void) strcpy (ascii, ps);
  76.                 return;
  77.             }
  78.             p = p + 3;
  79.         }
  80.  
  81.         else {
  82.  
  83.             if (isdigit (*(p + 1)) && isdigit (*(p + 2))
  84.                 && (*(p + 3)) && *(p + 4) == ')')
  85.             {
  86.                 (void) sscanf (p + 1, "%3d", &i);
  87.                 p = p + 5;
  88.             }
  89.             else
  90.             {
  91.                 PP_LOG (LLOG_EXCEPTIONS, 
  92.                     ("Unkown digit '%s'", ps)); 
  93.                 (void) strcpy (ascii, ps);
  94.                 return;
  95.             }
  96.  
  97.  
  98.             if (i <= 0 || i >= 127) {
  99.                 PP_LOG (LLOG_EXCEPTIONS, 
  100.                     ("Digit '%d' out of range '%s'", i, ps)); 
  101.                 (void) strcpy (ascii, ps);
  102.                 return;
  103.             }
  104.  
  105.             *q++ = (char) i;
  106.  
  107.         }  /* end of if */
  108.  
  109.     }  /* end of if */
  110.  
  111.     }  /* end of for */
  112.  
  113.     *q = '\0';
  114. }
  115.