tcsh with editor (again) (1 of 7)

Paul Placeway paul at osu-dbs.UUCP
Sat Apr 21 04:32:52 AEST 1984


(I'm trying again for everyone who missed some of it)

The following code is my changes to Ken Greer's tcsh.  I have added a visual
mini-editor to the shell, and cleaned up the expansion routines some what.
note that this is the 4.1 version.  When we get 4.2 up I'll repost the new
changes.

Please send any changes back to me so that I can update our version.

Note: this is part 1 of 7, you need all of the parts to make tcsh.

					Paul W. Placeway
					The Ohio State University
					(UUCP: cbosgd!osu-dbs!paul)
					(CSNet: paul at ohio-state)

================ cut here ================
: This is a shar archive.  Extract with sh, not csh.
echo x - INSTALL
cat > INSTALL << '!Funky!Stuff!'
Installing the new T-C shell...

1. Make a new directory and copy the original csh sources to it.

2. Copy these sources to that directory.

3. The file "DIFFS" is a list of differences between the orignal csh and the
   same files in tcsh.  Go through the file, making the changes to the files.

4. make

5. Move ./tcsh wherever you like.

6. Enjoy.

Note:
   The files dir.h and dir14.c support the old 14 character UNIX
   directories.  Change the makefile if you have the Berkeley arbitrary
   length file names.

   Any references to /u0/osu should be changed to whatever your local
   software directory is.

See tcsh.1 (man file) for changes made.

If you make any fixes or changes, please mail them back to

					Paul W. Placeway
					The Ohio State University IRCC
					(UUCP: cbosgd!osu-dbs!paul)
					(CSNet: paul at ohio-state)

!Funky!Stuff!
echo x - DIFFS1
cat > DIFFS1 << '!Funky!Stuff!'
========	diff -bc csh/sh.c tcsh/sh.c	========

*** csh/sh.c	Fri Apr 13 10:43:58 1984
--- tcsh/sh.c	Fri Apr 13 10:45:00 1984
***************
*** 12,18
   * April 1980
   */
  
! char	*pathlist[] =	{ ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  char	HIST = '!';
  char	HISTSUB = '^';
  bool	nofile;

--- 12,20 -----
   * April 1980
   */
  
! #define AUTOLOGOUT      "60"            /* 1 Hour alarm */
! char    *pathlist[] =   { ".", "/u0/osu/bin", "/usr/ucb", "/bin",
! 			  "/usr/bin", "/u0/local/bin", 0 };
  char    HIST = '!';
  char    HISTSUB = '^';
  bool    nofile;
***************
*** 23,28
  bool	fast;
  bool	prompt = 1;
  
  main(c, av)
  	int c;
  	char **av;

--- 25,38 -----
  bool    fast;
  bool    prompt = 1;
  
+ auto_logout ()
+ {
+     printf("auto-logout\n");
+     close(SHIN);
+     child++;
+     goodbye();
+ }
+ 
  main(c, av)
          int c;
          char **av;
***************
*** 54,59
  	 */
  
  	set("status", "0");
  	dinit(cp = getenv("HOME"));	/* dinit thinks that HOME == cwd in a
  					 * login shell */
  	if (cp == NOSTR)

--- 64,72 -----
           */
  
          set("status", "0");
+ 	set("tcsh", "1");
+         set("autologout", AUTOLOGOUT);
+         sigset (SIGALRM, auto_logout);
          dinit(cp = getenv("HOME"));     /* dinit thinks that HOME == cwd in a
                                           * login shell */
          if (cp == NOSTR)
***************
*** 69,74
  	if ((cp = getenv("TERM")) != NOSTR)
  		set("term", savestr(cp));
  	/*
  	 * Re-initialize path if set in environment
  	 */
  	if ((cp = getenv("PATH")) == NOSTR)

--- 82,99 -----
          if ((cp = getenv("TERM")) != NOSTR)
                  set("term", savestr(cp));
  	/*
+ 	 * set the shell-level var to 1 or increment it.
+ 	 */
+         if ((cp = getenv("SHLVL")) != NOSTR) {
+ 		char buff[128];
+ 		itoa (1 + atoi (cp), buff);
+                 set("shlvl", savestr (buff));
+ 		setenv ("SHLVL", buff);
+ 	} else {
+ 		set("shlvl", savestr("1"));
+ 		setenv ("SHLVL", "1");
+ 	}
+         /*
           * Re-initialize path if set in environment
           */
          if ((cp = getenv("PATH")) == NOSTR)
***************
*** 95,100
  		pv[i] = 0;
  		set1("path", pv, &shvhed);
  	}
  	set("shell", SHELLPATH);
  
  	doldol = putn(getpid());		/* For $$ */

--- 120,126 -----
                  pv[i] = 0;
                  set1("path", pv, &shvhed);
          }
