174#ifndef SCRIPT_TOKEN_TESTING
175# include "MagickWand/studio.h"
176# include "MagickWand/MagickWand.h"
177# include "MagickWand/script-token.h"
178# include "MagickCore/string-private.h"
179# include "MagickCore/utility-private.h"
205WandExport
ScriptTokenInfo *AcquireScriptTokenInfo(
const char *filename)
210 token_info=(
ScriptTokenInfo *) AcquireMagickMemory(
sizeof(*token_info));
213 (void) memset(token_info,0,
sizeof(*token_info));
215 token_info->opened=MagickFalse;
216 if ( LocaleCompare(filename,
"-") == 0 ) {
217 token_info->stream=stdin;
218 token_info->opened=MagickFalse;
220 else if ( LocaleNCompare(filename,
"fd:",3) == 0 ) {
221 token_info->stream=fdopen(StringToLong(filename+3),
"r");
222 token_info->opened=MagickFalse;
225 token_info->stream=fopen_utf8(filename,
"r");
227 if ( token_info->stream == (FILE *) NULL ) {
232 token_info->curr_line=1;
233 token_info->length=INITAL_TOKEN_LENGTH;
234 token_info->token=(
char *) AcquireQuantumMemory(1,token_info->length);
236 token_info->status=(token_info->token != (
char *) NULL)
237 ? TokenStatusOK : TokenStatusMemoryFailed;
238 token_info->signature=MagickWandSignature;
269 assert(token_info->signature == MagickWandSignature);
271 if ( token_info->opened != MagickFalse )
272 fclose(token_info->stream);
274 if (token_info->token != (
char *) NULL )
275 token_info->token=(
char *) RelinquishMagickMemory(token_info->token);
320 c=fgetc(token_info->stream); \
321 token_info->curr_column++; \
323 c=fgetc(token_info->stream); \
324 ungetc(c,token_info->stream); \
325 c = (c!='\n')?'\n':'\r'; \
328 token_info->curr_line++, token_info->curr_column=0; \
331 if ( (c>='\0' && c<'\a') || (c>'\r' && c<' ' && c!='\033') ) { \
332 token_info->status=TokenStatusBinary; \
339 if ((size_t) offset >= (token_info->length-1)) { \
340 if (token_info == (ScriptTokenInfo *) NULL) \
342 if ( token_info->length >= MagickPathExtent ) \
343 token_info->length += MagickPathExtent; \
345 token_info->length *= 4; \
346 token_info->token=(char *) ResizeQuantumMemory(token_info->token, \
347 token_info->length,sizeof(*token_info->token)); \
348 if ( token_info->token == (char *) NULL ) { \
349 token_info->status=TokenStatusMemoryFailed; \
353 if ( token_info->token == (char *) NULL ) \
354 token_info->status=TokenStatusMemoryFailed; \
356 token_info->token[offset++]=(char) (c); \
359WandExport MagickBooleanType GetScriptToken(
ScriptTokenInfo *token_info)
374 if (token_info->status != TokenStatusOK)
376 token_info->token[0]=
'\0';
382DisableMSCWarning(4127)
390 if ( state == IN_COMMENT ) {
396 if ( state == IN_WHITE )
398 ( token_info->curr_column==1 && (c ==
':' || c ==
'@' ) ) )
401 if (strchr(
" \n\r\t",c) != (
char *) NULL) {
404 token_info->token[offset]=
'\0';
413 if ( c==
'\'' || c ==
'"' ) {
416 token_info->token_line=token_info->curr_line;
417 token_info->token_column=token_info->curr_column;
438 if ( state==IN_QUOTE && quote ==
'\'' ) {
458 token_info->token_line=token_info->curr_line;
459 token_info->token_column=token_info->curr_column;
463 if (c != quote && c !=
'\\')
473 token_info->token_line=token_info->curr_line;
474 token_info->token_column=token_info->curr_column;
486 token_info->token[offset]=
'\0';
487 if ( token_info->status != TokenStatusOK )
489 token_info->status = TokenStatusEOF;
490 if ( state == IN_QUOTE)
491 token_info->status = TokenStatusBadQuotes;
492 if ( state == IN_TOKEN)