diff --git a/src/sourcery.cpp b/src/sourcery.cpp index 27e34b25..79f1eecc 100644 --- a/src/sourcery.cpp +++ b/src/sourcery.cpp @@ -1,25 +1,89 @@ ///\file sourcery.cpp ///Utility program used for c-string dumping files. +#undef DEBUG +#define DEBUG -1 #include +#include +#include #include #include #include +#include +#include "../lib/url.h" +#include "../lib/url.cpp" +#include "../lib/encode.h" +#include "../lib/encode.cpp" + +std::string getContents(const char * fileName){ + std::ifstream inFile(fileName); + std::string fullText; + if (inFile){ + std::ostringstream contents; + contents << inFile.rdbuf(); + inFile.close(); + return contents.str(); + } + return ""; +} + int main(int argc, char* argv[]){ + if (argc < 4) { - std::cerr << "Usage: " << argv[0] << " " << std::endl; + std::cerr << "Usage: " << argv[0] << " []" << std::endl; return 42; } + const char * splitText = 0; + if (argc >= 5){splitText = argv[4];} + + char workDir[512]; + getcwd(workDir, 512); + HTTP::URL inUri(std::string("file://") + workDir + "/"); + inUri = inUri.link(argv[1]); + + //Read the entire first argument into a string buffer + std::string fullText = getContents(inUri.getFilePath().c_str()); + + //replace every with the contents of the file '*' + while (fullText.find("", locStart); + //Assume we should abort if the strlen of the filename is > 230 chars + if (locEnd - locStart >= 230){break;} + HTTP::URL fileName = inUri.link(fullText.substr(locStart+13, locEnd-locStart-13)); + std::string subText = getContents(fileName.getFilePath().c_str()); + fullText = fullText.substr(0, locStart) + "