NHDT->ANH, nethack->anethack, nhdat->anhdat
[aNetHack.git] / win / share / thintile.c
blob6cb764a973ad910e4a908c1b71c7628e073398d3
1 /* aNetHack 0.0.1 thintile.c $ANH-Date: 1457207049 2016/03/05 19:44:09 $ $ANH-Branch: chasonr $:$ANH-Revision: 1.10 $ */
2 /* Copyright (c) aNetHack Development Team 1995 */
3 /* aNetHack may be freely redistributed. See license for details. */
5 /* Create a set of overview tiles by eliminating even pixels in original */
7 #include "config.h"
8 #include "tile.h"
10 #ifdef __GO32__
11 #include <unistd.h>
12 #endif
14 static char pixels[TILE_Y][TILE_X];
16 static char *tilefiles[] = { "../win/share/monsters.txt",
17 "../win/share/objects.txt",
18 "../win/share/other.txt" };
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];
29 static void
30 copy_colormap()
32 int r, g, b;
33 char c[2];
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);
41 static boolean
42 read_txttile()
44 int i, j;
45 char buf[BUFSZ];
46 char buf2[BUFSZ];
48 char c[2];
50 if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
51 return FALSE;
53 Sprintf(comment, "# tile %d (%s)", i, buf);
55 /* look for non-whitespace at each stage */
56 if (fscanf(infile, "%1s", c) < 0) {
57 Fprintf(stderr, "unexpected EOF\n");
58 return FALSE;
60 if (c[0] != '{') {
61 Fprintf(stderr, "didn't find expected '{'\n");
62 return FALSE;
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;
70 pixels[j][i] = c[0];
73 if (fscanf(infile, "%1s ", c) < 0) {
74 Fprintf(stderr, "unexpected EOF\n");
75 return FALSE;
77 if (c[0] != '}') {
78 Fprintf(stderr, "didn't find expected '}'\n");
79 return FALSE;
81 return TRUE;
84 static void
85 write_thintile()
87 int i, j;
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);
96 Fprintf(outfile, "\n");
98 Fprintf(outfile, "}\n");
101 main(argc, argv)
102 int argc;
103 char *argv[];
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++;
115 fclose(outfile);
116 fclose(infile);
117 printf("%d tiles processed from %s\n", tilecount_per_file,
118 tilefiles[filenum]);
119 ++filenum;
121 printf("Grand total of %d tiles processed.\n", tilecount);
122 exit(EXIT_SUCCESS);
123 /*NOTREACHED*/
124 return 0;
127 /*thintile.c*/