home *** CD-ROM | disk | FTP | other *** search
- /*********
- *
- * CAPFIRST.C
- *
- * by Tom Rettig
- * modified by Leonard Zerman
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: CAPFIRST( <expC> )
- * Return: <expC> with the first letter of each word uppercase,
- * and all other alpha lowercase.
- * Error message <expC> if not enough memory.
- * Note : A new word is assumed to begin after a space or a hyphen.
- *********/
-
- #include "trlib.h"
-
- TRTYPE capfirst()
- {
- static char funcname[] = { "capfirst" };
- char *instr, *ret;
- int i, len;
- int isnew;
-
- if ( PCOUNT==1 && ISCHAR(1) )
- {
- instr = _parc(1);
- len = _tr_strlen(instr);
- ret = _tr_allocmem( (unsigned)(len+1));
-
- if ( ret )
- {
- isnew = TRUE;
- for ( i = 0; i < len; i++ )
- {
- if ( instr[i] >= UC1 && instr[i] <= UC2 && !isnew )
- ret[i] = instr[i] + CASEDIFF;
- else if ( instr[i] >= LC1 && instr[i] <= LC2 && isnew )
- ret[i] = instr[i] - CASEDIFF;
- else
- ret[i] = instr[i];
-
- isnew = ( (instr[i]==SPACEC) ||
- (instr[i]=='-') ); /* new word */
- }
- ret[i] = NULLC;
- _retc( ret );
- _tr_freemem( ret , len+1);
- }
- else
- _retc( _tr_errmsgs(funcname,E_ALLOC) );
- }
- else
- _retc( _tr_errmsgs(funcname,E_SYNTAX) );
- }
-