Add DOS script launcher line (to be ignored)
diff --git a/MagickWand/script-token.c b/MagickWand/script-token.c
index d05e2c2..036a2c3 100644
--- a/MagickWand/script-token.c
+++ b/MagickWand/script-token.c
@@ -80,28 +80,50 @@
% 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
+%
+% UNIX script Launcher...
+%
+% Th euse 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 launsher...
+%
% 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
% #
-% # Shell Launcher for Magick Script
-% : echo "This part is run in the shell"
+% : echo "This part is run in the shell, but ignored by Magick"
% : exec magick -script "$0" "$@"; exit 10
% #
-% # 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
+%
+%
+% DOS script launcher...
+%
+% Similarly for DOS, any '@' at the start of the line (outside of quotes)
+% will also be treated as comment. To allow the same DOS script launcher
+% code
+%
+% @echo This line is DOS executed but ignored by Magick
+% @magick -script %~dpnx0 %*
+% @GOTO :EOF
+% #
+% # The rest of the file is magick script
% -read label:"This is a Magick Script!"
% -write show: -exit
%
@@ -326,10 +348,12 @@
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 +366,7 @@
continue;
}
/* quote character */
- if (strchr("'\"",c) != (char *)NULL) {
+ if ( c=='\'' || c =='"' ) {
switch (state) {
case IN_WHITE:
token_info->token_line=token_info->curr_line;
diff --git a/MagickWand/tests/Makefile b/MagickWand/tests/Makefile
index 8aba510..08a58df 100644
--- a/MagickWand/tests/Makefile
+++ b/MagickWand/tests/Makefile
@@ -21,3 +21,4 @@
test_script:
script-token-test.sh | diff script-token-test-results.txt -
+
diff --git a/MagickWand/tests/script-token-test-data.txt b/MagickWand/tests/script-token-test-data.txt
index cdea6d1..6e1e035 100644
--- a/MagickWand/tests/script-token-test-data.txt
+++ b/MagickWand/tests/script-token-test-data.txt
@@ -1,6 +1,10 @@
#
# Comments should be ignored
#
+: Shell script launcher comment ignore
+@ DOS script launcher comment ignore
+
+
-option key # end of line comment
+reset imbedded#hash # <- not a comment, thought this is
diff --git a/MagickWand/tests/script-token-test-results.txt b/MagickWand/tests/script-token-test-results.txt
index 834eeb1..4d0de96 100644
--- a/MagickWand/tests/script-token-test-results.txt
+++ b/MagickWand/tests/script-token-test-results.txt
@@ -1,42 +1,42 @@
-l=4, c=1, stat=0, len=64, token="-option"
-l=4, c=9, stat=0, len=64, token="key"
-l=5, c=1, stat=0, len=64, token="+reset"
-l=5, c=10, stat=0, len=64, token="imbedded#hash"
-l=7, c=1, stat=0, len=64, token="This is a single token"
-l=9, c=1, stat=0, len=64, token="And\ 'even '"more "complex"
-l=11, c=1, stat=0, len=64, token="Backslash chars \n are returned as is"
-l=12, c=1, stat=0, len=64, token="regardless \n of quoting"
-l=14, c=1, stat=0, len=64, token="Single quote escapes"
-l=15, c=2, stat=0, len=64, token="'"
-l=15, c=4, stat=0, len=64, token="'"
-l=17, c=1, stat=0, len=64, token="Double quote escapes"
-l=18, c=2, stat=0, len=64, token="""
-l=18, c=4, stat=0, len=64, token="""
-l=18, c=8, stat=0, len=64, token="""
-l=20, c=1, stat=0, len=64, token="Back slash escapes"
-l=21, c=2, stat=0, len=64, token="\"
-l=21, c=4, stat=0, len=64, token="\"
-l=21, c=9, stat=0, len=64, token="\"
-l=23, c=1, stat=0, len=64, token="Space Character Escapes"
-l=24, c=2, stat=0, len=64, token=" "
-l=24, c=4, stat=0, len=64, token=" "
-l=24, c=9, stat=0, len=64, token=" "
-l=26, c=1, stat=0, len=64, token="Empty Tokens, using quotes"
-l=27, c=1, stat=0, len=64, token=""
-l=27, c=6, stat=0, len=64, token=""
-l=29, c=1, stat=0, len=64, token="Unicode charcaters are handled"
-l=30, c=1, stat=0, len=64, token="° ' ² ³ ` ´"
-l=31, c=1, stat=0, len=64, token="µ ¶ ⨀ ⨁ ⨂"
-l=32, c=1, stat=0, len=64, token="测试用的汉字"
-l=34, c=1, stat=0, len=64, token="Line____Continuation"
-l=37, c=1, stat=0, len=64, token="Double_Quoted_Line____Continuation"
-l=40, c=1, stat=0, len=64, token="Single_Quoted_Line__\
+l=8, c=1, stat=0, len=64, token="-option"
+l=8, c=9, stat=0, len=64, token="key"
+l=9, c=1, stat=0, len=64, token="+reset"
+l=9, c=10, stat=0, len=64, token="imbedded#hash"
+l=11, c=1, stat=0, len=64, token="This is a single token"
+l=13, c=1, stat=0, len=64, token="And\ 'even '"more "complex"
+l=15, c=1, stat=0, len=64, token="Backslash chars \n are returned as is"
+l=16, c=1, stat=0, len=64, token="regardless \n of quoting"
+l=18, c=1, stat=0, len=64, token="Single quote escapes"
+l=19, c=2, stat=0, len=64, token="'"
+l=19, c=4, stat=0, len=64, token="'"
+l=21, c=1, stat=0, len=64, token="Double quote escapes"
+l=22, c=2, stat=0, len=64, token="""
+l=22, c=4, stat=0, len=64, token="""
+l=22, c=8, stat=0, len=64, token="""
+l=24, c=1, stat=0, len=64, token="Back slash escapes"
+l=25, c=2, stat=0, len=64, token="\"
+l=25, c=4, stat=0, len=64, token="\"
+l=25, c=9, stat=0, len=64, token="\"
+l=27, c=1, stat=0, len=64, token="Space Character Escapes"
+l=28, c=2, stat=0, len=64, token=" "
+l=28, c=4, stat=0, len=64, token=" "
+l=28, c=9, stat=0, len=64, token=" "
+l=30, c=1, stat=0, len=64, token="Empty Tokens, using quotes"
+l=31, c=1, stat=0, len=64, token=""
+l=31, c=6, stat=0, len=64, token=""
+l=33, c=1, stat=0, len=64, token="Unicode charcaters are handled"
+l=34, c=1, stat=0, len=64, token="° ' ² ³ ` ´"
+l=35, c=1, stat=0, len=64, token="µ ¶ ⨀ ⨁ ⨂"
+l=36, c=1, stat=0, len=64, token="测试用的汉字"
+l=38, c=1, stat=0, len=64, token="Line____Continuation"
+l=41, c=1, stat=0, len=64, token="Double_Quoted_Line____Continuation"
+l=44, c=1, stat=0, len=64, token="Single_Quoted_Line__\
__Continuation_NOT!"
-l=43, c=1, stat=0, len=64, token="double_quoted_newlines__
+l=47, c=1, stat=0, len=64, token="double_quoted_newlines__
__are_part_of_token"
-l=46, c=1, stat=0, len=64, token="single_quoted_newlines__
+l=50, c=1, stat=0, len=64, token="single_quoted_newlines__
__are_part_of_token"
-l=49, c=1, stat=0, len=64, token="Last Token before EOF"
+l=53, c=1, stat=0, len=64, token="Last Token before EOF"
EOF Found
l=1, c=1, stat=0, len=64, token="Next token bad quotes"