home *** CD-ROM | disk | FTP | other *** search
- /* Last revision: November 19, 1986 at 18:58 */
-
-
- /**************************************************************************/
-
- #include <extend.h>
-
- #define HARD_CR 0x0D
- #define SOFT_CR 0x8D
- #define LINE_FEED 0x0A
- #define MAX_SIZE 0x7FF0 /* 32K */
-
- /*************************************************************
- * MEMOXLT()
- * Syntax: MEMOXLT(mem_var [, hard_xlt [,soft_xlt [,lf_xlt [, strip_flag]]]] )
- * Return: A string containing in the contents of the mem_var string
- * with hard/soft CR and LF converted and hi bit stripped.
-
- * default: hard/soft CRs (0D/8D) plus LF (0A) are removed
- *........: and all other characters are bitwise anded with 7F.
- *........: MEMOXLT(mem_var, "", "", "", .T.) is default settings
- *........: MEMOXLT(mem_var, CHR(13), CHR(141), CHR(10), .F.) no changes
-
- * Note..: compile with Lattice >LC -ml -v -n filename
- *
- */
-
- MEMOXLT() {
-
- unsigned char *_str_all();
- unsigned char *pos1; /* pointer into source string */
- unsigned char *str2, *pos2;
- unsigned size2;
- unsigned char hard_xlt, soft_xlt, lf_xlt;
- int strip_flag;
-
- /* default xlt chars */
- hard_xlt = '\0';
- soft_xlt = '\0';
- lf_xlt = '\0';
- strip_flag = 1;
-
- if (PCOUNT >= 1 && ISCHAR(1)) {
- /* get pointer to the memo string */
- pos1 = _parc(1);
-
- /* allocate temp space for result string */
- size2 = strlen(pos1) + 1;
- if (size2 < MAX_SIZE) {
- str2 = _str_all(size2);
- pos2 = str2;
-
- /* check for explicit xlt chars */
- if (PCOUNT >= 2 && ISCHAR(2)) {
- hard_xlt = *_parc(2);
- if (PCOUNT >= 3 && ISCHAR(3)) {
- soft_xlt = *_parc(3);
- if (PCOUNT >= 4 && ISCHAR(4)) {
- lf_xlt = *_parc(4);
- if (PCOUNT >= 5 && ISLOG(5)) {
- strip_flag = _parl(5);
- }
- }
- }
- }
-
- /* translate */
- while (*pos1)
- {
- switch (*pos1)
- {
- case HARD_CR:
- /* if *_xlt = "", do nothing, ie skip over the character */
- if (hard_xlt != '\0')
- *pos2++ = hard_xlt;
- break;
-
- case SOFT_CR:
- if (soft_xlt != '\0')
- *pos2++ = soft_xlt;
- break;
-
- case LINE_FEED:
- if (lf_xlt != '\0')
- *pos2++ = lf_xlt;
- break;
-
- default:
- if (strip_flag)
- *pos2++ = ((*pos1) & 0x7F);
- else
- *pos2++ = *pos1;
- break;
- }
- pos1++;
- }
- *pos2 = '\0'; /* terminate string */
- _retc(str2); /* return value of function */
- _str_rel(str2, size2); /* release temp space */
- }
- else
- _retc("ERROR: String too long for MEMOXLT()!");
- }
- else
- _retc("ERROR: MEMOXLT() has no string parameter!");
- }
-
-
-
-