+ 
          set("shell", SHELLPATH);
  
          doldol = putn(getpid());                /* For $$ */
***************
*** 236,243
  	/*
  	 * Set up the prompt.
  	 */
! 	if (prompt)
! 		set("prompt", uid == 0 ? "# " : "% ");
  
  	/*
  	 * If we are an interactive shell, then start fiddling

--- 262,270 -----
          /*
           * Set up the prompt.
           */
!         if (prompt) {
!                 set("prompt", uid == 0 ? "} " : "> ");
! 	}
  
          /*
           * If we are an interactive shell, then start fiddling
***************
*** 312,317
  	haderr = 0;		/* In case second time through */
  	if (!fast && reenter == 0) {
  		reenter++;
  		/* Will have value("home") here because set fast if don't */
  		srccat(value("home"), "/.cshrc");
  		if (!fast && !arginp && !onelflg)

--- 339,349 -----
          haderr = 0;             /* In case second time through */
          if (!fast && reenter == 0) {
                  reenter++;
+                 if (!fast && !arginp && !onelflg) {
+ 		    tw_init_bindings();
+ 		    ilsetup(SHIN, SHOUT);
+ 	    		/* setup the editor BEFORE doing .tcshrc */
+ 		}    
                  /* Will have value("home") here because set fast if don't */
                  srccat(value("home"), "/.tcshrc");
                  if (!fast && !arginp && !onelflg) {
***************
*** 313,320
  	if (!fast && reenter == 0) {
  		reenter++;
  		/* Will have value("home") here because set fast if don't */
! 		srccat(value("home"), "/.cshrc");
! 		if (!fast && !arginp && !onelflg)
  			dohash();
  		if (loginsh) {
  			int ldisc;

--- 345,352 -----
  	    		/* setup the editor BEFORE doing .tcshrc */
  		}    
                  /* Will have value("home") here because set fast if don't */
!                 srccat(value("home"), "/.tcshrc");
!                 if (!fast && !arginp && !onelflg) {
                          dohash();
  		}		/* setup the command compleation path */
                  if (loginsh) {
***************
*** 316,321
  		srccat(value("home"), "/.cshrc");
  		if (!fast && !arginp && !onelflg)
  			dohash();
  		if (loginsh) {
  			int ldisc;
  			srccat(value("home"), "/.login");

--- 348,354 -----
                  srccat(value("home"), "/.tcshrc");
                  if (!fast && !arginp && !onelflg) {
                          dohash();
+ 		}		/* setup the command compleation path */
                  if (loginsh) {
                          int ldisc;
                          srccat(value("home"), "/.login");
***************
*** 414,419
  #ifdef INGRES
  	srcunit(unit, 0);
  #else
  	srcunit(unit, 1);
  #endif
  }

--- 447,455 -----
  #ifdef INGRES
          srcunit(unit, 0);
  #else
+ #ifdef OSU
+         srcunit(unit, 0);
+ #else
          srcunit(unit, 1);
  #endif
  #endif
***************
*** 416,421
  #else
  	srcunit(unit, 1);
  #endif
  }
  
  /*

--- 452,458 -----
  #else
          srcunit(unit, 1);
  #endif
+ #endif
  }
  
  /*
***************
*** 420,426
  
  /*
   * Source to a unit.  If onlyown it must be our file or our group or
!  * we don't chance it.	This occurs on ".cshrc"s and the like.
   */
  srcunit(unit, onlyown)
  	register int unit;

--- 457,463 -----
  
  /*
   * Source to a unit.  If onlyown it must be our file or our group or
!  * we don't chance it.  This occurs on ".tcshrc"s and the like.
   */
  srcunit(unit, onlyown)
          register int unit;
***************
*** 623,629
  	getexit(osetexit);
  	for (;;) {
  		pendjob();
! 		paraml.next = paraml.prev = ¶ml;
  		paraml.word = "";
  		t = 0;
  		setexit();

--- 660,666 -----
          getexit(osetexit);
          for (;;) {
                  pendjob();
!                 paraml.next = paraml .prev = ¶ml;
                  paraml.word = "";
                  t = 0;
                  setexit();
***************
*** 677,697
  			 * need or want to prompt.
  			 */
  			if (fseekp == feobp)
! 				if (!whyles)
! 					for (cp = value("prompt"); *cp; cp++)
! 						if (*cp == HIST)
! 							printf("%d", eventno + 1);
! 						else {
! 							if (*cp == '\\' && cp[1] == HIST)
! 								cp++;
! 							putchar(*cp | QUOTE);
! 						}
! 				else
! 					/*
! 					 * Prompt for forward reading loop
! 					 * body content.
! 					 */
! 					printf("? ");
  			flush();
  		}
  		err = 0;

--- 714,720 -----
                           * need or want to prompt.
                           */
                          if (fseekp == feobp)
!                                 printprompt ();
                          flush();
                          if (cp = value("autologout"))
                              alarm (atoi(cp) * 60);
***************
*** 693,698
  					 */
  					printf("? ");
  			flush();
  		}
  		err = 0;
  

--- 716,723 -----
                          if (fseekp == feobp)
                                  printprompt ();
                          flush();
+                         if (cp = value("autologout"))
+                             alarm (atoi(cp) * 60);
                  }
                  err = 0;
  
***************
*** 705,710
  			prlex(&paraml);
  			haderr = 0;
  		}
  
  		/*
  		 * The parser may lose space if interrupted.

--- 730,736 -----
                          prlex(&paraml);
                          haderr = 0;
                  }
+                 alarm (0);                      /* Turn auto-logout off */
  
                  /*
                   * The parser may lose space if interrupted.
***************
*** 859,862
  #else
  	_exit(i);
  #endif
  }

--- 885,917 -----
  #else
          _exit(i);
  #endif
+ }
+ 
+ printprompt ()
+ {
+     register char *cp;
+     extern char *value ();
+     char buff[128];
+     PromptBuf[0] = '\0';
+     if (!whyles) {
+             for (cp = value("prompt"); *cp; cp++) {
+                     if (*cp == HIST) {
+                             itoa(eventno + 1, buff);
+ 			    strcat(PromptBuf, buff);
+ 		    }
+                     else {
+                             if (*cp == '\\' && cp[1] == HIST) {
+                                     cp++;
+ 			    }
+                             strncat(PromptBuf, cp, 1);
+                     }
+ 	    }
+     }
+     else {
+             /*
+              * Prompt for forward reading loop
+              * body content.
+              */
+ 	    strncat(PromptBuf, "? ", 2);
+     }
  }

========	diff -bc csh/sh.exec.c tcsh/sh.exec.c	========

*** csh/sh.exec.c	Fri Apr 13 10:44:01 1984
--- tcsh/sh.exec.c	Fri Apr 13 10:45:04 1984
***************
*** 252,257
  	struct stat stb;
  	struct direct dirbuf[BUFSIZ / sizeof (struct direct)];
  	char d_name[DIRSIZ + 1];
  	register int dirf, cnt;
  	int i = 0;
  	struct varent *v = adrof("path");

--- 252,258 -----
  	struct stat stb;
  	struct direct dirbuf[BUFSIZ / sizeof (struct direct)];
  	char d_name[DIRSIZ + 1];
+ 	char fnamebuf[BUFSIZ];
  	register int dirf, cnt;
  	int i = 0;
  	struct varent *v = adrof("path");
***************
*** 257,262
  	struct varent *v = adrof("path");
  	char **pv;
  
  	havhash = 1;
  	for (cnt = 0; cnt < HSHSIZ; cnt++)
  		xhash[cnt] = 0;

--- 258,264 -----
  	struct varent *v = adrof("path");
  	char **pv;
  
+ 	tw_clear_comm_list();
  	havhash = 1;
  	for (cnt = 0; cnt < HSHSIZ; cnt++)
  		xhash[cnt] = 0;
***************
*** 272,278
  			close(dirf);
  			continue;
  		}
