iface patches for System V

Reid rae at unicus.UUCP
Sat Mar 5 08:17:53 AEST 1988


Below are patches to iface to allow it to run under System V.  Beware --
this is my first patch posting. :-)

It's mostly fixing ioctl() calls and adding some flags to CFLAGS to
define index to strchr and that sort of thing.  I made a small addition
to newterm() and oldterm() to use a static termio/sgttyb structure to
save the original state of the terminal instead of assuming things.

I created 'patchlevel.h' and set PATCHLEVEL to 3, since I have applied
the previous two patches that were posted.

Reid Ellis
rae at unicus.com
================
Index: Makefile
*** Makefile.old
--- Makefile
**************
*** 1,4
! CFLAGS = -O
  BIN=iface
  
  iface: iface.o init.o fns.o exec.o iface.h comc.o io.o
--- 1,7 -----
! # For System V
! CFLAGS = -O -Dsgttyb=termio -DSYSV -Dindex=strchr -Drindex=strrchr -Drandom=rand -Dsrandom=srand
! # For BSD
! # CFLAGS = -O
  BIN=iface
  
  iface: iface.o init.o fns.o exec.o iface.h comc.o io.o
**************
*** 3,8
  
  iface: iface.o init.o fns.o exec.o iface.h comc.o io.o
  	cc -g -o ${BIN} iface.o init.o fns.o exec.o comc.o io.o
  
  lint:
  	lint iface.c init.c fns.c exec.c iface.h comc.c io.c
--- 6,12 -----
  
  iface: iface.o init.o fns.o exec.o iface.h comc.o io.o
  	cc -g -o ${BIN} iface.o init.o fns.o exec.o comc.o io.o
+ 	@echo All done.
  
  lint:
  	lint iface.c init.c fns.c exec.c iface.h comc.c io.c

Index: exec.c
*** exec.c.old
--- exec.c
**************
*** 1,5
  #include "iface.h"
  
  print_version()
  {
  	int ref;
--- 1,7 -----
  #include "iface.h"
  
+ static struct sgttyb savedterm;
+ 
  print_version()
  {
  	int ref;
**************
*** 57,62
  
  oldterm()
  {
  	ioctl(fileno(stdin),TIOCGETP,&iobasic);
  	iobasic.sg_flags = oldflags;
  	ioctl(fileno(stdin),TIOCSETP,&iobasic);
--- 59,68 -----
  
  oldterm()
  {
+ #ifdef SYSV
+ 	/* Use the saved terminal state */
+ 	ioctl(fileno(stdin),TCSETA,&savedterm);
+ #else
  	ioctl(fileno(stdin),TIOCGETP,&iobasic);
  	iobasic.sg_flags = oldflags;
  	ioctl(fileno(stdin),TIOCSETP,&iobasic);
**************
*** 65,70
  	termc.t_suspc = 26;
  	termc.t_dsuspc = 25;
  	ioctl(fileno(stdin),TIOCSLTC,&termc);
  }
  
  newterm()
--- 71,77 -----
  	termc.t_suspc = 26;
  	termc.t_dsuspc = 25;
  	ioctl(fileno(stdin),TIOCSLTC,&termc);
+ #endif
  }
  
  newterm()
**************
*** 69,74
  
  newterm()
  {
  	ioctl(fileno(stdin),TIOCGETP,&iobasic);
  	oldflags = iobasic.sg_flags;
  	iobasic.sg_flags |= CBREAK;
--- 76,98 -----
  
  newterm()
  {
+ #ifdef SYSV
+ 	/* Save a copy of the current serial state
+ 	 * in 'savedterm'.
+ 	 * ioctl() is called twice, since structure
+ 	 * assigns aren't very portable :-)
+ 	 */
+ 	ioctl(fileno(stdin),TCGETA,&savedterm);
+ 	ioctl(fileno(stdin),TCGETA,&iobasic);
+ 
+ 	/* how to do CBREAK and ~ECHO in System V */
+ 	iobasic.c_cc[VMIN]=1;
+ 	iobasic.c_cc[VTIME]=1;
+ 	iobasic.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
+ 
+ 	/* set the terminal state */
+ 	ioctl(fileno(stdin),TCSETA,&iobasic);
+ #else
  	ioctl(fileno(stdin),TIOCGETP,&iobasic);
  	oldflags = iobasic.sg_flags;
  	iobasic.sg_flags |= CBREAK;
**************
*** 79,84
  	termc.t_suspc = -1;
  	termc.t_dsuspc = -1;
  	ioctl(fileno(stdin),TIOCSLTC,&termc);
  }
  
  extended_command()
--- 103,109 -----
  	termc.t_suspc = -1;
  	termc.t_dsuspc = -1;
  	ioctl(fileno(stdin),TIOCSLTC,&termc);
+ #endif
  }
  
  extended_command()

Index: iface.c
*** iface.c.old
--- iface.c
**************
*** 13,18
  int sortcmd = 0;
  #endif
  
  struct ltchars termc;
  struct sgttyb iobasic;
  jmp_buf topenv;
--- 13,19 -----
  int sortcmd = 0;
  #endif
  
+ #ifndef SYSV
  struct ltchars termc;
  #endif
  struct sgttyb iobasic;
**************
*** 14,19
  #endif
  
  struct ltchars termc;
  struct sgttyb iobasic;
  jmp_buf topenv;
  void sigtrap();
--- 15,21 -----
  
  #ifndef SYSV
  struct ltchars termc;
+ #endif
  struct sgttyb iobasic;
  jmp_buf topenv;
  void sigtrap();

Index: iface.h
*** iface.h.old
--- iface.h
**************
*** 1,5
  #include <setjmp.h>
! #include <sgtty.h>
  #include <signal.h>
  #include <stdio.h>
  #define NSYM 256
--- 1,9 -----
  #include <setjmp.h>
! #ifdef SYSV
! #	include <termio.h>
! #else
! #	include <sgtty.h>
! #endif
  #include <signal.h>
  #include <stdio.h>
  
**************
*** 2,7
  #include <sgtty.h>
  #include <signal.h>
  #include <stdio.h>
  #define NSYM 256
  #define COMMAND 0
  #define VARIABLE 1
--- 6,12 -----
  #endif
  #include <signal.h>
  #include <stdio.h>
+ 
  #define NSYM 256
  #define COMMAND 0
  #define VARIABLE 1
**************
*** 5,10
  #define NSYM 256
  #define COMMAND 0
  #define VARIABLE 1
  extern char *cmds[256], *syms[NSYM], lastkey;
  extern int (*cptr[256])(), binding[128][4];
  extern int oldflags, ncmds, nsyms;
--- 10,16 -----
  #define NSYM 256
  #define COMMAND 0
  #define VARIABLE 1
+ 
  extern char *cmds[256], *syms[NSYM], lastkey;
  extern int (*cptr[256])(), binding[128][4];
  extern int oldflags, ncmds, nsyms;
**************
*** 12,18
  extern int sortcmd;
  #endif
  
! extern struct ltchars termc;
  extern struct sgttyb iobasic;
  jmp_buf topenv;
  void sigtrap();
--- 18,26 -----
  extern int sortcmd;
  #endif
  
! #ifndef SYSV
! 	extern struct ltchars termc;
! #endif
  extern struct sgttyb iobasic;
  jmp_buf topenv;
  void sigtrap();

Index: patchlevel.h
*** patchlevel.h.old
--- patchlevel.h
**************
*** 0,1
--- 1 -----
+ #define PATCHLEVEL 3



More information about the Comp.sources.bugs mailing list