(qprint): Change it into a printf()-like function. Simplify callers.

No functional changes.  From Marc Olzheim.
This commit is contained in:
Markus Armbruster 2004-03-23 15:20:17 +00:00
parent 0608bff5b4
commit 16761c8c29

View file

@ -68,6 +68,7 @@ static int quiet = 0;
#include <unistd.h> #include <unistd.h>
#endif /* aix or linux */ #endif /* aix or linux */
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
@ -88,7 +89,8 @@ static int quiet = 0;
#define PLATMIN 36 /* plate altitude for plateau */ #define PLATMIN 36 /* plate altitude for plateau */
#define HIGHMIN 98 /* plate altitude for mountains */ #define HIGHMIN 98 /* plate altitude for mountains */
static void qprint(const char *str); static void qprint(const char * const fmt, ...)
ATTRIBUTE((format (printf, 1, 2)));
static const char *outfile = "newcap_script"; static const char *outfile = "newcap_script";
/* mark the continents with a * so you can tell them /* mark the continents with a * so you can tell them
@ -245,11 +247,10 @@ main(int argc, char *argv[])
do { do {
init(); init();
if (!quiet && i) if (i)
printf("\ntry #%d (out of %d)...", i + 1, NUMTRIES); qprint("\ntry #%d (out of %d)...", i + 1, NUMTRIES);
qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n"); qprint("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n");
if (!quiet) qprint("seed is %lu\n", rnd_seed);
printf("seed is %lu\n", rnd_seed);
qprint("placing capitals...\n"); qprint("placing capitals...\n");
if (!drift()) if (!drift())
qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n"); qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n");
@ -274,8 +275,8 @@ main(int argc, char *argv[])
exit(-1); exit(-1);
output(); output();
write_newcap_script(); write_newcap_script();
if (!ORE && !quiet) if (!ORE)
printf("\t*** Resources have not been added ***\n"); qprint("\t*** Resources have not been added ***\n");
exit(0); exit(0);
} }
@ -737,9 +738,8 @@ grow_one_sector(int c)
} while (!done && coast_search < COAST_SEARCH_MAX && } while (!done && coast_search < COAST_SEARCH_MAX &&
(secs == 1 || x != sx || y != sy)); (secs == 1 || x != sx || y != sy));
if (!done && c < nc) { if (!done && c < nc) {
if (!quiet) qprint("fairland: error -- continent %c had no room to grow!\n",
printf("fairland: error -- continent %c had no room to grow!\n", numletter[c % 62]);
numletter[c % 62]);
fl_status |= STATUS_NO_ROOM; fl_status |= STATUS_NO_ROOM;
} }
return done; return done;
@ -767,8 +767,8 @@ grow_continents(void)
grow_one_sector(c); grow_one_sector(c);
} }
} }
if (fl_status && !quiet) if (fl_status)
printf("Only managed to grow %d out of %d sectors.\n", secs, sc); qprint("Only managed to grow %d out of %d sectors.\n", secs, sc);
ctot = nc; ctot = nc;
} }
@ -822,8 +822,7 @@ grow_islands(void)
++secs; ++secs;
find_coast(c); find_coast(c);
} while (secs < isiz && grow_one_sector(c)); } while (secs < isiz && grow_one_sector(c));
if (quiet == 0) qprint(" %d(%d)", c - nc + 1, secs);
printf(" %d(%d)", c - nc + 1, secs);
isecs[c] = secs; isecs[c] = secs;
ctot = c; ctot = c;
} }
@ -1236,17 +1235,21 @@ write_newcap_script(void)
fprintf(script, "add %d visitor visitor v i\n", c + 1); fprintf(script, "add %d visitor visitor v i\n", c + 1);
++c; ++c;
fclose(script); fclose(script);
if (quiet == 0) qprint("\n\nA script for adding all the countries can be found in \"%s\".\n",
printf("\n\nA script for adding all the countries can be found in \"%s\".\n", outfile);
outfile);
return 0; return 0;
} }
static void static void
qprint(const char *str) qprint(const char * const fmt, ...)
{ {
if (quiet == 0) va_list ap;
fputs(str, stdout);
if (!quiet) {
va_start(ap, fmt);
vfprintf(stdout, fmt, ap);
va_end(ap);
}
} }
static void static void