Revision: 76114
          http://sourceforge.net/p/brlcad/code/76114
Author:   starseeker
Date:     2020-06-11 18:02:39 +0000 (Thu, 11 Jun 2020)
Log Message:
-----------
Start looking at using errfile in logging...

Modified Paths:
--------------
    brlcad/branches/bioh/src/burst2/burst.cpp
    brlcad/branches/bioh/src/burst2/burst.h
    brlcad/branches/bioh/src/burst2/grid.cpp

Modified: brlcad/branches/bioh/src/burst2/burst.cpp
===================================================================
--- brlcad/branches/bioh/src/burst2/burst.cpp   2020-06-11 17:33:13 UTC (rev 
76113)
+++ brlcad/branches/bioh/src/burst2/burst.cpp   2020-06-11 18:02:39 UTC (rev 
76114)
@@ -54,6 +54,20 @@
 
 #define DEFAULT_BURST_PROMPT "burst> "
 
+
+/* logging function that takes care of writing output to errfile if it is 
defined */
+void
+brst_log(struct burst_state *s, const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    if (s->errfile) {
+       vfprintf(s->errfile, fmt, ap);
+    } else {
+       vfprintf(stderr, fmt, ap);
+    }
+}
+
 /* Forward declare so we can use this function in a command
  * called by this function */
 int burst_process_line(struct burst_state *s, const char *line);
@@ -1071,13 +1085,13 @@
     std::ifstream fs;
     fs.open(argv[1]);
     if (!fs.is_open()) {
-       bu_log("Unable to open command file: %s\n", argv[1]);
+       brst_log(s, "Unable to open command file: %s\n", argv[1]);
        return BRLCAD_ERROR;
     }
     std::string bline;
     while (std::getline(fs, bline)) {
        if (burst_process_line(s, bline.c_str()) != BRLCAD_OK) {
-           bu_log("Error processing line: %s\n", bline.c_str());
+           brst_log(s, "Error processing line: %s\n", bline.c_str());
            fs.close();
            return BRLCAD_ERROR;
        }
@@ -1602,12 +1616,15 @@
     /* Let bu_brlcad_root and friends know where we are */
     bu_setprogname(argv[0]);
 
+    /* Initialize */
+    burst_state_init(&s);
+
     /* Done with program name */
     argv++; argc--;
 
     /* Parse options, fail if anything goes wrong */
     if ((argc = bu_opt_parse(&msg, argc, argv, d)) == -1) {
-       bu_log("%s", bu_vls_cstr(&msg));
+       brst_log(&s, "%s", bu_vls_cstr(&msg));
        bu_vls_free(&msg);
        bu_exit(EXIT_FAILURE, NULL);
     }
@@ -1617,13 +1634,12 @@
        const char *help = bu_opt_describe(d, NULL);
        bu_vls_sprintf(&msg, "Usage: 'burst [options] 
cmd_file'\n\nOptions:\n%s\n", help);
        bu_free((char *)help, "done with help string");
-       bu_log("%s", bu_vls_cstr(&msg));
+       brst_log(&s, "%s", bu_vls_cstr(&msg));
        bu_vls_free(&msg);
        bu_exit(EXIT_SUCCESS, NULL);
     }
 
     /* We're in business - initalize the burst state */
-    burst_state_init(&s);
     s.cmds = _burst_cmds;
 
     /* If we have a batch file, process it. */
@@ -1631,13 +1647,13 @@
        std::ifstream fs;
        fs.open(argv[0]);
        if (!fs.is_open()) {
-           bu_log("Unable to open burst batch file: %s\n", argv[0]);
+           brst_log(&s, "Unable to open burst batch file: %s\n", argv[0]);
            return EXIT_FAILURE;
        }
        std::string bline;
        while (std::getline(fs, bline)) {
            if (burst_process_line(&s, bline.c_str()) != BRLCAD_OK) {
-               bu_log("Error processing line: %s\n", bline.c_str());
+               brst_log(&s, "Error processing line: %s\n", bline.c_str());
                fs.close();
                return EXIT_FAILURE;
            }

Modified: brlcad/branches/bioh/src/burst2/burst.h
===================================================================
--- brlcad/branches/bioh/src/burst2/burst.h     2020-06-11 17:33:13 UTC (rev 
76113)
+++ brlcad/branches/bioh/src/burst2/burst.h     2020-06-11 18:02:39 UTC (rev 
76114)
@@ -199,24 +199,27 @@
     const struct bu_cmdtab *cmds;
 };
 
-void burst_state_init(struct burst_state *s);
 
-int findIdents(int ident, struct bu_ptbl *idpl);
-int readIdents(struct bu_ptbl *idlist, const char *fname);
-int readColors(struct bu_ptbl *idlist, const char *fname);
 
-struct colors *findColors(int ident, struct bu_ptbl *colp);
+extern void burst_state_init(struct burst_state *s);
 
+extern int findIdents(int ident, struct bu_ptbl *idpl);
+extern int readIdents(struct bu_ptbl *idlist, const char *fname);
+extern int readColors(struct bu_ptbl *idlist, const char *fname);
+extern struct colors *findColors(int ident, struct bu_ptbl *colp);
 
-void gridModel(struct burst_state *s);
-void gridInit(struct burst_state *s);
-void spallInit(struct burst_state *s);
+extern void gridModel(struct burst_state *s);
+extern void gridInit(struct burst_state *s);
+extern void spallInit(struct burst_state *s);
 
-void paintCellFb(struct application *ap, unsigned char *pixpaint, unsigned 
char *pixexpendable);
-void paintSpallFb(struct application *ap);
-void paintGridFb(struct burst_state *s);
+extern void paintCellFb(struct application *ap, unsigned char *pixpaint, 
unsigned char *pixexpendable);
+extern void paintSpallFb(struct application *ap);
+extern void paintGridFb(struct burst_state *s);
+extern int imageInit(struct burst_state *s);
 
-int imageInit(struct burst_state *s);
+/* as far as I can tell the original burst code didn't actually use errfile,
+ * but since it is a defined command we will set up to support it */
+extern void brst_log(struct burst_state *s, const char *, ...);
 
 #endif  /* BURST_BURST_H */
 

Modified: brlcad/branches/bioh/src/burst2/grid.cpp
===================================================================
--- brlcad/branches/bioh/src/burst2/grid.cpp    2020-06-11 17:33:13 UTC (rev 
76113)
+++ brlcad/branches/bioh/src/burst2/grid.cpp    2020-06-11 18:02:39 UTC (rev 
76114)
@@ -205,7 +205,7 @@
            }
            break;
        default :
