home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix CD 2.0
/
Phoenix_CD.cdr
/
01e
/
margin.zip
/
MARGIN.C
next >
Wrap
Text File
|
1986-11-18
|
2KB
|
80 lines
/* Last revision: November 18, 1986 at 18:56 */
/**************************************************************************/
#include <extend.h>
#define LF '\n'
#define SOFT_LF ('\n' | 0x80)
#define MAX_SIZE 0x7FF0 /* 32K */
/*************************************************************
* MARGIN()
* Syntax: MARGIN( <expC>, [<expN>] )
* Return: A string containing in the contents of the
* expC string with all hi bits stripped and a margin
* width of expN. Range of expN is 0..32, default of 8
* Note..: compile with Lattice >LC -ml -v -n MARGIN
*
*/
MARGIN()
{
unsigned char *_str_all();
unsigned char *str1, *pos1; /* string and a pointer into it */
unsigned char *str2, *pos2;
unsigned char c;
unsigned size2;
int spaces, idx, lines;
if (PCOUNT >= 1 && ISCHAR(1)) {
str1 = _parc(1);
pos1 = str1;
spaces = 8;
if (PCOUNT == 2 && ISNUM(2)) {
spaces = _parni(2);
if (spaces < 0 || spaces > 32)
spaces = 8;
}
lines = 2;
while (*pos1) {
if (*pos1 == LF || *pos1 == SOFT_LF )
lines++;
pos1++;
}
pos1 = str1;
size2 = strlen(str1) + (spaces*(lines)) + 2;
if (size2 < MAX_SIZE) {
str2 = _str_all(size2);
pos2 = str2;
while ((*pos1) && *pos1 != 0x1A) { /* scan the str1 until it's end */
*pos2 = ((*pos1) & 0x7F); /* strip hi bit and move char */
c = *pos2; /* get the char from str1 */
pos1++;
pos2++;
if (c == LF && (spaces)) { /* if we found a new line */
if (*pos1 >= ' ') /* and the new line has text on it */
/* insert the proper number of spaces into str2 */
for (idx = 1; idx <= spaces; ++idx)
*pos2++ = ' ';
}
}
*pos2 = '\0'; /* terminate string */
_retc(str2);
_str_rel(str2, size2); /* release temp space */
}
else
_retc("ERROR: String too long for MARGIN()!");
}
else
_retc("ERROR: MARGIN() has no string parameter!");
}