Revision: 73069
          http://sourceforge.net/p/brlcad/code/73069
Author:   brlcad
Date:     2019-05-16 05:52:38 +0000 (Thu, 16 May 2019)
Log Message:
-----------
prevent burst from crashing if provided no options, displays usage.  it's not 
clear what the intended behavior is supposed to be now that there is no longer 
an interactive prompt, but the tool doesn't seem to be in a usable or intuitive 
state..  made it go into an interactive command mode if provided -p without a 
file, but there doesn't seem to be built-in help or discovery commands (which 
presumably were presented via text UI menu previously).  needs to be reconciled 
with the manual page.

Modified Paths:
--------------
    brlcad/trunk/src/burst/burst.c

Modified: brlcad/trunk/src/burst/burst.c
===================================================================
--- brlcad/trunk/src/burst/burst.c      2019-05-15 14:39:49 UTC (rev 73068)
+++ brlcad/trunk/src/burst/burst.c      2019-05-16 05:52:38 UTC (rev 73069)
@@ -160,12 +160,13 @@
 main(int argc, const char *argv[])
 {
     const char *bfile = NULL;
-    int ret_ac;
     int burst_opt; /* unused, for option compatibility */
-    struct bu_vls pmsg = BU_VLS_INIT_ZERO;
+    int plot_lines = 0;
     int plot_points = 0;
-    int plot_lines = 0;
+    int ret_ac;
     struct bu_opt_desc d[4];
+    struct bu_vls pmsg = BU_VLS_INIT_ZERO;
+
     BU_OPT(d[0],  "p", "", "",  NULL,   &plot_points, "Plot points");
     BU_OPT(d[1],  "P", "", "",  NULL,   &plot_lines,  "Plot lines");
     BU_OPT(d[2],  "b", "", "",  NULL,   &burst_opt,   "Batch mode");
@@ -177,14 +178,15 @@
 
     bu_setlinebuf(stderr);
 
-    tmpfp = bu_temp_file(tmpfname, TIMER_LEN);
-    if (!tmpfp) {
-       bu_exit(EXIT_FAILURE, "ERROR: Unable to create temporary file.\n");
-    }
-
     /* Skip first arg */
     argv++; argc--;
 
+    /* no options imply a request for usage */
+    if (argc < 1 || !argv || argv[0] == NULL) {
+       (void)fprintf(stderr, "%s\n", usage);
+       return EXIT_SUCCESS;
+    }
+
     /* Process options */
     ret_ac = bu_opt_parse(&pmsg, argc, argv, d);
     if (ret_ac < 0) {
@@ -197,6 +199,7 @@
 
     if (ret_ac) {
        if (!bu_file_exists(argv[0], NULL)) {
+           (void)fprintf(stderr, "ERROR: Input file [%s] does not exist!\n", 
argv[0]);
            (void)fprintf(stderr, "%s\n", usage);
            return EXIT_FAILURE;
        } else {
@@ -204,9 +207,18 @@
        }
     }
 
+    tmpfp = bu_temp_file(tmpfname, TIMER_LEN);
+    if (!tmpfp) {
+       bu_exit(EXIT_FAILURE, "ERROR: Unable to create temporary file.\n");
+    }
+
     setupSigs();
-    if (! initUi()) /* must be called before any output is produced */
+
+    /* must be called before any output is produced */
+    if (!initUi()) {
+       fclose(tmpfp);
        return EXIT_FAILURE;
+    }
 
 #if DEBUG_BURST
     prntTrie(cmdtrie, 0);
@@ -215,13 +227,15 @@
     assert(armorids.i_next == NULL);
     assert(critids.i_next == NULL);
 
-    if (!isatty(0) && !bfile ) {
-       readBatchInput(stdin);
-    } else {
+    if (bfile) {
        FILE *fp = fopen(bfile, "rb");
        readBatchInput(fp);
+       fclose(fp);
+    } else {
+       readBatchInput(stdin);
     }
-    /* not reached */
+
+    fclose(tmpfp);
     return EXIT_SUCCESS;
 }
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to