From b41e5ccc77679096017f445548cec7820b2047dd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 20 Jan 2014 17:03:29 +0000 Subject: [PATCH] Changed the default directory for the output files to be the current working directory, with the --write-to-source-file-directory added to allow one to have the original behaviour of writing to the same directory as the original source file. --- examples/osg2cpp/osg2cpp.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/osg2cpp/osg2cpp.cpp b/examples/osg2cpp/osg2cpp.cpp index 893eb1956..ee306eab4 100644 --- a/examples/osg2cpp/osg2cpp.cpp +++ b/examples/osg2cpp/osg2cpp.cpp @@ -30,13 +30,13 @@ void writeShader(osg::Shader* shader, const std::string& cppFileName, const std: searchAndReplace(shaderSource, "\r\n", "\n"); searchAndReplace(shaderSource, "\r", "\n"); searchAndReplace(shaderSource, "\"", "\\\""); - + std::string variableString = std::string("char ")+variableName+std::string("[] = "); - + std::string::size_type startOfLine = 0; std::string::size_type endOfLine = shaderSource.find_first_of('\n', startOfLine); - - if (endOfLine==std::string::npos) + + if (endOfLine==std::string::npos) { fout<setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is a utility for converting glsl shader files into char arrays that can be compiled into applications."); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); arguments.getApplicationUsage()->addCommandLineOption("--shader ","Shader file to create a .cpp file for."); + arguments.getApplicationUsage()->addCommandLineOption("--write-to-source-file-directory","Use the path to the source filename as the directory to write to."); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) - { + { arguments.getApplicationUsage()->write(std::cout); return 1; } - + + bool useSamePathAsSourceFile = false; + if (arguments.read("--write-to-source-file-directory")) useSamePathAsSourceFile = true; + std::string filename; if (arguments.read("--shader",filename)) { @@ -94,9 +98,11 @@ int main( int argc, char **argv ) name[pos] = '_'; pos = name.find_first_of(invalidCharacters); } - + std::string ext = osgDB::getFileExtension(filename); - std::string cppFileName = osgDB::concatPaths(path, name + "_" + ext + ".cpp"); + std::string cppFileName = name + "_" + ext + ".cpp"; + if (useSamePathAsSourceFile) cppFileName = osgDB::concatPaths(path, cppFileName); + std::string variableName = name + "_" + ext; writeShader(shader.get(), cppFileName, variableName); @@ -107,7 +113,7 @@ int main( int argc, char **argv ) std::cout<<"Error: could not find file '"<