Debian Codegraph @

src/core/chuck_shell.h

raw symbols SCIP
1 /*----------------------------------------------------------------------------
2 ChucK Strongly-timed Audio Programming Language
3 Compiler, Virtual Machine, and Synthesis Engine
4
5 Copyright (c) 2003 Ge Wang and Perry R. Cook. All rights reserved.
6 http://chuck.stanford.edu/
7 http://chuck.cs.princeton.edu/
8
9 This program is free software; you can redistribute it and/or modify
10 it under the dual-license terms of EITHER the MIT License OR the GNU
11 General Public License (the latter as published by the Free Software
12 Foundation; either version 2 of the License or, at your option, any
13 later version).
14
15 This program is distributed in the hope that it will be useful and/or
16 interesting, but WITHOUT ANY WARRANTY; without even the implied warranty
17 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 MIT Licence and/or the GNU General Public License for details.
19
20 You should have received a copy of the MIT License and the GNU General
21 Public License (GPL) along with this program; a copy of the GPL can also
22 be obtained by writing to the Free Software Foundation, Inc., 59 Temple
23 Place, Suite 330, Boston, MA 02111-1307 U.S.A.
24 -----------------------------------------------------------------------------*/
25
26 //-----------------------------------------------------------------------------
27 // file: chuck_shell.h
28 // desc: chuck shell implementation
29 //
30 // author: Spencer Salazar ([email protected])
31 // date: Autumn 2005
32 //-----------------------------------------------------------------------------
33 #ifndef __CHUCK_SHELL_H__
34 #define __CHUCK_SHELL_H__
35
36 #include "chuck_def.h"
37 #include "chuck_errmsg.h"
38 #include "chuck_vm.h"
39
40 #include <string>
41 #include <map>
42 #include <vector>
43
44 using namespace std;
45
46 // forward references
47 class Chuck_Shell_VM;
48 class Chuck_Shell_UI;
49
50 typedef string Chuck_Shell_Request;
51 typedef string Chuck_Shell_Response;
52
53 //-----------------------------------------------------------------------------
54 // name: class Chuck_Shell
55 // desc: controller class for facilitating interaction between a shell UI and a
56 // shell mode.
57 //-----------------------------------------------------------------------------
58 class Chuck_Shell
59 {
60 public:
61 Chuck_Shell();
62 virtual ~Chuck_Shell();
63
64 t_CKBOOL init( Chuck_VM * process_vm, Chuck_Shell_UI * );
65 void run();
66 t_CKBOOL execute( string &, string & );
67 void close();
68 void exit();
69
70 public: // HACK-GE: these were moved from protected for win32
71 vector < Chuck_Shell_VM * > vms;
72 Chuck_VM * process_vm;
73 Chuck_Shell_VM * current_vm;
74
75 //forward declaration
76 class Command;
77
78 // alias, variable, and command maps
79 map < string, string > aliases;
80 map < string, string > variables;
81 map < string, Command * > commands;
82 vector < Command * > allocated_commands;
83
84 map < string, string > saved_code;
85
86 string code;
87
88 // helper functions
89 t_CKBOOL do_glob( const string &, string &, vector < string > & );
90 void do_code( string &, string &, string command = "+ " );
91 void do_code_context( string & );
92
93 protected:
94 // helper functions
95 void do_aliases();
96 void do_variables();
97
98 // code helper functions
99 void start_code();
100 void continue_code( string & );
101 void string_hash( string &, string & );
102
103 Chuck_Shell_UI * ui;
104
105 t_CKBOOL initialized;
106 t_CKBOOL stop;
107
108 string prompt;
109
110 string in;
111
112 // code entry variables
113 t_CKBOOL code_entry_active;
114 t_CKUINT scope;
115
116 public: // HACK-GE: moved from protected for win32
117
118 //-----------------------------------------------------------------------------
119 // name: class Chuck_Shell::Command
120 // desc: superclass to Chuck_Shell_Commands
121 //-----------------------------------------------------------------------------
122 class Command
123 {
124 public:
125 // virtual destructor (gewang)
126 virtual ~Command() { }
127
128 public:
129 virtual t_CKBOOL init( Chuck_Shell * );
130 virtual t_CKINT execute( vector< string > &, string & ) = 0;
131 virtual string usage();
132 virtual string long_usage();
133
134 protected:
135 Chuck_Shell * caller;
136 };
137
138 //-----------------------------------------------------------------------------
139 // name: class Chuck_Shell::Command_VM
140 // desc: ...
141 //-----------------------------------------------------------------------------
142 class Command_VM : public Command
143 {
144 public:
145 ~Command_VM();
146 t_CKBOOL init( Chuck_Shell * );
147 t_CKINT execute( vector< string > &, string & );
148 string usage();
149
150 protected:
151 map < string, Command * > commands;
152 vector < Command * > allocated_commands;
153 };
154
155 //-----------------------------------------------------------------------------
156 // name: class Chuck_Shell::Command_VM_Add
157 // desc: ...
158 //-----------------------------------------------------------------------------
159 class Command_VMAdd : public Command
160 {
161 public:
162 t_CKINT execute( vector< string > &, string & );
163 };
164
165 //-----------------------------------------------------------------------------
166 // name: class Chuck_Shell::Command_VM_Remove
167 // desc: ...
168 //-----------------------------------------------------------------------------
169 class Command_VMRemove : public Command
170 {
171 public:
172 t_CKINT execute( vector< string > &, string & );
173 };
174
175 //-----------------------------------------------------------------------------
176 // name: class Chuck_Shell::Command_VM_Attach
177 // desc: ...
178 //-----------------------------------------------------------------------------
179 class Command_VMAttach : public Command
180 {
181 public:
182 t_CKINT execute( vector< string > &, string & );
183 };
184
185 //-----------------------------------------------------------------------------
186 // name: class Chuck_Shell::Command_VM_List
187 // desc: ...
188 //-----------------------------------------------------------------------------
189 class Command_VMList : public Command
190 {
191 public:
192 t_CKINT execute( vector< string > &, string & );
193 };
194
195 //-----------------------------------------------------------------------------
196 // name: class Chuck_Shell::Command_VM_Swap
197 // desc: ...
198 //-----------------------------------------------------------------------------
199 class Command_VMSwap : public Command
200 {
201 public:
202 t_CKINT execute( vector< string > &, string & );
203 };
204
205 //-----------------------------------------------------------------------------
206 // name: class Chuck_Shell::Command_VM_AttachAdd
207 // desc: ...
208 //-----------------------------------------------------------------------------
209 class Command_VMAttachAdd : public Command
210 {
211 public:
212 t_CKINT execute( vector< string > &, string & );
213 };
214
215 //-----------------------------------------------------------------------------
216 // name: class Chuck_Shell::Command_Add
217 // desc: ...
218 //-----------------------------------------------------------------------------
219 class Command_Add : public Command
220 {
221 public:
222 t_CKINT execute( vector < string > &, string & );
223 string usage();
224 };
225
226 //-----------------------------------------------------------------------------
227 // name: class Chuck_Shell::Command_Remove
228 // desc: ...
229 //-----------------------------------------------------------------------------
230 class Command_Remove : public Command
231 {
232 public:
233 t_CKINT execute( vector < string > &, string & );
234 string usage();
235 };
236
237 //-----------------------------------------------------------------------------
238 // name: class Chuck_Shell::Command_Status
239 // desc: ...
240 //-----------------------------------------------------------------------------
241 class Command_Status : public Command
242 {
243 public:
244 t_CKINT execute( vector < string > &, string & );
245 string usage();
246 };
247
248 //-----------------------------------------------------------------------------
249 // name: class Chuck_Shell::Command_Removeall
250 // desc: ...
251 //-----------------------------------------------------------------------------
252 class Command_Removeall : public Command
253 {
254 public:
255 t_CKINT execute( vector< string > &, string & );
256 string usage();
257 };
258
259 //-----------------------------------------------------------------------------
260 // name: class Chuck_Shell::Command_Removelast
261 // desc: ...
262 //-----------------------------------------------------------------------------
263 class Command_Removelast : public Command
264 {
265 public:
266 t_CKINT execute( vector< string > &, string & );
267 string usage();
268 };
269
270 //-----------------------------------------------------------------------------
271 // name: class Chuck_Shell::Command_Replace
272 // desc: ...
273 //-----------------------------------------------------------------------------
274 class Command_Replace : public Command
275 {
276 public:
277 t_CKINT execute( vector< string > &, string & );
278 string usage();
279 };
280
281 //-----------------------------------------------------------------------------
282 // name: class Chuck_Shell::Command_Kill
283 // desc: ...
284 //-----------------------------------------------------------------------------
285 class Command_Kill : public Command
286 {
287 public:
288 t_CKINT execute( vector< string > &, string & );
289 //string usage();
290 };
291
292 //-----------------------------------------------------------------------------
293 // name: class Chuck_Shell::Command_Close
294 // desc: ...
295 //-----------------------------------------------------------------------------
296 class Command_Close : public Command
297 {
298 public:
299 t_CKINT execute( vector< string > &, string & );
300 //string usage();
301 };
302
303 //-----------------------------------------------------------------------------
304 // name: class Chuck_Shell::Command_Exit
305 // desc: ...
306 //-----------------------------------------------------------------------------
307 class Command_Exit : public Command
308 {
309 public:
310 t_CKINT execute( vector< string > &, string & );
311 //string usage();
312 };
313
314 //-----------------------------------------------------------------------------
315 // name: class Chuck_Shell::Command_Ls
316 // desc: ...
317 //-----------------------------------------------------------------------------
318 class Command_Ls : public Command
319 {
320 public:
321 t_CKINT execute( vector< string > &, string & );
322 //string usage();
323 };
324
325 //-----------------------------------------------------------------------------
326 // name: class Chuck_Shell::Command_Cd
327 // desc: ...
328 //-----------------------------------------------------------------------------
329 class Command_Cd : public Command
330 {
331 public:
332 t_CKINT execute( vector< string > &, string & );
333 //string usage();
334 };
335
336 //-----------------------------------------------------------------------------
337 // name: class Chuck_Shell::Command_Pwd
338 // desc: ...
339 //-----------------------------------------------------------------------------
340 class Command_Pwd : public Command
341 {
342 public:
343 t_CKINT execute( vector< string > &, string & );
344 };
345
346 //-----------------------------------------------------------------------------
347 // name: class Chuck_Shell::Command_Alias
348 // desc: ...
349 //-----------------------------------------------------------------------------
350 class Command_Alias : public Command
351 {
352 public:
353 t_CKINT execute( vector< string > &, string & );
354 };
355
356 //-----------------------------------------------------------------------------
357 // name: class Chuck_Shell::Command_Unalias
358 // desc: ...
359 //-----------------------------------------------------------------------------
360 class Command_Unalias : public Command
361 {
362 public:
363 t_CKINT execute( vector< string > &, string & );
364 };
365
366 //-----------------------------------------------------------------------------
367 // name: class Chuck_Shell::Command_Source
368 // desc: ...
369 //-----------------------------------------------------------------------------
370 class Command_Source : public Command
371 {
372 public:
373 t_CKINT execute( vector< string > &, string & );
374 };
375
376 //-----------------------------------------------------------------------------
377 // name: class Chuck_Shell::Command_Code
378 // desc: ...
379 //-----------------------------------------------------------------------------
380 class Command_Code : public Command
381 {
382 public:
383 ~Command_Code();
384 t_CKBOOL init( Chuck_Shell * );
385 t_CKINT execute( vector< string > &, string & );
386 string usage();
387
388 private:
389 map < string, Command * > commands;
390 vector < Command * > allocated_commands;
391 };
392
393 //-----------------------------------------------------------------------------
394 // name: class Chuck_Shell::Command_CodeContext
395 // desc: ...
396 //-----------------------------------------------------------------------------
397 class Command_CodeContext : public Command
398 {
399 public:
400 t_CKINT execute( vector< string > &, string & );
401 };
402
403 //-----------------------------------------------------------------------------
404 // name: class Chuck_Shell::Command_CodeSave
405 // desc: ...
406 //-----------------------------------------------------------------------------
407 class Command_CodeSave : public Command
408 {
409 public:
410 t_CKINT execute( vector< string > &, string & );
411 };
412
413 //-----------------------------------------------------------------------------
414 // name: class Chuck_Shell::Command_CodeDelete
415 // desc: ...
416 //-----------------------------------------------------------------------------
417 class Command_CodeDelete : public Command
418 {
419 public:
420 t_CKINT execute( vector< string > &, string & );
421 };
422
423 //-----------------------------------------------------------------------------
424 // name: class Chuck_Shell::Command_CodeAdd
425 // desc: ...
426 //-----------------------------------------------------------------------------
427 class Command_CodeAdd : public Command
428 {
429 public:
430 t_CKINT execute( vector< string > &, string & );
431 };
432
433 //-----------------------------------------------------------------------------
434 // name: class Chuck_Shell::Command_CodeList
435 // desc: ...
436 //-----------------------------------------------------------------------------
437 class Command_CodeList : public Command
438 {
439 public:
440 t_CKINT execute( vector< string > &, string & );
441 };
442
443 //-----------------------------------------------------------------------------
444 // name: class Chuck_Shell::Command_CodePrint
445 // desc: ...
446 //-----------------------------------------------------------------------------
447 class Command_CodePrint : public Command
448 {
449 public:
450 t_CKINT execute( vector< string > &, string & );
451 };
452
453 //-----------------------------------------------------------------------------
454 // name: class Chuck_Shell::Command_CodeWrite
455 // desc: ...
456 //-----------------------------------------------------------------------------
457 class Command_CodeWrite : public Command
458 {
459 public:
460 t_CKINT execute( vector< string > &, string & );
461 };
462
463 //-----------------------------------------------------------------------------
464 // name: class Chuck_Shell::Command_CodeRead
465 // desc: ...
466 //-----------------------------------------------------------------------------
467 class Command_CodeRead : public Command
468 {
469 public:
470 t_CKINT execute( vector< string > &, string & );
471 };
472
473 //-----------------------------------------------------------------------------
474 // name: class Chuck_Shell::Command_Help
475 // desc: ...
476 //-----------------------------------------------------------------------------
477 class Command_Help : public Command
478 {
479 public:
480 t_CKINT execute( vector< string > &, string & );
481 };
482
483 };
484
485
486 //-----------------------------------------------------------------------------
487 // name: class Chuck_Shell_VM
488 // desc: encapsulates local and network VMs into a single class
489 //-----------------------------------------------------------------------------
490 class Chuck_Shell_VM
491 {
492 public:
493 virtual ~Chuck_Shell_VM() {}
494
495 public:
496 virtual Chuck_Shell_VM * copy()=0;
497 virtual t_CKBOOL add_shred( const vector< string > &, string & )=0;
498 virtual t_CKBOOL remove_shred( const vector< string > &, string & )=0;
499 virtual t_CKBOOL remove_all( string & )=0;
500 virtual t_CKBOOL remove_last( string & )=0;
501 virtual t_CKBOOL replace_shred( const vector< string > &, string & )=0;
502 virtual t_CKBOOL status( string & )=0;
503 virtual t_CKBOOL kill( string & )=0;
504 virtual string fullname()=0;
505 };
506
507 //-----------------------------------------------------------------------------
508 // name: class Chuck_Shell_Network_VM
509 // desc: VM across the network
510 //-----------------------------------------------------------------------------
511 class Chuck_Shell_Network_VM : public Chuck_Shell_VM
512 {
513 public:
514 virtual ~Chuck_Shell_Network_VM() {}
515
516 public:
517 Chuck_Shell_VM * copy();
518 t_CKBOOL init( const string &, t_CKINT );
519 t_CKBOOL add_shred( const vector< string > &, string & );
520 t_CKBOOL remove_shred( const vector< string > &, string & );
521 t_CKBOOL remove_all( string & );
522 t_CKBOOL remove_last( string & );
523 t_CKBOOL replace_shred( const vector< string > &, string & );
524 t_CKBOOL status( string & );
525 t_CKBOOL kill( string & );
526 string fullname();
527
528 private:
529 string hostname;
530 t_CKINT port;
531 };
532 /*
533 //-----------------------------------------------------------------------------
534 // name: class Chuck_Shell_Network_VM
535 // desc: VM across the network
536 //-----------------------------------------------------------------------------
537 class Chuck_Shell_Process_VM : public Chuck_Shell_VM
538 {
539 public:
540 virtual ~Chuck_Shell_Process_VM() {}
541
542 public:
543 Chuck_Shell_VM * copy();
544 t_CKBOOL init( const string &, t_CKINT );
545 t_CKBOOL add_shred( const vector< string > &, string & );
546 t_CKBOOL remove_shred( const vector< string > &, string & );
547 t_CKBOOL remove_all( string & );
548 t_CKBOOL remove_last( string & );
549 t_CKBOOL replace_shred( const vector< string > &, string & );
550 t_CKBOOL status( string & );
551 t_CKBOOL kill( string & );
552 string fullname();
553
554 t_CKUINT last_shred_id();
555
556 private:
557 Chuck_VM * vm;
558 Chuck_Compiler * compiler;
559 };
560 */
561 //-----------------------------------------------------------------------------
562 // name: class Chuck_Shell_UI
563 // desc: superclass to various types of Chuck UIs
564 //-----------------------------------------------------------------------------
565 class Chuck_Shell_UI
566 {
567 public:
568 virtual ~Chuck_Shell_UI() {}
569
570 public:
571 virtual t_CKBOOL init();
572 virtual t_CKBOOL next_command( const string &, string & ) = 0;
573 virtual void next_result( const string & ) = 0;
574 };
575
576 // prototype for shell thread routine
577 void * shell_cb( void * p );
578
579 #endif //__CHUCK_SHELL_H__