From 799889aea36b61cd7033414e2d5a613fb91dca7e Mon Sep 17 00:00:00 2001 From: anthony Date: Sun, 11 Mar 2012 11:00:32 +0000 Subject: [PATCH] EOL handling problem with scripts (cut-n-paste uses only return chars for EOL) --- MagickWand/magick-cli.c | 13 ++----------- MagickWand/script-token.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/MagickWand/magick-cli.c b/MagickWand/magick-cli.c index 37bb16f20..8dcf7c59f 100644 --- a/MagickWand/magick-cli.c +++ b/MagickWand/magick-cli.c @@ -62,7 +62,7 @@ 3 - mnemonic lookup 4 - output options/artifacts */ -#define MagickCommandDebug 0 +#define MagickCommandDebug 3 #define ThrowFileException(exception,severity,tag,context) \ { \ @@ -207,16 +207,6 @@ WandExport void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv, break; } - /* Sanity check: option is larger than anything that should be posible */ - if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { - token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; - token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; - token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; - token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; - CLIWandException(OptionFatalError,"UnrecognizedOption",token_info->token); - break; - } - /* save option details */ CloneString(&option,token_info->token); @@ -512,6 +502,7 @@ next_argument: Implicit Write of images to final CLI argument */ option=argv[i]; + cli_wand->line=i; #if MagickCommandDebug (void) FormatLocaleFile(stderr, "CLI Write File: \"%s\"\n", option ); diff --git a/MagickWand/script-token.c b/MagickWand/script-token.c index 9af2b3797..ad0bdc042 100644 --- a/MagickWand/script-token.c +++ b/MagickWand/script-token.c @@ -213,11 +213,22 @@ WandExport ScriptTokenInfo * DestroyScriptTokenInfo(ScriptTokenInfo *token_info) #define IN_QUOTE 2 #define IN_COMMENT 3 -/* macro to read character from stream */ +/* Macro to read character from stream + + This also keeps track of the line and column counts. + The EOL is defined as either '\r\n', or '\r', or '\n'. + A '\r' on its own is converted into a '\n' to correctly handle + raw input, typically due to 'copy-n-paste' of text files. +*/ #define GetChar(c) \ { \ c=fgetc(token_info->stream); \ token_info->curr_column++; \ + if ( c == '\r' ) { \ + c=fgetc(token_info->stream); \ + ungetc(c,token_info->stream); \ + c = (c!='\n')?'\n':'\r'; \ + } \ if ( c == '\n' ) \ token_info->curr_line++, token_info->curr_column=0; \ if (c == EOF ) \ -- 2.40.0