/[svn]/linuxsampler/trunk/src/ls_instr_script.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/ls_instr_script.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3307 by schoenebeck, Fri Jul 22 15:51:40 2016 UTC revision 3308 by schoenebeck, Sat Jul 15 01:14:20 2017 UTC
# Line 13  Line 13 
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
# Line 42  static void printUsage() { Line 43  static void printUsage() {
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;
# Line 69  static void printUsage() { Line 73  static void printUsage() {
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) {
# Line 76  int main(int argc, char *argv[]) { Line 81  int main(int argc, char *argv[]) {
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;
# Line 110  int main(int argc, char *argv[]) { Line 116  int main(int argc, char *argv[]) {
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;
# Line 118  int main(int argc, char *argv[]) { Line 127  int main(int argc, char *argv[]) {
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();
# Line 258  static void dumpSyntaxHighlighting(Scrip Line 273  static void dumpSyntaxHighlighting(Scrip
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    }

Legend:
Removed from v.3307  
changed lines
  Added in v.3308

  ViewVC Help
Powered by ViewVC