| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#include <stdio.h> |
| 55 |
#include <string.h> |
| 56 |
#include <stdlib.h> |
| 57 |
#include <assert.h> |
| 58 |
#include <errno.h> |
| 59 |
|
| 60 |
|
| 61 |
#define MagickPathExtent 4096 |
| 62 |
#define MagickFalse 0 |
| 63 |
#define MagickTrue 1 |
| 64 |
#define MagickBooleanType int |
| 65 |
|
| 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) |
| 75 |
#define WandExport |
| 76 |
|
| 77 |
|
| 78 |
#define SCRIPT_TOKEN_TESTING 1 |
| 79 |
#include "../script-token.h" |
| 80 |
#include "../script-token.c" |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
int main(int argc, char *argv[]) |
| 85 |
{ |
| 86 |
ScriptTokenInfo |
| 87 |
*token_info; |
| 88 |
|
| 89 |
token_info = AcquireScriptTokenInfo( (argc>1) ? argv[1] : "-" ); |
| 90 |
if (token_info == (ScriptTokenInfo *) NULL) { |
| 91 |
printf("Script Open Failure : %s\n", strerror(errno)); |
| 92 |
return(1); |
| 93 |
} |
| 94 |
|
| 95 |
while (1) { |
| 96 |
if( GetScriptToken(token_info) == MagickFalse ) |
| 97 |
break; |
| 98 |
|
| 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'; |
| 104 |
} |
| 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); |
| 108 |
} |
| 109 |
|
| 110 |
switch( token_info->status ) { |
| 111 |
case TokenStatusOK: |
| 112 |
break; |
| 113 |
case TokenStatusEOF: |
| 114 |
printf("EOF Found\n"); |
| 115 |
break; |
| 116 |
case TokenStatusBadQuotes: |
| 117 |
|
| 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'; |
| 123 |
} |
| 124 |
printf("Bad Quotes l=%d, c=%d token=\"%s\"\n", |
| 125 |
token_info->token_line,token_info->token_column, token_info->token); |
| 126 |
break; |
| 127 |
case TokenStatusMemoryFailed: |
| 128 |
printf("Out of Memory l=%d, c=%d\n", |
| 129 |
token_info->token_line,token_info->token_column); |
| 130 |
break; |
| 131 |
case TokenStatusBinary: |
| 132 |
printf("Binary Char at l=%d, c=%d\n", |
| 133 |
token_info->curr_line,token_info->curr_column); |
| 134 |
break; |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
token_info = DestroyScriptTokenInfo(token_info); |
| 139 |
|
| 140 |
return(0); |
| 141 |
} |