-           //bu_log("colorPartition: bad type %d.\n", type);
+           brst_log(s, "colorPartition: bad type %d.\n", type);
            break;
     }
     bu_semaphore_release(BU_SEM_SYSCALL);
@@ -309,8 +309,8 @@
     }
     if (f > 0.0) {
        flipct++;
-       bu_log("Fixed flipped entry normal:\n");
-       bu_log("\tregion \"%s\" solid \"%s\" type %d \"%s\".\n",
+       brst_log(s, "Fixed flipped entry normal:\n");
+       brst_log(s, "\tregion \"%s\" solid \"%s\" type %d \"%s\".\n",
                 pp->pt_regionp->reg_name, stp->st_name,
                 stp->st_id, purpose);
        VSCALE(normvec, normvec, -1.0);
@@ -331,33 +331,14 @@
     /* Dot product of ray direction with normal *should* be positive. */
     f = VDOT(rayp->r_dir, normvec);
     if (ZERO(f)) {
-#ifdef DEBUG
-       bu_log("chkExitNorm: near 90 degree obliquity.\n");
-       bu_log("\tPnt %g, %g, %g\n\tDir %g, %g, %g\n\tNorm %g, %g, %g.\n",
-                rayp->r_pt[X], rayp->r_pt[Y], rayp->r_pt[Z],
-                rayp->r_dir[X], rayp->r_dir[Y], rayp->r_dir[Z],
-                normvec[X], normvec[Y], normvec[Z]);
-#endif
        ret = 0;
     }
     if (f < 0.0) {
        flipct++;
-       bu_log("Fixed flipped exit normal:\n");
-       bu_log("\tregion \"%s\" solid \"%s\" type %d \"%s\".\n",
+       brst_log("Fixed flipped exit normal:\n");
+       brst_log("\tregion \"%s\" solid \"%s\" type %d \"%s\".\n",
                 pp->pt_regionp->reg_name, stp->st_name,
                 stp->st_id, purpose);
-#ifdef DEBUG
-       bu_log("\tPnt %g, %g, %g\n\tDir %g, %g, %g\n\tNorm %g, %g, %g.\n",
-                rayp->r_pt[X], rayp->r_pt[Y], rayp->r_pt[Z],
-                rayp->r_dir[X], rayp->r_dir[Y], rayp->r_dir[Z],
-                normvec[X], normvec[Y], normvec[Z]);
-       bu_log("\tDist %g Hit Pnt %g, %g, %g\n",
-                pp->pt_outhit->hit_dist,
-                pp->pt_outhit->hit_point[X],
-                pp->pt_outhit->hit_point[Y],
-                pp->pt_outhit->hit_point[Z]);
-       bu_log("\t%d of %d normals flipped.\n", flipct, totalct);
-#endif
        VSCALE(normvec, normvec, -1.0);
        ret = 0;
     }
@@ -367,9 +348,10 @@
 static int
 f_Nerror(struct application *ap)
 {
-    bu_log("Couldn't compute thickness or exit point along normal 
direction.\n");
-    bu_log("\tpnt\t<%12.6f, %12.6f, %12.6f>\n", V3ARGS(ap->a_ray.r_pt));
-    bu_log("\tdir\t<%12.6f, %12.6f, %12.6f>\n", V3ARGS(ap->a_ray.r_dir));
+    struct burst_state *s = (struct burst_state *)ap->a_uptr;
+    brst_log(s, "Couldn't compute thickness or exit point along normal 
direction.\n");
+    brst_log(s, "\tpnt\t<%12.6f, %12.6f, %12.6f>\n", V3ARGS(ap->a_ray.r_pt));
+    brst_log(s, "\tdir\t<%12.6f, %12.6f, %12.6f>\n", V3ARGS(ap->a_ray.r_dir));
     ap->a_rbeam = 0.0;
     return 0;
 }

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