[BACK]Return to plot.c.diff CVS log [TXT][DIR] Up to [local] / OpenXM / src / gnuplot-diff

Annotation of OpenXM/src/gnuplot-diff/plot.c.diff, Revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>