| 381 | } |
| 382 | |
| 383 | boolean |
| 384 | fopen_text_file(const char *filename, const char *type) |
| 385 | { |
| 386 | const char *p; |
| 387 | int i; |
| 388 | |
| 389 | if (tile_file != (FILE *) 0) { |
| 390 | Fprintf(stderr, "can only open one text file at a time\n"); |
| 391 | return FALSE; |
| 392 | } |
| 393 | |
| 394 | tile_file = fopen(filename, type); |
| 395 | if (tile_file == (FILE *) 0) { |
| 396 | Fprintf(stderr, "cannot open text file %s\n", filename); |
| 397 | return FALSE; |
| 398 | } |
| 399 | |
| 400 | p = strrchr(filename, '/'); |
| 401 | if (p) |
| 402 | p++; |
| 403 | else |
| 404 | p = filename; |
| 405 | |
| 406 | tile_set = 0; |
| 407 | for (i = 0; i < SIZE(text_sets); i++) { |
| 408 | if (!strcmp(p, text_sets[i])) |
| 409 | tile_set = i; |
| 410 | } |
| 411 | tile_set_indx = 0; |
| 412 | |
| 413 | if (!strcmp(type, RDTMODE)) { |
| 414 | /* Fill placeholder with noise */ |
| 415 | if (!placeholder_init) { |
| 416 | placeholder_init++; |
| 417 | for (i = 0; i < (int) sizeof placeholder; i++) |
| 418 | ((char *) placeholder)[i] = i % 256; |
| 419 | } |
| 420 | |
| 421 | read_text_colormap(tile_file); |
| 422 | if (!colorsinmainmap) |
| 423 | init_colormap(); |
| 424 | else |
| 425 | merge_colormap(); |
| 426 | return TRUE; |
| 427 | } else if (!strcmp(type, WRTMODE)) { |
| 428 | if (!colorsinmainmap) { |
| 429 | Fprintf(stderr, "no colormap set yet\n"); |
| 430 | return FALSE; |
| 431 | } |
| 432 | return (write_text_colormap(tile_file)); |
| 433 | } else { |
| 434 | Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type); |
| 435 | return FALSE; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | boolean |
| 440 | read_text_tile(pixel (*pixels)[TILE_X]) |
no test coverage detected