cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % TTTTT OOO K K EEEEE N N % |
| 7 | % T O O K K E NN N % |
| 8 | % T O O KKK EEE N N N % |
| 9 | % T O O K K E N NN % |
| 10 | % T OOO K K EEEEE N N % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Token Methods % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % January 1993 % |
| 18 | % % |
| 19 | % % |
Cristy | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 20 | % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame^] | 26 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/exception.h" |
| 45 | #include "MagickCore/exception-private.h" |
| 46 | #include "MagickCore/image.h" |
| 47 | #include "MagickCore/memory_.h" |
| 48 | #include "MagickCore/string_.h" |
| 49 | #include "MagickCore/string-private.h" |
| 50 | #include "MagickCore/token.h" |
| 51 | #include "MagickCore/token-private.h" |
| 52 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 53 | #include "MagickCore/utility-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | Typedef declaractions. |
| 57 | */ |
| 58 | struct _TokenInfo |
| 59 | { |
| 60 | int |
| 61 | state; |
| 62 | |
| 63 | MagickStatusType |
| 64 | flag; |
| 65 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 66 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | offset; |
| 68 | |
| 69 | char |
| 70 | quote; |
| 71 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 72 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 73 | signature; |
| 74 | }; |
| 75 | |
| 76 | /* |
| 77 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 78 | % % |
| 79 | % % |
| 80 | % % |
| 81 | % A c q u i r e T o k e n I n f o % |
| 82 | % % |
| 83 | % % |
| 84 | % % |
| 85 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 86 | % |
| 87 | % AcquireTokenInfo() allocates the TokenInfo structure. |
| 88 | % |
| 89 | % The format of the AcquireTokenInfo method is: |
| 90 | % |
| 91 | % TokenInfo *AcquireTokenInfo() |
| 92 | % |
| 93 | */ |
| 94 | MagickExport TokenInfo *AcquireTokenInfo(void) |
| 95 | { |
| 96 | TokenInfo |
| 97 | *token_info; |
| 98 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 99 | token_info=(TokenInfo *) AcquireMagickMemory(sizeof(*token_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 100 | if (token_info == (TokenInfo *) NULL) |
| 101 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 102 | token_info->signature=MagickCoreSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | return(token_info); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 108 | % % |
| 109 | % % |
| 110 | % % |
| 111 | % D e s t r o y T o k e n I n f o % |
| 112 | % % |
| 113 | % % |
| 114 | % % |
| 115 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 116 | % |
| 117 | % DestroyTokenInfo() deallocates memory associated with an TokenInfo |
| 118 | % structure. |
| 119 | % |
| 120 | % The format of the DestroyTokenInfo method is: |
| 121 | % |
| 122 | % TokenInfo *DestroyTokenInfo(TokenInfo *token_info) |
| 123 | % |
| 124 | % A description of each parameter follows: |
| 125 | % |
| 126 | % o token_info: Specifies a pointer to an TokenInfo structure. |
| 127 | % |
| 128 | */ |
| 129 | MagickExport TokenInfo *DestroyTokenInfo(TokenInfo *token_info) |
| 130 | { |
| 131 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 132 | assert(token_info != (TokenInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 133 | assert(token_info->signature == MagickCoreSignature); |
| 134 | token_info->signature=(~MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | token_info=(TokenInfo *) RelinquishMagickMemory(token_info); |
| 136 | return(token_info); |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 141 | % % |
| 142 | % % |
| 143 | % % |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 144 | + G e t N e x t T o k e n % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | % % |
| 146 | % % |
| 147 | % % |
| 148 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 149 | % |
dirk | ce9583c | 2016-03-26 10:29:25 +0100 | [diff] [blame] | 150 | % GetNextToken() gets a token from the token stream. A token is defined as |
cristy | df11e55 | 2011-04-23 17:18:30 +0000 | [diff] [blame] | 151 | % a sequence of characters delimited by whitespace (e.g. clip-path), a |
| 152 | % sequence delimited with quotes (.e.g "Quote me"), or a sequence enclosed in |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 153 | % parenthesis (e.g. rgb(0,0,0)). GetNextToken() also recognizes these |
cristy | dd8327f | 2010-05-12 12:39:46 +0000 | [diff] [blame] | 154 | % separator characters: ':', '=', ',', and ';'. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | % |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 156 | % The format of the GetNextToken method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | % |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 158 | % void GetNextToken(const char *start,const char **end, |
Cristy | 0f9ed5e | 2016-03-25 19:22:45 -0400 | [diff] [blame] | 159 | % const size_t extent,char *token) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | % |
| 161 | % A description of each parameter follows: |
| 162 | % |
| 163 | % o start: the start of the token sequence. |
| 164 | % |
| 165 | % o end: point to the end of the token sequence. |
| 166 | % |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 167 | % o extent: maximum extent of the token. |
| 168 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | % o token: copy the token to this buffer. |
| 170 | % |
| 171 | */ |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 172 | MagickExport void GetNextToken(const char *start,const char **end, |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 173 | const size_t extent,char *token) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 174 | { |
| 175 | double |
| 176 | value; |
| 177 | |
| 178 | register const char |
| 179 | *p; |
| 180 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 181 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | i; |
| 183 | |
cristy | 32f6912 | 2011-04-22 02:26:00 +0000 | [diff] [blame] | 184 | assert(start != (const char *) NULL); |
| 185 | assert(token != (char *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | i=0; |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 187 | p=start; |
| 188 | while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0')) |
| 189 | p++; |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 190 | switch (*p) |
| 191 | { |
cristy | 04861e2 | 2014-05-01 11:14:12 +0000 | [diff] [blame] | 192 | case '\0': |
| 193 | break; |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 194 | case '"': |
| 195 | case '\'': |
| 196 | case '`': |
| 197 | case '{': |
| 198 | { |
| 199 | register char |
| 200 | escape; |
| 201 | |
| 202 | switch (*p) |
| 203 | { |
| 204 | case '"': escape='"'; break; |
| 205 | case '\'': escape='\''; break; |
| 206 | case '`': escape='\''; break; |
| 207 | case '{': escape='}'; break; |
| 208 | default: escape=(*p); break; |
| 209 | } |
| 210 | for (p++; *p != '\0'; p++) |
| 211 | { |
| 212 | if ((*p == '\\') && ((*(p+1) == escape) || (*(p+1) == '\\'))) |
| 213 | p++; |
| 214 | else |
| 215 | if (*p == escape) |
| 216 | { |
| 217 | p++; |
| 218 | break; |
| 219 | } |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 220 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 221 | token[i++]=(*p); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 222 | } |
| 223 | break; |
| 224 | } |
| 225 | case '/': |
| 226 | { |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 227 | if (i < (ssize_t) (extent-1)) |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 228 | token[i++]=(*p++); |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 229 | if ((*p == '>') || (*p == '/')) |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 230 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 231 | token[i++]=(*p++); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | default: |
| 235 | { |
| 236 | char |
| 237 | *q; |
| 238 | |
| 239 | value=StringToDouble(p,&q); |
| 240 | (void) value; |
| 241 | if ((p != q) && (*p != ',')) |
| 242 | { |
| 243 | for ( ; (p < q) && (*p != ','); p++) |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 244 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 245 | token[i++]=(*p); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 246 | if (*p == '%') |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 247 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 248 | token[i++]=(*p++); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | if ((*p != '\0') && (isalpha((int) ((unsigned char) *p)) == 0) && |
| 252 | (*p != *DirectorySeparator) && (*p != '#') && (*p != '<')) |
| 253 | { |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 254 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 255 | token[i++]=(*p++); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 256 | break; |
| 257 | } |
| 258 | for ( ; *p != '\0'; p++) |
| 259 | { |
| 260 | if (((isspace((int) ((unsigned char) *p)) != 0) || (*p == '=') || |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 261 | (*p == ',') || (*p == ':') || (*p == ';')) && (*(p-1) != '\\')) |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 262 | break; |
| 263 | if ((i > 0) && (*p == '<')) |
| 264 | break; |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 265 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 266 | token[i++]=(*p); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 267 | if (*p == '>') |
| 268 | break; |
| 269 | if (*p == '(') |
| 270 | for (p++; *p != '\0'; p++) |
| 271 | { |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 272 | if (i < (ssize_t) (extent-1)) |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 273 | token[i++]=(*p); |
cristy | 708e3c6 | 2014-05-01 00:48:26 +0000 | [diff] [blame] | 274 | if ((*p == ')') && (*(p-1) != '\\')) |
| 275 | break; |
| 276 | } |
| 277 | } |
| 278 | break; |
| 279 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 280 | } |
| 281 | token[i]='\0'; |
| 282 | if (LocaleNCompare(token,"url(",4) == 0) |
| 283 | { |
| 284 | ssize_t |
| 285 | offset; |
| 286 | |
| 287 | offset=4; |
| 288 | if (token[offset] == '#') |
| 289 | offset++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 290 | i=(ssize_t) strlen(token); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 291 | (void) CopyMagickString(token,token+offset,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | token[i-offset-1]='\0'; |
| 293 | } |
| 294 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 295 | p++; |
| 296 | if (end != (const char **) NULL) |
| 297 | *end=(const char *) p; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | % G l o b E x p r e s s i o n % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % GlobExpression() returns MagickTrue if the expression matches the pattern. |
| 312 | % |
| 313 | % The format of the GlobExpression function is: |
| 314 | % |
| 315 | % MagickBooleanType GlobExpression(const char *expression, |
| 316 | % const char *pattern,const MagickBooleanType case_insensitive) |
| 317 | % |
| 318 | % A description of each parameter follows: |
| 319 | % |
| 320 | % o expression: Specifies a pointer to a text string containing a file name. |
| 321 | % |
| 322 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 323 | % |
| 324 | % o case_insensitive: set to MagickTrue to ignore the case when matching |
| 325 | % an expression. |
| 326 | % |
| 327 | */ |
| 328 | MagickExport MagickBooleanType GlobExpression(const char *expression, |
| 329 | const char *pattern,const MagickBooleanType case_insensitive) |
| 330 | { |
| 331 | MagickBooleanType |
| 332 | done, |
| 333 | match; |
| 334 | |
| 335 | register const char |
| 336 | *p; |
| 337 | |
| 338 | /* |
| 339 | Return on empty pattern or '*'. |
| 340 | */ |
| 341 | if (pattern == (char *) NULL) |
| 342 | return(MagickTrue); |
| 343 | if (GetUTFCode(pattern) == 0) |
| 344 | return(MagickTrue); |
| 345 | if (LocaleCompare(pattern,"*") == 0) |
| 346 | return(MagickTrue); |
| 347 | p=pattern+strlen(pattern)-1; |
| 348 | if ((GetUTFCode(p) == ']') && (strchr(pattern,'[') != (char *) NULL)) |
| 349 | { |
| 350 | ExceptionInfo |
| 351 | *exception; |
| 352 | |
| 353 | ImageInfo |
| 354 | *image_info; |
| 355 | |
| 356 | /* |
| 357 | Determine if pattern is a scene, i.e. img0001.pcd[2]. |
| 358 | */ |
| 359 | image_info=AcquireImageInfo(); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 360 | (void) CopyMagickString(image_info->filename,pattern,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | exception=AcquireExceptionInfo(); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 362 | (void) SetImageInfo(image_info,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 363 | exception=DestroyExceptionInfo(exception); |
| 364 | if (LocaleCompare(image_info->filename,pattern) != 0) |
| 365 | { |
| 366 | image_info=DestroyImageInfo(image_info); |
| 367 | return(MagickFalse); |
| 368 | } |
| 369 | image_info=DestroyImageInfo(image_info); |
| 370 | } |
| 371 | /* |
| 372 | Evaluate glob expression. |
| 373 | */ |
| 374 | done=MagickFalse; |
| 375 | while ((GetUTFCode(pattern) != 0) && (done == MagickFalse)) |
| 376 | { |
| 377 | if (GetUTFCode(expression) == 0) |
| 378 | if ((GetUTFCode(pattern) != '{') && (GetUTFCode(pattern) != '*')) |
| 379 | break; |
| 380 | switch (GetUTFCode(pattern)) |
| 381 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 382 | case '*': |
| 383 | { |
| 384 | MagickBooleanType |
| 385 | status; |
| 386 | |
| 387 | status=MagickFalse; |
| 388 | pattern+=GetUTFOctets(pattern); |
| 389 | while ((GetUTFCode(expression) != 0) && (status == MagickFalse)) |
| 390 | { |
| 391 | status=GlobExpression(expression,pattern,case_insensitive); |
| 392 | expression+=GetUTFOctets(expression); |
| 393 | } |
| 394 | if (status != MagickFalse) |
| 395 | { |
| 396 | while (GetUTFCode(expression) != 0) |
| 397 | expression+=GetUTFOctets(expression); |
| 398 | while (GetUTFCode(pattern) != 0) |
| 399 | pattern+=GetUTFOctets(pattern); |
| 400 | } |
| 401 | break; |
| 402 | } |
| 403 | case '[': |
| 404 | { |
cristy | 55a91cd | 2010-12-01 00:57:40 +0000 | [diff] [blame] | 405 | int |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 406 | c; |
| 407 | |
| 408 | pattern+=GetUTFOctets(pattern); |
| 409 | for ( ; ; ) |
| 410 | { |
| 411 | if ((GetUTFCode(pattern) == 0) || (GetUTFCode(pattern) == ']')) |
| 412 | { |
| 413 | done=MagickTrue; |
| 414 | break; |
| 415 | } |
| 416 | if (GetUTFCode(pattern) == '\\') |
| 417 | { |
| 418 | pattern+=GetUTFOctets(pattern); |
| 419 | if (GetUTFCode(pattern) == 0) |
| 420 | { |
| 421 | done=MagickTrue; |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | if (GetUTFCode(pattern+GetUTFOctets(pattern)) == '-') |
| 426 | { |
| 427 | c=GetUTFCode(pattern); |
| 428 | pattern+=GetUTFOctets(pattern); |
| 429 | pattern+=GetUTFOctets(pattern); |
| 430 | if (GetUTFCode(pattern) == ']') |
| 431 | { |
| 432 | done=MagickTrue; |
| 433 | break; |
| 434 | } |
| 435 | if (GetUTFCode(pattern) == '\\') |
| 436 | { |
| 437 | pattern+=GetUTFOctets(pattern); |
| 438 | if (GetUTFCode(pattern) == 0) |
| 439 | { |
| 440 | done=MagickTrue; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | if ((GetUTFCode(expression) < c) || |
| 445 | (GetUTFCode(expression) > GetUTFCode(pattern))) |
| 446 | { |
| 447 | pattern+=GetUTFOctets(pattern); |
| 448 | continue; |
| 449 | } |
| 450 | } |
| 451 | else |
| 452 | if (GetUTFCode(pattern) != GetUTFCode(expression)) |
| 453 | { |
| 454 | pattern+=GetUTFOctets(pattern); |
| 455 | continue; |
| 456 | } |
| 457 | pattern+=GetUTFOctets(pattern); |
| 458 | while ((GetUTFCode(pattern) != ']') && (GetUTFCode(pattern) != 0)) |
| 459 | { |
| 460 | if ((GetUTFCode(pattern) == '\\') && |
| 461 | (GetUTFCode(pattern+GetUTFOctets(pattern)) > 0)) |
| 462 | pattern+=GetUTFOctets(pattern); |
| 463 | pattern+=GetUTFOctets(pattern); |
| 464 | } |
| 465 | if (GetUTFCode(pattern) != 0) |
| 466 | { |
| 467 | pattern+=GetUTFOctets(pattern); |
| 468 | expression+=GetUTFOctets(expression); |
| 469 | } |
| 470 | break; |
| 471 | } |
| 472 | break; |
| 473 | } |
| 474 | case '?': |
| 475 | { |
| 476 | pattern+=GetUTFOctets(pattern); |
| 477 | expression+=GetUTFOctets(expression); |
| 478 | break; |
| 479 | } |
| 480 | case '{': |
| 481 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 482 | pattern+=GetUTFOctets(pattern); |
| 483 | while ((GetUTFCode(pattern) != '}') && (GetUTFCode(pattern) != 0)) |
| 484 | { |
| 485 | p=expression; |
| 486 | match=MagickTrue; |
| 487 | while ((GetUTFCode(p) != 0) && (GetUTFCode(pattern) != 0) && |
| 488 | (GetUTFCode(pattern) != ',') && (GetUTFCode(pattern) != '}') && |
| 489 | (match != MagickFalse)) |
| 490 | { |
| 491 | if (GetUTFCode(pattern) == '\\') |
| 492 | pattern+=GetUTFOctets(pattern); |
| 493 | match=(GetUTFCode(pattern) == GetUTFCode(p)) ? MagickTrue : |
| 494 | MagickFalse; |
| 495 | p+=GetUTFOctets(p); |
| 496 | pattern+=GetUTFOctets(pattern); |
| 497 | } |
| 498 | if (GetUTFCode(pattern) == 0) |
| 499 | { |
| 500 | match=MagickFalse; |
| 501 | done=MagickTrue; |
| 502 | break; |
| 503 | } |
Cristy | 530d3d7 | 2016-08-07 08:42:26 -0400 | [diff] [blame] | 504 | if (match != MagickFalse) |
| 505 | { |
| 506 | expression=p; |
| 507 | while ((GetUTFCode(pattern) != '}') && |
| 508 | (GetUTFCode(pattern) != 0)) |
| 509 | { |
| 510 | pattern+=GetUTFOctets(pattern); |
| 511 | if (GetUTFCode(pattern) == '\\') |
| 512 | { |
| 513 | pattern+=GetUTFOctets(pattern); |
| 514 | if (GetUTFCode(pattern) == '}') |
| 515 | pattern+=GetUTFOctets(pattern); |
| 516 | } |
| 517 | } |
| 518 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | else |
Cristy | 530d3d7 | 2016-08-07 08:42:26 -0400 | [diff] [blame] | 520 | { |
| 521 | while ((GetUTFCode(pattern) != '}') && |
| 522 | (GetUTFCode(pattern) != ',') && |
| 523 | (GetUTFCode(pattern) != 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | { |
Cristy | 530d3d7 | 2016-08-07 08:42:26 -0400 | [diff] [blame] | 525 | pattern+=GetUTFOctets(pattern); |
| 526 | if (GetUTFCode(pattern) == '\\') |
| 527 | { |
| 528 | pattern+=GetUTFOctets(pattern); |
| 529 | if ((GetUTFCode(pattern) == '}') || |
| 530 | (GetUTFCode(pattern) == ',')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | pattern+=GetUTFOctets(pattern); |
Cristy | 530d3d7 | 2016-08-07 08:42:26 -0400 | [diff] [blame] | 532 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 533 | } |
Cristy | 530d3d7 | 2016-08-07 08:42:26 -0400 | [diff] [blame] | 534 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | if (GetUTFCode(pattern) != 0) |
| 536 | pattern+=GetUTFOctets(pattern); |
| 537 | } |
| 538 | break; |
| 539 | } |
cristy | ecbe37f | 2010-04-22 13:50:04 +0000 | [diff] [blame] | 540 | case '\\': |
| 541 | { |
| 542 | pattern+=GetUTFOctets(pattern); |
cristy | 4705fe8 | 2010-04-23 16:20:03 +0000 | [diff] [blame] | 543 | if (GetUTFCode(pattern) == 0) |
| 544 | break; |
cristy | ecbe37f | 2010-04-22 13:50:04 +0000 | [diff] [blame] | 545 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | default: |
| 547 | { |
| 548 | if (case_insensitive != MagickFalse) |
| 549 | { |
| 550 | if (tolower((int) GetUTFCode(expression)) != |
| 551 | tolower((int) GetUTFCode(pattern))) |
| 552 | { |
| 553 | done=MagickTrue; |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | else |
| 558 | if (GetUTFCode(expression) != GetUTFCode(pattern)) |
| 559 | { |
| 560 | done=MagickTrue; |
| 561 | break; |
| 562 | } |
| 563 | expression+=GetUTFOctets(expression); |
| 564 | pattern+=GetUTFOctets(pattern); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | while (GetUTFCode(pattern) == '*') |
| 569 | pattern+=GetUTFOctets(pattern); |
| 570 | match=(GetUTFCode(expression) == 0) && (GetUTFCode(pattern) == 0) ? |
| 571 | MagickTrue : MagickFalse; |
| 572 | return(match); |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 577 | % % |
| 578 | % % |
| 579 | % % |
| 580 | + I s G l o b % |
| 581 | % % |
| 582 | % % |
| 583 | % % |
| 584 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 585 | % |
| 586 | % IsGlob() returns MagickTrue if the path specification contains a globbing |
| 587 | % pattern. |
| 588 | % |
| 589 | % The format of the IsGlob method is: |
| 590 | % |
| 591 | % MagickBooleanType IsGlob(const char *geometry) |
| 592 | % |
| 593 | % A description of each parameter follows: |
| 594 | % |
| 595 | % o path: the path. |
| 596 | % |
| 597 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 598 | MagickPrivate MagickBooleanType IsGlob(const char *path) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 599 | { |
| 600 | MagickBooleanType |
cristy | a21ae82 | 2012-11-11 17:12:12 +0000 | [diff] [blame] | 601 | status = MagickFalse; |
| 602 | |
| 603 | register const char |
| 604 | *p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | |
| 606 | if (IsPathAccessible(path) != MagickFalse) |
| 607 | return(MagickFalse); |
cristy | a21ae82 | 2012-11-11 17:12:12 +0000 | [diff] [blame] | 608 | for (p=path; *p != '\0'; p++) |
| 609 | { |
| 610 | switch (*p) |
| 611 | { |
| 612 | case '*': |
| 613 | case '?': |
| 614 | case '{': |
| 615 | case '}': |
| 616 | case '[': |
| 617 | case ']': |
| 618 | { |
| 619 | status=MagickTrue; |
| 620 | break; |
| 621 | } |
| 622 | default: |
| 623 | break; |
| 624 | } |
| 625 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 626 | return(status); |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 631 | % % |
| 632 | % % |
| 633 | % % |
| 634 | % T o k e n i z e r % |
| 635 | % % |
| 636 | % % |
| 637 | % % |
| 638 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 639 | % |
| 640 | % Tokenizer() is a generalized, finite state token parser. It extracts tokens |
| 641 | % one at a time from a string of characters. The characters used for white |
| 642 | % space, for break characters, and for quotes can be specified. Also, |
| 643 | % characters in the string can be preceded by a specifiable escape character |
| 644 | % which removes any special meaning the character may have. |
| 645 | % |
| 646 | % Here is some terminology: |
| 647 | % |
| 648 | % o token: A single unit of information in the form of a group of |
| 649 | % characters. |
| 650 | % |
| 651 | % o white space: Apace that gets ignored (except within quotes or when |
| 652 | % escaped), like blanks and tabs. in addition, white space terminates a |
| 653 | % non-quoted token. |
| 654 | % |
| 655 | % o break set: One or more characters that separates non-quoted tokens. |
| 656 | % Commas are a common break character. The usage of break characters to |
| 657 | % signal the end of a token is the same as that of white space, except |
| 658 | % multiple break characters with nothing or only white space between |
| 659 | % generate a null token for each two break characters together. |
| 660 | % |
| 661 | % For example, if blank is set to be the white space and comma is set to |
| 662 | % be the break character, the line |
| 663 | % |
| 664 | % A, B, C , , DEF |
| 665 | % |
| 666 | % ... consists of 5 tokens: |
| 667 | % |
| 668 | % 1) "A" |
| 669 | % 2) "B" |
| 670 | % 3) "C" |
| 671 | % 4) "" (the null string) |
| 672 | % 5) "DEF" |
| 673 | % |
| 674 | % o Quote character: A character that, when surrounding a group of other |
| 675 | % characters, causes the group of characters to be treated as a single |
| 676 | % token, no matter how many white spaces or break characters exist in |
| 677 | % the group. Also, a token always terminates after the closing quote. |
| 678 | % For example, if ' is the quote character, blank is white space, and |
| 679 | % comma is the break character, the following string |
| 680 | % |
| 681 | % A, ' B, CD'EF GHI |
| 682 | % |
| 683 | % ... consists of 4 tokens: |
| 684 | % |
| 685 | % 1) "A" |
| 686 | % 2) " B, CD" (note the blanks & comma) |
| 687 | % 3) "EF" |
| 688 | % 4) "GHI" |
| 689 | % |
| 690 | % The quote characters themselves do not appear in the resultant |
| 691 | % tokens. The double quotes are delimiters i use here for |
| 692 | % documentation purposes only. |
| 693 | % |
| 694 | % o Escape character: A character which itself is ignored but which |
| 695 | % causes the next character to be used as is. ^ and \ are often used |
| 696 | % as escape characters. An escape in the last position of the string |
| 697 | % gets treated as a "normal" (i.e., non-quote, non-white, non-break, |
| 698 | % and non-escape) character. For example, assume white space, break |
| 699 | % character, and quote are the same as in the above examples, and |
| 700 | % further, assume that ^ is the escape character. Then, in the string |
| 701 | % |
| 702 | % ABC, ' DEF ^' GH' I ^ J K^ L ^ |
| 703 | % |
| 704 | % ... there are 7 tokens: |
| 705 | % |
| 706 | % 1) "ABC" |
| 707 | % 2) " DEF ' GH" |
| 708 | % 3) "I" |
| 709 | % 4) " " (a lone blank) |
| 710 | % 5) "J" |
| 711 | % 6) "K L" |
| 712 | % 7) "^" (passed as is at end of line) |
| 713 | % |
| 714 | % The format of the Tokenizer method is: |
| 715 | % |
| 716 | % int Tokenizer(TokenInfo *token_info,const unsigned flag,char *token, |
| 717 | % const size_t max_token_length,const char *line,const char *white, |
| 718 | % const char *break_set,const char *quote,const char escape, |
| 719 | % char *breaker,int *next,char *quoted) |
| 720 | % |
| 721 | % A description of each parameter follows: |
| 722 | % |
| 723 | % o flag: right now, only the low order 3 bits are used. |
| 724 | % |
| 725 | % 1 => convert non-quoted tokens to upper case |
| 726 | % 2 => convert non-quoted tokens to lower case |
| 727 | % 0 => do not convert non-quoted tokens |
| 728 | % |
| 729 | % o token: a character string containing the returned next token |
| 730 | % |
| 731 | % o max_token_length: the maximum size of "token". Characters beyond |
| 732 | % "max_token_length" are truncated. |
| 733 | % |
| 734 | % o string: the string to be parsed. |
| 735 | % |
| 736 | % o white: a string of the valid white spaces. example: |
| 737 | % |
| 738 | % char whitesp[]={" \t"}; |
| 739 | % |
| 740 | % blank and tab will be valid white space. |
| 741 | % |
| 742 | % o break: a string of the valid break characters. example: |
| 743 | % |
| 744 | % char breakch[]={";,"}; |
| 745 | % |
| 746 | % semicolon and comma will be valid break characters. |
| 747 | % |
| 748 | % o quote: a string of the valid quote characters. An example would be |
| 749 | % |
| 750 | % char whitesp[]={"'\""); |
| 751 | % |
| 752 | % (this causes single and double quotes to be valid) Note that a |
| 753 | % token starting with one of these characters needs the same quote |
| 754 | % character to terminate it. |
| 755 | % |
| 756 | % for example: |
| 757 | % |
| 758 | % "ABC ' |
| 759 | % |
| 760 | % is unterminated, but |
| 761 | % |
| 762 | % "DEF" and 'GHI' |
| 763 | % |
| 764 | % are properly terminated. Note that different quote characters |
| 765 | % can appear on the same line; only for a given token do the quote |
| 766 | % characters have to be the same. |
| 767 | % |
| 768 | % o escape: the escape character (NOT a string ... only one |
| 769 | % allowed). Use zero if none is desired. |
| 770 | % |
| 771 | % o breaker: the break character used to terminate the current |
| 772 | % token. If the token was quoted, this will be the quote used. If |
| 773 | % the token is the last one on the line, this will be zero. |
| 774 | % |
| 775 | % o next: this variable points to the first character of the |
| 776 | % next token. it gets reset by "tokenizer" as it steps through the |
| 777 | % string. Set it to 0 upon initialization, and leave it alone |
| 778 | % after that. You can change it if you want to jump around in the |
| 779 | % string or re-parse from the beginning, but be careful. |
| 780 | % |
| 781 | % o quoted: set to True if the token was quoted and MagickFalse |
| 782 | % if not. You may need this information (for example: in C, a |
| 783 | % string with quotes around it is a character string, while one |
| 784 | % without is an identifier). |
| 785 | % |
| 786 | % o result: 0 if we haven't reached EOS (end of string), and 1 |
| 787 | % if we have. |
| 788 | % |
| 789 | */ |
| 790 | |
| 791 | #define IN_WHITE 0 |
| 792 | #define IN_TOKEN 1 |
| 793 | #define IN_QUOTE 2 |
| 794 | #define IN_OZONE 3 |
| 795 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 796 | static ssize_t sindex(int c,const char *string) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 797 | { |
| 798 | register const char |
| 799 | *p; |
| 800 | |
| 801 | for (p=string; *p != '\0'; p++) |
| 802 | if (c == (int) (*p)) |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 803 | return((ssize_t) (p-string)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 804 | return(-1); |
| 805 | } |
| 806 | |
| 807 | static void StoreToken(TokenInfo *token_info,char *string, |
| 808 | size_t max_token_length,int c) |
| 809 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 810 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 811 | i; |
| 812 | |
| 813 | if ((token_info->offset < 0) || |
| 814 | ((size_t) token_info->offset >= (max_token_length-1))) |
| 815 | return; |
| 816 | i=token_info->offset++; |
| 817 | string[i]=(char) c; |
| 818 | if (token_info->state == IN_QUOTE) |
| 819 | return; |
| 820 | switch (token_info->flag & 0x03) |
| 821 | { |
| 822 | case 1: |
| 823 | { |
| 824 | string[i]=(char) toupper(c); |
| 825 | break; |
| 826 | } |
| 827 | case 2: |
| 828 | { |
| 829 | string[i]=(char) tolower(c); |
| 830 | break; |
| 831 | } |
| 832 | default: |
| 833 | break; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | MagickExport int Tokenizer(TokenInfo *token_info,const unsigned flag, |
| 838 | char *token,const size_t max_token_length,const char *line,const char *white, |
| 839 | const char *break_set,const char *quote,const char escape,char *breaker, |
| 840 | int *next,char *quoted) |
| 841 | { |
| 842 | int |
| 843 | c; |
| 844 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 845 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 846 | i; |
| 847 | |
| 848 | *breaker='\0'; |
| 849 | *quoted='\0'; |
| 850 | if (line[*next] == '\0') |
| 851 | return(1); |
| 852 | token_info->state=IN_WHITE; |
| 853 | token_info->quote=(char) MagickFalse; |
| 854 | token_info->flag=flag; |
| 855 | for (token_info->offset=0; (int) line[*next] != 0; (*next)++) |
| 856 | { |
| 857 | c=(int) line[*next]; |
| 858 | i=sindex(c,break_set); |
| 859 | if (i >= 0) |
| 860 | { |
| 861 | switch (token_info->state) |
| 862 | { |
| 863 | case IN_WHITE: |
| 864 | case IN_TOKEN: |
| 865 | case IN_OZONE: |
| 866 | { |
| 867 | (*next)++; |
| 868 | *breaker=break_set[i]; |
| 869 | token[token_info->offset]='\0'; |
| 870 | return(0); |
| 871 | } |
| 872 | case IN_QUOTE: |
| 873 | { |
| 874 | StoreToken(token_info,token,max_token_length,c); |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | continue; |
| 879 | } |
| 880 | i=sindex(c,quote); |
| 881 | if (i >= 0) |
| 882 | { |
| 883 | switch (token_info->state) |
| 884 | { |
| 885 | case IN_WHITE: |
| 886 | { |
| 887 | token_info->state=IN_QUOTE; |
| 888 | token_info->quote=quote[i]; |
| 889 | *quoted=(char) MagickTrue; |
| 890 | break; |
| 891 | } |
| 892 | case IN_QUOTE: |
| 893 | { |
| 894 | if (quote[i] != token_info->quote) |
| 895 | StoreToken(token_info,token,max_token_length,c); |
| 896 | else |
| 897 | { |
| 898 | token_info->state=IN_OZONE; |
| 899 | token_info->quote='\0'; |
| 900 | } |
| 901 | break; |
| 902 | } |
| 903 | case IN_TOKEN: |
| 904 | case IN_OZONE: |
| 905 | { |
| 906 | *breaker=(char) c; |
| 907 | token[token_info->offset]='\0'; |
| 908 | return(0); |
| 909 | } |
| 910 | } |
| 911 | continue; |
| 912 | } |
| 913 | i=sindex(c,white); |
| 914 | if (i >= 0) |
| 915 | { |
| 916 | switch (token_info->state) |
| 917 | { |
| 918 | case IN_WHITE: |
| 919 | case IN_OZONE: |
| 920 | break; |
| 921 | case IN_TOKEN: |
| 922 | { |
| 923 | token_info->state=IN_OZONE; |
| 924 | break; |
| 925 | } |
| 926 | case IN_QUOTE: |
| 927 | { |
| 928 | StoreToken(token_info,token,max_token_length,c); |
| 929 | break; |
| 930 | } |
| 931 | } |
| 932 | continue; |
| 933 | } |
| 934 | if (c == (int) escape) |
| 935 | { |
| 936 | if (line[(*next)+1] == '\0') |
| 937 | { |
| 938 | *breaker='\0'; |
| 939 | StoreToken(token_info,token,max_token_length,c); |
| 940 | (*next)++; |
| 941 | token[token_info->offset]='\0'; |
| 942 | return(0); |
| 943 | } |
| 944 | switch (token_info->state) |
| 945 | { |
| 946 | case IN_WHITE: |
| 947 | { |
| 948 | (*next)--; |
| 949 | token_info->state=IN_TOKEN; |
| 950 | break; |
| 951 | } |
| 952 | case IN_TOKEN: |
| 953 | case IN_QUOTE: |
| 954 | { |
| 955 | (*next)++; |
| 956 | c=(int) line[*next]; |
| 957 | StoreToken(token_info,token,max_token_length,c); |
| 958 | break; |
| 959 | } |
| 960 | case IN_OZONE: |
| 961 | { |
| 962 | token[token_info->offset]='\0'; |
| 963 | return(0); |
| 964 | } |
| 965 | } |
| 966 | continue; |
| 967 | } |
| 968 | switch (token_info->state) |
| 969 | { |
| 970 | case IN_WHITE: |
cristy | 326182d | 2014-05-18 21:48:30 +0000 | [diff] [blame] | 971 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 972 | token_info->state=IN_TOKEN; |
cristy | 326182d | 2014-05-18 21:48:30 +0000 | [diff] [blame] | 973 | StoreToken(token_info,token,max_token_length,c); |
| 974 | break; |
| 975 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 976 | case IN_TOKEN: |
| 977 | case IN_QUOTE: |
| 978 | { |
| 979 | StoreToken(token_info,token,max_token_length,c); |
| 980 | break; |
| 981 | } |
| 982 | case IN_OZONE: |
| 983 | { |
| 984 | token[token_info->offset]='\0'; |
| 985 | return(0); |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | token[token_info->offset]='\0'; |
| 990 | return(0); |
| 991 | } |