home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MEMOXLT.ZIP / MEMOXLT.C next >
Encoding:
C/C++ Source or Header  |  1986-11-19  |  3.1 KB  |  111 lines

  1. /*    Last revision: November 19, 1986 at 18:58  */
  2.  
  3.  
  4. /**************************************************************************/
  5.  
  6. #include <extend.h> 
  7.  
  8. #define HARD_CR    0x0D
  9. #define SOFT_CR    0x8D
  10. #define LINE_FEED  0x0A
  11. #define MAX_SIZE 0x7FF0    /* 32K */
  12.  
  13. /*************************************************************
  14. * MEMOXLT()
  15. * Syntax: MEMOXLT(mem_var [, hard_xlt [,soft_xlt [,lf_xlt [, strip_flag]]]] )
  16. * Return: A string containing in the contents of the mem_var string 
  17. *         with hard/soft CR and LF converted and  hi bit stripped.
  18.  
  19. * default: hard/soft CRs (0D/8D) plus LF (0A) are removed
  20. *........: and all other characters are bitwise anded with 7F.
  21. *........: MEMOXLT(mem_var, "", "", "", .T.) is default settings
  22. *........: MEMOXLT(mem_var, CHR(13), CHR(141), CHR(10), .F.) no changes
  23.  
  24. * Note..: compile with Lattice >LC -ml -v -n filename
  25. *         
  26. */
  27.  
  28. MEMOXLT() {
  29.  
  30.    unsigned char *_str_all();
  31.    unsigned char *pos1;             /* pointer into source string */
  32.    unsigned char *str2, *pos2;
  33.    unsigned size2;
  34.    unsigned char hard_xlt, soft_xlt, lf_xlt;
  35.    int  strip_flag;
  36.  
  37.    /* default xlt chars */
  38.    hard_xlt   = '\0';
  39.    soft_xlt   = '\0';
  40.    lf_xlt     = '\0';
  41.    strip_flag = 1;
  42.  
  43.    if (PCOUNT >= 1 && ISCHAR(1)) {
  44.       /* get pointer to the memo string */
  45.       pos1 = _parc(1);
  46.  
  47.       /*  allocate temp space for result string */
  48.       size2 = strlen(pos1) + 1;
  49.       if (size2 < MAX_SIZE) {
  50.          str2  = _str_all(size2);
  51.          pos2  = str2;
  52.  
  53.          /* check for explicit xlt chars */
  54.          if (PCOUNT >= 2 && ISCHAR(2)) {
  55.             hard_xlt = *_parc(2);
  56.             if (PCOUNT >= 3 && ISCHAR(3)) {
  57.                soft_xlt = *_parc(3);
  58.                if (PCOUNT >= 4 && ISCHAR(4)) {
  59.                   lf_xlt = *_parc(4);
  60.                   if (PCOUNT >= 5 && ISLOG(5)) {
  61.                      strip_flag = _parl(5);
  62.                    }
  63.                 }
  64.             }
  65.          }
  66.  
  67.          /* translate */
  68.          while (*pos1)
  69.          {
  70.             switch (*pos1)
  71.             {
  72.                case HARD_CR:
  73.                   /* if *_xlt = "", do nothing, ie skip over the character */
  74.                   if (hard_xlt != '\0')
  75.                     *pos2++ = hard_xlt;
  76.                   break;
  77.  
  78.                case SOFT_CR:
  79.                   if (soft_xlt != '\0')
  80.                     *pos2++ = soft_xlt;
  81.                   break;
  82.  
  83.                case LINE_FEED:
  84.                   if (lf_xlt != '\0')
  85.                      *pos2++ = lf_xlt;
  86.                   break;
  87.  
  88.                default:
  89.                   if (strip_flag)
  90.                     *pos2++ = ((*pos1) & 0x7F);
  91.                   else
  92.                     *pos2++ = *pos1;
  93.                   break;
  94.             }
  95.             pos1++;
  96.          }
  97.          *pos2 = '\0';                /* terminate string */
  98.          _retc(str2);                 /* return value of function */
  99.          _str_rel(str2, size2);       /* release temp space */
  100.       }
  101.       else
  102.          _retc("ERROR: String too long for MEMOXLT()!");
  103.    }
  104.    else
  105.      _retc("ERROR: MEMOXLT() has no string parameter!");
  106. }
  107.  
  108.  
  109.  
  110.  
  111.