📄 strsub.c
字号:
/**********************************/ /** STRING PARSING SUBROUTINES **/ /**********************************//************************************************************************History************************************************************************//*2 Jan 1997 For unknown reasons, strcmpi() has started to fail on AIX when strsub.c compiled with O3 option. Have rewritten routine to include explicit indexing of input strings (rather than incrementing char *). It works now.*//************************************************************************Include Files************************************************************************/#include <stdlib.h>#include <ctype.h>#include "strsub.h"/************************************************************************Defines************************************************************************/#define BOOLEAN int#define TRUE 1#define FALSE 0/************************************************************************Module Variables************************************************************************//* String holding White Space Characters *//* PULLS AND RETURNS POINTER TO FIRST TOKEN */char *strhed (char **tadd){ char *head, *sep, *tail; tail = (*tadd); /* FIND FIRST NONBLANK CHARACTER */ while ( (*tail) && ( (*tail)==' ' || (*tail)=='\t' || (*tail)=='\n' ) ) tail++; /* FIND NEXT WHITE SPACE CHARCTER */ head = (sep = tail); while ((*sep) && (*sep)!=' ' && (*sep)!='\n' && (*sep)!='\t') sep++; /* INSERT NULL CHARACTER */ tail = sep; if (*sep) { (*sep) = 0; tail++; } /* RETURN FIRST TOKEN */ SkipWhiteSpace (&tail); *tadd = tail; return(head);}/* COMPARES TWO STRINGS BUT IGNORES CASE *//* RETURNS -1 if a< b *//* 0 if a==b *//* 1 if a> b */int strcmpi (const char *FirstString, const char *SecondString) { int ichar; char FirstChar; char SecondChar; ichar = 0; do { /* Convert characters to uppercase */ FirstChar = toupper(FirstString [ichar]); SecondChar = toupper(SecondString[ichar]); /* Increment ichar */ ichar++; } while (FirstChar==SecondChar && FirstChar!='\0' && SecondChar!='\0'); if (FirstChar<SecondChar) return -1; else if (FirstChar>SecondChar) return 1; else return 0; }#ifdef OLD_STRCMPIint strcmpi (char *a, char *b) { int flag; char inc = 'a' - 'A'; char ta, tb;/*test*/printf ("File %s line %i\n", __FILE__, __LINE__);printf ("a <%s> b <%s>\n", a, b);/*end test*/ do { ta = *a; tb = *b; flag = (ta==tb); if (!flag) { if (ta>='A' && ta<='Z') ta += inc; if (tb>='A' && tb<='Z') tb += inc; ; flag = (ta==tb); } } while (flag && *a++!=0 && *b++!=0);/*test*/printf ("flag = %i\n", flag);/*end test*/ if (flag) return(0); if (ta<tb) return(-1); return( 1);}#endif/* PULLS LEADING TOKEN: EVALUATES AS CONSTANT - RETURNS DOUBLE */double dblstr (char **s) { char *t = strhed (s); if (*t==0) return (0.0); else return (atof(t));}/* PULLS LEADING TOKEN: EVALUATES AS CONSTANT - RETURNS INT */int intstr (char **s) { char *t = strhed (s); if (*t==0) return (0); else return (atoi(t));}/* PULLS LEADING TOKEN: EVALUATES AS CONSTANT - RETURNS LONG */long lngstr (char **s) { char *t = strhed (s); if (*t==0) return (0L); else return (atol(t));}/* CONVERTS STRING TO UPPER CASE */void upstr (char *t ) { while (*t!=0) { *t = toupper(*t); t++; }}/* BREAKS STRING INTO LINES ACCORDING TO ';' OR '\n' */char *strlin (char **tadd){ char *head, *tail; head = tail = *tadd; /* FIND FIRST SEPARATOR (; or \n) */ while ( *tail && *tail!=';' && *tail!='\n') tail++; /* INSERT NULL CHARACTER */ if (*tail) { *tail=0; tail++; } /* RETURN FIRST TOKEN */ *tadd = tail; return(head);}/* Returns True if first non-whitespace characters is in string */BOOLEAN IsComment (char *InputString, char *CommentChars) { char LeadingChar; int TestIndex; /* Find first non-white space character */ SkipWhiteSpace (&InputString); LeadingChar = InputString[0]; /* Scan list of comment characters to see if leading character belongs */ TestIndex = 0; while ( CommentChars[TestIndex]!='\0' && CommentChars[TestIndex]!=LeadingChar ) TestIndex++; /* Return true if matching characters not string terminatore */ return (CommentChars[TestIndex] != '\0'); }BOOLEAN IsBlank (char *InputString) { SkipWhiteSpace (&InputString); if (InputString[0]=='\0') return TRUE; else return FALSE; }void SkipWhiteSpace (char **s) { while ( **s == ' ' || **s == '\n' || **s == '\t' || **s == '\r' || **s == '\b' || **s == '\f' || **s == '\v' ) (*s)++; }#ifdef ULTRIXchar *strdup (char *s){ char *t = (char *) calloc (strlen(s)+1, sizeof(char)); strcpy (t, s); return (t);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -