home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
rettig.zip
/
TRSOURCE.EXE
/
STREET.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
3KB
|
94 lines
/*********
* Function: STREET
* by Tom Rettig, Leonard Zerman
* Placed in the public domain by Tom Rettig Associates, 10/22/1990.
*
* Syntax: STREET( <expC> )
* Return: <expC> street name from street address string
* Note : Return string is same length as <expC>.
* Fails on:
* One Snobby Court (use 1 Snobby Court)
* 123 1/2 31st Street (use 123-1/2 31st Street)
* 123 N.E. Central Ave. (use Central Ave. N.E.)
* 69th Street & Main (use Main & 69th Street)
* 69th Street & 34th (spell out first street name)
*********/
#include "trlib.h"
TRTYPE street()
{
static char *direction[] = { "NORTH ", "SOUTH ", "EAST ", "WEST " };
static char funcname[] = { "street" };
char *instr, *start, *outbuffer;
int i, j, strlen;
int found = FALSE;
if ( PCOUNT==1 && ISCHAR(1) )
{
instr = start = _parc(1); /* get parameter */
strlen = _tr_strlen( instr ); /* get lenth of string */
outbuffer = _tr_allocmem( (unsigned)strlen+1); /* allocate return buffer */
if (!(outbuffer)) /* if error on allocation */
{
_retc(instr); /* return original string */
return;
}
while ( *instr==SPACEC ) /* skip leading spaces */
instr++;
/* if first char is a digit, skip to next space */
/* fails if address is a word; e.g.: One Snobby Court */
if ( ISDIGIT(*instr) )
{
while ( *instr != SPACEC && *instr )
instr++;
}
/* skip any extra spaces after leading 'digitword' */
/* digitword could be 1234-A or 123-1/2 */
while ( *instr==SPACEC )
instr++;
/* skip N/S/E/W direction */
for ( i=0; i<4; i++ )
{
for ( j=0; instr[j]==direction[i][j] ||
instr[j]-UPPER==direction[i][j] ||
(instr[j]==ABRENDCHAR && (j==1||j==2)); j++ )
{
/* if both end with space or instr is one or two letter abbre */
if ( instr[j]==SPACEC || instr[j]==ABRENDCHAR )
{
instr += ++j;
found = TRUE;
break;
}
}
if ( found )
break;
}
/* skip any extra spaces after direction */
while ( *instr==SPACEC )
instr++;
_tr_strcpy( outbuffer, instr ); /* copy to output buff */
for (i=_tr_strlen(outbuffer), j=0; i<strlen; i++, j++)
outbuffer[i] = start[j]; /* pad to original length */
outbuffer[i] = NULLC; /* null terminator */
_tr_toup(outbuffer); /* uppercase return string */
_retc(outbuffer); /* return balance of string */
_tr_freemem(outbuffer,(unsigned)strlen+1);
}
else
_retc( _tr_errmsgs( funcname, E_SYNTAX )); /* syntax error */
}