#include #include #include #include #include #include #include #include #include "FRC.h" #include "input.h" #include "map.h" extern const char* vnum; //HelpStr, iHelpStr #include "strings.h" using std::string; using std::vector; using std::cin; using std::cout; using std::cerr; using std::endl; using namespace std::string_literals; //main interface, generates 1024x1024 map with all default settings // void genMap(vector inList); bool Continue = true; #ifdef _DEBUG bool verbose = true; #else bool verbose = false; #endif input_trie commands; void runCommand(input_trie commands, string in); void drawMap(vector inList) { std::string file{inList[2]}; unsigned cmapID{lookupMap(inList[1])}, size{pFromStr(unsigned short, inList[6])}; float x{pFromStr(float, inList[3])}, y{pFromStr(float, inList[4])}, width{pFromStr(float, inList[5])}; bool archimedian{!(inList[0].find_first_of('l') != string::npos)}; if (current_cmap[cmapID].second.size() > 256) { auto image = genMap_impl(cmapID, archimedian, x, y, width, size); image.write(file); } else { auto image = genMap_impl(cmapID, archimedian, x, y, width, size); image.write(file); } } int main(int argc, char** argv) { string in; commands.insert(vector>({{ std::pair("h"s, new functdata( [](vector inList){ if (inList.size() > 1) { int len = 0; functdata *found = commands.longestPrefix(toLower(inList[1]), &len); if (found) { cout<help<("q"s, new functdata( []([[maybe_unused]] vector inList){ Continue = false; }, 0, "Quit"s)), std::pair("e"s, new functdata( [](vector inList){ cout<<'['; for (unsigned i = 0; i != inList.size(); i++) { cout<("x"s, new functdata( [](vector inList){ inList.erase(inList.begin()); int len = 0; functdata *found = commands.longestPrefix(toLower(inList[0]), &len); if (found) { if (inList.size() > (unsigned)found->argC) { (*found)(inList); } else { cout<<"Please specify all "<argC<<" arguments for "<("p"s, new functdata( [](vector inList){ if (inList.size() == 1) { auto dump = commands.getIndex(); for (unsigned i = 0; i != dump.size(); i++) { cout<help<<" [takes "<argC<<']'<<(found->call?' ':'!')<("m"s, new functdata( [](vector inList){ bool archimedian{true}; unsigned cmapID{1}; auto split = inList[0].find_first_of("0123456789abcdef"); if (split == string::npos) { split = inList[0].size(); } string fname{inList[0].substr(0,split)}, cmapnum{inList[0].substr(split)}; if (fname.find_first_of('l') != string::npos) { archimedian = false; } inList.insert(inList.begin()+1, cmapnum); inList[0] = "d"s + fname; drawMap(inList); }, 5, "Draw map (filename left upper width resolution)"s)), std::pair("d"s, new functdata( drawMap, 6, "Draw map "s)), std::pair("c"s, new functdata( [](vector inList){ int maxlen{0}; for (auto& m : current_cmap) { (m.second.size() > maxlen) ? maxlen = m.second.size() : false; } png::image image(maxlen,current_cmap.size()); for (int i = 0; i < (signed)current_cmap.size(); ++i) { auto cmap = current_cmap[i].second; for (int x = 0; x < maxlen; ++x) { auto v = x*cmap.size()/maxlen; image[i][x] = {cmap[v].red,cmap[v].green,cmap[v].blue}; } } image.write(inList[1]); }, 1, "Print colormaps ()"s)), std::pair("cr"s, new functdata( [](vector inList){ auto cmaps = read_cmap(inList[1]); int maxlen{0}; for (auto& m : cmaps) { (m.second.size() > maxlen) ? maxlen = m.second.size() : false; } png::image image(maxlen,cmaps.size()); for (int i = 0; i < (signed)cmaps.size(); ++i) { auto& cmap = cmaps[i].second; for (int x = 0; x < maxlen; ++x) { auto v = x*cmap.size()/maxlen; image[i][x] = {cmap[v].red,cmap[v].green,cmap[v].blue}; } } image.write(inList[2]); }, 2, "Print colormaps from file "s)), std::pair("pc"s, new functdata( []([[maybe_unused]] vector inList){ for (int i = 0; i < (signed)current_cmap.size(); ++i) { std::string name; png::palette cmap; std::tie(name,cmap) = current_cmap[i]; cout<<":"<("pcr"s, new functdata( []([[maybe_unused]] vector inList){ auto cmaps = read_cmap(inList[1]); for (int i = 0; i < (signed)cmaps.size(); ++i) { std::string name; png::palette cmap; std::tie(name,cmap) = cmaps[i]; for (int c = 0; c != (signed)name.size(); ++c) { if (name[c] == ':' || name[c] == '\\') { name.insert(c, "\\"); ++c; } } cout<<":"<("rc"s, new functdata( [](vector inList){ try { current_cmap = read_cmap(inList[1]); cout<<"Read "<"s)), }})); vector scriptedCommands; bool display_promt = true, display_promt_s = false, cont_after = false; for (int i = 1; i < argc; i++) { //cout<<"["< "< "; getline(cin, in); if (in.empty()) { continue; } runCommand(commands, in); } catch (const std::runtime_error& err) { cout<<"Failed to read input. "< inList = tokenizeInput(in); //inList[0] = toLower(inList[0]); std::transform(inList[0].begin(), inList[0].end(), inList[0].begin(), ::tolower); int len = 0; functdata *found = commands.longestPrefix(toLower(inList[0]), &len); if (found) { if (inList.size() > (unsigned)found->argC) { (*found)(inList); } else { cout<<"Please specify all "<argC<<" arguments for "<