Roughly try to get the base name for output files
This commit is contained in:
parent
c380a3c3cd
commit
d7ff6b194e
1 changed files with 31 additions and 11 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <libgen.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
|
@ -22,6 +23,19 @@
|
||||||
int verbosity = 0;
|
int verbosity = 0;
|
||||||
|
|
||||||
|
|
||||||
|
static std::string
|
||||||
|
GetBaseFilename(const std::string& filename)
|
||||||
|
{
|
||||||
|
std::string bn = basename(const_cast<char*>(filename.c_str()));
|
||||||
|
size_t lastDot = bn.find_last_of('.');
|
||||||
|
if (lastDot == std::string::npos) {
|
||||||
|
return bn;
|
||||||
|
} else {
|
||||||
|
return bn.substr(0, lastDot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(const char *progname)
|
usage(const char *progname)
|
||||||
{
|
{
|
||||||
|
@ -96,22 +110,28 @@ main(int argc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up logging */
|
std::string baseFilename;
|
||||||
if (logLevel > 0) {
|
|
||||||
if (logFilename.empty()) {
|
|
||||||
logFilename = "charles.log";
|
|
||||||
}
|
|
||||||
Log::Init(logFilename, logLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optind >= argc) {
|
int numInputFiles = argc - optind;
|
||||||
LOG_ERROR << "Input file required.";
|
if (numInputFiles <= 0) {
|
||||||
fprintf(stderr, "Input file required.\n");
|
fprintf(stderr, "Input file required.\n");
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
infile = argv[optind];
|
if (numInputFiles == 1) {
|
||||||
|
baseFilename = GetBaseFilename(argv[optind]);
|
||||||
|
} else {
|
||||||
|
baseFilename = "charles";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set up logging */
|
||||||
|
if (logLevel > 0) {
|
||||||
|
if (logFilename.empty()) {
|
||||||
|
logFilename = baseFilename + ".log";
|
||||||
|
}
|
||||||
|
Log::Init(logFilename, logLevel);
|
||||||
|
}
|
||||||
|
|
||||||
if (outfile.empty()) {
|
if (outfile.empty()) {
|
||||||
outfile = "charles_out.png";
|
outfile = "charles_out.png";
|
||||||
|
@ -120,11 +140,11 @@ main(int argc,
|
||||||
/* Parse YAML files. */
|
/* Parse YAML files. */
|
||||||
YAMLReader reader(scene);
|
YAMLReader reader(scene);
|
||||||
for (int i = optind; i < argc; i++) {
|
for (int i = optind; i < argc; i++) {
|
||||||
|
infile = argv[i];
|
||||||
reader.read_file(infile);
|
reader.read_file(infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call tracer. */
|
/* Call tracer. */
|
||||||
LOG_INFO << "Beginning render";
|
|
||||||
scene.render();
|
scene.render();
|
||||||
|
|
||||||
/* Write rendered scene to PNG file. */
|
/* Write rendered scene to PNG file. */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue