/* This file include a few string manipulation functions; based upon ANSI standard functions. Written by: Warren M Myers 21 Feb 2000 Updated by: Warren M Myers 22 Jun 2000 Updated by: Warren M Myers 08 Dec 2006 - yank & clean Copyright: none -- All included functions may be modified at will, and distributed freely. No fee may be applied to their distribution other than media charges. int isendpunct(int c); checks to see if the character passed down is a sentence-ending puntuation mark and returns 1 if it is, 0 if not. int len(char *); This function returns the length of the string passed. void ucase(char []); Takes a pointer to a char/array of type char and converts it to uppercase. The name is the same as the BasIc function for doing the same operation. void lcase(char []); Takes a pointer to a char/array of type char and converts it to lowercase. The name is the same as the BasIc function for doing the same operation. int comparestr(char *, char *); Takes 2 pointers to type char and compares them for lexigraphic equivilency. eG- 'english' = 'eNGlIsH'. char *purgecomma(char *); Takes a pointer to a char and searches through for the first comma. This is used when reading in a list from a file which contains comma-delimited items that you wish to see removed. eg- read in "Schmoe,Joe" and purge, giving "SchmoeJoe". This simplifies string comparisons. This function only purges the first comma. void *splitstr(char *, char *, char *, char *); This function is designed to split a string into 2 components, the first argument is the original string, the second the first segment, the thrid the second segment, and the fourth argument the character to split at. char *swapstr(char *, char *); This function will split a string at the point of the second argument and swap the 'first half' with the 'second half' and return the swapped string to the calling module. int parselinew(char *); counts the number of words in the passed string. int parselines(char *); counts the number of sentence-ending characters in the passed string. assumes elipsis (...) is not end sentence. int parselinec(char *); counts the number of characters (alphanumerics) in the passed string. int find(char *,char *); looks for first string in second string. If found, returns 1, else 0. char *left(char *,int); Returns the left most segment of the string going until the number character, same as Basic function. char *mid(char *, int, int); Returns the middle of the string passed down, starting at the first int point, and running through the second, same as Basic function. char *right(char *,int); Returns the right most segment of the string starting at the number character and going to the end, same as Basic function. char *yank(char *, char) remove all instances of char from char* char *remove(char *, char *) remove all instances of items in list (second arg) from first string */ #ifndef STRFUNCS_H #define STRFUNCS_H #include #include #include #define TRUE 1 #define FALSE 0 int isendpunct(int); int len(char*); void ucase(char[]); void lcase(char[]); int comparestr(char*, char*); char *purgecomma(char*); void splitstr(char*, char*, char*, char*); char *swapstr(char*, char*); int parselinew(char *line); int parselines(char *line); int parselinec(char *line); int find(char *,char *); char *left(char *, int); char *mid(char *, int, int); char *right(char *, int); int isendpunct(int c){ if(c == 33) return 1; if(c == 46) return 1; if(c == 63) return 1; return 0; } int len(char *s){ int l=0; while(s[l++] != '\0'); return l; } void ucase(char l[]){ int i=0; while(l[i] != '\0') l[i] = toupper(l[i++]); } void lcase(char u[]){ int i=0; while(u[i] != '\0') u[i] = tolower(u[i++]); } int comparestr(char *s1, char *s2){ char *c1 = (char*)malloc(sizeof(char)*len(s1)); char *c2 = (char*)malloc(sizeof(char)*len(s2)); strcpy(c1,s1); strcpy(c2,s2); ucase(c1); ucase(c2); if(strcmp(c1,c2)){ /* not equal */ return 0;} else{ /* equal */ return 1;} } char *purgecomma(char *orig){ int i=0,flag=0; char sep = ','; char *purged = (char*)malloc(sizeof(char)*len(orig)); while((orig[i] != sep) && (orig[i] != '\0')) strncpy(purged,orig,i++); strcat(purged,&orig[i]); return purged; } void splitstr(char *orig, char *firstseg, char *lastseg, char *splitchar){ char *copy,*temp; copy = (char*)malloc(sizeof(char)*len(orig)); strcpy(copy,orig); temp = strtok(copy,splitchar); strcpy(firstseg,temp); strcat(firstseg,splitchar); temp = strtok(NULL,NULL); strcpy(lastseg,temp); } char *swapstr(char *orig, char *splitchar){ char *temp,*seg1,*seg2; char *copy = (char*)malloc(sizeof(char)*len(orig)); char *swapped = (char*)malloc(sizeof(char)*len(orig)); strcpy(copy,orig); temp = strtok(copy,splitchar); while(*copy != '\0') copy++; copy++; seg2 = (char*)malloc(sizeof(char)*len(temp)); strcpy(seg2,temp); seg1 = (char*)malloc(sizeof(char)*len(copy)); strcpy(seg1,copy); strcat(seg1,splitchar); strcpy(swapped,seg1); strcat(swapped,seg2); return swapped; } int parselinew(char *line){ int ct = 0; int lt = ct; int w = 0; int l = len(line); if(((line[l-1] == '-') && (isalpha(line[l-2])||isdigit(line[l-2]))) || ((line[l-2] == '-') && (isalpha(line[l-3])||isdigit(line[l-3]))) || ((line[l-3] == '-') && (isalpha(line[l-4])||isdigit(line[l-4]))) || ((line[l-4] == '-') && (isalpha(line[l-5])||isdigit(line[l-5]))) || ((line[l-5] == '-') && (isalpha(line[l-6])||isdigit(line[l-6])))){ w--;} strcat(line, " "); while((line[ct] != '\0') && (ct=0;i--){ r[i] = '\0';} for(;j