00001
00024
00025
00026
00027
00028
00029
00030
00031 #include <sent/stddefs.h>
00032
00033
00034
00036 #define ISTOKEN(A) strchr(delim, A)
00037
00050 char *
00051 mystrtok_quotation(char *str, char *delim, int left_paren, int right_paren, int mode)
00052 {
00053 static char *buf;
00054 static char *pos;
00055 char *p;
00056 char *from;
00057 int c;
00058
00059 if (str != NULL) {
00060 pos = buf = str;
00061 }
00062
00063
00064 p = pos;
00065 while (*p != '\0' && ISTOKEN(*p)) p++;
00066 if (*p == '\0') return NULL;
00067
00068
00069 if (mode == 1) {
00070 pos = p;
00071 return p;
00072 }
00073
00074
00075 c = *p;
00076 if (c == left_paren) {
00077 p++;
00078 if (*p == '\0') return NULL;
00079 from = p;
00080 while ((c = *p) != '\0' &&
00081 ((c != right_paren) || (*(p+1) != '\0' && !ISTOKEN(*(p+1))))) p++;
00082
00083
00084
00085 } else {
00086 from = p;
00087 while ((c = *p) != '\0' && (!ISTOKEN(c))) p++;
00088 }
00089 if (*p != '\0') {
00090 *p = '\0';
00091 p++;
00092 }
00093 pos = p;
00094 return from;
00095 }
00096
00097
00106 char *
00107 mystrtok_quote(char *str, char *delim)
00108 {
00109 return(mystrtok_quotation(str, delim, 34, 34, 0));
00110 }
00111
00120 char *
00121 mystrtok(char *str, char *delim)
00122 {
00123 return(mystrtok_quotation(str, delim, -1, -1, 0));
00124 }
00125
00134 char *
00135 mystrtok_movetonext(char *str, char *delim)
00136 {
00137 return(mystrtok_quotation(str, delim, -1, -1, 1));
00138 }