new SocketObj and ipl touchups
ivtools patch distribution <[email protected]> Mon, 15 Sep 2008 16:47:48 -0700
| Newsgroups | gmane.comp.lib.ivtools.patches |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-9-549616758 Content-Disposition: attachment; filename=ivtools-080915-johnston-019 Content-Type: application/octet-stream; x-unix-mode=0644; name="ivtools-080915-johnston-019" Content-Transfer-Encoding: 7bit Patch: ivtools-080915-johnston-019 For: ivtools-1.2 Author: [email protected] Subject: new SocketObj for comterp, ipl related touchups Requires: This is an intermediate patch to ivtools-1.2. To apply, cd to the top-level directory of the ivtools source tree (the directory with src and config subdirs), and apply like this: patch -p0 <ThisFile Summary of Changes: Index: ComGlyph/comtextview.c diff -c ComGlyph/comtextview.c:1.3 ComGlyph/comtextview.c:1.4 *** ComGlyph/comtextview.c:1.3 Fri May 16 10:47:51 2008 --- src/ComGlyph/comtextview.c Mon Sep 15 16:43:06 2008 *************** *** 234,240 **** #if 0 ComValue result(comterp()->stack_top(1)); #else ! ComValue result(comterp()->pop_stack()); #endif ostream* out = new std::strstream(); if (*comterp()->errmsg()) { --- 234,241 ---- #if 0 ComValue result(comterp()->stack_top(1)); #else ! // don't evaluate ! ComValue result(comterp()->pop_stack(false)); #endif ostream* out = new std::strstream(); if (*comterp()->errmsg()) { Index: ComTerp/bitfunc.h diff -c ComTerp/bitfunc.h:1.1 ComTerp/bitfunc.h:1.2 *** ComTerp/bitfunc.h:1.1 Wed Aug 29 10:37:48 2007 --- src/ComTerp/bitfunc.h Mon Sep 15 16:43:02 2008 *************** *** 31,76 **** #include <ComTerp/numfunc.h> ! //: & (bitwise-and) operator. class BitAndFunc : public NumFunc { public: BitAndFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "& is the bitwise-and operator"; } }; ! //: ^ (bitwise-xor) operator. class BitXorFunc : public NumFunc { public: BitXorFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "^ is the bitwise-xor operator"; } }; ! //: | (bitwise-or) operator. class BitOrFunc : public NumFunc { public: BitOrFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "| is the bitwise-or operator"; } }; ! //: ~ (bitwise-not) operator. class BitNotFunc : public NumFunc { public: BitNotFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "~ is the bitwise-not operator"; } }; --- 31,76 ---- #include <ComTerp/numfunc.h> ! //: & (bit_and) operator. class BitAndFunc : public NumFunc { public: BitAndFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "& is the bit_and operator"; } }; ! //: ^ (bit_xor) operator. class BitXorFunc : public NumFunc { public: BitXorFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "^ is the bit_xor operator"; } }; ! //: | (bit_or) operator. class BitOrFunc : public NumFunc { public: BitOrFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "| is the bit_or operator"; } }; ! //: ~ (bit_not) operator. class BitNotFunc : public NumFunc { public: BitNotFunc(ComTerp*); virtual void execute(); virtual const char* docstring() { ! return "~ is the bit_not operator"; } }; Index: ComTerp/boolfunc.c diff -c ComTerp/boolfunc.c:1.2 ComTerp/boolfunc.c:1.3 *** ComTerp/boolfunc.c:1.2 Sat Oct 6 11:10:28 2007 --- src/ComTerp/boolfunc.c Mon Sep 15 16:43:02 2008 *************** *** 23,28 **** --- 23,29 ---- * */ + #include <Unidraw/Components/grview.h> #include <ComTerp/boolfunc.h> #include <ComTerp/comvalue.h> #include <ComTerp/comterp.h> *************** *** 256,264 **** operand1.array_val() == operand2.array_val(); break; case ComValue::ObjectType: ! result.boolean_ref() = operand2.type() == ComValue::ObjectType && ! operand1.obj_val() == operand2.obj_val() && ! operand1.class_symid() == operand2.class_symid(); break; default: result.boolean_ref() = operand1.is_type(ComValue::UnknownType) && --- 257,272 ---- operand1.array_val() == operand2.array_val(); break; case ComValue::ObjectType: ! if (!operand1.object_compview()) ! result.boolean_ref() = operand2.type() == ComValue::ObjectType && ! operand1.obj_val() == operand2.obj_val() && ! operand1.class_symid() == operand2.class_symid(); ! else ! result.boolean_ref() = operand2.type() == ComValue::ObjectType && ! operand1.class_symid() == operand2.class_symid() && ! operand2.object_compview() && ! ((GraphicView*)operand1.obj_val())->GetGraphicComp() == ! ((GraphicView*)operand2.obj_val())->GetGraphicComp(); break; default: result.boolean_ref() = operand1.is_type(ComValue::UnknownType) && *************** *** 335,340 **** --- 343,360 ---- result.boolean_ref() = operand2.type() != ComValue::ArrayType || operand1.array_val() != operand2.array_val(); break; + case ComValue::ObjectType: + if (!operand1.object_compview()) + result.boolean_ref() = operand2.type() != ComValue::ObjectType || + operand1.obj_val() != operand2.obj_val() || + operand1.class_symid() != operand2.class_symid(); + else + result.boolean_ref() = operand2.type() != ComValue::ObjectType || + operand1.class_symid() != operand2.class_symid() || + !operand2.object_compview() || + ((GraphicView*)operand1.obj_val())->GetGraphicComp() != + ((GraphicView*)operand2.obj_val())->GetGraphicComp(); + break; case ComValue::UnknownType: result.boolean_ref() = operand2.is_known(); break; Index: ComTerp/comfunc.h diff -c ComTerp/comfunc.h:1.3 ComTerp/comfunc.h:1.4 *** ComTerp/comfunc.h:1.3 Thu Nov 15 14:18:04 2007 --- src/ComTerp/comfunc.h Mon Sep 15 16:43:02 2008 *************** *** 98,103 **** --- 98,104 ---- // return ComTerp this ComFunc is associated with. ComTerpServ* comterpserv(); // return ComTerpServ this ComFunc is associated with. + void comterpserv( ComTerpServ* serv) { _comterp = (ComTerp*)serv; } ComValue pop_stack(); Index: ComTerp/comhandler.c diff -c ComTerp/comhandler.c:1.4 ComTerp/comhandler.c:1.5 *** ComTerp/comhandler.c:1.4 Tue May 6 10:55:04 2008 --- src/ComTerp/comhandler.c Mon Sep 15 16:43:02 2008 *************** *** 219,225 **** } if (!ComterpHandler::logger_mode()) { comterp_->load_string(inbuf); ! if (fd>0) cerr << "(" << fd << "): " << inbuf << "\n"; comterp_->_fd = fd; comterp_->_outfunc = (outfuncptr)&ComTerpServ::fd_fputs; --- 219,225 ---- } if (!ComterpHandler::logger_mode()) { comterp_->load_string(inbuf); ! if (fd>0 && (!comterp_->_muted || strncmp(inbuf, "ready", 5)!=0)) cerr << "(" << fd << "): " << inbuf << "\n"; comterp_->_fd = fd; comterp_->_outfunc = (outfuncptr)&ComTerpServ::fd_fputs; Index: ComTerp/comterp.c diff -c ComTerp/comterp.c:1.9 ComTerp/comterp.c:1.10 *** ComTerp/comterp.c:1.9 Fri May 16 10:47:37 2008 --- src/ComTerp/comterp.c Mon Sep 15 16:43:02 2008 *************** *** 357,365 **** } if (stack_base+1 < _stack_top) - fprintf(stderr, "func \"%s\" failed to push a single value on stack\n", symbol_pntr(func->funcid())); - else if (stack_base+1 > _stack_top) fprintf(stderr, "func \"%s\" pushed more than a single value on stack\n", symbol_pntr(func->funcid())); } else if (sv.type() == ComValue::SymbolType) { --- 357,365 ---- } if (stack_base+1 < _stack_top) fprintf(stderr, "func \"%s\" pushed more than a single value on stack\n", symbol_pntr(func->funcid())); + else if (stack_base+1 > _stack_top) + fprintf(stderr, "func \"%s\" failed to push a single value on stack\n", symbol_pntr(func->funcid())); } else if (sv.type() == ComValue::SymbolType) { Index: ComTerp/comterpserv.c diff -c ComTerp/comterpserv.c:1.4 ComTerp/comterpserv.c:1.5 *** ComTerp/comterpserv.c:1.4 Tue Apr 29 11:41:21 2008 --- src/ComTerp/comterpserv.c Mon Sep 15 16:43:02 2008 *************** *** 528,533 **** --- 528,534 ---- if (!_defaults_added) { ComTerp::add_defaults(); add_command("remote", new RemoteFunc(this)); + add_command("socket", new SocketFunc(this)); add_command("eval", new EvalFunc(this)); } } Index: ComTerp/comterpserv.h diff -c ComTerp/comterpserv.h:1.3 ComTerp/comterpserv.h:1.4 *** ComTerp/comterpserv.h:1.3 Tue Apr 29 11:41:21 2008 --- src/ComTerp/comterpserv.h Mon Sep 15 16:43:02 2008 *************** *** 42,48 **** //: extended ComTerp that works with buffered IO. class ComTerpServ : public ComTerp { public: ! ComTerpServ(int bufsize = 1024*1024, int fd = -1); // construct with optional 'bufsize', and on an optional 'fd'. ~ComTerpServ(); --- 42,48 ---- //: extended ComTerp that works with buffered IO. class ComTerpServ : public ComTerp { public: ! ComTerpServ(int bufsize = 1024/* *1024 */, int fd = -1); // construct with optional 'bufsize', and on an optional 'fd'. ~ComTerpServ(); Index: ComTerp/comvalue.c diff -c ComTerp/comvalue.c:1.2 ComTerp/comvalue.c:1.3 *** ComTerp/comvalue.c:1.2 Sun Sep 23 09:11:27 2007 --- src/ComTerp/comvalue.c Mon Sep 15 16:43:02 2008 *************** *** 22,28 **** * */ ! #include <Unidraw/Components/compview.h> #include <ComTerp/comfunc.h> #include <ComTerp/comvalue.h> #include <ComTerp/comterp.h> --- 22,28 ---- * */ ! #include <Unidraw/Components/grview.h> #include <ComTerp/comfunc.h> #include <ComTerp/comvalue.h> #include <ComTerp/comterp.h> *************** *** 389,395 **** void* ComValue::geta(int id) { if (is_object(id)) { if (object_compview()) ! return ((ComponentView*)obj_val())->GetSubject(); else return obj_val(); } else --- 389,395 ---- void* ComValue::geta(int id) { if (is_object(id)) { if (object_compview()) ! return ((GraphicView*)obj_val())->GetGraphicComp(); else return obj_val(); } else Index: ComTerp/ctrlfunc.c diff -c ComTerp/ctrlfunc.c:1.7 ComTerp/ctrlfunc.c:1.8 *** ComTerp/ctrlfunc.c:1.7 Fri May 16 10:47:37 2008 --- src/ComTerp/ctrlfunc.c Mon Sep 15 16:43:02 2008 *************** *** 116,124 **** } void RemoteFunc::execute() { ! ComValue hostv(stack_arg(0, true)); ! ComValue portv(stack_arg(1)); ! ComValue cmdstrv(stack_arg(2)); static int nowait_sym = symbol_add("nowait"); ComValue nowaitv(stack_key(nowait_sym)); reset_stack(); --- 116,124 ---- } void RemoteFunc::execute() { ! ComValue arg1v(stack_arg(0)); ! ComValue arg2v(stack_arg(1)); ! ComValue arg3v(stack_arg(2)); static int nowait_sym = symbol_add("nowait"); ComValue nowaitv(stack_key(nowait_sym)); reset_stack(); *************** *** 131,188 **** return; #endif ! if (hostv.is_string() && portv.is_known() && cmdstrv.is_string()) { ! ! const char* hoststr = hostv.string_ptr(); ! const char* portstr = portv.is_string() ? portv.string_ptr() : nil; ! u_short portnum = portstr ? atoi(portstr) : portv.ushort_val(); ACE_INET_Addr addr (portnum, hoststr); ! ACE_SOCK_Stream socket; ! ACE_SOCK_Connector conn; ! if (conn.connect (socket, addr) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "open")); push_stack(ComValue::nullval()); return; } #if __GNUC__<3 ! filebuf ofbuf; ! ofbuf.attach(socket.get_handle()); #elif __GNUC__<4 && !defined(__CYGWIN__) ! fileptr_filebuf ofbuf((int)socket.get_handle(), ios_base::out, ! false, static_cast<size_t>(BUFSIZ)); #else ! fileptr_filebuf ofbuf((int)socket.get_handle(), ios_base::out, ! static_cast<size_t>(BUFSIZ)); #endif ! ostream out(&ofbuf); ! const char* cmdstr = cmdstrv.string_ptr(); ! out << cmdstr; ! if (cmdstr[strlen(cmdstr)-1] != '\n') out << "\n"; ! out.flush(); ! if (nowaitv.is_false()) { #if __GNUC__<3 ! filebuf ifbuf; ! ifbuf.attach(socket.get_handle()); ! istream in(&ifbuf); ! char* buf; ! in.gets(&buf); #else ! char buf[BUFSIZ]; ! int i=0; ! do { ! read(socket.get_handle(), buf+i++, 1); ! } while (i<BUFSIZ-1 && buf[i-1]!='\n'); ! if (buf[i-1]=='\n') buf[i-1]=0; #endif ! ComValue retval(comterpserv()->run(buf, true)); ! push_stack(retval); ! } - if (socket.close () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "close")); - } - return; #else --- 131,214 ---- return; #endif ! ACE_SOCK_STREAM *socket = nil; ! ACE_SOCK_Connector *conn = nil; ! SocketObj* socketobj = nil; ! const char* cmdstr = nil; ! if (arg1v.is_string() && arg2v.is_num() && arg3v.is_string()) { ! ! cmdstr = arg3v.string_ptr(); ! const char* hoststr = arg1v.string_ptr(); ! const char* portstr = arg2v.is_string() ? arg2v.string_ptr() : nil; ! u_short portnum = portstr ? atoi(portstr) : arg2v.ushort_val(); ACE_INET_Addr addr (portnum, hoststr); ! socket = new ACE_SOCK_STREAM; ! conn = new ACE_SOCK_Connector; ! if (conn->connect (*socket, addr) == -1) { ACE_ERROR ((LM_ERROR, "%p\n", "open")); push_stack(ComValue::nullval()); return; } + } else if (arg1v.is_object() && arg2v.is_string()) { + + cmdstr = arg2v.string_ptr(); + socketobj = (SocketObj*)arg1v.geta(SocketObj::class_symid()); + if (socketobj) + socket = socketobj->socket(); + + } else + return; + + #if 0 #if __GNUC__<3 ! filebuf ofbuf; ! ofbuf.attach(socket->get_handle()); #elif __GNUC__<4 && !defined(__CYGWIN__) ! fileptr_filebuf ofbuf((int)socket->get_handle(), ios_base::out, ! false, static_cast<size_t>(BUFSIZ)); ! #else ! fileptr_filebuf ofbuf((int)socket->get_handle(), ios_base::out, ! static_cast<size_t>(BUFSIZ)); ! #endif ! ostream out(&ofbuf); ! out << cmdstr; ! if (cmdstr[strlen(cmdstr)-1] != '\n') out << "\n"; ! out.flush(); #else ! int i=0; ! do { ! write(socket->get_handle(), cmdstr+i++, 1); ! } while ( cmdstr[i]!='\0'); ! if (cmdstr[i-1] != '\n') ! write(socket->get_handle(), "\n", 1); #endif ! if (nowaitv.is_false()) { #if __GNUC__<3 ! filebuf ifbuf; ! ifbuf.attach(socket->get_handle()); ! istream in(&ifbuf); ! char* buf; ! in.gets(&buf); #else ! char buf[BUFSIZ]; ! int i=0; ! do { ! read(socket->get_handle(), buf+i++, 1); ! } while (i<BUFSIZ-1 && buf[i-1]!='\n'); ! if (buf[i-1]=='\n') buf[i]=0; #endif ! ComValue retval(comterpserv()->run(buf, true)); ! push_stack(retval); ! } ! ! if(!socketobj) { ! if (socket->close () == -1) ! ACE_ERROR ((LM_ERROR, "%p\n", "close")); ! delete socket; ! delete conn; ! } return; #else *************** *** 196,201 **** --- 222,306 ---- /*****************************************************************************/ + int SocketObj::_symid = -1; + + SocketObj::SocketObj(const char* host, unsigned short port) { + _socket = nil; + _conn = nil; + _host = strnew(host); + _port = port; + } + + SocketObj::~SocketObj() { + if( _socket ) { + _socket->close(); + delete _socket; + delete _conn; + delete _host; } + } + + int SocketObj::connect() { + ACE_INET_Addr addr(_port, _host); + _socket = new ACE_SOCK_STREAM; + _conn = new ACE_SOCK_Connector; + return _conn->connect(*_socket, addr); + } + + int SocketObj::close() { + return _socket->close(); + } + + int SocketObj::get_handle() { + return _socket->get_handle(); + } + + /*****************************************************************************/ + + SocketFunc::SocketFunc(ComTerp* comterp) : ComFunc(comterp) { + } + + + void SocketFunc::execute() { + ComValue hostv(stack_arg(0, true)); + ComValue portv(stack_arg(1)); + reset_stack(); + + #ifdef HAVE_ACE + + #if __GNUC__==3&&__GNUC_MINOR__<1 + fprintf(stderr, "Please upgrade to gcc-3.1 or greater\n"); + push_stack(ComValue::nullval()); + return; + #endif + + if (hostv.is_string() && portv.is_known()) { + + const char* hoststr = hostv.string_ptr(); + const char* portstr = portv.is_string() ? portv.string_ptr() : nil; + u_short portnum = portstr ? atoi(portstr) : portv.ushort_val(); + SocketObj* socket = new SocketObj(hoststr, portnum); + if (socket->connect() == -1 ) { + ACE_ERROR ((LM_ERROR, "%p\n", "open")); + push_stack(ComValue::nullval()); + return; + } + + ComValue retval(SocketObj::class_symid(), (void*)socket); + push_stack(retval); + } + + return; + + #else + cerr << "for the socket command to work rebuild comterp with ACE\n"; + return; + + #endif + + } + + /*****************************************************************************/ + EvalFunc::EvalFunc(ComTerp* comterp) : ComFunc(comterp) { } Index: ComTerp/ctrlfunc.h diff -c ComTerp/ctrlfunc.h:1.3 ComTerp/ctrlfunc.h:1.4 *** ComTerp/ctrlfunc.h:1.3 Tue May 6 10:55:04 2008 --- src/ComTerp/ctrlfunc.h Mon Sep 15 16:43:02 2008 *************** *** 85,94 **** virtual void execute(); virtual const char* docstring() { ! return "%s(hoststr portnum cmdstr :nowait) -- remotely evaluate command string then locally evaluate result string"; } }; //: eval string command for ComTerp. // str|lst=eval(cmdstr [cmdstr ...] :symret) -- evaluate string as commands, optionally returning symbol instead of nil. class EvalFunc : public ComFunc { --- 85,130 ---- virtual void execute(); virtual const char* docstring() { ! return "%s(hoststr|sockobj [portnum] cmdstr :nowait) -- remotely evaluate command string then locally evaluate result string"; } }; + #ifdef HAVE_ACE + class ACE_SOCK_STREAM; + class ACE_SOCK_Connector; + + class SocketObj { + public: + SocketObj(const char* host, unsigned short port); + virtual ~SocketObj(); + ACE_SOCK_STREAM* socket() { return _socket; } + int connect(); + int close(); + const char* host() { return _host; } + unsigned short port() { return _port; } + int get_handle(); + + ACE_SOCK_STREAM* _socket; + ACE_SOCK_Connector* _conn; + char* _host; + unsigned short _port; + + CLASS_SYMID("SocketObj"); + }; + + //: create socket object + // sockobj=socket(hoststr portnum) -- create and open socket object + // create and open socket object + class SocketFunc : public ComFunc { + public: + SocketFunc(ComTerp*); + + virtual void execute(); + virtual const char* docstring() { + return "%s(hoststr portnum ) -- create and open socket object"; } + }; + #endif + //: eval string command for ComTerp. // str|lst=eval(cmdstr [cmdstr ...] :symret) -- evaluate string as commands, optionally returning symbol instead of nil. class EvalFunc : public ComFunc { Index: ComTerp/typefunc.c diff -c ComTerp/typefunc.c:1.1 ComTerp/typefunc.c:1.2 *** ComTerp/typefunc.c:1.1 Wed Aug 29 10:37:49 2007 --- src/ComTerp/typefunc.c Mon Sep 15 16:43:02 2008 *************** *** 84,90 **** if (!numargs) return; int class_syms[numargs]; for (int i=0; i<numargs; i++) { ! ComValue& val = stack_arg(i); if (val.is_object()) class_syms[i] = val.class_symid(); else --- 84,90 ---- if (!numargs) return; int class_syms[numargs]; for (int i=0; i<numargs; i++) { ! ComValue val = stack_arg(i); if (val.is_object()) class_syms[i] = val.class_symid(); else Index: config_ivtools/config.mk diff -c config_ivtools/config.mk:1.1 config_ivtools/config.mk:1.2 *** config_ivtools/config.mk:1.1 Wed Aug 29 10:39:32 2007 --- config/config.mk Mon Sep 15 16:42:14 2008 *************** *** 1,4 **** ! XCONFIGDIR = /usr/X11R6/lib/X11/config ABSTOP = /Users/scott/src/ivtools-1.2 CPU = DARWIN LIBSTDCPLUSPLUS2 = 0 --- 1,4 ---- ! XCONFIGDIR = /usr/X11/lib/X11/config ABSTOP = /Users/scott/src/ivtools-1.2 CPU = DARWIN LIBSTDCPLUSPLUS2 = 0 *** /dev/null Mon Sep 15 16:43:10 PDT 2008 --- patches/ivtools-080915-johnston-019 *************** patches/ivtools-080915-johnston-019 *** 0 **** --- 1 ---- + ivtools-080915-johnston-019 --Apple-Mail-9-549616758 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ --Apple-Mail-9-549616758 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Ivtools-patch mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ivtools-patch --Apple-Mail-9-549616758--