home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * st_alph.c - string alpha functions.
- *
- * Purpose: This file contains string functions dealing with
- * alpha conversion.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <stdlib.h>
- #include <string.h>
- #include "blackstr.h"
- #include "kb_head.h"
-
-
- /********
- *
- * st_squ(str,c) - squeeze c characters out of string
- *
- **/
-
- char *st_squ(char *str, char c)
- {
- int i,j;
-
- for(i=j=0; str[i]!= '\0'; i++)
- if(str[i] != c)
- str[j++] = str[i];
- str[j] = NUL;
- return(str);
- }
-
-
- /********
- *
- * st_ccmpu(s1,s2,n) - compare two strings for n bytes in upper case
- * NOTE: s1 and s2 must be longer than n bytes
- **/
-
- int st_ccmpu(char *s1, char *s2, int n)
- {
- while(*s1&&*s2&&n) {
- if(toupper(*s1)<toupper(*s2))
- return(-1);
- else if(toupper(*s1)>toupper(*s2))
- return(TRUE);
- else
- --n,++s1,++s2;
- }
- return(FALSE);
- }
-
-
- /********
- *
- * st_ncmpi(s1,s2,n) - compare strings for n bytes, ignore case
- *
- **/
-
- int st_ncmpi(char *s1, char *s2, int n)
- {
- while ((*s1!=NUL) && (*s2!=NUL) &&(n)) {
- if(toupper(*s1)>toupper(*s2))
- return(-1);
- else if(toupper(*s1)<toupper(*s2))
- return(TRUE);
- else {
- ++s1;
- ++s2;
- --n;
- }
- }
- return(FALSE); /* strings are identical for n bytes */
- }
-
-
- /********
- *
- * st_ccat (s1,s2,n) - append n bytes of s2 onto s1
- *
- **/
-
- void st_ccat(char *s1, char *s2, int n)
- {
- while(*s1++); /* go to end of s1 */
- s1--; /* last character */
- while ((*s2!=NUL) && (n)) {
- *s1++ = *s2++;
- --n;
- }
- *s1 = NUL; /* null terminate the result */
- }
-
-
- /********
- *
- * st_bcpy(buff,str) - copy string to buffer
- *
- **/
-
- void st_bcpy(char *buff, char *str)
- {
- while(*str!=NUL)
- *buff++ = *str++;
- }
-
-
- /********
- *
- * st_instr(str2,str1) - see if str1 is in str2
- *
- **/
-
- char *st_instr(char *str2, char *str1)
- {
- while(*str2) {
- if((st_patma(str1,str2)))
- return(str2);
- else
- str2++;
- }
- return(FALSE);
- }
-
-
- /********
- *
- * st_instri(str2,str1) - see if str1 is in str2 ignore case
- *
- **/
-
- char *st_instri(char *str2, char *str1)
- {
- while(*str2) {
- if((st_patmai(str1, str2)))
- return(str2);
- else
- str2++;
- }
- return(NULL);
- }
-
-
- /********
- *
- * st_inbuf(str,buff,n) - see if string is in buffer
- *
- **/
-
- char *st_inbuf(char *str, char *buff, int n)
- {
- char *ans,*ptr;
-
- ptr = malloc(n+1);
- strcpy(ptr,buff);
- ptr[n] = NUL; /* null terminate buffer */
- ans=st_instr(ptr,str);
- free(ptr);
- return(ans);
- }
-
-
- /********
- *
- * st_patmai(str1,str2) - pattern match anchored - ignore case
- *
- **/
-
- int st_patmai(char *str1, char *str2)
- {
- while(*str1 && *str2) {
- if(*str1 != '?')
- if(toupper(*str1) != toupper(*str2))
- return(FALSE);
- ++str1,++str2;
- }
- return(TRUE);
- }
-
-
- /********
- *
- * st_patma(str1,str2) - do anchored pattern match of str1 in str2
- *
- **/
-
- int st_patma(char *str1, char *str2)
- {
- while(*str1&&*str2) {
- if(*str1 != '?')
- if(*str1 != *str2)
- return(FALSE);
- ++str1,++str2;
- }
- return(TRUE);
- }
-
-
- /********
- *
- * st_bllz(str) - blank leading zeroes
- *
- **/
-
- char *st_bllz(char *str)
- {
- char *ptr;
-
- ptr = str;
- while(!isdigit(*str++)) ; /* first find a digit */
- while(*str=='0') {
- *str++ = ' '; /* convert to blank */
- }
- return(ptr);
- }
-
-
- /********
- *
- * st_zlbl(str) - zero leading blanks
- *
- **/
-
- char *st_zlbl(char *str)
- {
- char *ptr;
-
- ptr = str;
- while(*str==BLANK)
- *str++='0';
- return(ptr);
- }
-
-
- /********
- *
- * st_delc(str,c) - find delimiter c in string
- *
- **/
-
- char *st_delc(char *str, char c)
- {
- while((*str!=NUL) && (*str!=c)) ++str;
- if(*str)
- return(str); /* return pointer to delimeter */
- else
- return(NULL); /* or NUL if not found */
- }
-
-
- /********
- *
- * st_wild(str) - see if string has wildcard chars
- *
- **/
-
- int st_wild(char *str)
- {
- while(*str)
- if((*str=='?')||(*str++=='*'))
- return(TRUE);
- return(FALSE);
- }
-
-
- /********
- *
- * st_tabr(str) - expand tabs in string
- *
- **/
-
- void st_tabr(char *str)
- {
- char *ostr,*temp,buff[256];
- int i;
-
- ostr=str;
- temp = buff;
- while(*str!=NUL) {
- if((*temp=*str++)=='\t')
- for(i=0; i<8; ++i)
- *temp++=' ';
- else ++temp;
- }
- *temp=NUL;
- strcpy(ostr,buff); /* copy back to string */
- }
-
-
- /********
- *
- * st_ptrs(buff,ptrs,cnt) - get pointers to strings in buffer
- *
- **/
-
- void st_ptrs(char *buff, char *ptrs[], int cnt)
- {
- int i;
-
- for(i=0; i<cnt; ++i) {
- ptrs[i] = buff;
- while(*buff++); /* find next null*/
- }
- }
-