Julius 4.2
|
00001 00024 /* 00025 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00026 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00027 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00028 * All rights reserved 00029 */ 00030 00031 #include <sent/stddefs.h> 00032 00033 /* strtok with quotation handling */ 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; /* target string buffer */ 00054 static char *pos; /* current pointer position */ 00055 char *p; 00056 char *from; 00057 int c; 00058 00059 if (str != NULL) { 00060 pos = buf = str; 00061 } 00062 00063 /* find start point */ 00064 p = pos; 00065 while (*p != '\0' && ISTOKEN(*p)) p++; 00066 if (*p == '\0') return NULL; /* no token left */ 00067 00068 /* if mode == 1, exit here */ 00069 if (mode == 1) { 00070 pos = p; 00071 return p; 00072 } 00073 00074 /* copy to ret_buf until end point is found */ 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 /* if quotation not terminated, allow the rest as one token */ 00084 /* if (*p == '\0') return NULL; */ 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)); /* "\"" == 34 */ 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 }