home *** CD-ROM | disk | FTP | other *** search
- /*********
- * LEADCHAR.C
- *
- * by Tom Rettig
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: LEADCHAR( <expC>, <char> )
- * Return: <expC> with each leading space replaced by <char>.
- * Unchanged if <char> omitted or null, or if out of memory.
- * Note : Return string is same length as <expC>.
- *********/
-
- #include "trlib.h"
-
- TRTYPE leadchar()
- {
- char *instr, *replace, *ret;
- int i, j;
- static char funcname[] = { "leadchar" };
-
- if ( PCOUNT==2 && ISCHAR(1) && ISCHAR(2) )
- {
- instr = _parc(1);
- replace = _parc(2);
- ret = _tr_allocmem((unsigned)(_tr_strlen(instr)+1));
-
- if ( ret )
- {
- if (instr[0]==SPACEC && replace[0] )
- {
- for ( i=j=0; instr[j]==SPACEC; i++, j++ )
- ret[i] = replace[0];
-
- for ( ; instr[j]; i++, j++ )
- ret[i] = instr[j];
-
- ret[i] = NULLC;
-
- _retc( ret );
- }
- else /* return unchanged if no leading spaces, or null replace */
- _retc( instr );
-
- _tr_freemem( ret,(unsigned)(_tr_strlen(instr)+1));
- }
- else /* return unchanged if no memory */
- _retc( instr );
- }
- else
- if ( PCOUNT==1 && ISCHAR(1) )
- _retc( _parc(1) );
- else
- _retc( _tr_errmsgs(funcname,E_SYNTAX) );
- }
-