Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site osu-dbs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!cbosgd!osu-dbs!paul From: paul@osu-dbs.UUCP (Paul Placeway) Newsgroups: net.sources Subject: tcsh with editor (again) (6 of 7) Message-ID: <570@osu-dbs.UUCP> Date: Fri, 20-Apr-84 13:37:24 EST Article-I.D.: osu-dbs.570 Posted: Fri Apr 20 13:37:24 1984 Date-Received: Sat, 21-Apr-84 07:21:07 EST Organization: Ohio State U., CIS Dept., Columbus Lines: 513 (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 6 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@ohio-state) ================ cut here ================ : This is a shar archive. Extract with sh, not csh. echo x - DIFFS2 cat > DIFFS2 << '!Funky!Stuff!' ======== diff -bc csh/sh.func.c tcsh/sh.func.c ======== *** csh/sh.func.c Fri Apr 13 10:44:03 1984 --- tcsh/sh.func.c Fri Apr 13 10:45:07 1984 *************** *** 498,504 bseek(0l); do { if (intty && fseekp == feobp) ! printf("? "), flush(); aword[0] = 0, getword(aword); switch (srchx(aword)) { --- 498,504 ----- bseek(0l); do { if (intty && fseekp == feobp) ! printprompt(); /* printf("? "), flush(); */ aword[0] = 0, getword(aword); switch (srchx(aword)) { *************** *** 727,732 blkfree(gargv), gargv = 0; } char **environ; dosetenv(v) --- 727,733 ----- blkfree(gargv), gargv = 0; } + char **environ; dosetenv(v) *************** *** 1005,1012 int old, ldisc; short ctpgrp; ! if (loginsh) ! error("Can't suspend a login shell (yet)"); untty(); old = sigsys(SIGTSTP, SIG_DFL); kill(0, SIGTSTP); --- 1006,1063 ----- int old, ldisc; short ctpgrp; ! if (loginsh) { ! error ("Use \'detach\' to suspend the login shell."); ! } ! untty(); ! old = sigsys(SIGTSTP, SIG_DFL); ! kill(0, SIGTSTP); ! /* the shell stops here */ ! sigsys(SIGTSTP, old); ! if (tpgrp != -1) { ! retry: ! ioctl(FSHTTY, TIOCGPGRP, &ctpgrp); ! if (ctpgrp != opgrp) { ! old = sigsys(SIGTTIN, SIG_DFL); ! kill(0, SIGTTIN); ! sigsys(SIGTTIN, old); ! goto retry; ! } ! ioctl(FSHTTY, TIOCSPGRP, &shpgrp); ! setpgrp(0, shpgrp); ! } ! ioctl(FSHTTY, TIOCGETD, &oldisc); ! if (oldisc != NTTYDISC) { ! printf("Switching to new tty driver...\n"); ! ldisc = NTTYDISC; ! ioctl(FSHTTY, TIOCSETD, &ldisc); ! } ! } ! ! /* dodetach - try to stop the shell and insulate it from the SIGKILL that ! init will send it by forking and having the PARENT exit(0) */ ! ! dodetach() ! { ! int old, ldisc; ! short ctpgrp; ! int fork_val; ! ! if (!loginsh) { ! dosuspend(); ! return; ! } ! printf ("Trying to detach, hang on..."); ! /* try to clone yourself */ ! fork_val = fork(); ! ! /* if you did, then die, else spit an error */ ! if (fork_val == -1) { ! error ("Could not make the fork for detaching."); ! } else if (fork_val != 0) { ! exit (0); /* parent fork dies at this point, leaving ! the orphan which we now are */ ! } untty(); old = sigsys(SIGTSTP, SIG_DFL); kill(0, SIGTSTP); ======== diff -bc csh/sh.h tcsh/sh.h ======== *** csh/sh.h Fri Apr 13 10:44:07 1984 --- tcsh/sh.h Fri Apr 13 10:45:09 1984 *************** *** 5,10 #include #endif /* * C shell * --- 5,12 ----- #include #endif + #define OSU + /* do the ohio state changes */ /* * C shell * *************** *** 73,79 short opgrp; /* Initial pgrp and tty pgrp */ int oldisc; /* Initial line discipline or -1 */ struct tms shtimes; /* shell and child times for process timing */ ! /* * These are declared here because they want to be * initialized in sh.init.c (to allow them to be made readonly) --- 75,83 ----- short opgrp; /* Initial pgrp and tty pgrp */ int oldisc; /* Initial line discipline or -1 */ struct tms shtimes; /* shell and child times for process timing */ ! char PromptBuf[256]; /* buffer for the actual printed prompt. ! this is used in tenex.c and sh.c for ! pegets.c */ /* * These are declared here because they want to be * initialized in sh.init.c (to allow them to be made readonly) ======== diff -bc csh/sh.init.c tcsh/sh.init.c ======== *** csh/sh.init.c Fri Apr 13 10:44:07 1984 --- tcsh/sh.init.c Fri Apr 13 10:45:11 1984 *************** *** 8,13 extern int doalias(); extern int dobg(); extern int dobreak(); extern int dochngd(); extern int docontin(); --- 8,14 ----- extern int doalias(); extern int dobg(); + extern int dobind(); extern int dobreak(); extern int dochngd(); extern int docontin(); *************** *** 11,16 extern int dobreak(); extern int dochngd(); extern int docontin(); extern int dodirs(); extern int doecho(); extern int doelse(); --- 12,18 ----- extern int dobreak(); extern int dochngd(); extern int docontin(); + extern int dodetach(); extern int dodirs(); extern int doecho(); extern int doelse(); *************** *** 78,83 "alloc", showall, 0, 1, #endif "bg", dobg, 0, INF, "break", dobreak, 0, 0, "breaksw", doswbrk, 0, 0, #ifdef IIASA --- 80,86 ----- "alloc", showall, 0, 1, #endif "bg", dobg, 0, INF, + "bind", dobind, 0, 2, "break", dobreak, 0, 0, "breaksw", doswbrk, 0, 0, #ifdef IIASA *************** *** 88,93 "chdir", dochngd, 0, 1, "continue", docontin, 0, 0, "default", dozip, 0, 0, "dirs", dodirs, 0, 1, "echo", doecho, 0, INF, "else", doelse, 0, INF, --- 91,97 ----- "chdir", dochngd, 0, 1, "continue", docontin, 0, 0, "default", dozip, 0, 0, + /* "detach", dodetach, 0, 0, */ "dirs", dodirs, 0, 1, "echo", doecho, 0, INF, "else", doelse, 0, INF, ======== diff -bc csh/sh.lex.c tcsh/sh.lex.c ======== *** csh/sh.lex.c Fri Apr 13 10:44:09 1984 --- tcsh/sh.lex.c Fri Apr 13 10:45:14 1984 *************** *** 1,4 static char *sccsid = "@(#)sh.lex.c 4.1 10/9/80"; #include "sh.h" --- 1,5 ----- static char *sccsid = "@(#)sh.lex.c 4.1 10/9/80"; + static char *SCCSid = "@(#)sh.lex.c 1.3 - 1/1/82 13:57:46 - HP/CRC"; #include "sh.h" *************** *** 1169,1174 bgetc() { register int buf, off, c; #ifdef TELL if (cantell) { --- 1170,1177 ----- bgetc() { register int buf, off, c; + char ttyline[BUFSIZ]; + register int numleft = 0, roomleft; #ifdef TELL if (cantell) { *************** *** 1207,1212 if (fseekp >= feobp) { buf = (int) feobp / BUFSIZ; off = (int) feobp % BUFSIZ; do c = read(SHIN, fbuf[buf] + off, BUFSIZ - off); while (c < 0 && errno == EINTR); --- 1210,1216 ----- if (fseekp >= feobp) { buf = (int) feobp / BUFSIZ; off = (int) feobp % BUFSIZ; + roomleft = BUFSIZ - off; do if (intty) /* then use tenex routine */ { *************** *** 1208,1214 buf = (int) feobp / BUFSIZ; off = (int) feobp % BUFSIZ; do ! c = read(SHIN, fbuf[buf] + off, BUFSIZ - off); while (c < 0 && errno == EINTR); if (c <= 0) return (-1); --- 1212,1235 ----- off = (int) feobp % BUFSIZ; roomleft = BUFSIZ - off; do ! if (intty) /* then use tenex routine */ ! { ! c = numleft ? numleft : ! (isatty (SHIN) ? twenex(ttyline, BUFSIZ) : ! read(SHIN, ttyline, BUFSIZ) ); ! if (c > roomleft) /* No room in this buffer? */ ! { ! /* start with fresh buffer */ ! feobp = fseekp = fblocks * BUFSIZ; ! numleft = c; ! goto again; ! } ! if (c > 0) ! copy (fbuf[buf] + off, ttyline, c); ! numleft = 0; ! } ! else ! c = read(SHIN, fbuf[buf] + off, roomleft); while (c < 0 && errno == EINTR); if (c <= 0) return (-1); *************** *** 1213,1218 if (c <= 0) return (-1); feobp += c; goto again; } c = fbuf[buf][(int) fseekp % BUFSIZ]; --- 1234,1240 ----- if (c <= 0) return (-1); feobp += c; + if (!intty) goto again; } c = fbuf[buf][(int) fseekp % BUFSIZ]; ======== diff -bc csh/sh.misc.c tcsh/sh.misc.c ======== *** csh/sh.misc.c Fri Apr 13 10:44:10 1984 --- tcsh/sh.misc.c Fri Apr 13 10:45:16 1984 *************** *** 370,372 return (0); } } --- 370,413 ----- return (0); } } + + itoa(n, s) /* convert n to characters in s */ + int n; + char *s; + { + int i, sign; + + if ((sign = n) < 0) /* record sign */ + n = -n; + i = 0; + do { + s[i++] = n % 10 + '0'; + } while ((n /= 10) > 0); + if (sign < 0) + s[i++] = '-'; + s[i] = '\0'; + Reverse(s); + } + + Reverse(s) + char *s; + { + int c, i, j; + + for (i=0, j = strlen(s)-1; i < j; i++, j--) { + c = s[i]; + s[i] = s[j]; + s[j] = c; + } + } + + #include + + isatty(f) + { + struct sgttyb ttyb; + + if (gtty(f, &ttyb) < 0) + return(0); + return(1); + } ======== diff -bc csh/sh.proc.c tcsh/sh.proc.c ======== *** csh/sh.proc.c Fri Apr 13 10:44:16 1984 --- tcsh/sh.proc.c Fri Apr 13 10:45:22 1984 *************** *** 299,305 register int index; if (pp->p_pid == 0) { ! printf("BUG: process flushed twice"); return; } while (pp->p_pid != pp->p_jobid) --- 299,305 ----- register int index; if (pp->p_pid == 0) { ! printf("BUG: process flushed twice\n"); return; } while (pp->p_pid != pp->p_jobid) *************** *** 605,611 break; default: ! printf("BUG: status=%-9o", status); } } } --- 605,611 ----- break; default: ! printf("BUG: status=%-9o\n", status); } } } ======== diff -bc csh/sh.set.c tcsh/sh.set.c ======== *** csh/sh.set.c Fri Apr 13 10:44:20 1984 --- tcsh/sh.set.c Fri Apr 13 10:45:24 1984 *************** *** 73,79 HIST = *p++; HISTSUB = *p; ! } else if (eq(vp, "user")) setenv("USER", value(vp)); else if (eq(vp, "term")) setenv("TERM", value(vp)); --- 73,79 ----- HIST = *p++; HISTSUB = *p; ! } else if (eq(vp, "user")) { setenv("USER", value(vp)); } else if (eq(vp, "shlvl")) { setenv("SHLVL", value(vp)); *************** *** 75,83 HISTSUB = *p; } else if (eq(vp, "user")) setenv("USER", value(vp)); ! else if (eq(vp, "term")) ! setenv("TERM", value(vp)); ! else if (eq(vp, "home")) setenv("HOME", value(vp)); } while (p = *v++); } --- 75,83 ----- HISTSUB = *p; } else if (eq(vp, "user")) { setenv("USER", value(vp)); ! } else if (eq(vp, "shlvl")) { ! setenv("SHLVL", value(vp)); ! } else if (eq(vp, "home")) { setenv("HOME", value(vp)); } else if (eq(vp, "term")) { setenv("TERM", value(vp)); *************** *** 79,84 setenv("TERM", value(vp)); else if (eq(vp, "home")) setenv("HOME", value(vp)); } while (p = *v++); } --- 79,88 ----- setenv("SHLVL", value(vp)); } else if (eq(vp, "home")) { setenv("HOME", value(vp)); + } else if (eq(vp, "term")) { + setenv("TERM", value(vp)); + ilsetup(SHIN, SHOUT); + } } while (p = *v++); } !Funky!Stuff!