version 1.2, 2000/02/01 10:24:12 |
version 1.3, 2000/03/20 18:54:24 |
|
|
$OpenXM$ |
$OpenXM: OpenXM/src/gnuplot/plot.c.diff,v 1.2 2000/02/01 10:24:12 maekawa Exp $ |
|
|
--- plot.c.orig Tue Feb 1 19:09:06 2000 |
*** plot.c.orig Sat Jan 22 23:15:59 2000 |
+++ plot.c Tue Feb 1 19:09:12 2000 |
--- plot.c Tue Mar 21 03:41:44 2000 |
@@ -42,6 +42,23 @@ |
*************** |
#include "fnproto.h" |
*** 42,47 **** |
#include <setjmp.h> |
--- 42,64 ---- |
|
#include "fnproto.h" |
+/* TAKAYAMA Nobuki */ |
#include <setjmp.h> |
+#include <sys/types.h> |
|
+#include <sys/socket.h> |
+ /* TAKAYAMA Nobuki */ |
+#include <sys/time.h> |
+ #include <sys/types.h> |
+#include <netinet/in.h> |
+ #include <sys/socket.h> |
+#include <netdb.h> |
+ #include <sys/time.h> |
+ |
+ #include <netinet/in.h> |
+FILE *openTCP __P((char *)); |
+ #include <netdb.h> |
+ |
+ |
+int socketConnect __P((char *, int)); |
+ FILE *openTCP __P((char *)); |
+int socketOpen __P((char *, int)); |
+ |
+int socketAccept __P((int)); |
+ int socketConnect __P((char *, int)); |
+ |
+ int socketOpen __P((char *, int)); |
+int oxSocketSelect0 __P((int, int)); |
+ int socketAccept __P((int)); |
+int oxSocketMultiSelect __P((int *, int, int, int *)); |
+ |
+/* END */ |
+ int oxSocketSelect0 __P((int, int)); |
+ |
+ int oxSocketMultiSelect __P((int *, int, int, int *)); |
#if defined(MSDOS) || defined(DOS386) || defined(__EMX__) |
+ /* END */ |
# include <io.h> |
+ |
#endif |
#if defined(MSDOS) || defined(DOS386) || defined(__EMX__) |
@@ -321,6 +338,7 @@ |
# include <io.h> |
int argc; |
#endif |
char **argv; |
*************** |
{ |
*** 321,326 **** |
+ FILE *fp; |
--- 338,344 ---- |
#ifdef LINUXVGA |
int argc; |
LINUX_setup(); |
char **argv; |
#endif |
{ |
@@ -527,8 +545,12 @@ |
+ FILE *fp; |
|
#ifdef LINUXVGA |
/* interactive = FALSE; */ /* should this be here? */ |
LINUX_setup(); |
|
#endif |
- } else |
*************** |
- load_file(fopen(*argv, "r"), *argv, FALSE); |
*** 527,534 **** |
+ } else { |
|
+ fp = openTCP(*argv); |
/* interactive = FALSE; */ /* should this be here? */ |
+ load_file(fp, *argv, FALSE); |
|
+ fprintf(stderr, "gnuplot : EOF or there was an error" |
! } else |
+ "in the input stream.\n"); |
! load_file(fopen(*argv, "r"), *argv, FALSE); |
+ } |
} |
} |
#ifdef _Windows |
#ifdef _Windows |
if (noend) { |
if (noend) { |
--- 545,556 ---- |
@@ -725,3 +747,308 @@ |
|
return 0; |
/* interactive = FALSE; */ /* should this be here? */ |
} |
|
#endif |
! } else { |
+ |
! fp = openTCP(*argv); |
+/* |
! load_file(fp, *argv, FALSE); |
+ * TAKAYAMA Nobuki |
! fprintf(stderr, "gnuplot : EOF or there was an error" |
+ */ |
! "in the input stream.\n"); |
+FILE * |
! } |
+openTCP(name) |
} |
+ char *name; |
#ifdef _Windows |
+{ |
if (noend) { |
+ FILE *fp; |
*************** |
+ int fd, port, reverse = 0; |
*** 725,727 **** |
+ |
--- 747,1053 ---- |
+ fprintf(stderr, "openTCP port number : %s\n", name); |
return 0; |
+ |
} |
+ if (name[0] == 'r') { |
#endif |
+ fprintf(stderr, "openTCP : trying to reverse connetion.\n"); |
+ |
+ reverse = 1; |
+ /* |
+ sscanf(&name[1], "%d", &port); |
+ * TAKAYAMA Nobuki |
+ } else { |
+ */ |
+ sscanf(name, "%d", &port); |
+ FILE * |
+ } |
+ openTCP(name) |
+ |
+ char *name; |
+ if (reverse) { |
+ { |
+ fd = socketConnect("localhost", port); |
+ FILE *fp; |
+ fprintf(stderr, "socketConnect is succeded: fd = %d.", fd); |
+ int fd, port, reverse = 0; |
+ } else { |
+ |
+ fprintf(stderr, "Port number is %d.\n", port); |
+ fprintf(stderr, "openTCP port number : %s\n", name); |
+ fd = socketOpen("localhost", port); |
+ |
+ fprintf(stderr, "socketOpen is succeded: fd = %d.", fd); |
+ if (name[0] == 'r') { |
+ fd = socketAccept(fd); |
+ fprintf(stderr, "openTCP : trying to reverse connetion.\n"); |
+ } |
+ reverse = 1; |
+ |
+ sscanf(&name[1], "%d", &port); |
+ fprintf(stderr, "\n Port %d : Connected.\n", port); |
+ } else { |
+ fp = fdopen(fd, "r"); |
+ sscanf(name, "%d", &port); |
+ |
+ } |
+ return(fp); |
+ |
+} |
+ if (reverse) { |
+ |
+ fd = socketConnect("localhost", port); |
+#define READBUFSIZE 10000 |
+ fprintf(stderr, "socketConnect is succeded: fd = %d.", fd); |
+ |
+ } else { |
+FILE *TcpioError = stderr; |
+ fprintf(stderr, "Port number is %d.\n", port); |
+int OpenedSocket = 0, Quiet = 0; |
+ fd = socketOpen("localhost", port); |
+ |
+ fprintf(stderr, "socketOpen is succeded: fd = %d.", fd); |
+int |
+ fd = socketAccept(fd); |
+socketConnect(serverName, portNumber) |
+ } |
+ char *serverName; |
+ |
+ int portNumber; |
+ fprintf(stderr, "\n Port %d : Connected.\n", port); |
+{ |
+ fp = fdopen(fd, "r"); |
+ struct hostent *servhost; |
+ |
+ struct sockaddr_in serv; |
+ return(fp); |
+ int socketid, on; |
+ } |
+ |
+ |
+ if ((servhost = gethostbyname(serverName)) == NULL) { |
+ #define READBUFSIZE 10000 |
+ fprintf(stderr, "Bad server name.\n\n"); |
+ |
+ return (-1); |
+ int OpenedSocket = 0, Quiet = 0; |
+ } |
+ |
+ |
+ int |
+ bzero((void *)&serv, sizeof(serv)); |
+ socketConnect(serverName, portNumber) |
+ serv.sin_family = AF_INET; |
+ char *serverName; |
+ serv.sin_port = htons(portNumber); |
+ int portNumber; |
+ bcopy(servhost->h_addr, (void *)&serv.sin_addr, servhost->h_length); |
+ { |
+ |
+ struct hostent *servhost; |
+ if ((socketid = socket(AF_INET, SOCK_STREAM, 0)) <0) { |
+ struct sockaddr_in serv; |
+ fprintf(stderr, "Socket allocation is failed.\n\n"); |
+ int socketid, on; |
+ return (-1); |
+ |
+ } |
+ if ((servhost = gethostbyname(serverName)) == NULL) { |
+ |
+ fprintf(stderr, "Bad server name.\n\n"); |
+#if 0 /* XXX */ |
+ return (-1); |
+ on = 1; |
+ } |
+ setsockopt(socketid, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
+ |
+#endif |
+ bzero((void *)&serv, sizeof(serv)); |
+ |
+ serv.sin_family = AF_INET; |
+ if (!Quiet) { |
+ serv.sin_port = htons(portNumber); |
+ fprintf(TcpioError, "Trying to connect port %d, ip=%x\n", |
+ bcopy(servhost->h_addr, (void *)&serv.sin_addr, servhost->h_length); |
+ ntohs(serv.sin_port), serv.sin_addr); |
+ |
+ } |
+ if ((socketid = socket(AF_INET, SOCK_STREAM, 0)) <0) { |
+ |
+ fprintf(stderr, "Socket allocation is failed.\n\n"); |
+ if (connect(socketid, (struct sockaddr *)&serv, sizeof(serv)) == -1) { |
+ return (-1); |
+ fprintf(stderr, "cannot connect\n"); |
+ } |
+ return (-1); |
+ |
+ } |
+ #if 0 /* XXX */ |
+ |
+ on = 1; |
+ if (!Quiet) |
+ setsockopt(socketid, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
+ fprintf(TcpioError, "connected.\n"); |
+ #endif |
+ |
+ |
+ return(socketid); |
+ if (!Quiet) { |
+} |
+ fprintf(stderr, "Trying to connect port %d, ip=%x\n", |
+ |
+ ntohs(serv.sin_port), serv.sin_addr); |
+int |
+ } |
+socketOpen(serverName, portNumber) |
+ |
+ char *serverName; |
+ if (connect(socketid, (struct sockaddr *)&serv, sizeof(serv)) == -1) { |
+ int portNumber; |
+ fprintf(stderr, "cannot connect\n"); |
+{ |
+ return (-1); |
+ static struct hostent *servhost; |
+ } |
+ static struct sockaddr_in serv; |
+ |
+ static int s_wait; |
+ if (!Quiet) |
+ static int on; |
+ fprintf(stderr, "connected.\n"); |
+ extern int errno; |
+ |
+ int tt; |
+ return(socketid); |
+ |
+ } |
+ fprintf(TcpioError, "Hello from open. serverName is %s " |
+ |
+ "and portNumber is %d\n", serverName, portNumber); |
+ int |
+ |
+ socketOpen(serverName, portNumber) |
+ if ((servhost = gethostbyname(serverName)) == NULL) { |
+ char *serverName; |
+ fprintf(stderr, "Bad server name.\n"); |
+ int portNumber; |
+ return (-1); |
+ { |
+ } |
+ static struct hostent *servhost; |
+ |
+ static struct sockaddr_in serv; |
+ bzero((void *)&serv, sizeof(serv)); |
+ static int s_wait; |
+ serv.sin_family = AF_INET; |
+ static int on; |
+ serv.sin_port = htons(portNumber); |
+ extern int errno; |
+ bcopy(servhost->h_addr, &serv.sin_addr, servhost->h_length); |
+ int tt; |
+ |
+ |
+ if ((s_wait = socket(AF_INET,SOCK_STREAM, 0)) < 0) { |
+ fprintf(stderr, "Hello from open. serverName is %s " |
+ fprintf(stderr, "Socket allocation is failed.\n"); |
+ "and portNumber is %d\n", serverName, portNumber); |
+ return (-1); |
+ |
+ } |
+ if ((servhost = gethostbyname(serverName)) == NULL) { |
+ |
+ fprintf(stderr, "Bad server name.\n"); |
+ on = 1; |
+ return (-1); |
+ setsockopt(s_wait, SOL_SOCKET,SO_REUSEADDR, &on, sizeof(on)); |
+ } |
+ |
+ |
+ /* important */ |
+ bzero((void *)&serv, sizeof(serv)); |
+ if ((tt = bind(s_wait, (struct sockaddr *)&serv, sizeof(serv))) == -1) { |
+ serv.sin_family = AF_INET; |
+ fprintf(TcpioError, "bind error. Error no is %d. " |
+ serv.sin_port = htons(portNumber); |
+ "See /usr/include/sys/errno.h. " |
+ bcopy(servhost->h_addr, &serv.sin_addr, servhost->h_length); |
+ "(asm/errno.h)\n", errno); |
+ |
+ fprintf(stderr, "cannot bind\n"); |
+ if ((s_wait = socket(AF_INET,SOCK_STREAM, 0)) < 0) { |
+ return (-1); |
+ fprintf(stderr, "Socket allocation is failed.\n"); |
+ } |
+ return (-1); |
+ |
+ } |
+#if 0 /* XXX */ |
+ |
+ printf("bind returns %d\n", tt); |
+ on = 1; |
+#endif |
+ setsockopt(s_wait, SOL_SOCKET,SO_REUSEADDR, &on, sizeof(on)); |
+ |
+ |
+ tt = sizeof(serv); |
+ /* important */ |
+ if (getsockname(s_wait, (struct sockaddr *)&serv, &tt) < 0) { |
+ if ((tt = bind(s_wait, (struct sockaddr *)&serv, sizeof(serv))) == -1) { |
+ fprintf(TcpioError, "getsockname error. Error no is %d. " |
+ fprintf(stderr, "bind error. Error no is %d. " |
+ "See /usr/include/sys/errno.h " |
+ "See /usr/include/sys/errno.h. " |
+ "(asm/errno.h).\n", errno); |
+ "(asm/errno.h)\n", errno); |
+ fprintf(stderr, "cannot getsockname\n"); |
+ fprintf(stderr, "cannot bind\n"); |
+ return (-1); |
+ return (-1); |
+ } |
+ } |
+ |
+ |
+ if (listen(s_wait, 1) < 0) { |
+ #if 0 /* XXX */ |
+ fprintf(stderr, "Listen failed\n"); |
+ printf("bind returns %d\n", tt); |
+ return (-1); |
+ #endif |
+ } |
+ |
+ |
+ tt = sizeof(serv); |
+ fprintf(TcpioError, "Done the initialization. " |
+ if (getsockname(s_wait, (struct sockaddr *)&serv, &tt) < 0) { |
+ "port =%d\n", ntohs(serv.sin_port)); |
+ fprintf(stderr, "getsockname error. Error no is %d. " |
+ OpenedSocket = ntohs(serv.sin_port); |
+ "See /usr/include/sys/errno.h " |
+ |
+ "(asm/errno.h).\n", errno); |
+ return (s_wait); |
+ fprintf(stderr, "cannot getsockname\n"); |
+} |
+ return (-1); |
+ |
+ } |
+int |
+ |
+socketAccept(snum) |
+ if (listen(s_wait, 1) < 0) { |
+ int snum; |
+ fprintf(stderr, "Listen failed\n"); |
+{ |
+ return (-1); |
+ int s, news; |
+ } |
+ |
+ |
+ s = snum; |
+ fprintf(stderr, "Done the initialization. " |
+ |
+ "port =%d\n", ntohs(serv.sin_port)); |
+ fprintf(TcpioError, "Trying to accept... "); |
+ OpenedSocket = ntohs(serv.sin_port); |
+ fflush(TcpioError); |
+ |
+ |
+ return (s_wait); |
+ if ((news = accept(s, NULL, NULL)) < 0) { |
+ } |
+ fprintf(stderr, "Error in accept.\n"); |
+ |
+ return (-1); |
+ int |
+ } |
+ socketAccept(snum) |
+ |
+ int snum; |
+ fprintf(TcpioError, "Accepted.\n"); |
+ { |
+ fflush(TcpioError); |
+ int s, news; |
+ |
+ |
+ if (close(s) < 0) { |
+ s = snum; |
+ fprintf(stderr, "Error in closing the old socket.\n"); |
+ |
+ return (-1); |
+ fprintf(stderr, "Trying to accept... "); |
+ } |
+ fflush(stderr); |
+ |
+ |
+ return(news); |
+ if ((news = accept(s, NULL, NULL)) < 0) { |
+} |
+ fprintf(stderr, "Error in accept.\n"); |
+ |
+ return (-1); |
+int |
+ } |
+oxSocketSelect0(fd, t) |
+ |
+ int fd, t; |
+ fprintf(stderr, "Accepted.\n"); |
+{ |
+ fflush(stderr); |
+ fd_set readfds; |
+ |
+ struct timeval timeout; |
+ if (close(s) < 0) { |
+ int debug = 0; |
+ fprintf(stderr, "Error in closing the old socket.\n"); |
+ extern int errno; |
+ return (-1); |
+ |
+ } |
+ FD_ZERO(&readfds); |
+ |
+ FD_SET(fd, &readfds); |
+ return(news); |
+ timeout.tv_sec = 0; |
+ } |
+ timeout.tv_usec = (long)t; |
+ |
+ |
+ int |
+ if (t >= 0) { |
+ oxSocketSelect0(fd, t) |
+ if (debug) { |
+ int fd, t; |
+ printf("select t >= 0 for fd = %d\n", fd); |
+ { |
+ fflush(NULL); |
+ fd_set readfds; |
+ } |
+ struct timeval timeout; |
+ |
+ int debug = 0; |
+ /* It must be fd + 1!, Not fd. */ |
+ extern int errno; |
+ if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) { |
+ |
+ fprintf(TcpioError, "select (non-block) error. " |
+ FD_ZERO(&readfds); |
+ "Error no is %d. " |
+ FD_SET(fd, &readfds); |
+ "See /usr/include/sys/errno.h " |
+ timeout.tv_sec = 0; |
+ "(asm/errno.h).\n", errno); |
+ timeout.tv_usec = (long)t; |
+ fprintf(stderr, "oxSocketSelect0() : select failed.\n"); |
+ |
+ return (0); |
+ if (t >= 0) { |
+ } |
+ if (debug) { |
+ |
+ printf("select t >= 0 for fd = %d\n", fd); |
+ if (debug) { |
+ fflush(NULL); |
+ printf("Return from select t >= 0 for fd = %d\n", fd); |
+ } |
+ fflush(NULL); |
+ |
+ } |
+ /* It must be fd + 1!, Not fd. */ |
+ } else { |
+ if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) { |
+ /* block */ |
+ fprintf(stderr, "select (non-block) error. " |
+ if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) { |
+ "Error no is %d. " |
+ fprintf(TcpioError, "select (block) error. " |
+ "See /usr/include/sys/errno.h " |
+ "Error no is %d. " |
+ "(asm/errno.h).\n", errno); |
+ "See /usr/include/sys/errno.h " |
+ fprintf(stderr, "oxSocketSelect0() : select failed.\n"); |
+ "(asm/errno.h).\n", errno); |
+ return (0); |
+ fprintf(stderr, "socketSelect0() : select failed.\n"); |
+ } |
+ return (0); |
+ |
+ } |
+ if (debug) { |
+ } |
+ printf("Return from select t >= 0 for fd = %d\n", fd); |
+ |
+ fflush(NULL); |
+ if (FD_ISSET(fd, &readfds)) { |
+ } |
+ return(1); |
+ } else { |
+ } else { |
+ /* block */ |
+ return(0); |
+ if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) { |
+ } |
+ fprintf(stderr, "select (block) error. " |
+} |
+ "Error no is %d. " |
+ |
+ "See /usr/include/sys/errno.h " |
+int |
+ "(asm/errno.h).\n", errno); |
+oxSocketMultiSelect(sid, size, t, result) |
+ fprintf(stderr, "socketSelect0() : select failed.\n"); |
+ int sid[], size, t, result[]; |
+ return (0); |
+{ |
+ } |
+ fd_set readfds; |
+ } |
+ struct timeval timeout; |
+ |
+ int i, fd, p, isdata = 0; |
+ if (FD_ISSET(fd, &readfds)) { |
+ extern int errno; |
+ return(1); |
+ |
+ } else { |
+ FD_ZERO(&readfds); |
+ return(0); |
+ timeout.tv_sec = 0; |
+ } |
+ timeout.tv_usec = (long)t; |
+ } |
+ |
+ |
+ fd = 0; |
+ int |
+ |
+ oxSocketMultiSelect(sid, size, t, result) |
+ for (i = 0 ; i < size ; i++) { |
+ int sid[], size, t, result[]; |
+ if (sid[i] >= 0) { |
+ { |
+ p = sid[i]; |
+ fd_set readfds; |
+ if (p > fd) |
+ struct timeval timeout; |
+ fd = p; |
+ int i, fd, p, isdata = 0; |
+ FD_SET(p,&readfds); |
+ extern int errno; |
+#if 0 /* XXX */ |
+ |
+ printf("p = %d, fd=%d", p, fd); |
+ FD_ZERO(&readfds); |
+#endif |
+ timeout.tv_sec = 0; |
+ } |
+ timeout.tv_usec = (long)t; |
+ } |
+ |
+ |
+ fd = 0; |
+#if 0 /* XXX */ |
+ |
+ printf("MultiSelect..\n"); |
+ for (i = 0 ; i < size ; i++) { |
+ fflush(NULL); |
+ if (sid[i] >= 0) { |
+#endif |
+ p = sid[i]; |
+ |
+ if (p > fd) |
+ if (t >= 0) { |
+ fd = p; |
+ /* It must be fd + 1!, Not fd. */ |
+ FD_SET(p,&readfds); |
+ if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) { |
+ #if 0 /* XXX */ |
+ fprintf(TcpioError, "Select error. Error no is %d. " |
+ printf("p = %d, fd=%d", p, fd); |
+ "See /usr/include/sys/errno.h " |
+ #endif |
+ "(asm/errno.h).\n", errno); |
+ } |
+ fprintf(stderr, "oxSocketMultiSelect() : " |
+ } |
+ "select failed.\n"); |
+ |
+ return (0); |
+ #if 0 /* XXX */ |
+ } |
+ printf("MultiSelect..\n"); |
+ } else { |
+ fflush(NULL); |
+ /* block */ |
+ #endif |
+ if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) { |
+ |
+ fprintf(TcpioError, "Select error. Error no is %d. " |
+ if (t >= 0) { |
+ "See /usr/include/sys/errno.h " |
+ /* It must be fd + 1!, Not fd. */ |
+ "(asm/errno.h).\n", errno); |
+ if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) { |
+ fprintf(stderr, "oxSocketMultiSelect() : " |
+ fprintf(stderr, "Select error. Error no is %d. " |
+ "(block) select failed.\n"); |
+ "See /usr/include/sys/errno.h " |
+ return (0); |
+ "(asm/errno.h).\n", errno); |
+ } |
+ fprintf(stderr, "oxSocketMultiSelect() : " |
+ } |
+ "select failed.\n"); |
+ |
+ return (0); |
+#if 0 /* XXX */ |
+ } |
+ printf("Done. MultiSelect.\n"); |
+ } else { |
+ fflush(NULL); |
+ /* block */ |
+#endif |
+ if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) { |
+ |
+ fprintf(stderr, "Select error. Error no is %d. " |
+ for (i = 0 ; i < size ; i++) { |
+ "See /usr/include/sys/errno.h " |
+ p = sid[i]; |
+ "(asm/errno.h).\n", errno); |
+ if ((sid[i] >= 0) && FD_ISSET(p, &readfds)) { |
+ fprintf(stderr, "oxSocketMultiSelect() : " |
+ result[i] = 1; |
+ "(block) select failed.\n"); |
+ isdata = 1; |
+ return (0); |
+ } else { |
+ } |
+ result[i] = 0; |
+ } |
+ } |
+ |
+ } |
+ #if 0 /* XXX */ |
+ |
+ printf("Done. MultiSelect.\n"); |
+ return (isdata); |
+ fflush(NULL); |
+} |
+ #endif |
|
+ |
|
+ for (i = 0 ; i < size ; i++) { |
|
+ p = sid[i]; |
|
+ if ((sid[i] >= 0) && FD_ISSET(p, &readfds)) { |
|
+ result[i] = 1; |
|
+ isdata = 1; |
|
+ } else { |
|
+ result[i] = 0; |
|
+ } |
|
+ } |
|
+ |
|
+ return (isdata); |
|
+ } |