| 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_console.cpp |
| 28 | // desc: chuck command line console |
| 29 | // |
| 30 | // author: Spencer Salazar ([email protected]) |
| 31 | // date: Autumn 2005 |
| 32 | //----------------------------------------------------------------------------- |
| 33 | #include "chuck_console.h" |
| 34 | #include "util_console.h" |
| 35 | |
| 36 | |
| 37 | //----------------------------------------------------------------------------- |
| 38 | // name: Chuck_Console() |
| 39 | // desc: ... |
| 40 | //----------------------------------------------------------------------------- |
| 41 | Chuck_Console::Chuck_Console() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | |
| 46 | //----------------------------------------------------------------------------- |
| 47 | // name: ~Chuck_Console() |
| 48 | // desc: ... |
| 49 | //----------------------------------------------------------------------------- |
| 50 | Chuck_Console::~Chuck_Console() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | |
| 55 | //----------------------------------------------------------------------------- |
| 56 | // name: init() |
| 57 | // desc: ... |
| 58 | //----------------------------------------------------------------------------- |
| 59 | t_CKBOOL Chuck_Console::init() |
| 60 | { |
| 61 | return TRUE; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | //----------------------------------------------------------------------------- |
| 66 | // name: nextCommand() |
| 67 | // desc: ... |
| 68 | //----------------------------------------------------------------------------- |
| 69 | t_CKBOOL Chuck_Console::next_command( const string & prompt, string & out ) |
| 70 | { |
| 71 | // the line read |
| 72 | char * line_read = NULL; |
| 73 | |
| 74 | // read the next line |
| 75 | line_read = io_readline( prompt.c_str() ); |
| 76 | |
| 77 | // check to see if EOF encountered |
| 78 | // do we need more return codes to differentiate between |
| 79 | // EOF encountered vs. empty line? |
| 80 | if( line_read == NULL ) |
| 81 | { |
| 82 | out = ""; |
| 83 | return FALSE; |
| 84 | } |
| 85 | |
| 86 | // check first character |
| 87 | if( *line_read != 0 ) |
| 88 | io_addhistory( line_read ); |
| 89 | |
| 90 | // copy the result |
| 91 | out = line_read; |
| 92 | |
| 93 | // free the thing |
| 94 | free( line_read ); |
| 95 | |
| 96 | return TRUE; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | //----------------------------------------------------------------------------- |
| 101 | // name: nextResult() |
| 102 | // desc: ... |
| 103 | //----------------------------------------------------------------------------- |
| 104 | void Chuck_Console::next_result( const Chuck_Shell_Response &in ) |
| 105 | { |
| 106 | fputs( in.c_str(), stdout ); |
| 107 | } |
| 108 | |
| 109 | |
| 110 |