| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "jacl.h" |
| 20 |
#include "language.h" |
| 21 |
#include "types.h" |
| 22 |
#include "prototypes.h" |
| 23 |
#include "encapsulate.h" |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
static int lines_written; |
| 27 |
|
| 28 |
static FILE *outputFile = NULL; |
| 29 |
static FILE *inputFile = NULL; |
| 30 |
|
| 31 |
static char *stripped_line; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
short int release = FALSE; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
static short int do_encrypt = TRUE; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
static short int encrypting = FALSE; |
| 44 |
|
| 45 |
static int process_file(const char *sourceFile1, const char *sourceFile2); |
| 46 |
|
| 47 |
int |
| 48 |
jpp() |
| 49 |
{ |
| 50 |
int game_version; |
| 51 |
|
| 52 |
lines_written = 0; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
if ((inputFile = fopen(game_file, "r")) != NULL) { |
| 58 |
int index = 0; |
| 59 |
char *result = NULL; |
| 60 |
|
| 61 |
result = fgets(text_buffer, 1024, inputFile); |
| 62 |
if (!result) { |
| 63 |
sprintf(error_buffer, CANT_OPEN_SOURCE, game_file); |
| 64 |
return (FALSE); |
| 65 |
} |
| 66 |
|
| 67 |
while (!feof(inputFile) && index < 10) { |
| 68 |
if (strstr(text_buffer, "#processed")) { |
| 69 |
|
| 70 |
|
| 71 |
if (sscanf(text_buffer, "#processed:%d", &game_version)) { |
| 72 |
if (INTERPRETER_VERSION < game_version) { |
| 73 |
sprintf (error_buffer, OLD_INTERPRETER, game_version); |
| 74 |
return (FALSE); |
| 75 |
} |
| 76 |
} |
| 77 |
strcpy(processed_file, game_file); |
| 78 |
|
| 79 |
return (TRUE); |
| 80 |
} |
| 81 |
result = fgets(text_buffer, 1024, inputFile); |
| 82 |
if (!result) { |
| 83 |
|
| 84 |
break; |
| 85 |
} |
| 86 |
index++; |
| 87 |
} |
| 88 |
|
| 89 |
fclose(inputFile); |
| 90 |
} else { |
| 91 |
sprintf (error_buffer, NOT_FOUND); |
| 92 |
return (FALSE); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
sprintf(processed_file, "%s%s.j2", temp_directory, prefix); |
| 97 |
|
| 98 |
|
| 99 |
if ((outputFile = fopen(processed_file, "w")) == NULL) { |
| 100 |
|
| 101 |
sprintf(processed_file, "%s.j2", prefix); |
| 102 |
if ((outputFile = fopen(processed_file, "w")) == NULL) { |
| 103 |
|
| 104 |
sprintf(error_buffer, CANT_OPEN_PROCESSED, processed_file); |
| 105 |
return (FALSE); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
if (process_file(game_file, (char *) NULL) == FALSE) { |
| 110 |
return (FALSE); |
| 111 |
} |
| 112 |
|
| 113 |
fclose(outputFile); |
| 114 |
|
| 115 |
|
| 116 |
return (TRUE); |
| 117 |
} |
| 118 |
|
| 119 |
int |
| 120 |
process_file(const char *sourceFile1, const char *sourceFile2) |
| 121 |
{ |
| 122 |
char temp_buffer1[1025]; |
| 123 |
char temp_buffer2[1025]; |
| 124 |
FILE *inputFile = NULL; |
| 125 |
char *includeFile = NULL; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
if ((inputFile = fopen(sourceFile1, "r")) == NULL) { |
| 131 |
if (sourceFile2 != NULL) { |
| 132 |
if ((inputFile = fopen(sourceFile2, "r")) == NULL) { |
| 133 |
sprintf(error_buffer, CANT_OPEN_OR, sourceFile1, sourceFile2); |
| 134 |
return (FALSE); |
| 135 |
} |
| 136 |
|
| 137 |
} else { |
| 138 |
sprintf(error_buffer, CANT_OPEN_SOURCE, sourceFile1); |
| 139 |
return (FALSE); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
*text_buffer = 0; |
| 144 |
|
| 145 |
if (fgets(text_buffer, 1024, inputFile) == NULL) { |
| 146 |
sprintf (error_buffer, READ_ERROR); |
| 147 |
return (FALSE); |
| 148 |
} |
| 149 |
|
| 150 |
while (!feof(inputFile) || *text_buffer != 0) { |
| 151 |
if (!strncmp(text_buffer, "#include", 8) || |
| 152 |
(!strncmp(text_buffer, "#debug", 6) & !release)) { |
| 153 |
includeFile = strrchr(text_buffer, '"'); |
| 154 |
|
| 155 |
if (includeFile != NULL) |
| 156 |
*includeFile = 0; |
| 157 |
|
| 158 |
includeFile = strchr(text_buffer, '"'); |
| 159 |
|
| 160 |
if (includeFile != NULL) { |
| 161 |
strcpy(temp_buffer1, game_path); |
| 162 |
strcat(temp_buffer1, includeFile + 1); |
| 163 |
strcpy(temp_buffer2, include_directory); |
| 164 |
strcat(temp_buffer2, includeFile + 1); |
| 165 |
if (process_file(temp_buffer1, temp_buffer2) == FALSE) { |
| 166 |
return (FALSE); |
| 167 |
} |
| 168 |
} else { |
| 169 |
sprintf (error_buffer, BAD_INCLUDE); |
| 170 |
return (FALSE); |
| 171 |
} |
| 172 |
} else { |
| 173 |
|
| 174 |
stripped_line = stripwhite(text_buffer); |
| 175 |
|
| 176 |
if (!encrypting && *stripped_line != '#' && *stripped_line != '\0' && do_encrypt & release) { |
| 177 |
|
| 178 |
|
| 179 |
fputs("#encrypted\n", outputFile); |
| 180 |
encrypting = TRUE; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
if (encrypting) { |
| 185 |
jacl_encrypt(stripped_line); |
| 186 |
} |
| 187 |
|
| 188 |
fputs(stripped_line, outputFile); |
| 189 |
|
| 190 |
lines_written++; |
| 191 |
if (lines_written == 1) { |
| 192 |
sprintf(temp_buffer, "#processed:%d\n", INTERPRETER_VERSION); |
| 193 |
fputs(temp_buffer, outputFile); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
*text_buffer = 0; |
| 198 |
|
| 199 |
if (fgets(text_buffer, 1024, inputFile) == NULL) { |
| 200 |
|
| 201 |
break; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
fclose(inputFile); |
| 206 |
|
| 207 |
|
| 208 |
return (TRUE); |
| 209 |
} |