! 		while ((cnt = read(dirf, (char *) dirbuf, sizeof dirbuf)) >= sizeof dirbuf[0]) {
  			register struct direct *ep = dirbuf;
  
  			for (cnt /= sizeof(struct direct); cnt > 0; cnt--, ep++) {

--- 274,282 -----
  			close(dirf);
  			continue;
  		}
! 				/* put check for non-exes here */
! 		while ((cnt = read(dirf, (char *) dirbuf, 
! 		    sizeof dirbuf)) >= sizeof dirbuf[0]) {
  			register struct direct *ep = dirbuf;
  
  			for (cnt /= sizeof(struct direct); 
***************
*** 275,281
  		while ((cnt = read(dirf, (char *) dirbuf, sizeof dirbuf)) >= sizeof dirbuf[0]) {
  			register struct direct *ep = dirbuf;
  
! 			for (cnt /= sizeof(struct direct); cnt > 0; cnt--, ep++) {
  				if (ep->d_ino == 0)
  					continue;
  				copdent(d_name, ep->d_name);

--- 279,286 -----
  		    sizeof dirbuf)) >= sizeof dirbuf[0]) {
  			register struct direct *ep = dirbuf;
  
! 			for (cnt /= sizeof(struct direct); 
! 			    cnt > 0; cnt--, ep++) {
  				if (ep->d_ino == 0)
  					continue;
  				copdent(d_name, ep->d_name);
***************
*** 279,284
  				if (ep->d_ino == 0)
  					continue;
  				copdent(d_name, ep->d_name);
  				xhash[hash(d_name)] |= (1 << i);
  			}
  		}

--- 284,299 -----
  				if (ep->d_ino == 0)
  					continue;
  				copdent(d_name, ep->d_name);
+ 				if (*d_name == '.')
+ 					continue;
+ 
+ 				strcpy (fnamebuf, *pv);
+ 				strcat (fnamebuf, "/");
+ 				strcat (fnamebuf, d_name);
+ 
+ 				if (access(fnamebuf, 1)) /* if not exe file */
+ 					continue;
+ 
  				xhash[hash(d_name)] |= (1 << i);
  				tw_add_comm_name (d_name);
  			}
***************
*** 280,285
  					continue;
  				copdent(d_name, ep->d_name);
  				xhash[hash(d_name)] |= (1 << i);
  			}
  		}
  		close(dirf);

--- 295,301 -----
  					continue;
  
  				xhash[hash(d_name)] |= (1 << i);
+ 				tw_add_comm_name (d_name);
  			}
  		}
  		close(dirf);
***************
*** 284,289
  		}
  		close(dirf);
  	}
  }
  
  dounhash()

--- 300,308 -----
  		}
  		close(dirf);
  	}
+ 	tw_add_builtins();
+ 	tw_add_aliases();
+ 	tw_sort_comms ();	/* re-build the command path for twenex.c */
  }
  
  dounhash()

!Funky!Stuff!



More information about the Comp.sources.unix mailing list