[comp.os.minix] Official Clam Patch #3 - 1 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:
# Makefiledif READMEdif alias.cdif builtin1.cdif clex.cdif comlined.cdif cx.cdif

echo x - Makefiledif
cat > "Makefiledif" << '//E*O*F Makefiledif//'
*** ../Clam/Makefile	Tue Sep 12 21:42:46 1989
--- Makefile	Wed Sep 13 12:21:26 1989
***************
*** 122,129 ****
  var.$(O) : var.c header.h
  	$(CC) $(DFLAGS) $(CFLAGS) $(DEFINES) -c var.c
  
! lint : header.h alias.c builtin.c clex.c comlined.c cx.c exec.c file.c global.c hash.c hist.c job.c main.c meta.c parse.c var.c
! 	lint $(DEFINES) header.h alias.c builtin.c clex.c comlined.c cx.c exec.c file.c global.c hash.c hist.c job.c main.c meta.c parse.c var.c
  
  clean :
  	rm -f *.$(O) clam
--- 122,129 ----
  var.$(O) : var.c header.h
  	$(CC) $(DFLAGS) $(CFLAGS) $(DEFINES) -c var.c
  
! lint : header.h alias.c builtin1.c builtin2.c clex.c comlined.c cx.c exec.c file.c global.c hash.c hist.c job.c main.c meta.c parse.c var.c
! 	lint $(DEFINES) header.h alias.c builtin1.c builtin2.c clex.c comlined.c cx.c exec.c file.c global.c hash.c hist.c job.c main.c meta.c parse.c var.c
  
  clean :
  	rm -f *.$(O) clam
//E*O*F Makefiledif//

