MagickWand  6.7.8
script-token-test.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
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 %
10 % %
11 % TTTTT EEEEE SSSSS TTTTT %
12 % T E SS T %
13 % T EEE SSS T %
14 % T E SS T %
15 % T EEEEE SSSSS T %
16 % %
17 % Perform "Magick" on Images via the Command Line Interface %
18 % %
19 % Dragon Computing %
20 % Anthony Thyssen %
21 % January 2012 %
22 % %
23 % %
24 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
25 % dedicated to making software imaging solutions freely available. %
26 % %
27 % You may not use this file except in compliance with the License. You may %
28 % obtain a copy of the License at %
29 % %
30 % http://www.imagemagick.org/script/license.php %
31 % %
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. %
37 % %
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %
40 % Test the raw tokanization of the ScriptToken Subroutines
41 %
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.
45 %
46 % Build
47 % cc script-token-test.c -o script-token-test
48 %
49 % For testing see script-token-test.sh
50 %
51 */
52 
53 /* System Replacement for MagickWand includes */
54 #include <stdio.h>
55 #include <string.h>
56 #include <stdlib.h>
57 #include <assert.h>
58 #include <errno.h>
59 
60 #define MaxTextExtent 4096
61 #define MagickFalse 0
62 #define MagickTrue 1
63 #define MagickBooleanType int
64 
65 #define AcquireMagickMemory(s) malloc(s)
66 #define RelinquishMagickMemory(p) (free(p),NULL)
67 #define ResizeMagickMemory(p,s) realloc(p,s)
68 #define ResetMagickMemory(p,b,s) memset(p,b,s)
69 #define StringToLong(s) strtol(s,(char **) NULL,10)
70 #define LocaleCompare(p,q) strcasecmp(p,q)
71 #define LocaleNCompare(p,q,l) strncasecmp(p,q,l)
72 #define WandSignature 0xabacadabUL
73 #define WandExport
74 
75 /* Include the actual code for ScriptToken functions */
76 #define SCRIPT_TOKEN_TESTING 1 /* Prevent MagickWand Includes */
77 #include "script-token.h"
78 #include "script-token.c"
79 
80 /* Test program to report what tokens it finds in given input file/stream */
81 
82 int main(int argc, char *argv[])
83 {
85  *token_info;
86 
87  token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" );
88  if (token_info == (ScriptTokenInfo *) NULL) {
89  printf("Script Open Failure : %s\n", strerror(errno));
90  return(1);
91  }
92 
93  while (1) {
94  if( GetScriptToken(token_info) == MagickFalse )
95  break;
96 
97  if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) {
98  token_info->token[INITAL_TOKEN_LENGTH-4] = '.';
99  token_info->token[INITAL_TOKEN_LENGTH-3] = '.';
100  token_info->token[INITAL_TOKEN_LENGTH-2] = '.';
101  token_info->token[INITAL_TOKEN_LENGTH-1] = '\0';
102  }
103  printf("l=%d, c=%d, stat=%d, len=%d, token=\"%s\"\n",
104  token_info->token_line, token_info->token_column,
105  token_info->status, token_info->length, token_info->token);
106  }
107 
108  switch( token_info->status ) {
109  case TokenStatusOK:
110  break;
111  case TokenStatusEOF:
112  printf("EOF Found\n");
113  break;
115  /* Ensure last token has a sane length for error report */
116  if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) {
117  token_info->token[INITAL_TOKEN_LENGTH-4] = '.';
118  token_info->token[INITAL_TOKEN_LENGTH-3] = '.';
119  token_info->token[INITAL_TOKEN_LENGTH-2] = '.';
120  token_info->token[INITAL_TOKEN_LENGTH-1] = '\0';
121  }
122  printf("Bad Quotes l=%d, c=%d token=\"%s\"\n",
123  token_info->token_line,token_info->token_column, token_info->token);
124  break;
125  case TokenStatusMemoryFailed: /* token is invalid */
126  printf("Out of Memory l=%d, c=%d\n",
127  token_info->token_line,token_info->token_column);
128  break;
129  case TokenStatusBinary: /* token is invalid */
130  printf("Binary Char at l=%d, c=%d\n",
131  token_info->curr_line,token_info->curr_column);
132  break;
133  }
134 
135  /* Clean up */
136  token_info = DestroyScriptTokenInfo(token_info);
137 
138  return(0);
139 }