home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / SOURCES / QSUBST / RTR / QSUBST. next >
Encoding:
Text File  |  1998-07-24  |  2.5 KB  |  121 lines

  1. --- qsubst.c.orig    Mon Feb  3 07:38:04 1997
  2. +++ qsubst.c    Mon Feb  3 08:34:49 1997
  3. @@ -77,10 +77,16 @@
  4.   *  are off.
  5.   */
  6.  #include <stdio.h>
  7. -#include <sgtty.h>
  8.  #include <signal.h>
  9. +#include <termios.h> 
  10. +#include <unistd.h>
  11. +#include <sys/types.h>
  12.  #include <sys/file.h>
  13.  
  14. +#define CBREAK O_CBREAK /* Because SysV doesn't have CBREAK??? */
  15. +#define bcopy(s1,s2,n)  memcpy(s2,s1,n)
  16. +#define bcmp            memcmp
  17. +
  18.  #ifndef sigmask
  19.  #define sigmask(sig) (1<<((sig)-1))
  20.  #endif
  21. @@ -120,7 +126,7 @@
  22.  char *endul;
  23.  char tcp_buf[1024];
  24.  char cap_buf[1024];
  25. -struct sgttyb orig_sg;
  26. +struct termios orig_sg;
  27.  
  28.  tstp_self()
  29.  {
  30. @@ -136,15 +142,15 @@
  31.  
  32.  sigtstp()
  33.  {
  34. - struct sgttyb sg;
  35. + struct termios sg;
  36.  
  37. - if (ioctl(fileno(stdin),TIOCGETP,&sg) < 0)
  38. + if (tcgetattr(fileno(stdin),&sg) < 0)
  39.    { tstp_self();
  40.      return;
  41.    }
  42. - ioctl(fileno(stdin),TIOCSETN,&orig_sg);
  43. + tcsetattr(fileno(stdin),TCSANOW,&orig_sg);
  44.   tstp_self();
  45. - ioctl(fileno(stdin),TIOCSETN,&sg);
  46. + tcsetattr(fileno(stdin),TCSANOW,&sg);
  47.  }
  48.  
  49.  main(ac,av)
  50. @@ -153,6 +159,7 @@
  51.  {
  52.   int skip;
  53.   char *cp;
  54. + char *cp_work;
  55.  
  56.   argvec = av;
  57.   if (ac < 3)
  58. @@ -194,7 +201,9 @@
  59.      }
  60.       }
  61.    }
  62. - cp = mktemp("/tmp/qsubst.XXXXXX");
  63. + cp_work = malloc(32);
  64. + strcpy (cp_work, "/tmp/qsubst.XXXXXX");
  65. + cp = mktemp(cp_work);
  66.   tempf = fopen(cp,"w+");
  67.   if (tempf == NULL)
  68.    { fprintf(stderr,"%s: cannot create temp file %s\n",argvec[0],cp);
  69. @@ -218,7 +227,7 @@
  70.                          argvec[0],BUF_SIZ/2);
  71.      exit(1);
  72.    }
  73. - ioctl(fileno(stdin),TIOCGETP,&orig_sg);
  74. + tcgetattr(fileno(stdin),&orig_sg);
  75.   signal(SIGTSTP,sigtstp);
  76.   allfly = 0;
  77.   cabove = 2;
  78. @@ -389,19 +398,19 @@
  79.  
  80.  char getc_cbreak()
  81.  {
  82. - struct sgttyb sg;
  83. - struct sgttyb osg;
  84. + struct termios sg;
  85. + struct termios osg;
  86.   char c;
  87.  
  88. - if (ioctl(fileno(stdin),TIOCGETP,&sg) < 0)
  89. + if (tcgetattr(fileno(stdin),&sg) < 0)
  90.    { return(getchar());
  91.    }
  92.   osg = sg;
  93. - sg.sg_flags |= CBREAK;
  94. - sg.sg_flags &= ~ECHO;
  95. - ioctl(fileno(stdin),TIOCSETN,&sg);
  96. + sg.c_lflag &= ~ICANON;
  97. + sg.c_lflag &= ~ECHO;
  98. + tcsetattr(fileno(stdin),TCSANOW,&sg);
  99.   c = getchar();
  100. - ioctl(fileno(stdin),TIOCSETN,&osg);
  101. + tcsetattr(fileno(stdin),TCSANOW,&osg);
  102.   return(c);
  103.  }
  104.  
  105. --- Makefile.orig    Mon Feb  3 07:38:03 1997
  106. +++ Makefile    Mon Feb  3 07:38:04 1997
  107. @@ -1,5 +1,10 @@
  108. +BINDIR =<installdir>/bin 
  109. +MANDIR =<installsharedir>/man/man1
  110.  all:    qsubst
  111. -install:    qsubst qsubst.1
  112. -    @echo copy qsubst and qsubst.1 to appropriate directories.
  113. +install:
  114. +    install -s qsubst $(BINDIR)
  115. +    install qsubst.1 $(MANDIR)
  116. +
  117.  qsubst:        qsubst.c
  118. -    $(CC) $(CFLAGS) -o qsubst qsubst.c
  119. +    $(CC) $(CFLAGS) -o qsubst qsubst.c -ltermcap
  120.