[comp.os.minix] Official Clam Patch #3 - 2 of 3

wtoomey@gara.une.oz (Warren Toomey) (09/13/89)

# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# exec.cdif file.cdif global.cdif hash.cdif header.h

echo x - exec.cdif
cat > "exec.cdif" << '//E*O*F exec.cdif//'
*** ../Clam/exec.c	Tue Sep 12 21:42:33 1989
--- exec.c	Wed Sep 13 12:21:30 1989
***************
*** 170,176 ****
    SYM_T act;
    struct adefn *ptr;
    struct tchars setsigc;
!   char line[MAXLL],pipeline[MAXLL],**oldargstemp,*oldcurraltemp;
    int i,pos,ppos,pid=0,oldnumargtemp,retval;
    bool skip_to_semi;
  
--- 170,176 ----
    SYM_T act;
    struct adefn *ptr;
    struct tchars setsigc;
!   char line[MAXLL],pipeline[MAXLL],**oldargstemp;
    int i,pos,ppos,pid=0,oldnumargtemp,retval;
    bool skip_to_semi;
  
***************
*** 356,362 ****
        return(FOUND);
      }
      strcpy(fullpathname,name);
!     if (executable(fullpathname,"",1)==FALSE) return(NOTEXEC);
      return(FOUND);
    }
  
--- 356,362 ----
        return(FOUND);
      }
      strcpy(fullpathname,name);
!     if (executable(fullpathname,NULL,1)==FALSE) return(NOTEXEC);
      return(FOUND);
    }
  
***************
*** 433,439 ****
  #ifdef DEBUG
  fprintf(stderr,"doing executable with %s<\n",fullpathname);
  #endif
