From andyb@wndrsvr.la.ca.us Fri Jun  5 11:04:08 1992
Date: Thu, 4 Jun 92 20:08:40 PDT
From: Andy Brager <andyb@wndrsvr.la.ca.us>
To: Laurence Lundblade <lgl@cac.washington.edu>
Subject: Re: port to System V complete

> I've tacked on the Raw() function we are using in Pine now. (It's tacked on as a
> MIME attachment, but I'm sure you can extract it without MIME.) It supports the
> regular termio and the termio based on streams. I didn't actually do the port,
> but looks like they've turned off all the signals with ~ISIG.

Uh oh.  ISIG does not look familar to me.  Is this for SysV4?  I have SysV3.

> I suggest you get the stuff to us as soon as possible, we integrate it and you
> continue work on a pre-release of Pine 3.0. You are also welcome to grab the

I am including all the pico files.  Let me know if there is a problem 
patching them in.  I'm not sure that I did the correct diff.  Please let 
me know if it works and I'll ship you the rest (pine and c-client).


> On the signatures, my signature is supposed to be just after this paragraph
> and before your included message. That is because I started typing before the
> signature. The situation where this doesn't work is when you intersperse the
> reply in the original message like you did. Then it wind up on top, which is
> clearly the wrong place. In Pine 2.28 there's an option you can set in the

Hmmm.  I'm not that's the problem...  When I started typing, the .sig
was above where I started typing because that's where the cursor ended
up.  I hope the alternate editor support is nearing completion, as I'm
pretty much a die-hard vi fan.  Can I suggest an enhancement for pico?
Give it block copying, cut, paste and move capabilities.  Lack of that 
drives me nuts.

> .pinerc to have it at the bottom. We figure it depends on whether you do more
> interspersed replies, or more replies like this one.

I wonder if you're trying to tell me that pine will reformat after I
leave the editor?  That's the only way I could understand it working
the way you describe.  Guess I'll have to experiment more.  

Here's all the pico diffs.  Note that I tried to make only necessary changes
except in places where I had to change variable names from single chars
to double chars so I could use sdb.   A makefile for isc is also included.
Sorry I didn't compress this stuff, I'm in a hurry these days and this 
was easiest right now.

-  Andy

*** os_unix.c	Thu Jun  4 19:42:39 1992
--- new/os_unix.c	Fri May 29 16:49:13 1992
***************
*** 1,7 ****
! static char rcsid[] = "$Id: os_unix.c,v 1.1 1992/04/27 20:12:32 andyb Exp $";
  
  #ifdef COMMENT
  $Log: os_unix.c,v $
   * Revision 1.1  1992/04/27  20:12:32  andyb
   * Initial revision
   *
--- 1,10 ----
! static char rcsid[] = "$Id: os_unix.c,v 1.2 1992/04/27 20:55:02 andyb Exp andyb $";
  
  #ifdef COMMENT
  $Log: os_unix.c,v $
+  * Revision 1.2  1992/04/27  20:55:02  andyb
+  * Modifications for ISC Unix.
+  *
   * Revision 1.1  1992/04/27  20:12:32  andyb
   * Initial revision
   *
***************
*** 53,62 ****
  #include        "edef.h"
  #include        "pico.h"
  
! #include        <sgtty.h>        /* for stty/gtty functions */
  
  struct  sgttyb  ostate;          /* saved tty state */
  struct  sgttyb  nstate;          /* values for editor mode */
  struct tchars	otchars;	/* Saved terminal special character set */
  struct tchars	ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  				/* A lot of nothing */
--- 56,99 ----
  #include        "edef.h"
  #include        "pico.h"
  
