tile.c formatting

Modify win/share/tilemap.c so that generated source file src/tile.c
uses similar formatting to the other sources.  Mainly, avoid tabs and
use 4 columns indentation instead of 8 columns in the short routine
near the end.

tilemap.c still treats STATUES_LOOK_LIKE_MONSTERS as conditional.
The main sources made that unconditional prior to release of 3.6.0.
This commit is contained in:
PatR
2018-09-30 02:11:32 -07:00
parent 3e19858edd
commit 317f0b56fa
+47 -44
View File
@@ -3,13 +3,15 @@
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
/* /*
* This source file is compiled twice: * This source file is compiled twice:
* once without TILETEXT defined to make tilemap.{o,obj}, * once without TILETEXT defined to make tilemap.{o,obj},
* then again with it defined to produce tiletxt.{o,obj}. * then again with it defined to produce tiletxt.{o,obj}.
*/ */
#include "hack.h" #include "hack.h"
#define Fprintf (void) fprintf
const char *FDECL(tilename, (int, int)); const char *FDECL(tilename, (int, int));
void NDECL(init_tilemap); void NDECL(init_tilemap);
void FDECL(process_substitutions, (FILE *)); void FDECL(process_substitutions, (FILE *));
@@ -40,7 +42,7 @@ struct conditionals {
int sequence, predecessor; int sequence, predecessor;
const char *name; const char *name;
} conditionals[] = { } conditionals[] = {
#ifndef CHARON /* not supported yet */ #ifndef CHARON /* not supported */
{ MON_GLYPH, PM_HELL_HOUND, "Cerberus" }, { MON_GLYPH, PM_HELL_HOUND, "Cerberus" },
#endif #endif
/* commented out in monst.c at present */ /* commented out in monst.c at present */
@@ -68,7 +70,8 @@ struct conditionals {
* don't know what a slime mold should look like when renamed anyway * don't know what a slime mold should look like when renamed anyway
*/ */
#ifndef MAIL #ifndef MAIL
{ OBJ_GLYPH, SCR_STINKING_CLOUD + EXTRA_SCROLL_DESCR_COUNT, "stamped / mail" }, { OBJ_GLYPH, SCR_STINKING_CLOUD + EXTRA_SCROLL_DESCR_COUNT,
"stamped / mail" },
#endif #endif
{ 0, 0, 0 } { 0, 0, 0 }
}; };
@@ -394,19 +397,20 @@ init_tilemap()
#endif #endif
} }
const char *prolog[] = { "", "", "void", "substitute_tiles(plev)", const char *prolog[] = { "", "void", "substitute_tiles(plev)",
"d_level *plev;", "{", "\tint i;", "" }; "d_level *plev;", "{", " int i;", "" };
const char *epilog[] = { "}" }; const char *epilog[] = { " return;", "}" };
/* write out the substitutions in an easily-used form. */ /* write out the substitutions in an easily-used form. */
void void
process_substitutions(ofp) process_substitutions(ofp)
FILE *ofp; FILE *ofp;
{ {
static const char Dent[] = " "; /* 4 space indentation */
int i, j, k, span, start; int i, j, k, span, start;
fprintf(ofp, "\n\n"); Fprintf(ofp, "\n");
j = 0; /* unnecessary */ j = 0; /* unnecessary */
span = -1; span = -1;
@@ -415,16 +419,16 @@ FILE *ofp;
|| substitutes[i].last_glyph != substitutes[j].last_glyph) { || substitutes[i].last_glyph != substitutes[j].last_glyph) {
j = i; j = i;
span++; span++;
fprintf(ofp, "short std_tiles%d[] = { ", span); Fprintf(ofp, "short std_tiles%d[] = { ", span);
for (k = substitutes[i].first_glyph; for (k = substitutes[i].first_glyph;
k < substitutes[i].last_glyph; k++) k < substitutes[i].last_glyph; k++)
fprintf(ofp, "%d, ", tilemap[k]); Fprintf(ofp, "%d, ", tilemap[k]);
fprintf(ofp, "%d };\n", tilemap[substitutes[i].last_glyph]); Fprintf(ofp, "%d };\n", tilemap[substitutes[i].last_glyph]);
} }
} }
for (i = 0; i < SIZE(prolog); i++) { for (i = 0; i < SIZE(prolog); i++) {
fprintf(ofp, "%s\n", prolog[i]); Fprintf(ofp, "%s\n", prolog[i]);
} }
j = -1; j = -1;
span = -1; span = -1;
@@ -433,43 +437,41 @@ FILE *ofp;
if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) { || substitutes[i].last_glyph != substitutes[j].last_glyph) {
if (i != 0) { /* finish previous span */ if (i != 0) { /* finish previous span */
fprintf(ofp, "\t} else {\n"); Fprintf(ofp, "%s} else {\n", Dent);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", Fprintf(ofp, "%s%sfor (i = %d; i <= %d; i++)\n", Dent, Dent,
substitutes[j].first_glyph, substitutes[j].first_glyph, substitutes[j].last_glyph);
substitutes[j].last_glyph); Fprintf(ofp, "%s%s%sglyph2tile[i] = std_tiles%d[i - %d];\n",
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", Dent, Dent, Dent, span, substitutes[j].first_glyph);
span, substitutes[j].first_glyph); Fprintf(ofp, "%s}\n\n", Dent);
fprintf(ofp, "\t}\n\n");
} }
j = i; j = i;
span++; span++;
} }
if (i != j) Fprintf(ofp, "%s%sif (%s) {\n", Dent, (i == j) ? "" : "} else ",
fprintf(ofp, "\t} else "); substitutes[i].level_test);
fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test); Fprintf(ofp, "%s%sfor (i = %d; i <= %d; i++)\n", Dent, Dent,
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[i].first_glyph, substitutes[i].last_glyph); substitutes[i].first_glyph, substitutes[i].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n", start, Fprintf(ofp, "%s%s%sglyph2tile[i] = %d + i - %d;\n",
substitutes[i].first_glyph); Dent, Dent, Dent, start, substitutes[i].first_glyph);
start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1; start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
} }
/* finish last span */ /* finish last span */
fprintf(ofp, "\t} else {\n"); Fprintf(ofp, "%s} else {\n", Dent);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n", Fprintf(ofp, "%s%sfor (i = %d; i <= %d; i++)\n", Dent, Dent,
substitutes[j].first_glyph, substitutes[j].last_glyph); substitutes[j].first_glyph, substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", span, Fprintf(ofp, "%s%s%sglyph2tile[i] = std_tiles%d[i - %d];\n",
substitutes[j].first_glyph); Dent, Dent, Dent, span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n"); Fprintf(ofp, "%s}\n", Dent);
for (i = 0; i < SIZE(epilog); i++) { for (i = 0; i < SIZE(epilog); i++) {
fprintf(ofp, "%s\n", epilog[i]); Fprintf(ofp, "%s\n", epilog[i]);
} }
lastothtile = start - 1; lastothtile = start - 1;
#ifdef STATUES_LOOK_LIKE_MONSTERS #ifdef STATUES_LOOK_LIKE_MONSTERS
start = laststatuetile + 1; start = laststatuetile + 1;
#endif #endif
fprintf(ofp, "\nint total_tiles_used = %d;\n", start); Fprintf(ofp, "\nint total_tiles_used = %d;\n", start);
} }
int int
@@ -489,27 +491,27 @@ main()
perror(filename); perror(filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fprintf(ofp, Fprintf(ofp,
"/* This file is automatically generated. Do not edit. */\n"); "/* This file is automatically generated. Do not edit. */\n");
fprintf(ofp, "\n#include \"hack.h\"\n\n"); Fprintf(ofp, "\n#include \"hack.h\"\n");
fprintf(ofp, "short glyph2tile[MAX_GLYPH] = {\n"); Fprintf(ofp, "\nshort glyph2tile[MAX_GLYPH] = {\n");
for (i = 0; i < MAX_GLYPH; i++) { for (i = 0; i < MAX_GLYPH; i++) {
fprintf(ofp, "%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n'); Fprintf(ofp, "%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n');
} }
fprintf(ofp, "%s};\n", (i % 12) ? "\n" : ""); Fprintf(ofp, "\n};\n");
process_substitutions(ofp); process_substitutions(ofp);
fprintf(ofp, "\n#define MAXMONTILE %d\n", lastmontile); Fprintf(ofp, "\n#define MAXMONTILE %d\n", lastmontile);
fprintf(ofp, "#define MAXOBJTILE %d\n", lastobjtile); Fprintf(ofp, "#define MAXOBJTILE %d\n", lastobjtile);
fprintf(ofp, "#define MAXOTHTILE %d\n", lastothtile); Fprintf(ofp, "#define MAXOTHTILE %d\n", lastothtile);
#ifdef STATUES_LOOK_LIKE_MONSTERS #ifdef STATUES_LOOK_LIKE_MONSTERS
fprintf(ofp, "/* #define MAXSTATUETILE %d */\n", laststatuetile); Fprintf(ofp, "/* #define MAXSTATUETILE %d */\n", laststatuetile);
#endif #endif
fprintf(ofp, "\n/*tile.c*/\n"); Fprintf(ofp, "\n/*tile.c*/\n");
fclose(ofp); (void) fclose(ofp);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
/*NOTREACHED*/ /*NOTREACHED*/
return 0; return 0;
@@ -634,3 +636,4 @@ const char *encountered, *expected;
return FALSE; return FALSE;
} }
/*tilemap.c*/