home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
expand.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-21
|
1KB
|
58 lines
/*********
* EXPAND.C
* by Tom Rettig
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: EXPAND( <expC> [,<expN>] )
* Return: <expC> with <expN> spaces between each character
* Note : If <expN> is omitted, default is one.
*********/
#include "trlib.h"
TRTYPE expand()
{
static char funcname[] = { "expand" };
char *instr, *ret;
int nspace, instrlen, k;
long i, j;
long mbytes;
if ( (PCOUNT==2 && ISCHAR(1) && ISNUM(2)) ||
(PCOUNT==1 && ISCHAR(1)) )
{
instr = _parc(1);
nspace = (PCOUNT==2) ? _parni(2) : 1;
if (nspace <= 0)
{
_retc(instr);
return;
}
instrlen = _tr_strlen(instr);
mbytes = (long) instrlen * (long) nspace;
ret = _tr_allocmem((unsigned)((instrlen+1)+(mbytes)));
if ( ret )
{
for ( i=0L, j=0L; instr[i]; i++ )
{
ret[j++] = instr[i];
if ( instr[i+1] ) /* don't expand after last char */
{
for ( k=0; k<nspace; k++ )
ret[j++] = SPACEC;
}
}
ret[j] = NULLC;
_retc( ret );
_tr_freemem( ret,(unsigned)((instrlen+1)+(mbytes)));
}
else
_retc( _tr_errmsgs(funcname,E_ALLOC) );
}
else
_retc( _tr_errmsgs(funcname,E_SYNTAX) );
}