home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff220.lzh / DNet / client / draw.c < prev    next >
C/C++ Source or Header  |  1989-06-04  |  2KB  |  89 lines

  1.  
  2. /*
  3.  *    DRAW.C
  4.  *
  5.  *    DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
  6.  *
  7.  *    DRAW [port#]
  8.  *
  9.  *    Put terminal into RAW mode and connect to the remote dnet port.
  10.  *    used mainly to test DNET.  Can also be used open a TERM window on
  11.  *    the amiga (via the STERM server), which is the default (port 8195)
  12.  */
  13.  
  14.  
  15.  
  16. #include <sys/types.h>
  17. #include <sys/ioctl.h>
  18. #include <stdio.h>
  19. #include <sys/file.h>
  20. #include <signal.h>
  21. #include <errno.h>
  22. #include "../server/servers.h"
  23.  
  24. int fd;
  25. char buf[4096];
  26.  
  27. main(ac,av)
  28. char *av[];
  29. {
  30.     int n;
  31.     extern int handler();
  32.     int port = (av[1]) ? atoi(av[1]) : PORT_AMIGATERM;
  33.  
  34.     puts("DRAW V1.01 11 March 1988 Connecting");
  35.     fd = DOpen(NULL, port, 0, 0);
  36.     if (fd < 0) {
  37.     perror("DOpen");
  38.     exit(1);
  39.     }
  40.     puts("Connected");
  41.     signal(SIGIO, handler);
  42.     ttyraw();
  43.     fcntl(fd, F_SETOWN, getpid());
  44.     fcntl(fd, F_SETFL, FNDELAY|FASYNC);
  45.     fcntl(0,  F_SETFL, FNDELAY);
  46.     while ((n = gread(0, buf, sizeof(buf))) > 0) {
  47.     gwrite(fd, buf, n);
  48.     }
  49.     fprintf(stderr, "EOF\n");
  50.     DEof(fd);
  51.     for (;;)
  52.     pause();
  53. }
  54.  
  55. handler()
  56. {
  57.     int n;
  58.     char buf[1024];
  59.  
  60.     while ((n = read(fd, buf, sizeof(buf))) > 0) 
  61.     write(1, buf, n);
  62.     if (n == 0) {
  63.     write(1, "REMEOF\n", 7);
  64.     ttynormal();
  65.     exit(1);
  66.     }
  67. }
  68.  
  69. static struct sgttyb ttym;
  70.  
  71. ttyraw()
  72. {
  73.     ioctl (0, TIOCGETP, &ttym);
  74.     ttym.sg_flags |= RAW;
  75.     ttym.sg_flags &= ~CBREAK;
  76.     ttym.sg_flags &= ~ECHO;
  77.     ioctl (0, TIOCSETP, &ttym);
  78. }
  79.  
  80. ttynormal()
  81. {
  82.     ioctl (0, TIOCGETP, &ttym);
  83.     ttym.sg_flags &= ~RAW;
  84.     ttym.sg_flags |= CBREAK;
  85.     ttym.sg_flags |= ECHO;
  86.     ioctl (0, TIOCSETP, &ttym);
  87. }
  88.  
  89.