From: Pasi Kallinen Date: Wed, 25 Feb 2015 20:29:17 +0000 (+0200) Subject: Add new parameters to makedefs: --debug and --make X-Git-Tag: NetHack-3.6.0_RC01~492^2~106 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56279a9950ec8064d85c4560d557332a226cbd8c;p=nethack Add new parameters to makedefs: --debug and --make "makedefs --debug --make q" is equivalent to "makedefs -q" with DEBUG defined. --- diff --git a/doc/makedefs.6 b/doc/makedefs.6 index 9a81780ec..7b850108c 100644 --- a/doc/makedefs.6 +++ b/doc/makedefs.6 @@ -118,6 +118,14 @@ and .IR vis_tab.h . .SH LONG COMMANDS .TP +.BI --debug +Show debugging output. +.br +.TP +.B --make \fR[\fIcommand\fR] +Execute a short command. Command is given without preceding dash. +.br +.TP .BI --input " file" Specify the input .I file diff --git a/util/makedefs.c b/util/makedefs.c index 6914af250..ad37677bc 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -6,7 +6,6 @@ /* NetHack may be freely redistributed. See license for details. */ #define MAKEDEFS_C /* use to conditionally include file sections */ -/* #define DEBUG */ /* uncomment for debugging info */ #include "config.h" #include "permonst.h" @@ -385,6 +384,7 @@ getfp(template, tag, mode) return rv; } +static boolean debug = FALSE; static FILE *inputfp; static FILE *outputfp; @@ -431,6 +431,15 @@ do_ext_makedefs(int argc, char **argv){ Fprintf(stdout, "%s", version_string(buf, delim)); exit(EXIT_SUCCESS); } + IS_OPTION("debug"){ + debug = TRUE; + CONTINUE; + } + IS_OPTION("make"){ + CONSUME; + do_makedefs(argv[0]); + exit(EXIT_SUCCESS); + } IS_OPTION("input"){ CONSUME; if(!strcmp(argv[0], "-")){ @@ -2246,36 +2255,30 @@ put_qt_hdrs() /* * The main header record. */ -#ifdef DEBUG - Fprintf(stderr, "%ld: header info.\n", ftell(ofp)); -#endif + if (debug) Fprintf(stderr, "%ld: header info.\n", ftell(ofp)); (void) fwrite((genericptr_t)&(qt_hdr.n_hdr), sizeof(int), 1, ofp); (void) fwrite((genericptr_t)&(qt_hdr.id[0][0]), sizeof(char)*LEN_HDR, qt_hdr.n_hdr, ofp); (void) fwrite((genericptr_t)&(qt_hdr.offset[0]), sizeof(long), qt_hdr.n_hdr, ofp); -#ifdef DEBUG - for(i = 0; i < qt_hdr.n_hdr; i++) + if (debug) { + for(i = 0; i < qt_hdr.n_hdr; i++) Fprintf(stderr, "%s @ %ld, ", qt_hdr.id[i], qt_hdr.offset[i]); - - Fprintf(stderr, "\n"); -#endif + Fprintf(stderr, "\n"); + } /* * The individual class headers. */ for(i = 0; i < qt_hdr.n_hdr; i++) { -#ifdef DEBUG - Fprintf(stderr, "%ld: %s header info.\n", ftell(ofp), - qt_hdr.id[i]); -#endif + if (debug) Fprintf(stderr, "%ld: %s header info.\n", ftell(ofp), + qt_hdr.id[i]); (void) fwrite((genericptr_t)&(msg_hdr[i].n_msg), sizeof(int), 1, ofp); (void) fwrite((genericptr_t)&(msg_hdr[i].qt_msg[0]), sizeof(struct qtmsg), msg_hdr[i].n_msg, ofp); -#ifdef DEBUG - { int j; + if (debug) { int j; for(j = 0; j < msg_hdr[i].n_msg; j++) { Fprintf(stderr, "msg %d @ %ld (%ld)", msg_hdr[i].qt_msg[j].msgnum, @@ -2287,7 +2290,6 @@ put_qt_hdrs() Fprintf(stderr, "\n"); } } -#endif } } @@ -2340,9 +2342,7 @@ do_questtxt() /* we have summary text; replace raw %E record with it */ Strcpy(in_line, summary_p); /* (guaranteed to fit) */ } else if(qt_comment(in_line)) continue; -#ifdef DEBUG - Fprintf(stderr, "%ld: %s", ftell(stdout), in_line); -#endif + if (debug) Fprintf(stderr, "%ld: %s", ftell(stdout), in_line); (void) fputs(xcrypt(in_line), ofp); } Fclose(ifp);