summaryrefslogtreecommitdiff
path: root/synth/in_synth_cli.cpp
blob: 7aa1d8eb3f2f0f956a9e550fdd35fa8a5cbfcc21 (plain)
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
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;
		}
	}
}