-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBasic.os
executable file
·122 lines (99 loc) · 2.23 KB
/
DBasic.os
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/local/bin/slang
// library imports
import libParam.ParameterHandler;
import System.Collections.List;
import System.IO.File;
import System.String;
import System.StringIterator;
// project imports
import Consts;
import Debugger;
// public variables
string filename;
public int Main( int argc, string args ) modify {
var debug = false;
var params = new ParameterHandler( argc, args );
// Handle parameters
// {
if ( params.contains( "debug" ) ) {
debug = true;
params.remove( "debug" );
}
if ( params.contains( "version" ) ) {
print( APPNAME + " " + VERSION );
return 0;
}
// }
if ( !params.empty() ) {
// set filename if any params are set
filename = params[ 0 ].Key;
}
try {
while ( true ) {
write( "DBasic> " );
var commandIt = new StringIterator( cin() );
if ( !commandIt.hasNext() ) {
continue;
}
switch ( commandIt.next() ) {
case "help": { printHelp(); break; }
case "load": { loadFile( commandIt ); break; }
case "run": { run( commandIt ); break; }
case "quit": { print( "Quitting..." ); return 0; }
default: { print( "Invalid command" ); break; }
}
}
}
catch ( string e ) {
print( "Exception: " + e );
}
catch ( IException e ) {
print( "Exception: " + e.what() );
}
catch {
print( "Exception: uncaught exception!" );
}
return 0;
}
void loadFile( StringIterator it ) modify {
if ( !it.hasNext() ) {
print( "filename expected!" );
return;
}
filename = it.next();
}
void printHelp() {
print( "" );
print( "Available commands:" );
print( "help This screen" );
print( "load Loads a file for execution" );
print( "run Starts a debugging session for the loaded file" );
print( "quit Quits the debugger" );
print( "" );
}
void run( StringIterator it ) modify {
if ( it.hasNext() ) {
loadFile( it );
}
if ( !filename ) {
print( "no file selected for debugging" );
return;
}
try {
var debugger = new Debugger( filename );
print( "Started debug session..." );
print( "" );
debugger.run();
print( "" );
print( "Debug session exited." );
}
catch ( IException e ) {
print( "Exception: " + e.what() );
}
catch ( string e ) {
print( "Exception: " + e );
}
catch {
print( "Exception: caught unknown exception!" );
}
}