OSDN Git Service

Initial Import
[nethackexpress/trunk.git] / win / share / thintile.c
1 /*   SCCS Id: @(#)thintile.c   3.4     1995/11/26                     */
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
51         if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
52                 return FALSE;
53         
54         Sprintf(comment,"# tile %d (%s)", i, buf);
55         
56         /* look for non-whitespace at each stage */
57         if (fscanf(infile, "%1s", c) < 0) {
58                 Fprintf(stderr, "unexpected EOF\n");
59                 return FALSE;
60         }
61         if (c[0] != '{') {
62                 Fprintf(stderr, "didn't find expected '{'\n");
63                 return FALSE;
64         }
65         for (j = 0; j < TILE_Y; j++) {
66                 for (i = 0; i < TILE_X; i++) {
67                         if (fscanf(infile, "%1s", c) < 0) {
68                                 Fprintf(stderr, "unexpected EOF\n");
69                                 return FALSE;
70                         }
71                         pixels[j][i] = c[0];
72                 }
73         }
74         if (fscanf(infile, "%1s ", c) < 0) {
75                 Fprintf(stderr, "unexpected EOF\n");
76                 return FALSE;
77         }
78         if (c[0] != '}') {
79                 Fprintf(stderr, "didn't find expected '}'\n");
80                 return FALSE;
81         }
82         return TRUE;
83 }
84
85 static void
86 write_thintile()
87 {
88         int i, j;
89
90
91         Fprintf(outfile, "%s\n", comment);
92         Fprintf(outfile, "{\n");
93         for (j = 0; j < TILE_Y; j++) {
94                 Fprintf(outfile, "  ");
95                 for (i = 0; i < TILE_X; i += 2) {
96                         (void) fputc(pixels[j][i], outfile);
97                 }
98                 Fprintf(outfile, "\n");
99         }
100         Fprintf(outfile, "}\n");
101 }
102 int
103 main(argc, argv)
104 int argc;
105 char *argv[];
106 {
107         while (filenum < 3) {
108                 tilecount_per_file = 0;
109                 infile = fopen(tilefiles[filenum], RDTMODE);
110                 outfile = fopen(thinfiles[filenum], WRTMODE);
111                 copy_colormap();
112                 while (read_txttile()) {
113                                 write_thintile();
114                                 tilecount_per_file++;
115                                 tilecount++;
116                 }
117                 fclose(outfile);
118                 fclose(infile);
119                 printf("%d tiles processed from %s\n",
120                         tilecount_per_file, tilefiles[filenum]);
121                 ++filenum;
122         }
123         printf("Grand total of %d tiles processed.\n", tilecount);
124         exit(EXIT_SUCCESS);
125         /*NOTREACHED*/
126         return 0;
127 }
128
129 /*thintile.c*/