Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

mystrtok.c

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

Generated on Tue Mar 28 16:01:39 2006 for Julius by  doxygen 1.4.2