-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusil.cpp
More file actions
68 lines (59 loc) · 1.72 KB
/
Copy pathmusil.cpp
File metadata and controls
68 lines (59 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// musil.cpp
//
#include "musil.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <string>
#include <ctime>
using namespace std;
int main (int argc, char* argv[]) {
std::srand(time (NULL));
Environment interpreter;
add_scientific(interpreter);
add_system(interpreter);
add_signals(interpreter);
add_plotting(interpreter);
add_rtsound(interpreter);
try {
bool interactive = false;
int opt = 0;
while ((opt = getopt(argc, argv, "i")) != -1) {
switch (opt) {
case 'i': interactive = true; break;
default:
std::stringstream msg;
msg << "usage is " << argv[0] << " [-i] [file...]";
throw runtime_error (msg.str ());
}
}
if (argc - optind == 0) {
cout << BOLDBLUE << "[musil, version "
<< VERSION <<"]" << RESET << endl << endl;
cout << "scripting language for sound and music computing" << endl;
cout << "(c) " << COPYRIGHT << " by Carmine-Emanuele Cella" << endl << endl;
repl(interpreter);
} else {
for (int i = optind; i < argc; ++i) {
std::ifstream f(argv[i]);
if (!f) {
std::cerr << "cannot open '" << argv[i] << "'\n";
return 1;
}
std::string src(std::istreambuf_iterator<char>(f), {});
interpreter.exec(src, argv[i]);
}
if (interactive) repl(interpreter);
}
} catch (Error& e) {
std::cerr << RED << format_error(e) << RESET << endl;
return 1;
} catch (std::exception& e) {
std::cerr << RED << "error: " << e.what() << RESET << endl;
return 1;
} catch (...) {
cerr << RED << "fatal unknown error" << RESET << endl;
}
return 0;
}
// eof