00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef IPPL_USE_STANDARD_HEADERS
00027 #include <iostream>
00028 #include <fstream>
00029 using namespace std;
00030 #else
00031 #include <iostream.h>
00032 #include <fstream.h>
00033 #endif
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <unistd.h>
00038 #include <sys/types.h>
00039 #include <sys/time.h>
00040 #include "aclvis/Interp.h"
00041
00042
00044
00045 Interp::Interp(const char *nm) : InterpNamedObj(nm) { }
00046
00047
00049
00050 Interp::~Interp() { }
00051
00052
00054
00055
00056
00057
00058 void Interp::interact(int timeoutseconds) {
00059
00060 char inbuf[2048];
00061
00062 #ifndef IPPL_LINUX
00063 fd_set readvec;
00064 int stdin_fd = 0;
00065 struct timeval timeout;
00066 timeout.tv_sec = timeoutseconds;
00067 timeout.tv_usec = 0;
00068 FD_ZERO(&readvec);
00069 FD_SET(stdin_fd, &readvec);
00070 #endif
00071
00072
00073
00074 bool done = false;
00075 while (!done) {
00076
00077
00078
00079 cout << name() << flush;
00080
00081
00082 #ifndef IPPL_LINUX
00083 int ret = select(16, &readvec, 0, 0, timeoutseconds < 0 ? 0 : &timeout);
00084 #else
00085 int ret = 1;
00086 #endif
00087 if (ret == -1) {
00088
00089 cerr << "Interp: Error reading input." << endl;
00090 return;
00091 } else if (ret == 0) {
00092
00093 done = true;
00094 } else {
00095
00096 if (fgets(inbuf, 2047, stdin) == 0) {
00097
00098 return;
00099 } else {
00100
00101
00102 cerr << "Read in string '" << inbuf << "'." << endl;
00103 if (!strcmp(inbuf, "go\n") || !strcmp(inbuf, "GO\n"))
00104 done = true;
00105 else
00106 evalCommand(inbuf);
00107 }
00108 }
00109 }
00110 }
00111
00112
00113
00114
00115
00116