echo x - READMEdif
cat > "READMEdif" << '//E*O*F READMEdif//'
*** ../Clam/README	Tue Sep 12 21:41:24 1989
--- README	Wed Sep 13 12:21:27 1989
***************
*** 56,62 ****
  O to be 's' while the normal UNIX people should have it as 'o'. Now type make
  and away it goes. There should be no warnings at all. If there are, please
  inform me about them as it could indicate that something is wrong (or that your
! compiler is unusually fussy - don't bother trying to lint it :-).
  
  Documentation.
  --------------
--- 56,64 ----
  O to be 's' while the normal UNIX people should have it as 'o'. Now type make
  and away it goes. There should be no warnings at all. If there are, please
  inform me about them as it could indicate that something is wrong (or that your
! compiler is unusually fussy - don't bother trying to lint it :-). Oh, and you
! may want to change the location of some .h files since I can't have ifdefs for
! everyone.
  
  Documentation.
  --------------
//E*O*F READMEdif//

echo x - alias.cdif
cat > "alias.cdif" << '//E*O*F alias.cdif//'
*** ../Clam/alias.c	Tue Sep 12 21:41:28 1989
--- alias.c	Wed Sep 13 12:21:27 1989
***************
*** 145,152 ****
    else
      if (lex==0)		/* alias already exists, just change definition */
      {
!       for (dptr=aptr->defin,d=dptr->nextln;dptr;dptr=d,d=d->nextln)
        {
  	free(dptr->a_line);
  	free(dptr);
        }
--- 145,153 ----
    else
      if (lex==0)		/* alias already exists, just change definition */
      {
!       for (dptr=aptr->defin;dptr;dptr=d)
        {
+ 	d=dptr->nextln;
  	free(dptr->a_line);
  	free(dptr);
        }
***************
*** 215,221 ****
  #ifdef DEBUG
  fprintf(stderr,"In makealias\n");
  #endif
!   defn_top=NULL;
    while (!feof(fp))
    {
      for (i=0;i<MAXLL;i++) line[i]=EOS;
--- 216,222 ----
  #ifdef DEBUG
  fprintf(stderr,"In makealias\n");
  #endif
!   dptr=defn_top=NULL;
    while (!feof(fp))
    {
      for (i=0;i<MAXLL;i++) line[i]=EOS;
***************
*** 224,230 ****
  #ifdef DEBUG
  fprintf(stderr,"alias line:\n%s<<-\n",line);
  #endif
!       if (defn_top)
        {
  	dptr->nextln=(struct adefn *) malloc ((unsigned)(sizeof(struct adefn)));
  	dptr=dptr->nextln;
--- 225,231 ----
  #ifdef DEBUG
  fprintf(stderr,"alias line:\n%s<<-\n",line);
  #endif
!       if (dptr!=NULL)	/* dptr==NULL iff defn_top==NULL */
        {
  	dptr->nextln=(struct adefn *) malloc ((unsigned)(sizeof(struct adefn)));
  	dptr=dptr->nextln;
//E*O*F alias.cdif//

echo x - builtin1.cdif
cat > "builtin1.cdif" << '//E*O*F builtin1.cdif//'
*** ../Clam/builtin1.c	Tue Sep 12 21:41:31 1989
--- builtin1.c	Wed Sep 13 12:21:28 1989
***************
*** 39,44 ****
--- 39,49 ----
  {
    extern void vset();
    extern char *vget();
+   extern int fromfile;
+   SYM_T t,retsym();
+   char cdpath[VARVL],dir[MAXWL],home[VARVL];
+   char fulldirname[MAXFNL], *cdpathptr, *s;
+   int pos=0, cdpcnum=0;
  #ifdef MINIX
    char dirname[128];
    extern char *getcwd();
***************
*** 51,57 ****
      return;
    }
    if (chdir(argv[1])!=0)
!     perror("cd");
    /* else if (hashed==TRUE) hashpath(); don't need this now */
  #ifndef MINIX
    if (argc==2) argv[1]=(char *) realloc (argv[1],(unsigned)(MAXPL));
--- 56,112 ----
      return;
    }
    if (chdir(argv[1])!=0)
!   {
!     /* absolute, so don't use cdpath, it failed */
!     if (*argv[1]=='/' || !strncmp(argv[1],"./",2) || !strncmp(argv[1],"../",3))
!       perror("cd");
!     else
!     {
!       /* use cdpath */
!       if ((cdpathptr=vget("cdpath"))==(char *)UNDEF)
! 	perror("cd");
!       else
!       {
! 	strcpy(cdpath,cdpathptr);
! 	/* search through cdpath for a suitable directory */
! 	while((t=retsym(cdpath,dir,&pos,FALSE))!=ENDLN)
! 	{
! 	  cdpcnum++;
! 	  if (t!=WORD)
! 	  {
! 	    fprintf(stderr,"Component %d of cdpath is illegal.\n",cdpcnum);
! 	    continue;
! 	  }
! 	  strcpy(fulldirname,dir);
! 	  strcat(fulldirname,"/");
! 	  strcat(fulldirname,argv[1]);
! 	  if (chdir(fulldirname)==0)
! 	  {
! 	    /* chdir was successful */
! 	    if (!fromfile && strcmp(dir,"."))
! 	    {
! 	      /* print the new directory if an interactive shell
! 		 and the new directory was not relative to the old */
! 	      strcpy(home,vget("HOME"));
! 	      if (strncmp(home,fulldirname,strlen(home)))
! 		write(2,fulldirname,strlen(fulldirname));
! 	      else
! 	      {
! 		/* substitute ~ for the home directory */
! 		write(2,"~/",2);
! 		s=fulldirname+(strlen(home)+1);
! 		write(2,s,strlen(s));
! 	      }
! 	      write(2,"\n",1);
! 	    }              
! 	    break;
! 	  }
! 	}
! 	if (t==ENDLN)
! 	  perror("cd");
!       }
!     }
!   }
    /* else if (hashed==TRUE) hashpath(); don't need this now */
  #ifndef MINIX
    if (argc==2) argv[1]=(char *) realloc (argv[1],(unsigned)(MAXPL));
***************
*** 101,107 ****
  printf("Exit: testing if login shell\n");
  #endif
    if (loginsh==TRUE)
!     logout(argc,argv,infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd);
    if (argc>2 || (argc!=1 && !isanum(argv[1])))
    {
      write(2,"Bad argument to exit.\n",22);
--- 156,162 ----
  printf("Exit: testing if login shell\n");
  #endif
    if (loginsh==TRUE)
!     logout(argc,argv,infd,outfd,errfd,ifil,ofil,efil,appnd,bckgnd,piped);
    if (argc>2 || (argc!=1 && !isanum(argv[1])))
    {
      write(2,"Bad argument to exit.\n",22);
***************
*** 182,188 ****
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
  {
!   extern void (*builtin_func)(),setdown();
    extern struct adefn *alias_defn;
    extern int errno,fromfile,getpath();
    char path[MAXPL],**startarg;
--- 237,243 ----
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
  {
!   extern void (*builtin_func)(),setdown(),redirect(),runalias();
    extern struct adefn *alias_defn;
    extern int errno,fromfile,getpath();
    char path[MAXPL],**startarg;
***************
*** 202,209 ****
      if (alias_defn!=0)
      {
        runalias(alias_defn,argc-1,startarg,infd,outfd,errfd,ifil,ofil,efil,
! 	       appnd,bckgnd, FALSE); /* is FALSE ok for piped ?? was */
! 				     /* missing in origonal code */
        if (!fromfile) setdown();
        exit(0);
      }
--- 257,263 ----
      if (alias_defn!=0)
      {
        runalias(alias_defn,argc-1,startarg,infd,outfd,errfd,ifil,ofil,efil,
! 	       appnd,bckgnd,piped);
        if (!fromfile) setdown();
        exit(0);
      }
***************
*** 477,483 ****
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
  {
!   extern void file(),resetsh();
  #ifdef HASH
    bool oldhashed;
    extern bool hashed;
--- 531,537 ----
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
  {
!   extern void File(),resetsh();
  #ifdef HASH
    bool oldhashed;
    extern bool hashed;
***************
*** 511,517 ****
  #ifdef DEBUG
  fprintf(stderr,"Calling file to source %s\n",argv[1]);
  #endif
!   file(fp,1);
    fclose(fp);
    arguments=oldargstemp;
    numargs=oldnumargtemp;
--- 565,571 ----
  #ifdef DEBUG
  fprintf(stderr,"Calling file to source %s\n",argv[1]);
  #endif
!   File(fp,1);
    fclose(fp);
    arguments=oldargstemp;
    numargs=oldnumargtemp;
***************
*** 532,538 ****
    bool appnd,bckgnd,piped;
  #endif
  {
!   extern void resetsh(),setdown(),file();
    extern bool loginsh;
    extern int fromfile;
    FILE *fp;
--- 586,592 ----
    bool appnd,bckgnd,piped;
  #endif
  {
!   extern void resetsh(),setdown(),File();
    extern bool loginsh;
    extern int fromfile;
    FILE *fp;
***************
*** 548,554 ****
    strcat(dir,"/.logout");
    if ((fp=fopen(dir,"r"))!=NULL)
    {
!     file(fp,1);
      fclose(fp);
    }
    setdown();
--- 602,608 ----
    strcat(dir,"/.logout");
    if ((fp=fopen(dir,"r"))!=NULL)
    {
!     File(fp,1);
      fclose(fp);
    }
    setdown();
***************
*** 763,770 ****
    bool appnd,bckgnd,piped;
  {
    extern struct job *currentjob,*findjob();
!   extern void setexec(),update(),newcurr();
!   extern int fromfile,waitfor();
    struct job *ptr;
    char *c;
    int pid,i;
--- 817,824 ----
    bool appnd,bckgnd,piped;
  {
    extern struct job *currentjob,*findjob();
!   extern void setexec(),newcurr();
!   extern int fromfile,waitfor(),update();
    struct job *ptr;
    char *c;
    int pid,i;
***************
*** 877,884 ****
    bool appnd,bckgnd,piped;
  {
    extern struct job *currentjob,*findjob();
!   extern void update(),newcurr();
!   extern int fromfile;
    struct job *ptr;
    char *c;
    int pid,i;
--- 931,938 ----
    bool appnd,bckgnd,piped;
  {
    extern struct job *currentjob,*findjob();
!   extern void newcurr();
!   extern int fromfile,update();
    struct job *ptr;
    char *c;
    int pid,i;
***************
*** 1060,1065 ****
--- 1114,1120 ----
    bool appnd,bckgnd,piped;
  {
    extern FILE *zin;
+   extern void vadd();
    extern int fromfile,getnextword();
    extern bool getfileline();
  #ifdef ATT
***************
*** 1137,1142 ****
--- 1192,1199 ----
    char *argv[],*ifil,*ofil,*efil;
    bool appnd,bckgnd,piped;
  {
+   extern void printlimit(),setlimit();
+ 
    if (argc>3)
    {
      write(2,"usage: limit [ <resource>  [ <limit> ] ]\n",41);
//E*O*F builtin1.cdif//

echo x - clex.cdif
cat > "clex.cdif" << '//E*O*F clex.cdif//'
*** ../Clam/clex.c	Tue Sep 12 21:42:33 1989
--- clex.c	Wed Sep 13 12:21:29 1989
***************
*** 37,43 ****
--- 37,45 ----
    int number,longest;
  {
    extern int wid,fromfile;
+ #ifndef ATT
    struct tchars setsigc;
+ #endif
    int i,j,collength,numperline,index;
    char format[6];
  
***************
*** 65,72 ****
        index=i+j*collength;
        if (index>=number) break;
        if ((csa[index].c_mode & S_IFMT) == S_IFDIR) strcat(csa[index].c_name,"/");
! 				/* No symbolic links in Minix */
! #ifndef MINIX
        else if ((csa[index].c_mode & S_IFMT) == S_IFLNK) strcat(csa[index].c_name,"@");
  #endif
  	   else if (csa[index].c_mode & 0111) strcat(csa[index].c_name,"*");
--- 67,74 ----
        index=i+j*collength;
        if (index>=number) break;
        if ((csa[index].c_mode & S_IFMT) == S_IFDIR) strcat(csa[index].c_name,"/");
! 			/* No symbolic links in Minix or SysV */
! #ifdef UCB
        else if ((csa[index].c_mode & S_IFMT) == S_IFLNK) strcat(csa[index].c_name,"@");
  #endif
  	   else if (csa[index].c_mode & 0111) strcat(csa[index].c_name,"*");
***************
*** 163,173 ****
      {
        for (i=0;word[i]!='/';i++);
        max=strlen(&word[i+1]);
!       start=0;
        for (aptr=atop;aptr;aptr=aptr->next)
  	if (!strncmp(&word[i+1],aptr->a_name,max))
  	{
! 	  if (start)
  	  {
  	    ptr->next=(struct candidates *) malloc ((unsigned)(sizeof(struct candidates)));
  	    ptr=ptr->next;
--- 165,175 ----
      {
        for (i=0;word[i]!='/';i++);
        max=strlen(&word[i+1]);
!       ptr=start=0;
        for (aptr=atop;aptr;aptr=aptr->next)
  	if (!strncmp(&word[i+1],aptr->a_name,max))
  	{
! 	  if (ptr!=NULL)	/* ptr==NULL iff start==NULL */
  	  {
  	    ptr->next=(struct candidates *) malloc ((unsigned)(sizeof(struct candidates)));
  	    ptr=ptr->next;
***************
*** 525,531 ****
--- 527,537 ----
  	  if (temp>maxlength) maxlength=temp;
  	  strcpy(statfile,dir);
  	  strcat(statfile,"/");strcat(statfile,entry->d_name);
+ #ifdef UCB
  	  lstat(statfile,buf);
+ #else
+ 	  stat(statfile,buf);
+ #endif
  	  carray[index].c_mode=buf->st_mode;
  	  index++;
  	}
//E*O*F clex.cdif//

echo x - comlined.cdif
cat > "comlined.cdif" << '//E*O*F comlined.cdif//'
*** ../Clam/comlined.c	Tue Sep 12 21:41:39 1989
--- comlined.c	Wed Sep 13 12:21:29 1989
***************
*** 340,350 ****
    int *pos,curs[];
  {
    int inword=0,l=1,charcount=0;
-   char c;
  
    while(l)
      if ((*pos)>0)
!       switch (c=line[(*pos)-1])
        {
  	case ' ':case '\t':case '<':case '>':case '|':case '/':
  	case ';':case '=':case '+':case '&':case '`':
--- 340,349 ----
    int *pos,curs[];
  {
    int inword=0,l=1,charcount=0;
  
    while(l)
      if ((*pos)>0)
!       switch (line[(*pos)-1])
        {
  	case ' ':case '\t':case '<':case '>':case '|':case '/':
  	case ';':case '=':case '+':case '&':case '`':
***************
*** 573,582 ****
    int *nosave,feature_off;
  {
    extern int loadline,curr_hist,maxhist,lenprompt,O_echoline,beeplength,
! 	     savehist();
    extern char beep[],yankbuf[],*vget();
    extern void loadhist(),leave_shell(),complete(),nameopt(),prprompt(),help(),(*charfn)(),(*ptif)();
!   char c;
    int times=1,i,pos=0,hist=curr_hist,curs[2],hsave=lenprompt,vsave=0,possave=0,
        try=0;
  
--- 572,581 ----
    int *nosave,feature_off;
  {
    extern int loadline,curr_hist,maxhist,lenprompt,O_echoline,beeplength,
! 	     savehist(),matchhline();
    extern char beep[],yankbuf[],*vget();
    extern void loadhist(),leave_shell(),complete(),nameopt(),prprompt(),help(),(*charfn)(),(*ptif)();
!   char c,remline[MAXLL];
    int times=1,i,pos=0,hist=curr_hist,curs[2],hsave=lenprompt,vsave=0,possave=0,
        try=0;
  
***************
*** 670,676 ****
  		 else write(1,beep,beeplength);		/* else ring bell */
  		 break;
        case '\t': if (line[0]!=EOS)
! 		   complete(line,&pos,curs,charfn); /* try to complete word */
  		 else write(1,beep,beeplength);
  		 break;
        case '\r':				/* end of the line, go and */
--- 669,675 ----
  		 else write(1,beep,beeplength);		/* else ring bell */
  		 break;
        case '\t': if (line[0]!=EOS)
! 		   complete(line,&pos,curs); /* try to complete word */
  		 else write(1,beep,beeplength);
  		 break;
        case '\r':				/* end of the line, go and */
***************
*** 771,779 ****
  			      prprompt(1);
  			      show(line,curs,TRUE);
  			      break;
  		   case  27 :
  		   case '\t': if (!feature_off)
! 				if (line[0]!=EOS) complete(line,&pos,curs,charfn);
  				else write(1,beep,beeplength);
  			      break;
  		   case 'b' : case 2:
--- 770,794 ----
  			      prprompt(1);
  			      show(line,curs,TRUE);
  			      break;
+ 		   case  16 : if (feature_off) break;
+ 			      if (hist==curr_hist)
+ 			      {
+ 				/* if equal then remember this line cause it's
+ 				   the one we have to match */
+ 				strncpy(remline,line,MAXLL-1);
+ 				remline[MAXLL-1]=EOS;
+ 			      }
+ 			      try=matchhline(remline,hist);
+ 			      if (try)
+ 			      {
+ 				loadhist(line,&pos,try,curs);
+ 				hist=try;
+ 			      }
+ 			      else write(1,beep,beeplength);
+ 			      break;
  		   case  27 :
  		   case '\t': if (!feature_off)
! 				if (line[0]!=EOS) complete(line,&pos,curs);
  				else write(1,beep,beeplength);
  			      break;
  		   case 'b' : case 2:
//E*O*F comlined.cdif//

echo x - cx.cdif
cat > "cx.cdif" << '//E*O*F cx.cdif//'
*** ../Clam/cx.c	Tue Sep 12 21:41:43 1989
--- cx.c	Wed Sep 13 12:21:30 1989
***************
*** 20,30 ****
    int *builtin;
  {
    extern void getdir();
!   extern char beep[];
    FILE *pswdp,*fopen();
!   char pwent[256],username[USERNL],restpath[MAXWL];
    int i,j,colon=0;
-   extern  char *getlogin();
  
  #ifdef DEBUG
  fprintf(stderr,"user_path is %s\n",user_path);
--- 20,30 ----
    int *builtin;
  {
    extern void getdir();
!   extern char beep[],*getlogin();
!   struct passwd *pw;
    FILE *pswdp,*fopen();
!   char *un,pwent[256],username[USERNL],restpath[MAXWL];
    int i,j,colon=0;
  
  #ifdef DEBUG
  fprintf(stderr,"user_path is %s\n",user_path);
***************
*** 49,55 ****
  #endif
    if (username[0]==EOS)			/* if we have ~/rest/of/path */
    {
!     strncpy(username,getlogin(),USERNL);
      i=strlen(username);
    }
    else i--;				/* now i equals strlen(username) */
--- 49,65 ----
  #endif
    if (username[0]==EOS)			/* if we have ~/rest/of/path */
    {
!     if ((un=getlogin()) == NULL)
!     {
!       if ((pw=getpwuid(getuid())) == NULL)
!       {
! 	fprintf(stderr,"\n%sCan't get username\n",beep);
! 	user_path[0]=EOS;
! 	return(FALSE);
!       }
!       else un=pw->pw_name;
!     }
!     strncpy(username,un,USERNL);
      i=strlen(username);
    }
    else i--;				/* now i equals strlen(username) */
//E*O*F cx.cdif//

exit 0