/* TUIpeer works in conjunction with an implementation of java.awt.Toolkit to provide a Text User Interface for programs using the Java AWT. Copyright (C) 1997-2000 Stuart D. Gathman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // $Log: tuipeer.cc,v $ // Revision 1.2 2000/12/18 01:58:57 stuart // Removed dependencies on libg++. // Changed all references to String to string. // Changed libg++ String idioms to string idioms. // Copied Obstack from libg++ and hacked it to throw an exception on error. // Hacked Set.cc to throw an exception on error. // Added Str.cc to relace the split function from libg++. // // Revision 1.1.1.1 2000/12/16 20:45:15 stuart // Released TUIPeer sources // // Revision 1.9 2000/12/14 20:51:58 stuart // changes for Linux // // Revision 1.8 1999/01/19 16:14:36 stuart // Check for valid controlling tty when in callback mode // // Revision 1.7 1997/09/18 21:15:34 stuart // Forward parameters from EDX environment // // Revision 1.6 1997/04/28 20:06:11 stuart // fix keyword // // Revision 1.5 1997/04/28 20:04:54 stuart // update help // // Revision 1.4 1997/04/28 20:01:37 stuart // Autoload, localtabs, scale // // Revision 1.3 1996/12/23 21:35:13 stuart // split source // // Revision 1.2 1996/10/17 13:02:33 stuart // Menus supported // #include #include #include #include #include #include #include #include #include #include #include #include #include #include "remotepeer.h" #include "toolkit.h" enum { RUNCLASS = 500, SETPARM = 126, SETPROP = 127 }; static void usage() { fputs("$Id: tuipeer.cc,v 1.2 2000/12/18 01:58:57 stuart Exp $\n\ Usage: tuipeer [-a] [-t[logfile]] [-sw,h] [-l] [-pport] [package.Class ...]\n\ -a autoloaded by java, use /dev/tty for screen & keyboard\n\ -l local tabs, handle tabs locally instead of through AWT\n\ -t trace AWT Thin Client messages\n\ -s pretend character cells are w x h pixels\n\ -p AWT host:port to connect to, default localhost:9712\n\ Class load classes or applets ",stderr); exit(1); } int main(int argc,char **argv) { extern const char version[]; int rc; catch (rc) int port = 9712; string host("127.0.0.1"); int sx = 1, sy = 1; int i; bool trace = false; bool localtabs = false; bool login = true; const char *tty = 0; if (argc < 2) usage(); for (i = 1; i < argc; ++i) { if (strncmp(argv[i],"-p",2) == 0) { // port string s(argv[i] + 2); if (s.length() == 0) s = argv[++i]; Array a; int n = split(s,a,":"); if (n < 2) { if (isdigit(s[0])) port = atoi(s.c_str()); else host = s; } else { host = a[0]; port = atoi(a[1].c_str()); fprintf(stderr,"Connecting to %s:%d\n",host.c_str(),port); } } else if (strncmp(argv[i],"-t",2) == 0) { // trace trace = true; if (argv[i][2]) freopen(argv[i]+2,"w",stderr); //PStrace(stderr); } else if (strcmp(argv[i],"-l") == 0) { // local tabs localtabs = true; } else if (strncmp(argv[i],"-s",2) == 0) { // scale Array s; split(argv[i]+2,s,","); sx = atoi(s[0].c_str()); if (sx <= 0) sx = 1; sy = atoi(s[1].c_str()); if (sy <= 0) sy = 1; } else if (strncmp(argv[i],"-a",2) == 0) { // autoloaded close(0); if (open("/dev/tty",O_RDWR) == 0) tty = ttyname(0); if (argv[i][2] != 0) tty = argv[i]+2; // override tty name if (tty == 0) return 1; string devname(tty); if (tty[0] != '/') // if not absolute path devname = "/dev/" + devname; #if 0 if (devname == "/dev/tty") { fprintf(stderr,"Can't discover tty name!\n"); return 1; } #endif close(0); close(1); //setpgrp(); dup(open(devname.c_str(),O_RDWR)); login = false; } else break; } //malloc_trace("tuipeer.tr"); Socket sock; if (sock.connect(host.c_str(),port)) { perror(host.c_str()); return 1; } int fd = sock.getfd(); Toolkit kit(fd); kit.trace = trace; kit.localtabs = localtabs; if (login) { // login if not autloaded from the JVM const char *login = (const char *)getlogin(); const char *clazz = "bmsi.tui.TUIKit"; fprintf(stderr,"login(%s,%s)\n",login,clazz); kit.writeUTF(login); kit.writeUTF(clazz); // capture any shell parameters char buf[1024]; Keydata parm(buf,sizeof buf); int plen = parm.parmget(); if (plen > 0) kit.callMethod(0,(int)SETPARM,buf,plen); } const char *btasdir = getenv("BTASDIR"); if (btasdir != 0) { kit.callMethod(0,(int)SETPROP,"bmsi.btasdir"); kit.writeUTF(btasdir); } const char *edxterm = getenv("EDXTERM"); if (edxterm != 0) { kit.callMethod(0,(int)SETPROP,"bmsi.term"); kit.writeUTF(edxterm); } const char *logtty = getenv("LOGTTY"); if (logtty != 0) { kit.callMethod(0,(int)SETPROP,"bmsi.tty"); kit.writeUTF(logtty); } kit.init(sx,sy); Keyboard kbd(stdin); Kbegin(1); Kdefine("\017",KEY_OPTIONS); signal(SIGPIPE,SIG_IGN); Signal sigint(SIGINT), sigterm(SIGTERM), sigpipe(SIGPIPE); Banner banner(12,version, "Copyright 1996,1997 Business Management Systems, Inc."); Ksync(); for (;i < argc; ++i) kit.callMethod(0,(int)RUNCLASS,string(argv[i])); kit.run(); #if 0 // reopen terminal in case we have been orphaned close(0); close(1); setpgrp(); if (open(tty,O_RDWR) < 0) perror(tty); else { dup(0); fprintf(stderr,"reopened %s\n",tty); } #endif Kend(); enverr fprintf(stderr,"tuipeer: internal error %d\n",rc); envend fprintf(stderr,"tuipeer shutdown\n"); return 0; }