13 |
#include "engines/common/InstrumentScriptVM.h" |
#include "engines/common/InstrumentScriptVM.h" |
14 |
#include "engines/gig/InstrumentScriptVM.h" |
#include "engines/gig/InstrumentScriptVM.h" |
15 |
#include <iostream> |
#include <iostream> |
16 |
|
#include <fstream> |
17 |
|
|
18 |
/* |
/* |
19 |
This command line tool is currently merely for development and testing |
This command line tool is currently merely for development and testing |
43 |
cout << " Either \"core\", \"gig\", \"sf2\" or \"sfz\"." << endl; |
cout << " Either \"core\", \"gig\", \"sf2\" or \"sfz\"." << endl; |
44 |
cout << endl; |
cout << endl; |
45 |
cout << " OPTIONS" << endl; |
cout << " OPTIONS" << endl; |
46 |
|
cout << " --file FILE | -f FILE" << endl; |
47 |
|
cout << " Read from this file instead from stdin." << endl; |
48 |
|
cout << endl; |
49 |
cout << " --syntax | -s" << endl; |
cout << " --syntax | -s" << endl; |
50 |
cout << " Prints the script to stdout with colored syntax highlighting" << endl; |
cout << " Prints the script to stdout with colored syntax highlighting" << endl; |
51 |
cout << " and exits immediately." << endl; |
cout << " and exits immediately." << endl; |
73 |
|
|
74 |
static void printCodeWithSyntaxHighlighting(ScriptVM* vm); |
static void printCodeWithSyntaxHighlighting(ScriptVM* vm); |
75 |
static void dumpSyntaxHighlighting(ScriptVM* vm); |
static void dumpSyntaxHighlighting(ScriptVM* vm); |
76 |
|
static String readTxtFromFile(String path); |
77 |
|
|
78 |
int main(int argc, char *argv[]) { |
int main(int argc, char *argv[]) { |
79 |
if (argc < 2) { |
if (argc < 2) { |
81 |
return -1; |
return -1; |
82 |
} |
} |
83 |
String engine = argv[1]; |
String engine = argv[1]; |
84 |
|
String path; |
85 |
bool runScript = false; |
bool runScript = false; |
86 |
|
|
87 |
ScriptVM* vm; |
ScriptVM* vm; |
116 |
return 0; |
return 0; |
117 |
} else if (opt == "--auto-suspend") { |
} else if (opt == "--auto-suspend") { |
118 |
vm->setAutoSuspendEnabled(true); |
vm->setAutoSuspendEnabled(true); |
119 |
|
} else if (opt == "-f" || opt == "--file") { |
120 |
|
if (++iArg < argc) |
121 |
|
path = argv[iArg]; |
122 |
} else { |
} else { |
123 |
cerr << "Unknown option '" << opt << "'" << endl; |
cerr << "Unknown option '" << opt << "'" << endl; |
124 |
cerr << endl; |
cerr << endl; |
127 |
} |
} |
128 |
} |
} |
129 |
|
|
130 |
VMParserContext* parserContext = vm->loadScript(&std::cin); |
VMParserContext* parserContext; |
131 |
|
if (path.empty()) |
132 |
|
parserContext = vm->loadScript(&std::cin); |
133 |
|
else { |
134 |
|
String txt = readTxtFromFile(path); |
135 |
|
parserContext = vm->loadScript(txt); |
136 |
|
} |
137 |
|
|
138 |
std::vector<ParserIssue> errors = parserContext->errors(); |
std::vector<ParserIssue> errors = parserContext->errors(); |
139 |
std::vector<ParserIssue> warnings = parserContext->warnings(); |
std::vector<ParserIssue> warnings = parserContext->warnings(); |
273 |
printf("L%d,C%d: %s \"%s\"\n", token.firstLine(), token.firstColumn(), type, token.text().c_str()); |
printf("L%d,C%d: %s \"%s\"\n", token.firstLine(), token.firstColumn(), type, token.text().c_str()); |
274 |
} |
} |
275 |
} |
} |
276 |
|
|
277 |
|
static String readTxtFromFile(String path) { |
278 |
|
std::ifstream f(path.c_str(), std::ifstream::in); |
279 |
|
String s; |
280 |
|
s += (char) f.get(); |
281 |
|
while (f.good()) { |
282 |
|
char c = f.get(); |
283 |
|
if (c == EOF) break; |
284 |
|
s += c; |
285 |
|
} |
286 |
|
f.close(); |
287 |
|
return s; |
288 |
|
} |