]> granicus.if.org Git - imagemagick/commitdiff
EOL handling problem with scripts
authoranthony <anthony@git.imagemagick.org>
Sun, 11 Mar 2012 11:00:32 +0000 (11:00 +0000)
committeranthony <anthony@git.imagemagick.org>
Sun, 11 Mar 2012 11:00:32 +0000 (11:00 +0000)
(cut-n-paste uses only return chars for EOL)

MagickWand/magick-cli.c
MagickWand/script-token.c

index 37bb16f208b722e53bf6d761f8f88a79d8ce6c00..8dcf7c59f1b78d44ea4c6af93af29df2cffa37ef 100644 (file)
@@ -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 );
index 9af2b3797e1e16a9d712d2b0dd1ab8b243d70ff8..ad0bdc042ed146441ab3139e93bf3e036c006feb 100644 (file)
@@ -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 ) \