]> granicus.if.org Git - imagemagick/blobdiff - MagickWand/script-token.c
(no commit message)
[imagemagick] / MagickWand / script-token.c
index d05e2c2966b19dbc707892afd6ae4be5afabe106..17b52a82c80b2097439e55d7feac2c2e301cc618 100644 (file)
@@ -15,7 +15,7 @@
 %                               January 2012                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  end of the line.  You can escape a comment '#', using quotes or backlsashes
 %  just as you can in a shell.
 %
-%  This allows the normal UNIX 'scripting' to be used to call on the magick
-%  command to parse the tokens from a file
+%  The parser will accept both newlines, returns, or return-newlines to mark
+%  the EOL. Though this is technically breaking (or perhaps adding to) the
+%  'BASH' syntax that is being followed.
+%
+%
+%  UNIX script Launcher...
+%
+%  The use of '#' comments allow normal UNIX 'scripting' to be used to call on
+%  the "magick" command to parse the tokens from a file
 %
 %    #!/path/to/command/magick -script
 %
-%  or
+%
+%  UNIX 'env' command launcher...
+%
+%  If "magick" is renamed "magick-script" you can use a 'env' UNIX launcher
 %
 %    #!/usr/bin/env magick-script
 %
+%
+%  Shell script launcher...
+%
 %  As a special case a ':' at the start of a line is also treated as a comment
 %  This allows a magick script to ignore a line that can be parsed by the shell
 %  and not by the magick script (tokenizer).  This allows for an alternative
-%  script 'launcher' to be used for magick scripts, and posibly windows DOS
-%  scripts.
+%  script 'launcher' to be used for magick scripts.
+%
+%    #!/bin/sh
+%    :; exec magick -script "$0" "$@"; exit 10
+%    #
+%    # The rest of the file is magick script
+%    -read label:"This is a Magick Script!"
+%    -write show: -exit
+%
+% Or with some shell pre/post processing...
 %
 %    #!/bin/sh
+%    :; echo "This part is run in the shell, but ignored by Magick"
+%    :; magick -script "$0" "$@"
+%    :; echo "This is run after the "magick" script is finished!"
+%    :; exit 10
 %    #
-%    # Shell Launcher for Magick Script
-%    : echo "This part is run in the shell"
-%    : exec magick -script "$0" "$@"; exit 10
+%    # The rest of the file is magick script
+%    -read label:"This is a Magick Script!"
+%    -write show: -exit
+%
+%
+%  DOS script launcher...
+%
+%  Similarly any '@' at the start of the line (outside of quotes) will also be
+%  treated as comment. This allow you to create a DOS script launcher, to
+%  allow a ".bat" DOS scripts to run as "magick" scripts instead.
+%
+%    @echo This line is DOS executed but ignored by Magick
+%    @magick -script %~dpnx0 %*
+%    @echo This line is processed after the Magick script is finished
+%    @GOTO :EOF
+%    #
+%    # The rest of the file is magick script
+%    -read label:"This is a Magick Script!"
+%    -write show: -exit
+%
+% But this can also be used as a shell script launcher as well!
+% Though is more restrictive and less free-form than using ':'.
+%
+%    #!/bin/sh
+%    @() { exec magick -script "$@"; }
+%    @ "$0" "$@"; exit
+%    #
+%    # The rest of the file is magick script
+%    -read label:"This is a Magick Script!"
+%    -write show: -exit
+%
+% Or even like this...
+%
+%    #!/bin/sh
+%    @() { }
+%    @; exec magick -script "$0" "$@"; exit
 %    #
-%    # The rest of the script is magick script
+%    # The rest of the file is magick script
 %    -read label:"This is a Magick Script!"
 %    -write show: -exit
 %
@@ -326,10 +384,12 @@ WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info)
         state=IN_WHITE;
       continue;
     }
+    /* comment lines start with '#' anywhere, or ':' or '@' at start of line */
     if ( state == IN_WHITE )
-      if (c == '#' || (c == ':' && token_info->curr_column==1))
+      if ( ( c == '#' ) ||
+           ( token_info->curr_column==1 && (c == ':' || c == '@' ) ) )
         state=IN_COMMENT;
-    /* whitespace break character */
+    /* whitespace token seperator character */
     if (strchr(" \n\r\t",c) != (char *)NULL) {
       switch (state) {
         case IN_TOKEN:
@@ -342,7 +402,7 @@ WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info)
       continue;
     }
     /* quote character */
-    if (strchr("'\"",c) != (char *)NULL) {
+    if ( c=='\'' || c =='"' ) {
       switch (state) {
         case IN_WHITE:
           token_info->token_line=token_info->curr_line;