Revision: 76100
http://sourceforge.net/p/brlcad/code/76100
Author: starseeker
Date: 2020-06-10 15:05:23 +0000 (Wed, 10 Jun 2020)
Log Message:
-----------
Set up to process batch files as well as do interactive mode
Modified Paths:
--------------
brlcad/branches/bioh/src/burst2/burst.cpp
Modified: brlcad/branches/bioh/src/burst2/burst.cpp
===================================================================
--- brlcad/branches/bioh/src/burst2/burst.cpp 2020-06-10 14:22:36 UTC (rev
76099)
+++ brlcad/branches/bioh/src/burst2/burst.cpp 2020-06-10 15:05:23 UTC (rev
76100)
@@ -23,7 +23,12 @@
#include "common.h"
-#include "bio.h"
+#include <cstdio>
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <string>
+
#include <stdlib.h>
#include <string.h>
@@ -246,7 +251,7 @@
FILE *critfp = fopen(argv[1], "rb");
if (!critfp) {
printf("failed to open critical component file: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
// TODO logCMd
@@ -629,7 +634,7 @@
FILE *airfp = fopen(argv[1], "rb");
if (!airfp) {
printf("failed to open burst air file: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
// TODO logCMd
@@ -995,7 +1000,7 @@
FILE *armorfp = fopen(argv[1], "rb");
if (!armorfp) {
printf("failed to open burst armor file: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
// TODO logCMd
@@ -1069,7 +1074,7 @@
FILE *cmdfp = fopen(argv[1], "rb");
if (!cmdfp) {
printf("failed to open command file: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
// TODO - use bu_cmd to process the lines in the file
@@ -1293,7 +1298,7 @@
FILE *cmdfp = fopen(argv[1], "wb");
if (!cmdfp) {
printf("failed to open cmd file for writing: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
fprintf(cmdfp, "%s", bu_vls_cstr(&s->cmdhist));
@@ -1467,7 +1472,7 @@
FILE *colorfp = fopen(argv[1], "rb");
if (!colorfp) {
printf("failed to open ident-to-color mapping file: %s\n", argv[1]);
- ret = BRLCAD_ERROR;
+ return BRLCAD_ERROR;
}
// TODO logCMd
@@ -1632,10 +1637,27 @@
burst_state_init(&s);
s.cmds = _burst_cmds;
- /* If we have a file, batch mode it. */
- if (argc > 1) {
- argv++; argc--;
- bu_exit(EXIT_SUCCESS, "Batch mode: [%s]\n", argv[0]);
+ /* If we have a batch file, process it. */
+ if (argc ) {
+ std::ifstream fs;
+ fs.open(argv[0]);
+ if (!fs.is_open()) {
+ bu_log("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());
+ fs.close();
+ return EXIT_FAILURE;
+ }
+ /* build up a command history buffer for write-input-file */
+ bu_vls_printf(&s.cmdhist, "%s\n", bline.c_str());
+ }
+ fs.close();
+
+ return EXIT_SUCCESS;
}
/* Start the interactive loop */
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