Revision: 70706 http://sourceforge.net/p/brlcad/code/70706 Author: starseeker Date: 2018-02-13 20:07:23 +0000 (Tue, 13 Feb 2018) Log Message: ----------- Get dump command running. Ordering is slightly different (dest is last, since the library has no concept of a destination file).
Modified Paths: -------------- brlcad/trunk/src/libanalyze/nirt.cxx brlcad/trunk/src/nirt/main.cxx Modified: brlcad/trunk/src/libanalyze/nirt.cxx =================================================================== --- brlcad/trunk/src/libanalyze/nirt.cxx 2018-02-13 18:46:38 UTC (rev 70705) +++ brlcad/trunk/src/libanalyze/nirt.cxx 2018-02-13 20:07:23 UTC (rev 70706) @@ -884,6 +884,31 @@ bu_vls_trimspace(ostr); } +/* Given a vector breakout of a format string, generate the NIRT fmt command that + * created it */ +HIDDEN void +_nirt_print_fmt_cmd(struct bu_vls *ostr, char f, std::vector<std::pair<std::string,std::string> > &fmt_vect) +{ + std::string fmt_str, fmt_keys; + std::vector<std::pair<std::string,std::string> >::iterator f_it; + + if (!ostr) return; + + for(f_it = fmt_vect.begin(); f_it != fmt_vect.end(); f_it++) { + for (std::string::size_type i = 0; i < (*f_it).first.size(); ++i) { + if ((*f_it).first[i] == '\n') { + fmt_str.push_back('\\'); + fmt_str.push_back('n'); + } else { + fmt_str.push_back((*f_it).first[i]); + } + } + fmt_keys.append(" "); + fmt_keys.append((*f_it).second); + } + bu_vls_sprintf(ostr, "fmt %c \"%s\"%s\n", f, fmt_str.c_str(), fmt_keys.c_str()); +} + /* Translate NIRT fmt substrings into fully evaluated printf output, while also * handling units on key values. This should never be called using any fmt * string that hasn't been validated by _nirt_fmt_sp_validate and _nirt_fmt_sp_key_check */ @@ -2171,6 +2196,51 @@ } return 0; } + if (BU_STR_EQUAL(argv[1], "-d")) { + struct bu_vls dumpstr = BU_VLS_INIT_ZERO; + bu_vls_printf(&dumpstr, "# file created by the dump command of nirt\n"); + bu_vls_printf(&dumpstr, "xyz %g %g %g\n", V3ARGS(nss->vals->orig)); + bu_vls_printf(&dumpstr, "dir %g %g %g\n", V3ARGS(nss->vals->dir)); + bu_vls_printf(&dumpstr, "useair %d\n", nss->use_air); + bu_vls_printf(&dumpstr, "units %s\n", bu_units_string(nss->local2base)); + bu_vls_printf(&dumpstr, "overlap_claims "); + switch (nss->overlap_claims) { + case NIRT_OVLP_RESOLVE: + bu_vls_printf(&dumpstr, "resolve\n"); + break; + case NIRT_OVLP_REBUILD_FASTGEN: + bu_vls_printf(&dumpstr, "rebuild_fastgen\n"); + break; + case NIRT_OVLP_REBUILD_ALL: + bu_vls_printf(&dumpstr, "rebuild_all\n"); + break; + case NIRT_OVLP_RETAIN: + bu_vls_printf(&dumpstr, "retain\n"); + break; + default: + bu_vls_printf(&dumpstr, "error: invalid overlap_clams value %d\n", nss->overlap_claims); + break; + } + struct bu_vls ostr = BU_VLS_INIT_ZERO; + _nirt_print_fmt_cmd(&ostr, 'r', nss->fmt_ray); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'h', nss->fmt_head); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'p', nss->fmt_part); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'f', nss->fmt_foot); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'm', nss->fmt_miss); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'o', nss->fmt_ovlp); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + _nirt_print_fmt_cmd(&ostr, 'g', nss->fmt_gap); + bu_vls_printf(&dumpstr, "%s", bu_vls_addr(&ostr)); + nout(nss, "%s", bu_vls_addr(&dumpstr)); + bu_vls_free(&dumpstr); + bu_vls_free(&ostr); + } + return 0; } Modified: brlcad/trunk/src/nirt/main.cxx =================================================================== --- brlcad/trunk/src/nirt/main.cxx 2018-02-13 18:46:38 UTC (rev 70705) +++ brlcad/trunk/src/nirt/main.cxx 2018-02-13 20:07:23 UTC (rev 70706) @@ -220,7 +220,7 @@ } int -nirt_app_stdout_hook(NIRT *ns, void *u_data) +nirt_show_menu_hook(NIRT *ns, void *u_data) { struct bu_vls *log = (struct bu_vls *)u_data; nirt_log(log, ns, NIRT_OUT); @@ -227,7 +227,19 @@ return 0; } +int +nirt_dump_hook(NIRT *ns, void *u_data) +{ + struct bu_vls tmp = BU_VLS_INIT_ZERO; + struct bu_vls *log = (struct bu_vls *)u_data; + nirt_log(&tmp, ns, NIRT_OUT); + bu_vls_printf(log, "%s", bu_vls_addr(&tmp)); + bu_vls_free(&tmp); + return 0; +} + + /* TODO - eventually, should support separate destinations for output * and error. */ void @@ -342,11 +354,18 @@ return -1; } struct bu_vls dumpstr = BU_VLS_INIT_ZERO; + // Capture output for post-processing (void)nirt_udata(ns, (void *)&dumpstr); - nirt_hook(ns, &nirt_app_stdout_hook, NIRT_OUT); + nirt_hook(ns, &nirt_dump_hook, NIRT_OUT); (void)nirt_exec(ns, "state -d"); + // Restore "normal" settings (void)nirt_udata(ns, (void *)io_data); nirt_hook(ns, &nirt_stdout_hook, NIRT_OUT); + if(BU_STR_EQUAL(bu_vls_addr(io_data->outfile), "stdout")) { + bu_vls_printf(&dumpstr, "dest default"); + } else { + bu_vls_printf(&dumpstr, "dest %s", bu_vls_addr(io_data->outfile)); + } FILE *sfPtr = fopen(bu_vls_addr(state_file), "wb"); if (!sfPtr) { @@ -402,7 +421,7 @@ // Get library documentation and add app level help to it. struct bu_vls helpstr = BU_VLS_INIT_ZERO; (void)nirt_udata(ns, (void *)&helpstr); - nirt_hook(ns, &nirt_app_stdout_hook, NIRT_OUT); + nirt_hook(ns, &nirt_show_menu_hook, NIRT_OUT); (void)nirt_exec(ns, "?"); (void)nirt_udata(ns, (void *)io_data); nirt_hook(ns, &nirt_stdout_hook, NIRT_OUT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits