summaryrefslogtreecommitdiff
path: root/synth/in_synth_cli.cpp
diff options
context:
space:
mode:
authorFlorian Jung <flo@thinkpad.(none)>2011-01-10 17:57:36 +0100
committerFlorian Jung <flo@thinkpad.(none)>2011-01-10 18:01:25 +0100
commitb34cab5dd6d4ac16a6a58589397a3d82df38b826 (patch)
treec76bde00d0ee62d3701aacbedde55ea0f3d287bc /synth/in_synth_cli.cpp
parent4b87549a645fd62107ddc5295a5027b2a5851096 (diff)
Implemented a yet very basic in-synth-interface
The interface understands "quit" and "exit", and accepts but ignores "reload" and "load". It catches CTRL+C.
Diffstat (limited to 'synth/in_synth_cli.cpp')
-rw-r--r--synth/in_synth_cli.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/synth/in_synth_cli.cpp b/synth/in_synth_cli.cpp
new file mode 100644
index 0000000..7aa1d8e
--- /dev/null
+++ b/synth/in_synth_cli.cpp
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <string>
+#include <signal.h>
+
+#include "in_synth_cli.h"
+#include "util.h"
+
+using namespace std;
+
+#define PROMPT "> "
+
+void signal_handler(int sig)
+{
+ cout << endl << PROMPT << flush;
+}
+
+void do_in_synth_cli()
+{
+ string input;
+ string command;
+ string params;
+
+ if (signal(2,signal_handler)==SIG_ERR)
+ {
+ cout << "WARNING: failed to set signal handler!" << endl;
+ }
+
+
+ while (true)
+ {
+ cout << PROMPT << flush;
+ getline(cin,input);
+ input=trim_spaces(input);
+
+ command=trim_spaces(str_before(input,' ',input));
+ params=trim_spaces(str_after(input,' ',""));
+
+ if ((command=="exit") || (command=="quit"))
+ break;
+ else if (command=="reload")
+ {
+ if ((!isnum(params)) || (params==""))
+ cout << "error: expected program-number, found '"<<params<<"'"<<endl;
+ else
+ {
+ //TODO: load program
+ }
+ }
+ else if (command=="load")
+ {
+ string prgstr, file;
+ prgstr=trim_spaces(str_before(params,' ',params));
+ file=trim_spaces(str_after(params,' ',""));
+
+ if ((!isnum(prgstr)) || (prgstr==""))
+ cout << "error: expected program-number, found '"<<prgstr<<"'"<<endl;
+ else if (file=="")
+ cout << "error: expected program-file to load, found nothing"<<endl;
+ else
+ {
+ //TODO: load program
+ }
+ }
+ else if (command!="")
+ {
+ cout << "error: unrecognized command '"<<command<<"'"<<endl;
+ }
+ }
+}