! #ifdef ISC
! #include	<termio.h>	/* For TIOCGETC and friends  */
! #include        <sys/ttold.h>        /* for stty/gtty functions */
! #include 	<sys/sioctl.h>	/* sockets; need for struct winsize and stuff */
! 
! #define CRMOD	020	/* sgtty.h is screwed up.  These are needed though */
! #define RAW	040
! 
! struct  termio  oterm;          /* saved tty state */
! 
! 
! /* This structure blatantly stolen from <sys/ttold.h> ; if ISC or AT&T
!    doesn't like it, tough.  Fix the include files.
! 
!    Unfortunately, ttold.h also has "struct sgttyb" which conflicts
!    with <sgtty.h>, but it does not contain enough to replace <sgtty.h>.   
!    This appears to be the best compromise.
! */
! 
! /*
!  * List of special characters
!  */
! 
! struct tchars	{
! 	unsigned char	t_intrc;
! 	unsigned char	t_quitc;
! 	unsigned char	t_startc;
! 	unsigned char	t_stopc;
! 	unsigned char	t_eofc;
! 	unsigned char	t_brkc;
! };
! 
! 
! #endif
  
  struct  sgttyb  ostate;          /* saved tty state */
  struct  sgttyb  nstate;          /* values for editor mode */
+ 
  struct tchars	otchars;	/* Saved terminal special character set */
  struct tchars	ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  				/* A lot of nothing */
***************
*** 78,83 ****
--- 115,125 ----
  SIGTYPE	winch_handler();
  #endif
  