! 	if (executable(fullpathname,"",1)==FALSE)
  	{
  #ifdef DEBUG
  fprintf(stderr,"executable failed\n");
--- 433,439 ----
  #ifdef DEBUG
  fprintf(stderr,"doing executable with %s<\n",fullpathname);
  #endif
! 	if (executable(fullpathname,NULL,1)==FALSE)
  	{
  #ifdef DEBUG
  fprintf(stderr,"executable failed\n");
***************
*** 679,685 ****
        mode=0777;
        if (open(efil,flags,mode)==-1)
        {
! 	write(2,"Can't open ");
  	write(2,efil,strlen(efil));
  	exit(0);
        }
--- 679,685 ----
        mode=0777;
        if (open(efil,flags,mode)==-1)
        {
! 	write(2,"Can't open ",11);
  	write(2,efil,strlen(efil));
  	exit(0);
        }
***************
*** 693,705 ****
  #ifdef __STDC__
  int execute(int argc, char **argv, int infd, int outfd, int errfd,
  	    char *ifil, char *ofil, char *efil, bool appnd,
! 	    bool bckgnd, bool piped, int fromfile)
  #else
! int execute(argc,argv,infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd,piped,fromfile)
    int argc,infd,outfd,errfd;
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
!   int fromfile;
  #endif
  {
    extern void makenv();
--- 693,705 ----
  #ifdef __STDC__
  int execute(int argc, char **argv, int infd, int outfd, int errfd,
  	    char *ifil, char *ofil, char *efil, bool appnd,
! 	    bool bckgnd, bool piped, int frmfile)
  #else
! int execute(argc,argv,infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd,piped,frmfile)
    int argc,infd,outfd,errfd;
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
!   int frmfile;
  #endif
  {
    extern void makenv();
***************
*** 760,766 ****
  fprintf(stderr,"maybe setexec from execute\n");
  #endif
  	       /*if (bckgnd==TRUE) setbgexec();
! 	       else*/ if (!NoIoctl && piped==FALSE && !fromfile) setexec(pid=getpid());
  	       redirect(infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd);
  	       if (alias_defn!=0)
  	       {
--- 760,766 ----
  fprintf(stderr,"maybe setexec from execute\n");
  #endif
  	       /*if (bckgnd==TRUE) setbgexec();
! 	       else*/ if (!NoIoctl && piped==FALSE && !frmfile) setexec(pid=getpid());
  	       redirect(infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd);
  	       if (alias_defn!=0)
  	       {
***************
*** 821,827 ****
    }
    else
    {
!     if (fromfile)
      {
        write(2,invokename,strlen(invokename));
        write(2,": ",2);
--- 821,827 ----
    }
    else
    {
!     if (frmfile)
      {
        write(2,invokename,strlen(invokename));
        write(2,": ",2);
//E*O*F exec.cdif//

echo x - file.cdif
cat > "file.cdif" << '//E*O*F file.cdif//'
*** ../Clam/file.c	Tue Sep 12 21:41:37 1989
--- file.c	Wed Sep 13 12:21:30 1989
***************
*** 47,53 ****
    else return(FALSE);
  }
  
! void file(finp,nosave)
    FILE *finp;
    int nosave;
  {
--- 47,53 ----
    else return(FALSE);
  }
  
! void File(finp,nosave)
    FILE *finp;
    int nosave;
  {
***************
*** 60,66 ****
    bool skip_to_semi;
  
  #ifdef DEBUG
! fprintf(stderr,"Starting file()\n");
  #endif
    while (!ffinish(finp))
    {
--- 60,66 ----
    bool skip_to_semi;
  
  #ifdef DEBUG
! fprintf(stderr,"Starting File()\n");
  #endif
    while (!ffinish(finp))
    {
//E*O*F file.cdif//

echo x - global.cdif
cat > "global.cdif" << '//E*O*F global.cdif//'
*** ../Clam/global.c	Tue Sep 12 21:41:40 1989
--- global.c	Wed Sep 13 12:21:31 1989
***************
*** 17,23 ****
  
  #ifndef lint
  static char copyright[]="Clam shell, (c)1988 by Callum Gibson";
! static char version[]="Version 1.3 890817";
  #endif
  
  char termcapbuf[1024],bs[10],nd[10],cl[10],cd[10],up[10],so[10],se[10],beep[20],
--- 17,23 ----
  
  #ifndef lint
  static char copyright[]="Clam shell, (c)1988 by Callum Gibson";
! static char version[]="Version 1.3.2 890912";
  #endif
  
  char termcapbuf[1024],bs[10],nd[10],cl[10],cd[10],up[10],so[10],se[10],beep[20],
***************
*** 32,39 ****
  void (*charfn)(),(*ptif)();	/* char inserting function pointer */
  
  /* Clam terminal driver characteristics which must always be set for Clam. */
  struct sgttyb clam_sgttyb;
  struct tchars clam_tchars;
! #ifndef MINIX
  struct ltchars clam_ltchars;
  #endif
--- 32,43 ----
  void (*charfn)(),(*ptif)();	/* char inserting function pointer */
  
  /* Clam terminal driver characteristics which must always be set for Clam. */
+ #ifdef ATT
+ struct termio clam_termio;
+ #else
  struct sgttyb clam_sgttyb;
  struct tchars clam_tchars;
! # ifdef UCB
  struct ltchars clam_ltchars;
+ # endif
  #endif
//E*O*F global.cdif//

echo x - hash.cdif
cat > "hash.cdif" << '//E*O*F hash.cdif//'
*** ../Clam/hash.c	Tue Sep 12 21:42:34 1989
--- hash.c	Wed Sep 13 12:21:31 1989
***************
*** 190,196 ****
  }
  
  
! 			/* Minix doesn't have hashing */
  void hashpath()
  {
    extern void vdel();
--- 190,207 ----
  }
  
  
! void inihash()
! {
!   int i;
! 
!   for (i=0;i<HSHSIZ;i++)
!   {
!     hasharray[i].name=NULL;
!     hasharray[i].flag=0;
!   }
! }
! 
! 
  void hashpath()
  {
    extern void vdel();
***************
*** 229,236 ****
  /* free up previous hash table */
    for (times=0;times<HSHSIZ;times++)
    {
!     free(hasharray[times].name);
!     hasharray[times].name=NULL;
      if (!(hasharray[times].flag&EXTYPE))		/* it's a string */
        free(hasharray[times].exec_ptr.dir);
      hasharray[times].exec_ptr.dir=NULL;		/* nullify pointer */
--- 240,250 ----
  /* free up previous hash table */
    for (times=0;times<HSHSIZ;times++)
    {
!     if (hasharray[times].name!=NULL)
!     {
!       free(hasharray[times].name);
!       hasharray[times].name=NULL;
!     }
      if (!(hasharray[times].flag&EXTYPE))		/* it's a string */
        free(hasharray[times].exec_ptr.dir);
      hasharray[times].exec_ptr.dir=NULL;		/* nullify pointer */
//E*O*F hash.cdif//

echo x - header.h
cat > "header.h" << '//E*O*F header.h//'
/*****************************************************************************
**                                                                          **
**          The Clam Shell is Copyright (C) 1988 by Callum Gibson.          **
**       This file is part of Clam Shell. You may freely use, copy and      **
**     distribute it, but if you alter any source code do not distribute    **
**   the altered copy. i.e. you may alter this file for your own use only.  **
**                                                                          **
*****************************************************************************/
/* You may need to change the location of some of the .h files. I can't
   account for everyone... */
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <errno.h>
#include <pwd.h>

#ifdef ATT
# include <dirent.h>
# include <termio.h>
# include <sys/file.h>
# include <sys/time.h>
#endif

#ifdef MINIX
# include <sgtty.h>
# include <dirent.h>
# include <fcntl.h>
#  ifndef ATARI_ST
#   include <sys/dir.h>
#   include <sys/time.h>
#  else
#   include <time.h>
#  endif
#endif

#ifdef UCB
# include <sgtty.h>
# include <sys/dir.h>
# include <sys/time.h>
# include <sys/file.h>
# include <sys/resource.h>
#  ifdef SUN
#   include <sys/wait.h>
#  else
#   include <wait.h>
#  endif
#endif

/* Here is the Minix section i.e all the things that had to be set up
   to get Minix to go */

#ifdef MINIX
# define TIOCSETN TIOCSETP
# define lstat stat
# define O_echoexpbefore O_ebefore
# define builtin_name b_name
# define builtin_func b_func
# define current_alias c_alias
# define getline getlin
# define alias_depth als_dpt
#endif

/* for some reason the read set the error flag before the eof flag so I
   wrote my own ffinish macro which does both feof and ferror simultaneously */

#ifdef MINIX
# define ffinish(p)	(((p)->_flags&(_EOF|_ERR))!=0)
#else
# define ffinish(p)	(((p)->_flag&(_IOEOF|_IOERR))!=0)
#endif

/***************************************************************************
	Anything that needs to be changed is under this line.
***************************************************************************/

/* name of file with user passwords and directory entries e.g. /etc/passwd */
#define PASSWD "/etc/passwd"

/* name of help program (full path, please) */
#define HELP "/usr/local/utilities/man"

/* name of default interpreter shell. Normally it will be Bourne Shell */
#define DFLTSH "/bin/sh"

/* name of default editor to use for alias creation. */
#define DFLTED "/usr/ucb/vi"

/* Clam needs to know where it is for customised popen */
#define CLAMSH "/ccen/callum/bin/clam"

/* Sizes of some data structures */
#ifdef MINIX
# define MAXARG  512			/* no. of arguments */
# define MAXWL 	 512			/* word length */
# define MAXFNL  128			/* file name length */
# define MAXLL  1024			/* line length */
# define MAXPL   128			/* path length */
# define MAXCAN 1000			/* maximum number of candidates */
# define VARNL    32			/* variable name length */
# define VARVL   256			/* variable value length */
# define USERNL   32			/* max length of user names */
# define MAXAL    16			/* max depth of aliases */
#else
# define MAXARG  512			/* no. of arguments */
# define MAXWL  1024			/* word length */
# define MAXFNL  256			/* file name length */
# define MAXLL  2048			/* line length */
# define MAXPL  2048			/* path length */
# define HSHSIZ 1021			/* size of hash array */
# define MAXCAN 2500			/* maximum number of candidates */
# define VARNL   256			/* variable name length */
# define VARVL  1024			/* variable value length */
# define USERNL   32			/* max length of user names */
# define MAXAL    32			/* max depth of aliases */
#endif

/* number of signals. For ucb usually 27, for att 19. */

#ifdef ATT
# define NUMSIG 19
#endif
#ifdef MINIX
# ifdef ATARI_ST
#  define NUMSIG NSIG		/* defined in <signal.h> */
# else
#  define NUMSIG 19
# endif
#endif
#ifdef UCB
# define NUMSIG 27
#endif

/****************************************************************************
	Don't change anything past this line unless you're hacking.
****************************************************************************/

/* Some general defines */
#define EOS '\0'
#define UNDEF -1
#define NFILES 20
#define ALIASEX   01		/* executable is alias */
#define BUILTEX   02		/* executable is builtin */
#define EXTYPE    03		/* mask for the type of executable */
#define BEFOREDOT  0		/* priority flag bit if before . on path */
#define AFTERDOT  04		/* priority flag bit if after . on path */
#define PRIORITY  04		/* mask for priority of executable (as above) */

/* Identification for error codes for metacharacter expansion function */
#ifdef OK	/* defined somewhere on minixST */
#undef OK
#endif
#define OK 0
#define SH_ERR -1
#define ST_ERR -2
#define BR_ERR -3
#define BQ_ERR -4
#define QM_ERR -5
#define TL_ERR -6
#define CY_ERR -7
#define CT_ERR -8
#define NX_ERR -9
#define DL_ERR -10

typedef enum TS {RDRIN,RDROUT,RDRERR,APPND,PIPE,WORD,ENDLN,SEMI,EQ,ADD,BCKGND,DBLPIPE,DBLAMP,ERRER} SYM_T;

/* some brain damaged people put these in stdio */
#ifdef FALSE
#undef FALSE
#endif

#ifdef TRUE
#undef TRUE
#endif

typedef enum bb {FALSE,TRUE} bool;

/* These structures are used to store the alias definitions. */
struct adefn
{
  char *a_line;
  struct adefn *nextln;
};

struct alias
{
  char *a_name;
  struct adefn *defin;
  struct alias *next;
};

/* ex_ptr is the hasharray structure's union which points to an executable's whereabouts */
union ex_ptr
{
  char *dir;
  void (*builtin_fn)();
  struct adefn *alias_defn;
};
  
/* har is the hasharray structure */
struct har
{
  char *name;
  char flag;
  union ex_ptr exec_ptr;
};

struct job
{
  int jobnumber;
  int pid;
  char *name;
  bool rdrout;
  char *dir;
#ifdef ATT
  int status;
#endif
#ifdef MINIX
  int status;
#endif
#ifdef UCB
  union wait status;
#endif
  long lastmod;
  struct job *next;
};

#ifdef __STDC__
#ifndef __NO_PROTO__

/* alias.c */
struct adefn *checkalias (char *aname);
void aliaslist (char *aname);
void savealias (char *aname, FILE *fp);
void addalias (char *aname, struct adefn *stdefn);
void makelinealias (char *aname, char *aline);
void makealias (char *aname, FILE *fp);
void delalias (char *aname);

/* builtin1.c */
void alias (int argc, char **argv, int infd, int outfd, int errfd,
	    char *ifil, char *ofil, char *efil, bool appnd, bool bckgnd);
void logout (int argc, char **argv, int infd, int outfd, int errfd,
	     char *ifil, char *ofil, char *efil, bool appnd, bool bckgnd);
void Kill (int argc, char *argv[], int infd, int outfd, int errfd,
	   char *ifil, char *ofil, char *efil, bool appnd, bool
	   bckgnd, bool piped);
void limit (int argc, char *argv[], int infd, int outfd, int errfd,
	    char *ifil, char *ofil, char *efil, bool appnd, bool
	    bckgnd, bool piped);
void unlimit (int argc, char *argv[], int infd, int outfd, int errfd,
	      char *ifil, char *ofil, char *efil, bool appnd, bool
	      bckgnd, bool piped);
void (*checkbuiltins())(char *);

/* builtin2.c */
void printlimit (char *limname);
void setlimit (char *limname, char *limval);
int getnextword (char *line, int *pos, char *word);
int convert (char *string);
void editalias (char *aname);

/* clex.c */
bool firstword (char *line, int pos);
void complete (char *line, int *pos, int curs[]);
void nameopt (char *line, int pos, int curs[]);

/* comlined.c */
void mputc (int c, FILE *f, int curs[]);
int oputc (int c);
void go (int curs[], int  hor, int vert);
void backward (int curs[]);
void forward (int curs[]);
void clrscrn (void);
void insert (char *line, int pos, int letter, int curs[]);
void overwr (char *line, int pos, int letter, int curs[]);
void show (char *line, int curs[], bool clearing);
void goend (char *line, int *pos, int curs[]);
void copyback (char *line, int pos, int curs[], int count);
void delnextword (char *line, int pos, int curs[]);
void delprevword (char *line, int *pos, int curs[]);
void backword (char *line, int *pos, int curs[]);
void forword (char *line, int *pos, int curs[]);
void yanknext (char *line, int pos, char *yankbuf);
void yankprev (char *line, int pos, char *yankbuf);
void clrline (char *line, int pos, int curs[]);
void transpose (char *line, int pos, int curs[]);
int strip (char *line);
void tardis (char *line, int *pos, int curs[]);
bool getline (char *line, int *nosave, int feature_off);

/* cx.c */
bool expand_tilde (char *user_path, int *builtin);
void help (char *line, int pos, int curs[]);

/* exec.c */
void setbgexec (void);
void resetsigdefaults (void);
bool findslash (char *string);
void runalias (struct adefn *start, int argc, char *argv[], int infd,
		int outfd, int errfd, char *ifil, char *ofil, char *efil,
		bool appnd, bool bckgnd, bool piped);
int getpath (char *fullpathname, char *name, int flag);
void panic (char *mess);
int atoo (char *str);
void setmask (char *str);
void redirect (int infd, int outfd, int errfd, char *ifil, char *ofil,
		char *efil, bool appnd, bool bckgnd);
int execute (int argc, char *argv[], int infd, int outfd, int errfd,
	     char *ifil, char *ofil, char *efil, bool appnd,
	     bool bckgnd, bool piped, int fromfile);

/* file.c */
bool getfileline (char *line, FILE *fp, int nostrip);
void File (FILE *finp, int nosave);


/* hash.c */
bool executable (char *dir, char *entname, int nojoin);
#ifdef HASH
int hash (char *name);
int hashaliases (void);
int hashbuiltins (void);
int tildehashisin (char *path);
void inihash (void);
void hashpath (void);
#endif

/* hist.c */
int savehist (char *line, int histnum, int max);
void loadhist (char *line, int *pos, int histnum, int curs[]);
void mprint (char *line, int nocr);
void history (char *argv[]);
bool gethist (char *event);
char *getnumhist (int histnum);
int matchhist (int histnum);
int matchhline (char *line, int startnum);

/* job.c */
#ifdef JOB
void joblist (void);
bool stoppedjobs (void);
struct job *findjob (int pid);
int pidfromjob (int jobno);
void addreport (struct job *newone);
int addjob (int pid, char *name, int outfd, bool bckgnd);
void newcurr (void);
void rmjob (int pid);
int update (int pid, union wait status);
void checkjobs (void);
int waitfor (int pid);
void reportjobs (void);
#endif

/* main.c */
int lengthint (int num);
void printime (void);
void prprompt (int prtype);
bool tflagexist (char *id, char *tc);
void printctrl (char *name, char *str);
void terminal (void);
void graceful (int sig);
void setup (void);
void resetsh (void);
void setdown (void);
void leave_shell (void);
int process (int argc, char *argv[], char *comfile);
void shinit (void);
void interact (void);
void execstring (int argc, char *argv[], int argp);
int main (int argc, char *argv[], char *envp[]);

/* meta.c */
void getdir (FILE *fp, char *line);
int isanum (char *string);
int meta_1 (char *line, int nosave);
int meta_2 (char *line);

/* parse.c */
bool getword (char *line, int *pos, char *word, bool allow_slash_or_bracket);
SYM_T retsym (char *line, char *word, int *pos, bool allow_colon);
bool getpipeline (char *line, int *pos, char *pipeline, bool sts);
SYM_T intercom (char *line, int *pos, int *wpid, int *outpfd,
		bool pipedin, int fromfile);

/* var.c */
char *vget (char *vname);
char *vwget (char *vname, int wnum);
bool export (char *vname, char *opt);
void makenvpath (void);
void makenventry (char *vname);
void makenv (void);
void vset (char *vname, char *vval);
void vadd (char *vname, char *vval);
void vdel (char *vname);
void venvdel (char *vname);
void vprint (void);
void venvprint (void);
void copyenv (char *newenv[], char *envp[]);
void loadenv (void);

#endif /* __NO_PROTO__ */
#endif /* __STDC__ */
//E*O*F header.h//

exit 0