| 119 | } |
| 120 | |
| 121 | int main(int argc, const char * const * const argv) |
| 122 | { |
| 123 | |
| 124 | vector<string> args(argv, argv+argc); |
| 125 | |
| 126 | opt_t&& options = parse_options(args); |
| 127 | |
| 128 | //Save default cout buffer. Need this to prevent crash. |
| 129 | auto bak = cout.rdbuf(); |
| 130 | unique_ptr<ofstream> outfile; |
| 131 | |
| 132 | // Set defaults |
| 133 | if(options["--name"] == "") { options["--name"] = "var"; } |
| 134 | if(options["--output"] != "") { |
| 135 | //redirect stream if output file is specified |
| 136 | outfile.reset(new ofstream(options["--output"])); |
| 137 | cout.rdbuf(outfile->rdbuf()); |
| 138 | } |
| 139 | |
| 140 | cout << "#pragma once\n"; |
| 141 | cout << "#include <string>\n"; // defines std::string |
| 142 | |
| 143 | int ns_cnt = 0; |
| 144 | int level = 0; |
| 145 | if(options["--namespace"] != "") { |
| 146 | std::stringstream namespaces(options["--namespace"]); |
| 147 | string name; |
| 148 | namespaces >> name; |
| 149 | do { |
| 150 | add_tabs(level++); |
| 151 | cout << "namespace " << name << "\n{\n"; |
| 152 | ns_cnt++; |
| 153 | namespaces >> name; |
| 154 | } while(!namespaces.fail()); |
| 155 | } |
| 156 | |
| 157 | if(options["--type"] == "") { |
| 158 | options["--type"] = "std::string"; |
| 159 | } |
| 160 | add_tabs(level); |
| 161 | cout << "static const " << options["--type"] << " " << options["--name"] << " = R\"shader(\n"; |
| 162 | level++; |
| 163 | |
| 164 | ifstream input(options["--file"]); |
| 165 | |
| 166 | for(std::string line; std::getline(input, line);) { |
| 167 | add_tabs(level); |
| 168 | cout << line << endl; |
| 169 | } |
| 170 | |
| 171 | if (options["--eof"].c_str()[0] == '1') { |
| 172 | // Add end of file character |
| 173 | cout << "0x0"; |
| 174 | } |
| 175 | |
| 176 | add_tabs(--level); |
| 177 | cout << ")shader\";\n"; |
| 178 |
nothing calls this directly
no test coverage detected