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