1
0
Fork 0
mirror of https://codeberg.org/noisytoot/notnotdnethack.git synced 2024-09-19 22:14:48 +01:00
notnotdnethack/win/share/thintile.c
Ron Nazarov bd8b743c9a
Convert all declarations from K&R style to ANSI style
Now compiles with gcc -Werror=old-style-definition.  It should also be
valid C23, although I haven't tried compiling with -std=c2x yet -
there might be something else making it invalid.

This also allows getting rid of (UN)WIDENED_PROTOTYPES and _P defines.
I kept OBJ_P, MONST_P, and DLB_P for now.

Done mostly by running

cproto -Iinclude -C"int\nf(\n\ta,\n\tb)" -F"int\nf(a, b)" -pa

then

sed -i 's/^\(\(static \)\?[a-zA-Z]\+\) $/\1/'

on each file, with some manual corrections/adjustments done after and
anything cproto can't handle manually converted.  The sed is to remove
the extra space that cproto adds at the end of the line with the
return type name.

"register" is inconsistently sometimes removed - generally, I removed
it when I did it manually but cproto didn't.  GCC ignores register
anyway so this shouldn't matter much.
2024-05-05 01:18:53 +01:00

124 lines
2.6 KiB
C

/* SCCS Id: @(#)thintile.c 3.4 1995/11/26 */
/* Copyright (c) NetHack Development Team 1995 */
/* NetHack may be freely redistributed. See license for details. */
/* Create a set of overview tiles by eliminating even pixels in original */
#include "config.h"
#include "tile.h"
static char pixels[TILE_Y][TILE_X];
static char *tilefiles[] = { "../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt"};
static char *thinfiles[] = { "../win/share/monthin.txt",
"../win/share/objthin.txt",
"../win/share/oththin.txt"};
static FILE *infile, *outfile;
static int tilecount;
static int tilecount_per_file;
static int filenum;
static char comment[BUFSZ];
static void
copy_colormap(void)
{
int r, g, b;
char c[2];
while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
== 4) {
Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
}
}
static boolean
read_txttile(void)
{
int i, j;
char buf[BUFSZ];
char buf2[BUFSZ];
char c[2];
if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
return FALSE;
Sprintf(comment,"# tile %d (%s)", i, buf);
/* look for non-whitespace at each stage */
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
pixels[j][i] = c[0];
}
}
if (fscanf(infile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
return TRUE;
}
static void
write_thintile(void)
{
int i, j;
Fprintf(outfile, "%s\n", comment);
Fprintf(outfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(outfile, " ");
for (i = 0; i < TILE_X; i += 2) {
(void) fputc(pixels[j][i], outfile);
}
Fprintf(outfile, "\n");
}
Fprintf(outfile, "}\n");
}
int
main(int argc, char *argv[])
{
while (filenum < 3) {
tilecount_per_file = 0;
infile = fopen(tilefiles[filenum], RDTMODE);
outfile = fopen(thinfiles[filenum], WRTMODE);
copy_colormap();
while (read_txttile()) {
write_thintile();
tilecount_per_file++;
tilecount++;
}
fclose(outfile);
fclose(infile);
printf("%d tiles processed from %s\n",
tilecount_per_file, tilefiles[filenum]);
++filenum;
}
printf("Grand total of %d tiles processed.\n", tilecount);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
/*thintile.c*/