--- /dev/null
+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="Lines____Continuation"
+l=37, c=1, stat=0, len=64, token="quoted_newlines__
+__are_part_of_token"
+l=40, 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"
+Bad Quotes l=1, c=25 token="unfinished quotes ->"
+
+l=1, c=1, stat=0, len=64, token="Binary input follows"
+Binary Char at l=2, c=4
+
+l=1, c=1, stat=0, len=64, token="Very BIG Token Tests"
+l=2, c=1, stat=0, len=256, token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..."
+l=3, c=1, stat=0, len=1024, token="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb..."
+l=4, c=1, stat=0, len=4096, token="cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc..."
+l=5, c=1, stat=0, len=8192, token="dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd..."
+l=6, c=1, stat=0, len=12288, token="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee..."
+l=7, c=1, stat=0, len=16384, token="ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff..."
+l=8, c=1, stat=0, len=8392704, token="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee..."
+l=9, c=1, stat=0, len=8392704, token="and all is well!"
+EOF Found
+
--- /dev/null
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% SSS CCC RRRR III PPPP TTTTT TTTTT OOO K K EEEE N N %
+% S C R R I P P T T O O K K E NN N %
+% SSS C RRRR I PPPP T T O O KK EEE N N N %
+% S C R R I P T T O O K K E N NN %
+% SSSS CCC R RR III P T T OOO K K EEEE N N %
+% %
+% TTTTT EEEEE SSSSS TTTTT %
+% T E SS T %
+% T EEE SSS T %
+% T E SS T %
+% T EEEEE SSSSS T %
+% %
+% Perform "Magick" on Images via the Command Line Interface %
+% %
+% Dragon Computing %
+% Anthony Thyssen %
+% January 2012 %
+% %
+% %
+% Copyright 1999-2012 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 %
+% obtain a copy of the License at %
+% %
+% http://www.imagemagick.org/script/license.php %
+% %
+% Unless required by applicable law or agreed to in writing, software %
+% distributed under the License is distributed on an "AS IS" BASIS, %
+% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
+% See the License for the specific language governing permissions and %
+% limitations under the License. %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% Test the raw tokanization of the ScriptToken Subroutines
+%
+% This actually uses very little of the magic core functions
+% and in fact creates a completely stand-alone program by substituting
+% required MagickCore with direct system equivelents.
+%
+% Build
+% cc script-token-test.c -o script-token-test
+%
+% For testing see script-token-test.sh
+%
+*/
+
+/* System Replacement for MagickWand includes */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
+
+/* Defines to replace MagickWand / MagickCore defintions */
+#define MaxTextExtent 4096
+#define MagickFalse 0
+#define MagickTrue 1
+#define MagickBooleanType int
+
+#define AcquireMagickMemory(s) malloc(s)
+#define RelinquishMagickMemory(p) (free(p),NULL)
+#define ResizeMagickMemory(p,s) realloc(p,s)
+#define ResetMagickMemory(p,b,s) memset(p,b,s)
+#define StringToLong(s) strtol(s,(char **) NULL,10)
+#define LocaleCompare(p,q) strcasecmp(p,q)
+#define LocaleNCompare(p,q,l) strncasecmp(p,q,l)
+#define WandSignature 0xabacadabUL
+#define WandExport
+
+/* Include the actual code for ScriptToken functions */
+#define SCRIPT_TOKEN_TESTING 1 /* Prevent MagickWand Includes */
+#include "../script-token.h"
+#include "../script-token.c"
+
+/* Test program to report what tokens it finds in given input file/stream */
+
+int main(int argc, char *argv[])
+{
+ ScriptTokenInfo
+ *token_info;
+
+ token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" );
+ if (token_info == (ScriptTokenInfo *) NULL) {
+ printf("Script Open Failure : %s\n", strerror(errno));
+ return(1);
+ }
+
+ while (1) {
+ if( GetScriptToken(token_info) == MagickFalse )
+ break;
+
+ 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';
+ }
+ printf("l=%d, c=%d, stat=%d, len=%d, token=\"%s\"\n",
+ token_info->token_line, token_info->token_column,
+ token_info->status, token_info->length, token_info->token);
+ }
+
+ switch( token_info->status ) {
+ case TokenStatusOK:
+ break;
+ case TokenStatusEOF:
+ printf("EOF Found\n");
+ break;
+ case TokenStatusBadQuotes:
+ /* Ensure last token has a sane length for error report */
+ 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';
+ }
+ printf("Bad Quotes l=%d, c=%d token=\"%s\"\n",
+ token_info->token_line,token_info->token_column, token_info->token);
+ break;
+ case TokenStatusMemoryFailed: /* token is invalid */
+ printf("Out of Memory l=%d, c=%d\n",
+ token_info->token_line,token_info->token_column);
+ break;
+ case TokenStatusBinary: /* token is invalid */
+ printf("Binary Char at l=%d, c=%d\n",
+ token_info->curr_line,token_info->curr_column);
+ break;
+ }
+
+ /* Clean up */
+ token_info = DestroyScriptTokenInfo(token_info);
+
+ return(0);
+}