+ #ifdef	ISC
+ SIGTYPE	do_int_signal();
+ void	(*save_sigint)();
+ #endif
+ 
  
  /*
   * This function is called once to set up the terminal device streams.
***************
*** 84,100 ****
   */
  ttopen()
  {
! 	if(!for_pine){
  	    ioctl(0, TIOCGETP, &ostate);	/* save old state */
  	    ioctl(0, TIOCGETP, &nstate);	/* get base of new state */
  	    nstate.sg_flags |= RAW;
  	    nstate.sg_flags &= ~(ECHO|CRMOD);	/* no echo for now... */
  	    ioctl(0, TIOCSETP, &nstate); 	/* set mode */
- 	    
  	    ioctl(0, TIOCGETC, &otchars); 	/* Save old characters */
  	    ioctl(0, TIOCSETC, &ntchars); 	/* put new character into K */
- 	}
  
  	signal(SIGHUP, (SIGTYPE *)do_hup_signal); /* deal with SIGHUP */
  	signal(SIGALRM, (SIGTYPE *)do_alarm_signal); /* timer for new mail */
  #ifdef	TIOCGWINSZ
--- 126,153 ----
   */
  ttopen()
  {
! #ifdef ISC
! /* 
! echoe parenb eof are all getting screwed up on exit.  This fixes that problem.
! Since termio structure contains more functionality then the sgtty struct, 
! you cannot fully restore the orginal settings without saving them in the 
! following manner first.
! */
! 
!             ioctl(0, TCGETA, &oterm);	/* save old state */
! #endif
  	    ioctl(0, TIOCGETP, &ostate);	/* save old state */
  	    ioctl(0, TIOCGETP, &nstate);	/* get base of new state */
  	    nstate.sg_flags |= RAW;
  	    nstate.sg_flags &= ~(ECHO|CRMOD);	/* no echo for now... */
  	    ioctl(0, TIOCSETP, &nstate); 	/* set mode */
  	    ioctl(0, TIOCGETC, &otchars); 	/* Save old characters */
  	    ioctl(0, TIOCSETC, &ntchars); 	/* put new character into K */
  
+ #ifdef ISC
+ 	/* deal with SIGINT */
+ 	save_sigint = (void (*)())signal(SIGINT, (SIGTYPE *)do_int_signal);
+ #endif
  	signal(SIGHUP, (SIGTYPE *)do_hup_signal); /* deal with SIGHUP */
  	signal(SIGALRM, (SIGTYPE *)do_alarm_signal); /* timer for new mail */
  #ifdef	TIOCGWINSZ
***************
*** 113,118 ****
--- 166,174 ----
  ttclose()
  {
      if(for_pine){
+ #ifdef ISC
+         (void)signal(SIGINT, save_sigint);
+ #endif
  	signal(SIGHUP, SIG_DFL);
  	signal(SIGCONT, SIG_DFL);
  	signal(SIGALRM, SIG_DFL);
***************
*** 122,127 ****
--- 178,186 ----
  	ioctl(0, TIOCSETP, &ostate);
  	ioctl(0, TIOCSETC, &otchars);
      }
+ #ifdef ISC
+ 	ioctl(0, TCSETAW, &oterm);	/* set old state */
+ #endif
  }
  
  
***************
*** 174,201 ****
   */
  GetKey()
  {
! 	int    c;
  
  	if(timeout){
  	    if(setjmp(alrm_state) == 0){
  		alarm(timeout);
  		errno = 0;
! 		c = (*term.t_getchar)();
  		if(errno == EINTR)
! 		  c = NODATA;
  	    }
  	    else
! 	      c = NODATA; 		/* alarm went off so go back */
  
  	    alarm(0);			/* shut off the alarm */
! 	    if(c == NODATA)
! 	      return(c);
  	}
  	else{
! 	    c = (*term.t_getchar)();
  	}
  
! 	if (c == METACH) {                      /* Apply M- prefix      */
  	    int status;
  	    
  	    /*
--- 233,260 ----
   */
  GetKey()
  {
! 	int    cc;
  
  	if(timeout){
  	    if(setjmp(alrm_state) == 0){
  		alarm(timeout);
  		errno = 0;
! 		cc = (*term.t_getchar)();
  		if(errno == EINTR)
! 		  cc = NODATA;
  	    }
  	    else
! 	      cc = NODATA; 		/* alarm went off so go back */
  
  	    alarm(0);			/* shut off the alarm */
! 	    if(cc == NODATA)
! 	      return(cc);
  	}
  	else{
! 	    cc = (*term.t_getchar)();
  	}
  
! 	if (cc == METACH) {                      /* Apply M- prefix      */
  	    int status;
  	    
  	    /*
***************
*** 202,210 ****
  	     * this code should intercept special keypad keys
  	     */
  
! 	    switch(status = kbseq(&c)){
  	      case 0 : 	/* no dice */
!     		return(c);
  	      case  K_PAD_UP		:
  	      case  K_PAD_DOWN		:
  	      case  K_PAD_RIGHT		:
--- 261,269 ----
  	     * this code should intercept special keypad keys
  	     */
  
! 	    switch(status = kbseq(&cc)){
  	      case 0 : 	/* no dice */
!     		return(cc);
  	      case  K_PAD_UP		:
  	      case  K_PAD_DOWN		:
  	      case  K_PAD_RIGHT		:
***************
*** 233,242 ****
  	    }
          }
  
!         if (c>=0x00 && c<=0x1F)                 /* C0 control -> C-     */
!           c = CTRL | (c+'@');
  
! 	    return (c);
  
  }
  
--- 292,301 ----
  	    }
          }
  
!         if (cc>=0x00 && cc<=0x1F)                 /* C0 control -> C-     */
!           cc = CTRL | (cc+'@');
  
! 	    return (cc);
  
  }
  
***************
*** 415,421 ****
--- 474,497 ----
      longjmp(alrm_state, 1);
  }
  
+ #ifdef ISC
+ /*
+  * do_int_signal - jump back in the stack to where we can handle this
+  */
+  /*  I don't know how this works for other OS's!  Seems like a bug, no? */
+ 
+ SIGTYPE do_int_signal()
+ {
+ extern	jmp_buf	finstate;    /* stack environment to return codes [pico.c] */
+ 			/* This will handle SIGINT */
+ 
+     if(for_pine){
+ 	signal(SIGINT, (SIGTYPE *)do_int_signal);
+ 	abort_composer(1,0);
+     }
+ }
  
+ #endif
  
  /*
   * do_hup_signal - jump back in the stack to where we can handle this
***************
*** 653,659 ****
--- 729,739 ----
      struct stat sbuf;
      char   inbox[256];
  
+ #ifdef ISC
+     sprintf(inbox,"/usr/mail/%s", getlogin());
+ #else
      sprintf(inbox,"/usr/spool/mail/%s", getlogin());
+ #endif
      if(stat(inbox, &sbuf) == 0){
  	ret = sbuf.st_atime <= sbuf.st_mtime &&
  	  (lastchk < sbuf.st_mtime && lastchk < sbuf.st_atime);



*** pico.c	Thu Jun  4 19:47:36 1992
--- new/pico.c	Tue May 19 19:57:07 1992
***************
*** 1,4 ****
! static char rcsid[] = "$Id: pico.c,v 1.1 1992/04/27 20:12:32 andyb Exp $";
  
  #ifdef COMMENT
  $Log: pico.c,v $
--- 1,4 ----
! static char rcsid[] = "$Id: pico.c,v 1.1 1992/04/27 20:12:32 andyb Exp andyb $";
  
  #ifdef COMMENT
  $Log: pico.c,v $
***************
*** 75,80 ****
--- 75,83 ----
   * 3.0  Daniel Lawrence, 29-Dec-85
   *	16-apr-86
   *	- updated documentation and froze development for 3.6 net release
+  *      
+  *      Andy Brager, 18-May-92
+  *	- Ported to ISC Unix V3 3.0
   */
  
  #include        <stdio.h>
***************
*** 139,145 ****
  int     use_suspend;                    /* flag to allow suspension     */
  int     _use_fkeys;                      /* flag to signal func key use  */
  {
!     register int    c;
      register int    f;
      register int    n;
      register BUFFER *bp;
--- 142,148 ----
  int     use_suspend;                    /* flag to allow suspension     */
  int     _use_fkeys;                      /* flag to signal func key use  */
  {
!     register int    cc;
      register int    f;
      register int    n;
      register BUFFER *bp;
***************
*** 240,256 ****
      while(1){
  	update();				/* Fix up the screen    */
  
! 	c = GetKey();	
  
! 	if(c == NODATA || time_to_check()){	/* new mail ? */
! 	    if(new_mail(&i, 0, c == NODATA ? 0 : 2)){
  		emlwrite("");
! 		display_message(c);
  		mpresf = 1;
  	    }
  	    if(i)
  	      movecursor(0, 0);
! 	    if(c == NODATA)		/* no op, getkey timed out */
  	      continue;
  	}
  
--- 243,259 ----
      while(1){
  	update();				/* Fix up the screen    */
  
! 	cc = GetKey();	
  
! 	if(cc == NODATA || time_to_check()){	/* new mail ? */
! 	    if(new_mail(&i, 0, cc == NODATA ? 0 : 2)){
  		emlwrite("");
! 		display_message(cc);
  		mpresf = 1;
  	    }
  	    if(i)
  	      movecursor(0, 0);
! 	    if(cc == NODATA)		/* no op, getkey timed out */
  	      continue;
  	}
  
***************
*** 263,269 ****
  	f = FALSE;
  	n = 1;
  	
! 	execute(c, f, n);		/* Do it.               */
      }
  }
  
--- 266,272 ----
  	f = FALSE;
  	n = 1;
  	
! 	execute(cc, f, n);		/* Do it.               */
      }
  }
  
***************
*** 431,445 ****
          wquit(f, n);                             /* conditionally quit   */
  }
  
