]> granicus.if.org Git - nethack/commitdiff
Add new parameters to makedefs: --debug and --make
authorPasi Kallinen <paxed@alt.org>
Wed, 25 Feb 2015 20:29:17 +0000 (22:29 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 17 Mar 2015 16:46:52 +0000 (18:46 +0200)
"makedefs --debug --make q" is equivalent to "makedefs -q" with
DEBUG defined.

doc/makedefs.6
util/makedefs.c

index 9a81780ecbaf1a9a227813d4d961be69aaad2648..7b850108c5e36f6e361f9769eec96f00048645aa 100644 (file)
@@ -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
index 6914af2506cf6ea8c547076ce6c469e4d0c71f69..ad37677bcd75e13362da170e0d397b3cdf85a6a6 100644 (file)
@@ -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);