Roughly try to get the base name for output files

This commit is contained in:
Eryn Wells 2014-08-05 22:00:49 -07:00
parent c380a3c3cd
commit d7ff6b194e

View file

@ -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. */