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