2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % SSS CCC RRRR III PPPP TTTTT TTTTT OOO K K EEEE N N %
6 % S C R R I P P T T O O K K E NN N %
7 % SSS C RRRR I PPPP T T O O KK EEE N N N %
8 % S C R R I P T T O O K K E N NN %
9 % SSSS CCC R RR III P T T OOO K K EEEE N N %
11 % TTTTT EEEEE SSSSS TTTTT %
17 % Perform "Magick" on Images via the Command Line Interface %
24 % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
25 % dedicated to making software imaging solutions freely available. %
27 % You may not use this file except in compliance with the License. You may %
28 % obtain a copy of the License at %
30 % http://www.imagemagick.org/script/license.php %
32 % Unless required by applicable law or agreed to in writing, software %
33 % distributed under the License is distributed on an "AS IS" BASIS, %
34 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
35 % See the License for the specific language governing permissions and %
36 % limitations under the License. %
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 % Test the raw tokanization of the ScriptToken Subroutines
42 % This actually uses very little of the magic core functions
43 % and in fact creates a completely stand-alone program by substituting
44 % required MagickCore with direct system equivelents.
47 % cc script-token-test.c -o script-token-test
49 % For testing see script-token-test.sh
53 /* System Replacement for MagickWand includes */
60 /* Defines to replace MagickWand / MagickCore defintions */
61 #define MaxTextExtent 4096
64 #define MagickBooleanType int
66 #define AcquireMagickMemory(s) malloc(s)
67 #define RelinquishMagickMemory(p) (free(p),NULL)
68 #define ResizeMagickMemory(p,s) realloc(p,s)
69 #define ResetMagickMemory(p,b,s) memset(p,b,s)
70 #define StringToLong(s) strtol(s,(char **) NULL,10)
71 #define LocaleCompare(p,q) strcasecmp(p,q)
72 #define LocaleNCompare(p,q,l) strncasecmp(p,q,l)
73 #define WandSignature 0xabacadabUL
74 #define fopen_utf8(p,q) fopen(p,q)
77 /* Include the actual code for ScriptToken functions */
78 #define SCRIPT_TOKEN_TESTING 1 /* Prevent MagickWand Includes */
79 #include "../script-token.h"
80 #include "../script-token.c"
82 /* Test program to report what tokens it finds in given input file/stream */
84 int main(int argc, char *argv[])
89 token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" );
90 if (token_info == (ScriptTokenInfo *) NULL) {
91 printf("Script Open Failure : %s\n", strerror(errno));
96 if( GetScriptToken(token_info) == MagickFalse )
99 if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) {
100 token_info->token[INITAL_TOKEN_LENGTH-4] = '.';
101 token_info->token[INITAL_TOKEN_LENGTH-3] = '.';
102 token_info->token[INITAL_TOKEN_LENGTH-2] = '.';
103 token_info->token[INITAL_TOKEN_LENGTH-1] = '\0';
105 printf("l=%d, c=%d, stat=%d, len=%d, token=\"%s\"\n",
106 token_info->token_line, token_info->token_column,
107 token_info->status, token_info->length, token_info->token);
110 switch( token_info->status ) {
114 printf("EOF Found\n");
116 case TokenStatusBadQuotes:
117 /* Ensure last token has a sane length for error report */
118 if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) {
119 token_info->token[INITAL_TOKEN_LENGTH-4] = '.';
120 token_info->token[INITAL_TOKEN_LENGTH-3] = '.';
121 token_info->token[INITAL_TOKEN_LENGTH-2] = '.';
122 token_info->token[INITAL_TOKEN_LENGTH-1] = '\0';
124 printf("Bad Quotes l=%d, c=%d token=\"%s\"\n",
125 token_info->token_line,token_info->token_column, token_info->token);
127 case TokenStatusMemoryFailed: /* token is invalid */
128 printf("Out of Memory l=%d, c=%d\n",
129 token_info->token_line,token_info->token_column);
131 case TokenStatusBinary: /* token is invalid */
132 printf("Binary Char at l=%d, c=%d\n",
133 token_info->curr_line,token_info->curr_column);
138 token_info = DestroyScriptTokenInfo(token_info);