Ticket #9202: string_output_and_semicolons.diff
File string_output_and_semicolons.diff, 9.4 KB (added by , 14 years ago) |
---|
-
engines/scumm/descumm-common.cpp
242 242 pendingElse = false; 243 243 } 244 244 } 245 246 char *put_ascii(char *buf, int i) { 247 if (i > 31 && i < 128) { 248 // non-printable chars are escaped by backslashes as so: "\x00" 249 // backslashes and quote marks are escaped like so: "\\" "\"" 250 if (i == '\\' || i == '"') { 251 buf[0] = '\\'; 252 buf++; 253 } 254 buf[0] = i; 255 buf[1] = 0; 256 return buf + 1; 257 } 258 return buf + sprintf(buf, "\\x%.2X", i); 259 } 260 261 char *get_string(char *buf) { 262 byte cmd; 263 char *e = buf; 264 bool in = false; 265 bool in_function = false; 266 int i; 267 268 while ((cmd = get_byte()) != 0) { 269 if (cmd == 0xFF || cmd == 0xFE) { 270 if (in) { 271 e += sprintf(e, "\" + "); 272 in = false; 273 } 274 in_function = true; 275 i = get_byte(); 276 switch (i) { 277 case 1: // newline 278 e += sprintf(e, "newline()"); 279 break; 280 case 2: 281 e += sprintf(e, "keepText()"); 282 break; 283 case 3: 284 e += sprintf(e, "wait()"); 285 break; 286 case 4: // addIntToStack 287 e += sprintf(e, "getInt("); 288 goto addVarToStack; 289 case 5: // addVerbToStack 290 e += sprintf(e, "getVerb("); 291 goto addVarToStack; 292 case 6: // addNameToStack 293 e += sprintf(e, "getName("); 294 goto addVarToStack; 295 case 7: // addStringToStack 296 e += sprintf(e, "getString("); 297 addVarToStack: 298 if (g_options.scriptVersion >= 6) { 299 e = get_var6(e); 300 } else { 301 e = get_var(e); 302 } 303 e += sprintf(e, ")"); 304 break; 305 case 9: 306 e += sprintf(e, "startAnim(%d)", get_word()); 307 break; 308 case 10: 309 e += sprintf(e, "sound("); 310 // positions 2, 3, 6, 7 are the offset in MONSTER.SOU (LE). 311 // positions 10, 11, 14, 15 are the VCTL block size (LE). 312 { 313 // show the voice's position in the MONSTER.SOU 314 int p = 0; 315 p += get_word(); 316 g_scriptCurPos += 2; // skip the next "0xFF 0x0A" 317 p += get_word() << 2; 318 e += sprintf(e, "0x%X, ", p); 319 320 g_scriptCurPos += 2; // skip the next "0xFF 0x0A" 321 322 // show the size of the VCTL chunk/lip-synch tags 323 p = 0; 324 p += get_word(); 325 g_scriptCurPos += 2; // skip the next "0xFF 0x0A" 326 p += get_word() << 2; 327 e += sprintf(e, "0x%X)", p); 328 } 329 break; 330 case 12: 331 e += sprintf(e, "setColor(%d)", get_word()); 332 break; 333 case 13: // was unk2 334 e += sprintf(e, "unknown13(%d)", get_word()); 335 break; 336 case 14: 337 e += sprintf(e, "setFont(%d)", get_word()); 338 break; 339 case 32: // Workaround for a script bug in Indy3 340 case 46: // Workaround for a script bug in Indy3 341 if (g_options.scriptVersion == 3 && g_options.IndyFlag) { 342 buf += sprintf(buf, "\\x%.2X", 0xE1); // should output German "sz" in-game. 343 continue; 344 } 345 // fall-through 346 default: 347 e += sprintf(e, "unknown%d(%d)", i, get_word()); 348 } 349 } else { 350 if (in_function) { 351 e += sprintf(e, " + "); 352 in_function = false; 353 } 354 if (!in) { 355 *e++ = '"'; 356 in = true; 357 } 358 e = put_ascii(e, cmd); 359 } 360 } 361 if (in) 362 *e++ = '"'; 363 *e = 0; 364 return e; 365 } -
engines/scumm/descumm.cpp
568 568 return strecpy(buf, "]"); 569 569 } 570 570 571 char *putascii(char *buf, int i) {572 if (i > 31 && i < 128) {573 // non-printable chars are escaped by backslashes as so: "\x00"574 // backslashes and quote marks are escaped like so: "\\" "\""575 if (i == '\\' || i == '"') {576 buf[0] = '\\';577 buf++;578 }579 buf[0] = i;580 buf[1] = 0;581 return buf + 1;582 }583 return buf + sprintf(buf, "\\x%.2X", i);584 }585 571 586 char *get_ascii(char *buf) {587 int i;588 589 buf = strecpy(buf, "\"");590 591 do {592 i = get_byte();593 if (!i)594 break;595 buf = putascii(buf, i);596 if (i == 255) {597 i = get_byte();598 buf = putascii(buf, i);599 600 // Workaround for a script bug in Indy3601 if (i == 46 && g_options.scriptVersion == 3 && g_options.IndyFlag)602 continue;603 604 if (i != 1 && i != 2 && i != 3 && i != 8) {605 buf = putascii(buf, get_byte());606 buf = putascii(buf, get_byte());607 }608 }609 } while (1);610 611 return strecpy(buf, "\"");612 }613 614 615 616 572 char *add_a_tok(char *buf, int type) { 617 573 switch (type) { 618 574 case TOK_BYTE: … … 628 584 buf = get_list(buf); 629 585 break; 630 586 case TOK_ASCII: 631 buf = get_ ascii(buf);587 buf = get_string(buf); 632 588 break; 633 589 case TOK_CHAR: 634 590 error("this code seems to be dead"); 635 buf = put ascii(buf, get_byte());591 buf = put_ascii(buf, get_byte()); 636 592 break; 637 593 } 638 594 return buf; … … 681 637 } else { 682 638 if (!(args & ANOLASTPAREN)) { 683 639 buf = strecpy(buf, ")"); 684 }640 } 685 641 if (!(args & ANOENDSEMICOLON) && buf[(strlen(buf) - 1)] != ';') { 686 642 buf = strecpy(buf, ";"); 687 643 } … … 955 911 buf = strchr(strcpy(buf, "PutCodeInString("), 0); 956 912 buf = get_var_or_byte(buf, opcode & 0x80); 957 913 buf = strchr(strcpy(buf, ", "), 0); 958 buf = get_ ascii(buf);914 buf = get_string(buf); 959 915 strcpy(buf, ");"); 960 916 } 961 917 … … 1477 1433 break; 1478 1434 case 0xF:{ 1479 1435 buf = strecpy(buf, "Text("); 1480 buf = get_ ascii(buf);1436 buf = get_string(buf); 1481 1437 buf = strecpy(buf, ")"); 1482 1438 } 1483 1439 goto exit_proc; … … 1934 1890 case 0xF9:{ 1935 1891 buf = strecpy(buf, "doSentence("); 1936 1892 if (!(opcode & 0x80) && *g_scriptCurPos == 0xFC) { 1937 strcpy(buf, "STOP) ");1893 strcpy(buf, "STOP);"); 1938 1894 g_scriptCurPos++; 1939 1895 } else if (!(opcode & 0x80) && *g_scriptCurPos == 0xFB) { 1940 strcpy(buf, "RESET) ");1896 strcpy(buf, "RESET);"); 1941 1897 g_scriptCurPos++; 1942 1898 } else { 1943 1899 do_tok(buf, "", … … 2313 2269 int i; 2314 2270 char first = 1; 2315 2271 2316 buf = do_tok(buf, "setVarRange", A1V | ANOLASTPAREN );2272 buf = do_tok(buf, "setVarRange", A1V | ANOLASTPAREN | ANOENDSEMICOLON); 2317 2273 i = get_byte(); 2318 2274 2319 2275 buf += sprintf(buf, ",%d,[", i); … … 3284 3240 buf = strecpy(buf, "doSentence("); 3285 3241 // FIXME: this is not exactly what ScummVM does... 3286 3242 if (!(opcode & 0x80) && (*g_scriptCurPos == 0xFE)) { 3287 strcpy(buf, "STOP) ");3243 strcpy(buf, "STOP);"); 3288 3244 g_scriptCurPos++; 3289 3245 } else { 3290 3246 do_tok(buf, "", … … 3367 3323 case 0xFF: 3368 3324 buf = 3369 3325 do_tok(buf, "drawBox", 3370 ((opcode & 0x80) ? A1V : A1W) | ((opcode & 0x40) ? A2V : A2W) | ANOLASTPAREN );3326 ((opcode & 0x80) ? A1V : A1W) | ((opcode & 0x40) ? A2V : A2W) | ANOLASTPAREN | ANOENDSEMICOLON); 3371 3327 opcode = get_byte(); 3372 3328 do_tok(buf, NULL, 3373 3329 ASTARTCOMMA | ANOFIRSTPAREN | ((opcode & 0x80) ? A1V : A1W) | … … 3510 3466 int i; 3511 3467 char first = 1; 3512 3468 3513 buf = do_tok(buf, "setVarRange", A1V | ANOLASTPAREN );3469 buf = do_tok(buf, "setVarRange", A1V | ANOLASTPAREN | ANOENDSEMICOLON); 3514 3470 i = get_byte(); 3515 3471 3516 3472 buf += sprintf(buf, ",%d,[", i); … … 3674 3630 break; 3675 3631 case 0x03: 3676 3632 buf += sprintf(buf, ", Open("); 3677 buf = get_ ascii(buf);3633 buf = get_string(buf); 3678 3634 buf += sprintf(buf, ")"); 3679 3635 break; 3680 3636 case 0x04: -
engines/scumm/descumm.h
172 172 extern bool maybeAddBreak(uint cur, uint to); 173 173 extern void writePendingElse(); 174 174 175 extern char *put_ascii(char *buf, int i); 176 extern char *get_string(char *buf); 177 178 extern char *get_var(char *buf); 179 extern char *get_var6(char *buf); 180 175 181 // 176 182 // Entry points for the descumming 177 183 // … … 184 190 extern void next_line_HE_V100(char *buf); 185 191 186 192 187 188 193 #endif -
engines/scumm/descumm6.cpp
1063 1063 return new ListStackEnt(pop()); 1064 1064 } 1065 1065 1066 char *get_var6(char *buf) { 1067 VarStackEnt tmp(get_word()); 1068 return tmp.asText(buf); 1069 } 1070 1066 1071 void invalidop(const char *cmd, int op) { 1067 1072 if (cmd) 1068 1073 error("Unknown opcode %s:0x%x (stack count %d)", cmd, op, num_stack); … … 1159 1164 delete se; 1160 1165 } 1161 1166 1167 1162 1168 StackEnt *se_get_string() { 1163 byte cmd;1164 1169 char buf[1024]; 1165 char *e = buf; 1166 bool in = false; 1167 int i; 1168 1169 while ((cmd = get_byte()) != 0) { 1170 if (cmd == 0xFF || cmd == 0xFE) { 1171 if (in) { 1172 *e++ = '"'; 1173 in = false; 1174 } 1175 i = get_byte(); 1176 switch (i) { 1177 case 1: 1178 e += sprintf(e, ":newline:"); 1179 break; 1180 case 2: 1181 e += sprintf(e, ":keeptext:"); 1182 break; 1183 case 3: 1184 e += sprintf(e, ":wait:"); 1185 break; 1186 case 4: // addIntToStack 1187 case 5: // addVerbToStack 1188 case 6: // addNameToStack 1189 case 7: // addStringToStack 1190 { 1191 VarStackEnt tmp(get_word()); 1192 e += sprintf(e, ":"); 1193 e = tmp.asText(e); 1194 e += sprintf(e, ":"); 1195 } 1196 break; 1197 case 9: 1198 e += sprintf(e, ":startanim=%d:", get_word()); 1199 break; 1200 case 10: 1201 e += sprintf(e, ":sound:"); 1202 g_scriptCurPos += 14; 1203 break; 1204 case 14: 1205 e += sprintf(e, ":setfont=%d:", get_word()); 1206 break; 1207 case 12: 1208 e += sprintf(e, ":setcolor=%d:", get_word()); 1209 break; 1210 case 13: 1211 e += sprintf(e, ":unk2=%d:", get_word()); 1212 break; 1213 default: 1214 e += sprintf(e, ":unk%d=%d:", i, get_word()); 1215 } 1216 } else { 1217 if (!in) { 1218 *e++ = '"'; 1219 in = true; 1220 } 1221 *e++ = cmd; 1222 } 1223 } 1224 if (in) 1225 *e++ = '"'; 1226 *e = 0; 1170 get_string(buf); // ignore returned value 1227 1171 return se_complex(buf); 1228 1172 } 1229 1173