Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ReadLine.C

00001 /* $Id: ReadLine.C,v 1.2 2000/11/03 22:03:28 rpav Exp $
00002  *
00003  * SFW - Studio FrameWork
00004  * Copyright (C) 2000  Ryan Pavlik
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  *
00020  */
00021 
00022 /*
00023  * ReadLine class for JavaScript
00024  *
00025  */ 
00026 
00027 #include <cstdio>
00028 #include <malloc.h>
00029 #include <readline/readline.h>
00030 #include <readline/history.h>
00031 #include <SFW/Log.H>
00032 #include <SFW/JavaScript.H>
00033 
00034 TYPE_INIT(SFW::JSReadLine);
00035 using namespace SFW;
00036 
00037 JSReadLine::JSReadLine() : JavaScriptClass("ReadLine") {
00038     JSCLASS_DEF;
00039 
00040     JSMETHOD_ADD(readline, JS_CF_STATIC);
00041 }
00042     
00043 JSCONSTRUCTOR_IMPL(JSReadLine)
00044     (void **_context,
00045      JSTArray &_argv,
00046      string &_error) {
00047     return true;
00048 }
00049 
00050 JSDESTRUCTOR_IMPL(JSReadLine)
00051     (void *_context) { }
00052 
00053 JSMETHOD_IMPL(JSReadLine, readline)
00054     (void *_context, JSTArray &_argv,
00055      JavaScriptType &ret, string &error) {
00056     
00057     char *line_read;
00058 
00059     if(_argv.size() > 1) {
00060     error = "too many arguments";
00061     return false;
00062     } else if(_argv.size() == 1) {
00063     line_read = readline(const_cast<char*>(((string)_argv[0]).c_str()));
00064     } else {
00065     line_read = readline("");
00066     }
00067 
00068     ret = string(line_read);
00069 
00070     if(line_read && *line_read)
00071     add_history(line_read);
00072     
00073     free(line_read);
00074 
00075     return true;
00076 }

Generated at Tue Jan 2 15:38:34 2001 for SFW by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000