OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / share / thintile.c
1 /* NetHack 3.6  thintile.c      $NHDT-Date: 1457207049 2016/03/05 19:44:09 $  $NHDT-Branch: chasonr $:$NHDT-Revision: 1.10 $ */
2 /*   Copyright (c) NetHack Development Team 1995                    */
3 /*   NetHack may be freely redistributed.  See license for details. */
4
5 /* Create a set of overview tiles by eliminating even pixels in original */
6
7 #include "config.h"
8 #include "tile.h"
9
10 #ifdef __GO32__
11 #include <unistd.h>
12 #endif
13
14 static char pixels[TILE_Y][TILE_X];
15
16 static char *tilefiles[] = { "../win/share/monsters.txt",
17                              "../win/share/objects.txt",
18                              "../win/share/other.txt" };
19
20 static char *thinfiles[] = { "../win/share/monthin.txt",
21                              "../win/share/objthin.txt",
22                              "../win/share/oththin.txt" };
23 static FILE *infile, *outfile;
24 static int tilecount;
25 static int tilecount_per_file;
26 static int filenum;
27 static char comment[BUFSZ];
28
29 static void
30 copy_colormap()
31 {
32     int r, g, b;
33     char c[2];
34
35     while (fscanf(infile, "%[A-Za-z0-9.] = (%d, %d, %d) ", c, &r, &g, &b)
36            == 4) {
37         Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
38     }
39 }
40
41 static boolean
42 read_txttile()
43 {
44     int i, j;
45     char buf[BUFSZ];
46     char buf2[BUFSZ];
47
48     char c[2];
49
50     if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
51         return FALSE;
52
53     Sprintf(comment, "# tile %d (%s)", i, buf);
54
55     /* look for non-whitespace at each stage */
56     if (fscanf(infile, "%1s", c) < 0) {
57         Fprintf(stderr, "unexpected EOF\n");
58         return FALSE;
59     }
60     if (c[0] != '{') {
61         Fprintf(stderr, "didn't find expected '{'\n");
62         return FALSE;
63     }
64     for (j = 0; j < TILE_Y; j++) {
65         for (i = 0; i < TILE_X; i++) {
66             if (fscanf(infile, "%1s", c) < 0) {
67                 Fprintf(stderr, "unexpected EOF\n");
68                 return FALSE;
69             }
70             pixels[j][i] = c[0];
71         }
72     }
73     if (fscanf(infile, "%1s ", c) < 0) {
74         Fprintf(stderr, "unexpected EOF\n");
75         return FALSE;
76     }
77     if (c[0] != '}') {
78         Fprintf(stderr, "didn't find expected '}'\n");
79         return FALSE;
80     }
81     return TRUE;
82 }
83
84 static void
85 write_thintile()
86 {
87     int i, j;
88
89     Fprintf(outfile, "%s\n", comment);
90     Fprintf(outfile, "{\n");
91     for (j = 0; j < TILE_Y; j++) {
92         Fprintf(outfile, "  ");
93         for (i = 0; i < TILE_X; i += 2) {
94             (void) fputc(pixels[j][i], outfile);
95         }
96         Fprintf(outfile, "\n");
97     }
98     Fprintf(outfile, "}\n");
99 }
100 int
101 main(argc, argv)
102 int argc;
103 char *argv[];
104 {
105     while (filenum < 3) {
106         tilecount_per_file = 0;
107         infile = fopen(tilefiles[filenum], RDTMODE);
108         outfile = fopen(thinfiles[filenum], WRTMODE);
109         copy_colormap();
110         while (read_txttile()) {
111             write_thintile();
112             tilecount_per_file++;
113             tilecount++;
114         }
115         fclose(outfile);
116         fclose(infile);
117         printf("%d tiles processed from %s\n", tilecount_per_file,
118                tilefiles[filenum]);
119         ++filenum;
120     }
121     printf("Grand total of %d tiles processed.\n", tilecount);
122     exit(EXIT_SUCCESS);
123     /*NOTREACHED*/
124     return 0;
125 }
126
127 /*thintile.c*/