- 
- 
  /* 
   * abort_composer - ask the question here, then go quit or 
   *                  return FALSE
   */
  abort_composer(f,n)
  {
! 	if(mldyesno("Cancelling will abandon your mail message.  Cancel", 
  		    FALSE) == TRUE)
  	  longjmp(finstate, COMP_CANCEL);
  	else
--- 434,447 ----
          wquit(f, n);                             /* conditionally quit   */
  }
  
  /* 
   * abort_composer - ask the question here, then go quit or 
   *                  return FALSE
   */
+ 
  abort_composer(f,n)
  {
! 	if(mldyesno("Cancelling will abandon your message.  Cancel", 
  		    FALSE) == TRUE)
  	  longjmp(finstate, COMP_CANCEL);
  	else



*** tcap.c	Thu Jun  4 19:50:36 1992
--- new/tcap.c	Tue May 19 19:57:07 1992
***************
*** 1,7 ****
! static char rcsid[] = "$Id: tcap.c,v 1.1 1992/04/27 20:12:32 andyb Exp $";
  
  #ifdef COMMENT
  $Log: tcap.c,v $
   * Revision 1.1  1992/04/27  20:12:32  andyb
   * Initial revision
   *
--- 1,10 ----
! static char rcsid[] = "$Id: tcap.c,v 1.2 1992/04/27 20:55:02 andyb Exp andyb $";
  
  #ifdef COMMENT
  $Log: tcap.c,v $
+  * Revision 1.2  1992/04/27  20:55:02  andyb
+  * Modifications for ISC Unix.
+  *
   * Revision 1.1  1992/04/27  20:12:32  andyb
   * Initial revision
   *
***************
*** 53,63 ****
  #include	"osdep.h"
  
  #if TERMCAP
- #include <sys/ioctl.h>
  #include        "pico.h"
  #include        <signal.h>
! #include        <sgtty.h>
  #include        <sys/ttydev.h>
  
  #define NROW    24
  #define NCOL    80
--- 56,72 ----
  #include	"osdep.h"
  
  #if TERMCAP
  #include        "pico.h"
  #include        <signal.h>
! #include        <sgtty.h> /* Both <sys/ttold.h> and <sgtty.h> seem to work */
! #ifndef ISC
  #include        <sys/ttydev.h>
+ #else
+ #define B9600 15 /* This is in <termio.h>, <termios.h> (yes, with an 's'), 
+ 			<sgtty.h> and <sys/termio.h>.  In <sgtty.h> it is 
+ 			defined as 13.	Everywhere else as 15.  What a mess.
+ 			*/
+ #endif
  
  #define NROW    24
  #define NCOL    80



#
# Makefile for Berkeley UNIX (4.3bsd) of the PINE composer library and 
# stand-alone editor pico.
#

DASHO=		

#includes symbol info for debugging 
CFLAGS=		-g -I/usr/include -Dbsd -DISC

#for the normal library
#CFLAGS=	-O -I/usr/include -Dbsd

# switches for library building
LIB=ar
LIBARGS=ru

OFILES=		ansi.o basic.o bind.o buffer.o composer.o display.o \
		file.o fileio.o line.o osdep.o pico.o random.o search.o \
		spell.o tcap.o window.o word.o

CFILES=		ansi.c basic.c bind.c buffer.c composer.c display.c \
		file.c fileio.c line.c osdep.c pico.c random.c search.c \
		spell.c tcap.c window.c word.c

HFILES=		estruct.h edef.h efunc.h ebind.h pico.h

RANLIB=		echo

#
# dependencies for the Unix versions of pico and libpico.a
#
all:		pico

osdep.c:	os_unix.c
		rm -f osdep.c
		cp os_unix.c osdep.c

osdep.h:	os_bsd.h
		rm -f osdep.h
		cp os_bsd.h osdep.h

libpico.a:	osdep.c osdep.h $(OFILES)
		$(LIB) $(LIBARGS) libpico.a $(OFILES)
		$(RANLIB) libpico.a

pico:		main.c libpico.a
		$(CC) $(CFLAGS) main.c libpico.a -ltermcap -lc -o pico

.c.o:		; $(CC) -c $(CFLAGS) $(DASHO) $*.c

$(OFILES):	$(HFILES)

clean:
		rm -f *.a *.o *~ osdep.c osdep.h

