Annotation of OpenXM/src/gnuplot/plot.c.diff, Revision 1.1
1.1 ! maekawa 1: $OpenXM$
! 2:
! 3: diff -ur gnuplot-3.7.orig/plot.c gnuplot-3.7/plot.c
! 4: --- gnuplot-3.7.orig/plot.c Thu Dec 10 00:24:14 1998
! 5: +++ gnuplot-3.7/plot.c Mon Nov 15 06:25:57 1999
! 6: @@ -42,6 +42,23 @@
! 7: #include "fnproto.h"
! 8: #include <setjmp.h>
! 9:
! 10: +/* TAKAYAMA Nobuki */
! 11: +#include <sys/types.h>
! 12: +#include <sys/socket.h>
! 13: +#include <sys/time.h>
! 14: +#include <netinet/in.h>
! 15: +#include <netdb.h>
! 16: +
! 17: +FILE *openTCP __P((char *));
! 18: +
! 19: +int socketConnect __P((char *, int));
! 20: +int socketOpen __P((char *, int));
! 21: +int socketAccept __P((int));
! 22: +
! 23: +int oxSocketSelect0 __P((int, int));
! 24: +int oxSocketMultiSelect __P((int *, int, int, int *));
! 25: +/* END */
! 26: +
! 27: #if defined(MSDOS) || defined(DOS386) || defined(__EMX__)
! 28: # include <io.h>
! 29: #endif
! 30: @@ -271,6 +288,7 @@
! 31: int argc;
! 32: char **argv;
! 33: {
! 34: + FILE *fp;
! 35: #ifdef LINUXVGA
! 36: LINUX_setup();
! 37: #endif
! 38: @@ -474,8 +492,12 @@
! 39:
! 40: /* interactive = FALSE; /* should this be here? */
! 41:
! 42: - } else
! 43: - load_file(fopen(*argv, "r"), *argv, FALSE);
! 44: + } else {
! 45: + fp = openTCP(*argv);
! 46: + load_file(fp, *argv, FALSE);
! 47: + fprintf(stderr, "gnuplot : EOF or there was an error"
! 48: + "in the input stream.\n");
! 49: + }
! 50: }
! 51: #ifdef _Windows
! 52: if (noend) {
! 53: @@ -672,3 +694,308 @@
! 54: return 0;
! 55: }
! 56: #endif
! 57: +
! 58: +/*
! 59: + * TAKAYAMA Nobuki
! 60: + */
! 61: +FILE *
! 62: +openTCP(name)
! 63: + char *name;
! 64: +{
! 65: + FILE *fp;
! 66: + int fd, port, reverse = 0;
! 67: +
! 68: + fprintf(stderr, "openTCP port number : %s\n", name);
! 69: +
! 70: + if (name[0] == 'r') {
! 71: + fprintf(stderr, "openTCP : trying to reverse connetion.\n");
! 72: + reverse = 1;
! 73: + sscanf(&name[1], "%d", &port);
! 74: + } else {
! 75: + sscanf(name, "%d", &port);
! 76: + }
! 77: +
! 78: + if (reverse) {
! 79: + fd = socketConnect("localhost", port);
! 80: + fprintf(stderr, "socketConnect is succeded: fd = %d.", fd);
! 81: + } else {
! 82: + fprintf(stderr, "Port number is %d.\n", port);
! 83: + fd = socketOpen("localhost", port);
! 84: + fprintf(stderr, "socketOpen is succeded: fd = %d.", fd);
! 85: + fd = socketAccept(fd);
! 86: + }
! 87: +
! 88: + fprintf(stderr, "\n Port %d : Connected.\n", port);
! 89: + fp = fdopen(fd, "r");
! 90: +
! 91: + return(fp);
! 92: +}
! 93: +
! 94: +#define READBUFSIZE 10000
! 95: +
! 96: +FILE *TcpioError = stderr;
! 97: +int OpenedSocket = 0, Quiet = 0;
! 98: +
! 99: +int
! 100: +socketConnect(serverName, portNumber)
! 101: + char *serverName;
! 102: + int portNumber;
! 103: +{
! 104: + struct hostent *servhost;
! 105: + struct sockaddr_in serv;
! 106: + int socketid, on;
! 107: +
! 108: + if ((servhost = gethostbyname(serverName)) == NULL) {
! 109: + fprintf(stderr, "Bad server name.\n\n");
! 110: + return (-1);
! 111: + }
! 112: +
! 113: + bzero((void *)&serv, sizeof(serv));
! 114: + serv.sin_family = AF_INET;
! 115: + serv.sin_port = htons(portNumber);
! 116: + bcopy(servhost->h_addr, (void *)&serv.sin_addr, servhost->h_length);
! 117: +
! 118: + if ((socketid = socket(AF_INET, SOCK_STREAM, 0)) <0) {
! 119: + fprintf(stderr, "Socket allocation is failed.\n\n");
! 120: + return (-1);
! 121: + }
! 122: +
! 123: +#if 0 /* XXX */
! 124: + on = 1;
! 125: + setsockopt(socketid, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
! 126: +#endif
! 127: +
! 128: + if (!Quiet) {
! 129: + fprintf(TcpioError, "Trying to connect port %d, ip=%x\n",
! 130: + ntohs(serv.sin_port), serv.sin_addr);
! 131: + }
! 132: +
! 133: + if (connect(socketid, (struct sockaddr *)&serv, sizeof(serv)) == -1) {
! 134: + fprintf(stderr, "cannot connect\n");
! 135: + return (-1);
! 136: + }
! 137: +
! 138: + if (!Quiet)
! 139: + fprintf(TcpioError, "connected.\n");
! 140: +
! 141: + return(socketid);
! 142: +}
! 143: +
! 144: +int
! 145: +socketOpen(serverName, portNumber)
! 146: + char *serverName;
! 147: + int portNumber;
! 148: +{
! 149: + static struct hostent *servhost;
! 150: + static struct sockaddr_in serv;
! 151: + static int s_wait;
! 152: + static int on;
! 153: + extern int errno;
! 154: + int tt;
! 155: +
! 156: + fprintf(TcpioError, "Hello from open. serverName is %s "
! 157: + "and portNumber is %d\n", serverName, portNumber);
! 158: +
! 159: + if ((servhost = gethostbyname(serverName)) == NULL) {
! 160: + fprintf(stderr, "Bad server name.\n");
! 161: + return (-1);
! 162: + }
! 163: +
! 164: + bzero((void *)&serv, sizeof(serv));
! 165: + serv.sin_family = AF_INET;
! 166: + serv.sin_port = htons(portNumber);
! 167: + bcopy(servhost->h_addr, &serv.sin_addr, servhost->h_length);
! 168: +
! 169: + if ((s_wait = socket(AF_INET,SOCK_STREAM, 0)) < 0) {
! 170: + fprintf(stderr, "Socket allocation is failed.\n");
! 171: + return (-1);
! 172: + }
! 173: +
! 174: + on = 1;
! 175: + setsockopt(s_wait, SOL_SOCKET,SO_REUSEADDR, &on, sizeof(on));
! 176: +
! 177: + /* important */
! 178: + if ((tt = bind(s_wait, (struct sockaddr *)&serv, sizeof(serv))) == -1) {
! 179: + fprintf(TcpioError, "bind error. Error no is %d. "
! 180: + "See /usr/include/sys/errno.h. "
! 181: + "(asm/errno.h)\n", errno);
! 182: + fprintf(stderr, "cannot bind\n");
! 183: + return (-1);
! 184: + }
! 185: +
! 186: +#if 0 /* XXX */
! 187: + printf("bind returns %d\n", tt);
! 188: +#endif
! 189: +
! 190: + tt = sizeof(serv);
! 191: + if (getsockname(s_wait, (struct sockaddr *)&serv, &tt) < 0) {
! 192: + fprintf(TcpioError, "getsockname error. Error no is %d. "
! 193: + "See /usr/include/sys/errno.h "
! 194: + "(asm/errno.h).\n", errno);
! 195: + fprintf(stderr, "cannot getsockname\n");
! 196: + return (-1);
! 197: + }
! 198: +
! 199: + if (listen(s_wait, 1) < 0) {
! 200: + fprintf(stderr, "Listen failed\n");
! 201: + return (-1);
! 202: + }
! 203: +
! 204: + fprintf(TcpioError, "Done the initialization. "
! 205: + "port =%d\n", ntohs(serv.sin_port));
! 206: + OpenedSocket = ntohs(serv.sin_port);
! 207: +
! 208: + return (s_wait);
! 209: +}
! 210: +
! 211: +int
! 212: +socketAccept(snum)
! 213: + int snum;
! 214: +{
! 215: + int s, news;
! 216: +
! 217: + s = snum;
! 218: +
! 219: + fprintf(TcpioError, "Trying to accept... ");
! 220: + fflush(TcpioError);
! 221: +
! 222: + if ((news = accept(s, NULL, NULL)) < 0) {
! 223: + fprintf(stderr, "Error in accept.\n");
! 224: + return (-1);
! 225: + }
! 226: +
! 227: + fprintf(TcpioError, "Accepted.\n");
! 228: + fflush(TcpioError);
! 229: +
! 230: + if (close(s) < 0) {
! 231: + fprintf(stderr, "Error in closing the old socket.\n");
! 232: + return (-1);
! 233: + }
! 234: +
! 235: + return(news);
! 236: +}
! 237: +
! 238: +int
! 239: +oxSocketSelect0(fd, t)
! 240: + int fd, t;
! 241: +{
! 242: + fd_set readfds;
! 243: + struct timeval timeout;
! 244: + int debug = 0;
! 245: + extern int errno;
! 246: +
! 247: + FD_ZERO(&readfds);
! 248: + FD_SET(fd, &readfds);
! 249: + timeout.tv_sec = 0;
! 250: + timeout.tv_usec = (long)t;
! 251: +
! 252: + if (t >= 0) {
! 253: + if (debug) {
! 254: + printf("select t >= 0 for fd = %d\n", fd);
! 255: + fflush(NULL);
! 256: + }
! 257: +
! 258: + /* It must be fd + 1!, Not fd. */
! 259: + if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) {
! 260: + fprintf(TcpioError, "select (non-block) error. "
! 261: + "Error no is %d. "
! 262: + "See /usr/include/sys/errno.h "
! 263: + "(asm/errno.h).\n", errno);
! 264: + fprintf(stderr, "oxSocketSelect0() : select failed.\n");
! 265: + return (0);
! 266: + }
! 267: +
! 268: + if (debug) {
! 269: + printf("Return from select t >= 0 for fd = %d\n", fd);
! 270: + fflush(NULL);
! 271: + }
! 272: + } else {
! 273: + /* block */
! 274: + if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) {
! 275: + fprintf(TcpioError, "select (block) error. "
! 276: + "Error no is %d. "
! 277: + "See /usr/include/sys/errno.h "
! 278: + "(asm/errno.h).\n", errno);
! 279: + fprintf(stderr, "socketSelect0() : select failed.\n");
! 280: + return (0);
! 281: + }
! 282: + }
! 283: +
! 284: + if (FD_ISSET(fd, &readfds)) {
! 285: + return(1);
! 286: + } else {
! 287: + return(0);
! 288: + }
! 289: +}
! 290: +
! 291: +int
! 292: +oxSocketMultiSelect(sid, size, t, result)
! 293: + int sid[], size, t, result[];
! 294: +{
! 295: + fd_set readfds;
! 296: + struct timeval timeout;
! 297: + int i, fd, p, isdata = 0;
! 298: + extern int errno;
! 299: +
! 300: + FD_ZERO(&readfds);
! 301: + timeout.tv_sec = 0;
! 302: + timeout.tv_usec = (long)t;
! 303: +
! 304: + fd = 0;
! 305: +
! 306: + for (i = 0 ; i < size ; i++) {
! 307: + if (sid[i] >= 0) {
! 308: + p = sid[i];
! 309: + if (p > fd)
! 310: + fd = p;
! 311: + FD_SET(p,&readfds);
! 312: +#if 0 /* XXX */
! 313: + printf("p = %d, fd=%d", p, fd);
! 314: +#endif
! 315: + }
! 316: + }
! 317: +
! 318: +#if 0 /* XXX */
! 319: + printf("MultiSelect..\n");
! 320: + fflush(NULL);
! 321: +#endif
! 322: +
! 323: + if (t >= 0) {
! 324: + /* It must be fd + 1!, Not fd. */
! 325: + if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) {
! 326: + fprintf(TcpioError, "Select error. Error no is %d. "
! 327: + "See /usr/include/sys/errno.h "
! 328: + "(asm/errno.h).\n", errno);
! 329: + fprintf(stderr, "oxSocketMultiSelect() : "
! 330: + "select failed.\n");
! 331: + return (0);
! 332: + }
! 333: + } else {
! 334: + /* block */
! 335: + if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) {
! 336: + fprintf(TcpioError, "Select error. Error no is %d. "
! 337: + "See /usr/include/sys/errno.h "
! 338: + "(asm/errno.h).\n", errno);
! 339: + fprintf(stderr, "oxSocketMultiSelect() : "
! 340: + "(block) select failed.\n");
! 341: + return (0);
! 342: + }
! 343: + }
! 344: +
! 345: +#if 0 /* XXX */
! 346: + printf("Done. MultiSelect.\n");
! 347: + fflush(NULL);
! 348: +#endif
! 349: +
! 350: + for (i = 0 ; i < size ; i++) {
! 351: + p = sid[i];
! 352: + if ((sid[i] >= 0) && FD_ISSET(p, &readfds)) {
! 353: + result[i] = 1;
! 354: + isdata = 1;
! 355: + } else {
! 356: + result[i] = 0;
! 357: + }
! 358: + }
! 359: +
! 360: + return (isdata);
! 361: +}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>