[net.sources] C shell command/filename completion for 4.1c

clyde@ut-ngp.UUCP (09/30/83)

Here are source changes required to put the command/filename
recognition code distributed by ucbvax!hplabs!kg into the 4.1c C shell.

The changes needed to make it work are involved with initialized char
arrays.  Since the makefile runs the C modules through xstr in order
to share strings, the code as distributed broke.  These arrays are
redeclared char pointers, and everybody is happy.

I also take more terminal chars out of termcap.
Apply these changes to tenex.c from the original distribution.

Also, make sure the printprompt() routine does a flush() before returning,
so the prompt will show up in the right place on command line redraw.

With these minor adjustments, the code dropped right in and works fine.

Thanks to Ken Greer for coming up with this jewel (it just
might shut up some of the TOPS-20 people around here who bitch about UNIX).

24c24
> #undef	putchar		/* for stand-alone testing to work */
44,45c44,48
< static char
<     *BELL = "\07";
---
> static char		/* Default terminal special chars */
>     *BELL = "\07",	/* Audible bell */
>     *BS = "\010",	/* Backspace */
>     *CR = "\r",		/* Carriage return */
>     *CLREOL = 0;	/* Clear to End of Line */
115c119,127
<     return;
---
> 
>     if (s = tgetstr ("bc", &ap))
> 	BS = s;
> 
>     if (s = tgetstr ("ce", &ap))
> 	CLREOL = s;
> 
>     if (s = tgetstr ("cr", &ap))
> 	CR = s;
124a137
> 
130c143
<     (void) write (SHOUT, "\r", 1);
---
>     (void) qput (CR);
234a248
> 
315c329
<     (void) write (SHOUT, BELL, strlen(BELL));
---
>     (void) qput (BELL);
531d544
< 
668,669c681,683
< 	    cmdstart[] = ";&(|`",
< 	    cmdalive[] = " \t'\"";
---
> 	    *cmdstart = ";&(|`",	/* This fixes xstr problems */
> 	    *cmdalive = " \t'\"";
> 
696c710
< 	    delims[] = " '\"\t;&<>()|^%";
---
> 	    *delims = " '\"\t;&<>()|^%";	/* Ditto here */
752,762c766,768
< 	    printf ("\210\210  \210\210");	/* Erase ^[ */
< 	    /*
< 	    if (num_read == 1)
< 	    {
< 	        num_read = tenedit (inputline, inputline_size, "");
< 		break;
< 	    }
< 	    else	
< 	    */
< 		command = RECOGNIZE;
< 		num_read--;
---
> 	    backover (2);
> 	    command = RECOGNIZE;
> 	    num_read--;
765,766c771,775
< 	    command = LIST,
< 	    putchar ('\n');
---
> 	{
> 	    command = LIST;
> 	    printf ("? One of the following:\n");  /* for real TENEX fans */
> /* 	    putchar ('\n'); */
> 	}	
774d782
< 			  
806a815,839
> static
> backover (nchars)
> int	nchars;
> {
> 	register int	nback;
> 
> 	for (nback = 0; nback < nchars; nback++)	/* Backup that far */
> 	{
> 	    qput (BS);		/* Back up */
> 	    if (CLREOL == 0) {	/* If clearing each char */
> 	   	qput (" ");	/* wipe */
> 		qput (BS);	/* then backup again */
> 	    }
> 	}
> 	if (CLREOL)		/* can clear to end of line */
> 	    qput (CLREOL);	/* just doit */
> }
> 
> static
> qput (str)
> register char *str;
> {
> 	(void )write (SHOUT, str, strlen(str));
> }