home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / tcsh.4.3 / part01 / DIFFS.1
Encoding:
Text File  |  1987-09-27  |  57.9 KB  |  2,621 lines

  1. *** sh.c    Sat Mar 29 07:17:01 1986
  2. --- /usr/src/local/tcsh/sh.c    Thu Sep 17 23:22:08 1987
  3. ***************
  4. *** 7,12
  5.   #ifndef lint
  6.   static char *sccsid = "@(#)sh.c    5.3 (Berkeley) 3/29/86";
  7.   #endif
  8.   
  9.   #include "sh.h"
  10.   #include <sys/ioctl.h>
  11.  
  12. --- 7,13 -----
  13.   #ifndef lint
  14.   static char *sccsid = "@(#)sh.c    5.3 (Berkeley) 3/29/86";
  15.   #endif
  16. + static char *Version = "tcsh 5.4 (Ohio State) 7/18/87 Patch level 0";
  17.   
  18.   #include "sh.h"
  19.   /* #include <sys/ioctl.h> */
  20. ***************
  21. *** 9,15
  22.   #endif
  23.   
  24.   #include "sh.h"
  25. ! #include <sys/ioctl.h>
  26.   /*
  27.    * C Shell
  28.    *
  29.  
  30. --- 10,27 -----
  31.   static char *Version = "tcsh 5.4 (Ohio State) 7/18/87 Patch level 0";
  32.   
  33.   #include "sh.h"
  34. ! /* #include <sys/ioctl.h> */
  35. ! #ifdef SVID
  36. ! struct termio termiob;
  37. ! # ifdef OREO
  38. ! struct ltchars ltcbuf;
  39. ! #include <compat.h>
  40. ! # endif OREO
  41. ! #endif SVID
  42.   /*
  43.    * C Shell
  44.    *
  45. ***************
  46. *** 18,23
  47.    *
  48.    * Jim Kulp, IIASA, Laxenburg, Austria
  49.    * April 1980
  50.    */
  51.   
  52.   char    *pathlist[] =    { ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  53.  
  54. --- 30,55 -----
  55.    *
  56.    * Jim Kulp, IIASA, Laxenburg, Austria
  57.    * April 1980
  58. +  *
  59. +  * Filename recognition added:
  60. +  * Ken Greer, Ind. Consultant, Palo Alto CA
  61. +  * October 1983.
  62. +  *
  63. +  * Karl Kleinpaste, Computer Consoles, Inc.
  64. +  * Added precmd, periodic/tperiod, prompt changes,
  65. +  * directory stack hack, and login watch.
  66. +  * Sometime March 1983 - Feb 1984.
  67. +  *
  68. +  * Added scheduled commands, including the "sched" command,
  69. +  * plus the call to sched_run near the precmd et al
  70. +  * routines.
  71. +  * Upgraded scheduled events for running events while
  72. +  * sitting idle at command input.
  73. +  *
  74. +  * Paul Placeway, Ohio State
  75. +  * added stuff for running with twenex/inputl  9 Oct 1984.
  76. +  *
  77. +  * ported to Apple Unix (TM) (OREO)  26 -- 29 Jun 1987
  78.    */
  79.   
  80.   char    *pathlist[] =    { ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  81. ***************
  82. *** 23,30
  83.   char    *pathlist[] =    { ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  84.   char    *dumphist[] =    { "history", "-h", 0, 0 };
  85.   char    *loadhist[] =    { "source", "-h", "~/.history", 0 };
  86. ! char    HIST = '!';
  87. ! char    HISTSUB = '^';
  88.   bool    nofile;
  89.   bool    reenter;
  90.   bool    nverbose;
  91.  
  92. --- 55,62 -----
  93.   char    *pathlist[] =    { ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  94.   char    *dumphist[] =    { "history", "-h", 0, 0 };
  95.   char    *loadhist[] =    { "source", "-h", "~/.history", 0 };
  96. ! /* char    HIST = '!'; */
  97. ! /* char    HISTSUB = '^'; */
  98.   bool    nofile;
  99.   bool    reenter;
  100.   bool    nverbose;
  101. ***************
  102. *** 34,39
  103.   bool    batch;
  104.   bool    prompt = 1;
  105.   bool    enterhist = 0;
  106.   
  107.   extern    gid_t getegid(), getgid();
  108.   extern    uid_t geteuid(), getuid();
  109.  
  110. --- 66,79 -----
  111.   bool    batch;
  112.   bool    prompt = 1;
  113.   bool    enterhist = 0;
  114. + bool    tellwhat = 0;
  115. + int    phup();
  116. + time_t    t_period;
  117. + time_t    watch_period = 0;
  118. + struct who *wholist;
  119. + bool    precmd_active = 0;
  120. + bool    periodic_active = 0;
  121. + char    buff[128];        /* for gethostname(2), and printprompt() */
  122.   
  123.   extern    gid_t getegid(), getgid();
  124.   extern    uid_t geteuid(), getuid();
  125. ***************
  126. *** 38,43
  127.   extern    gid_t getegid(), getgid();
  128.   extern    uid_t geteuid(), getuid();
  129.   
  130.   main(c, av)
  131.       int c;
  132.       char **av;
  133.  
  134. --- 78,111 -----
  135.   extern    gid_t getegid(), getgid();
  136.   extern    uid_t geteuid(), getuid();
  137.   
  138. + #define DEFAULT_AUTOLOGOUT    "60"    /* 1 Hour Alarm default */
  139. + auto_logout ()
  140. + {
  141. +     printf ("auto-logout\n");
  142. +     close (SHIN);
  143. +     set ("logout", "automatic");
  144. +     child++;
  145. +     goodbye ();
  146. + }
  147. + alrmcatch ()
  148. + {
  149. +     extern    struct    sched_event *sched_ptr;
  150. +     time_t    cl;
  151. +     if (!sched_ptr)
  152. +         auto_logout();    /* no other possibility - logout */
  153. +     time(&cl);
  154. +     if (sched_ptr->t_when <= cl + 1)
  155. +         sched_run();
  156. +     else
  157. +         auto_logout();
  158. +     setalarm();
  159. + }
  160. + char    *ttyname();
  161.   main(c, av)
  162.       int c;
  163.       char **av;
  164. ***************
  165. *** 47,52
  166.       struct sigvec osv;
  167.   
  168.       settimes();            /* Immed. estab. timing base */
  169.       v = av;
  170.       if (eq(v[0], "a.out"))        /* A.out's are quittable */
  171.           quitit = 1;
  172.  
  173. --- 115,128 -----
  174.       struct sigvec osv;
  175.   
  176.       settimes();            /* Immed. estab. timing base */
  177. + #ifdef OREO
  178. +     set42sig();
  179. +     setcompat (COMPAT_BSDPROT | COMPAT_BSDNBIO | COMPAT_BSDSIGNALS |
  180. +           COMPAT_SYSCALLS);
  181. + #endif
  182. +     HIST = '!';
  183. +     HISTSUB = '^';
  184.       v = av;
  185.       if (eq(v[0], "a.out"))        /* A.out's are quittable */
  186.           quitit = 1;
  187. ***************
  188. *** 56,61
  189.           (void) time(&chktim);
  190.   
  191.       /*
  192.        * Move the descriptors to safe places.
  193.        * The variable didfds is 0 while we have only FSH* to work with.
  194.        * When didfds is true, we have 0,1,2 and prefer to use these.
  195.  
  196. --- 132,144 -----
  197.           (void) time(&chktim);
  198.   
  199.       /*
  200. +      * Initialize for periodic command intervals.
  201. +      * Also, initialize the dummy tty list for login-watch.
  202. +      */
  203. +     time(&t_period);
  204. +     initwatch();
  205. +     /*
  206.        * Move the descriptors to safe places.
  207.        * The variable didfds is 0 while we have only FSH* to work with.
  208.        * When didfds is true, we have 0,1,2 and prefer to use these.
  209. ***************
  210. *** 69,74
  211.        * CHILD is munged when forking/waiting
  212.        */
  213.   
  214.       set("status", "0");
  215.       dinit(cp = getenv("HOME"));    /* dinit thinks that HOME == cwd in a
  216.                        * login shell */
  217.  
  218. --- 152,181 -----
  219.        * CHILD is munged when forking/waiting
  220.        */
  221.   
  222. +     /* 7-10-87 Paul Placeway
  223. +      * autologout should be set ONLY on login shells and on shells
  224. +      * running as root.  Out of these, autologout should NOT be set
  225. +      * for any psudo-terminals (this catches most window systems)
  226. +      * and not for any terminal running X windows.
  227. +      *
  228. +      * At Ohio State, we have had problems with a user having his
  229. +      * X session drop out from under him (on a Sun) because the shell
  230. +      * in his master xterm timed out and exited.
  231. +      *
  232. +      * Really, this should be done with a program external to the
  233. +      * shell, that watches for no activity (and NO running programs,
  234. +      * such as dump) on a terminal for a long peroid of time, and
  235. +      * then SIGHUPS the shell on that terminal.
  236. +      */
  237. +     if (loginsh || getuid() == 0) { /* only for login shells or root */
  238. +         cp = ttyname(SHIN);
  239. +         if ((strncmp (cp, "ttyp", 4) != 0) &&
  240. +         (strncmp (cp, "ttyp", 4) != 0))
  241. +         if (getenv("DISPLAY") == NOSTR) /* NOT on X window shells */
  242. +             set("autologout", DEFAULT_AUTOLOGOUT);
  243. +     }
  244. +     signal(SIGALRM, alrmcatch);
  245.       set("status", "0");
  246.       set("tcsh", "1");        /* so I can tell the difference */
  247.       dinit(cp = getenv("HOME"));    /* dinit thinks that HOME == cwd in a
  248. ***************
  249. *** 70,75
  250.        */
  251.   
  252.       set("status", "0");
  253.       dinit(cp = getenv("HOME"));    /* dinit thinks that HOME == cwd in a
  254.                        * login shell */
  255.       if (cp == NOSTR)
  256.  
  257. --- 177,183 -----
  258.   
  259.       signal(SIGALRM, alrmcatch);
  260.       set("status", "0");
  261. +     set("tcsh", "1");        /* so I can tell the difference */
  262.       dinit(cp = getenv("HOME"));    /* dinit thinks that HOME == cwd in a
  263.                        * login shell */
  264.       if (cp == NOSTR)
  265. ***************
  266. *** 84,89
  267.           set("user", savestr(cp));
  268.       if ((cp = getenv("TERM")) != NOSTR)
  269.           set("term", savestr(cp));
  270.       /*
  271.        * Re-initialize path if set in environment
  272.        */
  273.  
  274. --- 192,199 -----
  275.           set("user", savestr(cp));
  276.       if ((cp = getenv("TERM")) != NOSTR)
  277.           set("term", savestr(cp));
  278. +     set ("version", Version); /* publish the shell version */
  279.       /*
  280.        * set usefull environment things for the user
  281.        */
  282. ***************
  283. *** 85,90
  284.       if ((cp = getenv("TERM")) != NOSTR)
  285.           set("term", savestr(cp));
  286.       /*
  287.        * Re-initialize path if set in environment
  288.        */
  289.       if ((cp = getenv("PATH")) == NOSTR)
  290.  
  291. --- 195,235 -----
  292.   
  293.       set ("version", Version); /* publish the shell version */
  294.       /*
  295. +      * set usefull environment things for the user
  296. +      */
  297. +     itoa (getuid(), buff);
  298. +     set ("uid", buff);
  299. +     if ((cp = getenv("HOST")) == NOSTR) { /* if not allready set */
  300. +         gethostname (buff, sizeof(buff));
  301. +         buff[sizeof(buff) -1] = '\0'; /* just in case */
  302. +         setenv ("HOST", buff);
  303. +     }
  304. +     if ((cp = getenv("HOSTTYPE")) == NOSTR) { /* if not allready set */
  305. + #ifdef vax
  306. +         setenv ("HOSTTYPE", "vax");
  307. + #endif
  308. + #ifdef sun
  309. + # ifdef mc68010
  310. +         setenv ("HOSTTYPE", "sun2");
  311. + # else
  312. + #  ifdef mc68020
  313. +         setenv ("HOSTTYPE", "sun3");
  314. + #  else
  315. +         setenv ("HOSTTYPE", "sun");
  316. + #  endif
  317. + # endif
  318. + #endif
  319. + #ifdef pyr            /* pyramid */
  320. +         setenv ("HOSTTYPE", "pyramid");
  321. + #endif
  322. + #ifdef OREO
  323. +         setenv ("HOSTTYPE", "mac2");
  324. + #endif OREO
  325. + #ifdef ns32000                  /* ugh!  This should change */
  326. +             setenv ("HOSTTYPE", "multimax");
  327. + #endif
  328. +     }
  329. +     /*
  330.        * Re-initialize path if set in environment
  331.        */
  332.       if ((cp = getenv("PATH")) == NOSTR)
  333. ***************
  334. *** 205,210
  335.           }
  336.           file = v[0];
  337.           SHIN = dmove(nofile, FSHIN);    /* Replace FSHIN */
  338.           (void) ioctl(SHIN, FIOCLEX, (char *)0);
  339.           prompt = 0;
  340.           c--, v++;
  341.  
  342. --- 350,356 -----
  343.           }
  344.           file = v[0];
  345.           SHIN = dmove(nofile, FSHIN);    /* Replace FSHIN */
  346. + #ifdef BSD4_3
  347.           (void) ioctl(SHIN, FIOCLEX, (char *)0);
  348.   #endif
  349.           prompt = 0;
  350. ***************
  351. *** 206,211
  352.           file = v[0];
  353.           SHIN = dmove(nofile, FSHIN);    /* Replace FSHIN */
  354.           (void) ioctl(SHIN, FIOCLEX, (char *)0);
  355.           prompt = 0;
  356.           c--, v++;
  357.       }
  358.  
  359. --- 352,358 -----
  360.           SHIN = dmove(nofile, FSHIN);    /* Replace FSHIN */
  361.   #ifdef BSD4_3
  362.           (void) ioctl(SHIN, FIOCLEX, (char *)0);
  363. + #endif
  364.           prompt = 0;
  365.           c--, v++;
  366.       }
  367. ***************
  368. *** 239,246
  369.       /*
  370.        * Set up the prompt.
  371.        */
  372. !     if (prompt)
  373. !         set("prompt", uid == 0 ? "# " : "% ");
  374.   
  375.       /*
  376.        * If we are an interactive shell, then start fiddling
  377.  
  378. --- 386,395 -----
  379.       /*
  380.        * Set up the prompt.
  381.        */
  382. !     if (prompt) {
  383. !         set("prompt", uid == 0 ? "# " : "> ");
  384. !         set("prompt2", "\277 "); /* that's a meta-questionmark */
  385. !     }
  386.   
  387.       /*
  388.        * If we are an interactive shell, then start fiddling
  389. ***************
  390. *** 275,280
  391.               else
  392.                   f = -1;
  393.   retry:
  394.               if (ioctl(f, TIOCGPGRP, (char *)&tpgrp) == 0 &&
  395.                   tpgrp != -1) {
  396.                   int ldisc;
  397.  
  398. --- 424,430 -----
  399.               else
  400.                   f = -1;
  401.   retry:
  402. + #ifdef BSDJOBS            /* if we have tty job control */
  403.               if (ioctl(f, TIOCGPGRP, (char *)&tpgrp) == 0 &&
  404.                   tpgrp != -1) {
  405.                   int ldisc;
  406. ***************
  407. *** 286,291
  408.                   }
  409.                   if (ioctl(f, TIOCGETD, (char *)&oldisc) != 0) 
  410.                       goto notty;
  411.                   if (oldisc != NTTYDISC) {
  412.   #ifdef DEBUG
  413.                       printf("Switching to new tty driver...\n");
  414.  
  415. --- 436,468 -----
  416.                   }
  417.                   if (ioctl(f, TIOCGETD, (char *)&oldisc) != 0) 
  418.                       goto notty;
  419. + # ifdef OREO
  420. +             if (ioctl(f, TCGETA, &termiob) != 0)
  421. +                     goto notty;
  422. +                 if ((getcompat(COMPAT_BSDTTY) & COMPAT_BSDTTY)
  423. +                     != COMPAT_BSDTTY) {
  424. + #  ifdef DEBUG
  425. +                     printf("Switching to new tty driver...\n");
  426. + #  endif DEBUG
  427. +                     setcompat(COMPAT_BSDTTY);
  428. +                     if (ioctl (f, TIOCGLTC, <cbuf) < 0) {
  429. +                     printf ("Couldn't get local chars.\n");
  430. +                     } else {
  431. + #  ifdef DEBUG
  432. +                     printf ("Setting ^Z, etc....\n");
  433. + #  endif DEBUG
  434. +                     ltcbuf.t_suspc = '\032'; /* ^Z */
  435. +                     ltcbuf.t_dsuspc = '\031'; /* ^Y */
  436. +                     ltcbuf.t_rprntc = '\022'; /* ^R */
  437. +                     ltcbuf.t_flushc = '\017'; /* ^O */
  438. +                     ltcbuf.t_werasc = '\027'; /* ^W */
  439. +                     ltcbuf.t_lnextc = '\026'; /* ^V */
  440. +                     ioctl (f, TIOCSLTC, <cbuf);
  441. +                     }
  442. +                     termiob.c_cc[VSWTCH] = '\0';
  443. +                     ioctl(f, TCSETAF, &termiob);
  444. +                 }
  445. + # else OREO
  446.                   if (oldisc != NTTYDISC) {
  447.   #  ifdef DEBUG
  448.                       printf("Switching to new tty driver...\n");
  449. ***************
  450. *** 287,293
  451.                   if (ioctl(f, TIOCGETD, (char *)&oldisc) != 0) 
  452.                       goto notty;
  453.                   if (oldisc != NTTYDISC) {
  454. ! #ifdef DEBUG
  455.                       printf("Switching to new tty driver...\n");
  456.   #endif DEBUG
  457.                       ldisc = NTTYDISC;
  458.  
  459. --- 464,470 -----
  460.                   }
  461.   # else OREO
  462.                   if (oldisc != NTTYDISC) {
  463. ! #  ifdef DEBUG
  464.                       printf("Switching to new tty driver...\n");
  465.   #  endif DEBUG
  466.                       ldisc = NTTYDISC;
  467. ***************
  468. *** 289,295
  469.                   if (oldisc != NTTYDISC) {
  470.   #ifdef DEBUG
  471.                       printf("Switching to new tty driver...\n");
  472. ! #endif DEBUG
  473.                       ldisc = NTTYDISC;
  474.                       (void) ioctl(f, TIOCSETD,
  475.                           (char *)&ldisc);
  476.  
  477. --- 466,472 -----
  478.                   if (oldisc != NTTYDISC) {
  479.   #  ifdef DEBUG
  480.                       printf("Switching to new tty driver...\n");
  481. ! #  endif DEBUG
  482.                       ldisc = NTTYDISC;
  483.                       (void) ioctl(f, TIOCSETD,
  484.                           (char *)&ldisc);
  485. ***************
  486. *** 295,300
  487.                           (char *)&ldisc);
  488.                   } else
  489.                       oldisc = -1;
  490.                   opgrp = shpgrp;
  491.                   shpgrp = getpid();
  492.                   tpgrp = shpgrp;
  493.  
  494. --- 472,478 -----
  495.                           (char *)&ldisc);
  496.                   } else
  497.                       oldisc = -1;
  498. + # endif OREO
  499.                   opgrp = shpgrp;
  500.                   shpgrp = getpid();
  501.                   tpgrp = shpgrp;
  502. ***************
  503. *** 307,312
  504.     printf("Warning: no access to tty; thus no job control in this shell...\n");
  505.                   tpgrp = -1;
  506.               }
  507.           }
  508.       }
  509.       if (setintr == 0 && parintr == SIG_DFL)
  510.  
  511. --- 485,494 -----
  512.     printf("Warning: no access to tty; thus no job control in this shell...\n");
  513.                   tpgrp = -1;
  514.               }
  515. + #else BSDJOBS            /* don't have job control, so frotz it */
  516. +             tpgrp = -1;
  517. +             printf ("Warning: jobs not implemented yet.\n");
  518. + #endif BSDJOBS
  519.           }
  520.       }
  521.       if (setintr == 0 && parintr == SIG_DFL)
  522. ***************
  523. *** 321,326
  524.       haderr = 0;        /* In case second time through */
  525.       if (!fast && reenter == 0) {
  526.           reenter++;
  527.           /* Will have value("home") here because set fast if don't */
  528.           srccat(value("home"), "/.cshrc");
  529.           if (!fast && !arginp && !onelflg && !havhash)
  530.  
  531. --- 503,512 -----
  532.       haderr = 0;        /* In case second time through */
  533.       if (!fast && reenter == 0) {
  534.           reenter++;
  535. +                 if (!fast && !arginp && !onelflg) { /* PWP setup stuff */
  536. +             ed_Init();    /* init the new line editor */
  537. +             /* PWP: setup the editor BEFORE doing .cshrc, else bugs! */
  538. +         }    
  539.           /* Will have value("home") here because set fast if don't */
  540.           srccat(value("home"), "/.cshrc");    /* upward compat. */
  541.           if (!fast && !arginp && !onelflg && !havhash)
  542. ***************
  543. *** 322,328
  544.       if (!fast && reenter == 0) {
  545.           reenter++;
  546.           /* Will have value("home") here because set fast if don't */
  547. !         srccat(value("home"), "/.cshrc");
  548.           if (!fast && !arginp && !onelflg && !havhash)
  549.               dohash();
  550.           if (loginsh) {
  551.  
  552. --- 508,514 -----
  553.               /* PWP: setup the editor BEFORE doing .cshrc, else bugs! */
  554.           }    
  555.           /* Will have value("home") here because set fast if don't */
  556. !         srccat(value("home"), "/.cshrc");    /* upward compat. */
  557.           if (!fast && !arginp && !onelflg && !havhash)
  558.               dohash();
  559.           if (loginsh) {
  560. ***************
  561. *** 350,360
  562.       /*
  563.        * Mop-up.
  564.        */
  565. !     if (loginsh) {
  566. !         printf("logout\n");
  567. !         (void) close(SHIN);
  568. !         child++;
  569. !         goodbye();
  570.       }
  571.       rechist();
  572.       exitstat();
  573.  
  574. --- 536,550 -----
  575.       /*
  576.        * Mop-up.
  577.        */
  578. !     if (intty) {
  579. !         if (loginsh) {
  580. !             printf("logout\n");
  581. !             (void) close(SHIN);
  582. !             child++;
  583. !             goodbye();
  584. !         } else {
  585. !             printf ("exit\n");
  586. !         }
  587.       }
  588.       rechist();
  589.       exitstat();
  590. ***************
  591. *** 362,368
  592.   
  593.   untty()
  594.   {
  595.       if (tpgrp > 0) {
  596.           (void) setpgrp(0, opgrp);
  597.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  598.  
  599. --- 552,558 -----
  600.   
  601.   untty()
  602.   {
  603. ! #ifdef BSDJOBS
  604.       if (tpgrp > 0) {
  605.           (void) setpgrp(0, opgrp);
  606.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  607. ***************
  608. *** 366,371
  609.       if (tpgrp > 0) {
  610.           (void) setpgrp(0, opgrp);
  611.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  612.           if (oldisc != -1 && oldisc != NTTYDISC) {
  613.   #ifdef DEBUG
  614.               printf("\nReverting to old tty driver...\n");
  615.  
  616. --- 556,562 -----
  617.       if (tpgrp > 0) {
  618.           (void) setpgrp(0, opgrp);
  619.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  620. + # ifndef OREO
  621.           if (oldisc != -1 && oldisc != NTTYDISC) {
  622.   #  ifdef DEBUG
  623.               printf("\nReverting to old tty driver...\n");
  624. ***************
  625. *** 367,373
  626.           (void) setpgrp(0, opgrp);
  627.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  628.           if (oldisc != -1 && oldisc != NTTYDISC) {
  629. ! #ifdef DEBUG
  630.               printf("\nReverting to old tty driver...\n");
  631.   #endif DEBUG
  632.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  633.  
  634. --- 558,564 -----
  635.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&opgrp);
  636.   # ifndef OREO
  637.           if (oldisc != -1 && oldisc != NTTYDISC) {
  638. ! #  ifdef DEBUG
  639.               printf("\nReverting to old tty driver...\n");
  640.   #  endif DEBUG
  641.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  642. ***************
  643. *** 369,375
  644.           if (oldisc != -1 && oldisc != NTTYDISC) {
  645.   #ifdef DEBUG
  646.               printf("\nReverting to old tty driver...\n");
  647. ! #endif DEBUG
  648.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  649.           }
  650.       }
  651.  
  652. --- 560,566 -----
  653.           if (oldisc != -1 && oldisc != NTTYDISC) {
  654.   #  ifdef DEBUG
  655.               printf("\nReverting to old tty driver...\n");
  656. ! #  endif DEBUG
  657.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  658.           }
  659.   # endif OREO
  660. ***************
  661. *** 372,377
  662.   #endif DEBUG
  663.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  664.           }
  665.       }
  666.   }
  667.   
  668.  
  669. --- 563,569 -----
  670.   #  endif DEBUG
  671.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  672.           }
  673. + # endif OREO
  674.       }
  675.   #endif BSDJOBS
  676.   }
  677. ***************
  678. *** 373,378
  679.               (void) ioctl(FSHTTY, TIOCSETD, (char *)&oldisc);
  680.           }
  681.       }
  682.   }
  683.   
  684.   importpath(cp)
  685.  
  686. --- 565,571 -----
  687.           }
  688.   # endif OREO
  689.       }
  690. + #endif BSDJOBS
  691.   }
  692.   
  693.   importpath(cp)
  694. ***************
  695. *** 421,426
  696.       register char *ep = strspl(cp, dp);
  697.       register int unit = dmove(open(ep, 0), -1);
  698.   
  699.       (void) ioctl(unit, FIOCLEX, (char *)0);
  700.       xfree(ep);
  701.   #ifdef INGRES
  702.  
  703. --- 614,620 -----
  704.       register char *ep = strspl(cp, dp);
  705.       register int unit = dmove(open(ep, 0), -1);
  706.   
  707. + #ifdef BSD4_3
  708.       (void) ioctl(unit, FIOCLEX, (char *)0);
  709.   #endif
  710.       xfree(ep);
  711. ***************
  712. *** 422,427
  713.       register int unit = dmove(open(ep, 0), -1);
  714.   
  715.       (void) ioctl(unit, FIOCLEX, (char *)0);
  716.       xfree(ep);
  717.   #ifdef INGRES
  718.       srcunit(unit, 0, 0);
  719.  
  720. --- 616,622 -----
  721.   
  722.   #ifdef BSD4_3
  723.       (void) ioctl(unit, FIOCLEX, (char *)0);
  724. + #endif
  725.       xfree(ep);
  726.   #ifdef INGRES
  727.       srcunit(unit, 0, 0);
  728. ***************
  729. *** 464,471
  730.       if (onlyown) {
  731.           struct stat stb;
  732.   
  733. !         if (fstat(unit, &stb) < 0 ||
  734. !             (stb.st_uid != uid && stb.st_gid != getgid())) {
  735.               (void) close(unit);
  736.               return;
  737.           }
  738.  
  739. --- 659,667 -----
  740.       if (onlyown) {
  741.           struct stat stb;
  742.   
  743. !         if (fstat(unit, &stb) < 0
  744. !         /*    || (stb.st_uid != uid && stb.st_gid != getgid()) */
  745. !             ) {
  746.               (void) close(unit);
  747.               return;
  748.           }
  749. ***************
  750. *** 573,578
  751.   
  752.   goodbye()
  753.   {
  754.       if (loginsh) {
  755.           (void) signal(SIGQUIT, SIG_IGN);
  756.           (void) signal(SIGINT, SIG_IGN);
  757.  
  758. --- 769,775 -----
  759.   
  760.   goodbye()
  761.   {
  762. +     rechist();
  763.       if (loginsh) {
  764.           (void) signal(SIGQUIT, SIG_IGN);
  765.           (void) signal(SIGINT, SIG_IGN);
  766. ***************
  767. *** 578,583
  768.           (void) signal(SIGINT, SIG_IGN);
  769.           (void) signal(SIGTERM, SIG_IGN);
  770.           setintr = 0;        /* No interrupts after "logout" */
  771.           if (adrof("home"))
  772.               srccat(value("home"), "/.logout");
  773.       }
  774.  
  775. --- 775,782 -----
  776.           (void) signal(SIGINT, SIG_IGN);
  777.           (void) signal(SIGTERM, SIG_IGN);
  778.           setintr = 0;        /* No interrupts after "logout" */
  779. +         if (!(adrof("logout")))
  780. +             set ("logout", "normal");
  781.           if (adrof("home"))
  782.               srccat(value("home"), "/.logout");
  783.       }
  784. ***************
  785. *** 581,587
  786.           if (adrof("home"))
  787.               srccat(value("home"), "/.logout");
  788.       }
  789. -     rechist();
  790.       exitstat();
  791.   }
  792.   
  793.  
  794. --- 780,785 -----
  795.           if (adrof("home"))
  796.               srccat(value("home"), "/.logout");
  797.       }
  798.       exitstat();
  799.   }
  800.   
  801. ***************
  802. *** 654,661
  803.           if (v = gargv)
  804.               gargv = 0, blkfree(v);
  805.           reset();
  806. !     } else if (intty && wantnl)
  807. !         printf("\n");        /* Some like this, others don't */
  808.       error(NOSTR);
  809.   }
  810.   
  811.  
  812. --- 852,862 -----
  813.           if (v = gargv)
  814.               gargv = 0, blkfree(v);
  815.           reset();
  816. !     } else if (intty && wantnl) {
  817. !         /* printf("\n");    /* Some like this, others don't */
  818. !         putraw ('\r');
  819. !         putraw ('\n');
  820. !     }
  821.       error(NOSTR);
  822.   }
  823.   
  824. ***************
  825. *** 730,735
  826.           if (intty && prompt && evalvec == 0) {
  827.               mailchk();
  828.               /*
  829.                * If we are at the end of the input buffer
  830.                * then we are going to read fresh stuff.
  831.                * Otherwise, we are rereading input and don't
  832.  
  833. --- 931,946 -----
  834.           if (intty && prompt && evalvec == 0) {
  835.               mailchk();
  836.               /*
  837. +              * Watch for logins/logouts.
  838. +              * Next is scheduled commands stored previously using "sched."
  839. +              * Then execute periodic commands.
  840. +              * Following that, the prompt precmd is run.
  841. +              */
  842. +             watch_login();
  843. +             sched_run();
  844. +             period_cmd();
  845. +             precmd();
  846. +             /*
  847.                * If we are at the end of the input buffer
  848.                * then we are going to read fresh stuff.
  849.                * Otherwise, we are rereading input and don't
  850. ***************
  851. *** 737,742
  852.                */
  853.               if (fseekp == feobp)
  854.                   printprompt();
  855.           }
  856.           err = 0;
  857.   
  858.  
  859. --- 948,954 -----
  860.                */
  861.               if (fseekp == feobp)
  862.                   printprompt();
  863. +             setalarm();
  864.           }
  865.           err = 0;
  866.   
  867. ***************
  868. *** 744,750
  869.            * Echo not only on VERBOSE, but also with history expansion.
  870.            * If there is a lexical error then we forego history echo.
  871.            */
  872. !         if (lex(¶ml) && !err && intty ||
  873.               adrof("verbose")) {
  874.               haderr = 1;
  875.               prlex(¶ml);
  876.  
  877. --- 956,962 -----
  878.            * Echo not only on VERBOSE, but also with history expansion.
  879.            * If there is a lexical error then we forego history echo.
  880.            */
  881. !         if (lex(¶ml) && !err && intty && !tellwhat ||
  882.               adrof("verbose")) {
  883.               haderr = 1;
  884.               prlex(¶ml);
  885. ***************
  886. *** 750,755
  887.               prlex(¶ml);
  888.               haderr = 0;
  889.           }
  890.   
  891.           /*
  892.            * The parser may lose space if interrupted.
  893.  
  894. --- 962,968 -----
  895.               prlex(¶ml);
  896.               haderr = 0;
  897.           }
  898. +         alarm (0);                /* Autologout OFF */
  899.   
  900.           /*
  901.            * The parser may lose space if interrupted.
  902. ***************
  903. *** 763,769
  904.            * is from the terminal at the top level and not
  905.            * in a loop.
  906.            */
  907. !         if (enterhist || catch && intty && !whyles)
  908.               savehist(¶ml);
  909.   
  910.           /*
  911.  
  912. --- 976,982 -----
  913.            * is from the terminal at the top level and not
  914.            * in a loop.
  915.            */
  916. !         if (enterhist || catch && intty && !whyles && !tellwhat)
  917.               savehist(¶ml);
  918.   
  919.           /*
  920. ***************
  921. *** 783,788
  922.           alias(¶ml);
  923.   
  924.           /*
  925.            * Parse the words of the input into a parse tree.
  926.            */
  927.           t = syntax(paraml.next, ¶ml, 0);
  928.  
  929. --- 996,1009 -----
  930.           alias(¶ml);
  931.   
  932.           /*
  933. +          * If had a tell_what from twenex() then do
  934. +          */
  935. +         if (tellwhat) {
  936. +             tellmewhat(¶ml);
  937. +             reset();
  938. +         }
  939. +         /*
  940.            * Parse the words of the input into a parse tree.
  941.            */
  942.           t = syntax(paraml.next, ¶ml, 0);
  943. ***************
  944. *** 821,826
  945.       xfree(f);
  946.       if (u < 0 && !hflg)
  947.           Perror(f);
  948.       (void) ioctl(u, FIOCLEX, (char *)0);
  949.       srcunit(u, 0, hflg);
  950.   }
  951.  
  952. --- 1042,1048 -----
  953.       xfree(f);
  954.       if (u < 0 && !hflg)
  955.           Perror(f);
  956. + #ifdef BSD4_3
  957.       (void) ioctl(u, FIOCLEX, (char *)0);
  958.   #endif
  959.       srcunit(u, 0, hflg);
  960. ***************
  961. *** 822,827
  962.       if (u < 0 && !hflg)
  963.           Perror(f);
  964.       (void) ioctl(u, FIOCLEX, (char *)0);
  965.       srcunit(u, 0, hflg);
  966.   }
  967.   
  968.  
  969. --- 1044,1050 -----
  970.           Perror(f);
  971.   #ifdef BSD4_3
  972.       (void) ioctl(u, FIOCLEX, (char *)0);
  973. + #endif
  974.       srcunit(u, 0, hflg);
  975.   }
  976.   
  977. ***************
  978. *** 870,876
  979.       chktim = t;
  980.   }
  981.   
  982. ! #include <pwd.h>
  983.   /*
  984.    * Extract a home directory from the password file
  985.    * The argument points to a buffer where the name of the
  986.  
  987. --- 1093,1099 -----
  988.       chktim = t;
  989.   }
  990.   
  991. ! /* #include <pwd.h> */
  992.   /*
  993.    * Extract a home directory from the password file
  994.    * The argument points to a buffer where the name of the
  995. ***************
  996. *** 896,901
  997.   {
  998.   
  999.       didfds = 0;            /* 0, 1, 2 aren't set up */
  1000.       (void) ioctl(SHIN = dcopy(0, FSHIN), FIOCLEX, (char *)0);
  1001.       (void) ioctl(SHOUT = dcopy(1, FSHOUT), FIOCLEX, (char *)0);
  1002.       (void) ioctl(SHDIAG = dcopy(2, FSHDIAG), FIOCLEX, (char *)0);
  1003.  
  1004. --- 1119,1125 -----
  1005.   {
  1006.   
  1007.       didfds = 0;            /* 0, 1, 2 aren't set up */
  1008. + #ifdef BSD4_3
  1009.       (void) ioctl(SHIN = dcopy(0, FSHIN), FIOCLEX, (char *)0);
  1010.       (void) ioctl(SHOUT = dcopy(1, FSHOUT), FIOCLEX, (char *)0);
  1011.       (void) ioctl(SHDIAG = dcopy(2, FSHDIAG), FIOCLEX, (char *)0);
  1012. ***************
  1013. *** 900,905
  1014.       (void) ioctl(SHOUT = dcopy(1, FSHOUT), FIOCLEX, (char *)0);
  1015.       (void) ioctl(SHDIAG = dcopy(2, FSHDIAG), FIOCLEX, (char *)0);
  1016.       (void) ioctl(OLDSTD = dcopy(SHIN, FOLDSTD), FIOCLEX, (char *)0);
  1017.       closem();
  1018.   }
  1019.   
  1020.  
  1021. --- 1124,1135 -----
  1022.       (void) ioctl(SHOUT = dcopy(1, FSHOUT), FIOCLEX, (char *)0);
  1023.       (void) ioctl(SHDIAG = dcopy(2, FSHDIAG), FIOCLEX, (char *)0);
  1024.       (void) ioctl(OLDSTD = dcopy(SHIN, FOLDSTD), FIOCLEX, (char *)0);
  1025. + #else
  1026. +     SHIN = dcopy(0, FSHIN);
  1027. +     SHOUT = dcopy(1, FSHOUT);
  1028. +     SHDIAG = dcopy(2, FSHDIAG);
  1029. +     OLDSTD = dcopy(SHIN, FOLDSTD);
  1030. + #endif
  1031.       closem();
  1032.   }
  1033.   
  1034. ***************
  1035. *** 903,908
  1036.       closem();
  1037.   }
  1038.   
  1039.   #ifdef PROF
  1040.   done(i)
  1041.   #else
  1042.  
  1043. --- 1133,1541 -----
  1044.       closem();
  1045.   }
  1046.   
  1047. +   
  1048. + /*
  1049. +  * Karl Kleinpaste, 21oct1983.
  1050. +  * Added precmd(), which checks for the alias
  1051. +  * precmd in aliases.  If it's there, the alias
  1052. +  * is executed as a command.  This is done
  1053. +  * after mailchk() and just before print-
  1054. +  * ing the prompt.  Useful for things like printing
  1055. +  * one's current directory just before each command.
  1056. +  */
  1057. + precmd()
  1058. + {
  1059. +     int    omask;
  1060. +     omask = sighold (SIGINT);
  1061. +     if (precmd_active) {    /* an error must have been caught */
  1062. +         aliasrun (2, "unalias", "precmd");
  1063. +         printf ("Faulty alias 'precmd' removed.\n");
  1064. +         goto leave;
  1065. +     }
  1066. +     precmd_active++;
  1067. +     if (!whyles && adrof1 ("precmd", &aliases))
  1068. +         aliasrun (1, "precmd", (char *) 0);
  1069. + leave:
  1070. +     precmd_active = 0;
  1071. +     sigsetmask(omask);
  1072. + }
  1073. + /*
  1074. +  * Karl Kleinpaste, 18 Jan 1984.
  1075. +  * Added period_cmd(), which executes the alias "periodic" every
  1076. +  * $tperiod minutes.  Useful for occasional checking of msgs and such.
  1077. +  */
  1078. + period_cmd()
  1079. + {
  1080. +     register char *vp;
  1081. +     time_t t, interval;
  1082. +     int    omask;
  1083. +     omask = sighold (SIGINT);
  1084. +     if (periodic_active) {    /* an error must have been caught */
  1085. +         aliasrun (2, "unalias", "periodic");
  1086. +         printf ("Faulty alias 'periodic' removed.\n");
  1087. +         goto leave;
  1088. +     }
  1089. +     periodic_active++;
  1090. +     if (!whyles && adrof1 ("periodic", &aliases)) {
  1091. +         vp = value ("tperiod");
  1092. +         if (vp == (char *) 0)
  1093. +             return;
  1094. +         interval = getn (vp);
  1095. +         time (&t);
  1096. +         if (t - t_period >= interval * 60) {
  1097. +             t_period = t;
  1098. +             aliasrun (1, "periodic", (char *) 0);
  1099. +         }
  1100. +     }
  1101. + leave:
  1102. +     periodic_active = 0;
  1103. +     sigsetmask(omask);
  1104. + }
  1105. + /*
  1106. +  * Karl Kleinpaste, 21oct1983.
  1107. +  * Set up a one-word alias command, for use for special things.
  1108. +  * This code is based on the mainline of process().
  1109. +  */
  1110. + aliasrun (cnt, s1, s2)
  1111. +     int cnt;
  1112. +     char *s1, *s2;
  1113. + {
  1114. +     struct    wordent    w, *new1, *new2;    /* for holding alias name */
  1115. +     struct    command    *t = (struct command *) 0;
  1116. +     err = NOSTR;            /* don't repeatedly print err msg. */
  1117. +     w.word = "";
  1118. +     new1 = (struct wordent *) calloc (1, sizeof w);
  1119. +     new1->word = savestr (s1);
  1120. +     if (cnt == 1) {
  1121. +         /* build a lex list with one word. */
  1122. +         w.next = w.prev = new1;
  1123. +         new1->next = new1->prev = &w;
  1124. +     } else {
  1125. +         /* build a lex list with two words. */
  1126. +         new2 = (struct wordent *) calloc (1, sizeof w);
  1127. +         new2->word = savestr (s2);
  1128. +         w.next = new2->prev = new1;
  1129. +         new1->next = w.prev = new2;
  1130. +         new1->prev = new2->next = &w;
  1131. +     }
  1132. +     /* expand aliases like process() does. */
  1133. +     alias (&w);
  1134. +     /* build a syntax tree for the command. */
  1135. +     t = syntax (w.next, &w, 0);
  1136. +     if (err)
  1137. +         error (err);
  1138. +     /* execute the parse tree. */
  1139. +     execute (t, -1);
  1140. +     /* done. free the lex list and parse tree. */
  1141. +     freelex (&w), freesyn (t);
  1142. + }
  1143. + /*
  1144. +  * Karl Kleinpaste, 26 Jan 1984.
  1145. +  * Initialize the dummy tty list for login watch.
  1146. +  * This dummy list eliminates boundary conditions
  1147. +  * when doing pointer-chase searches.
  1148. +  */
  1149. + initwatch()
  1150. + {
  1151. +     wholist = (struct who *) calloc (1, sizeof *wholist);
  1152. +     wholist->w_next = (struct who *) calloc (1, sizeof *wholist);
  1153. +     wholist->w_next->w_prev = wholist;
  1154. +     strcpy (wholist->w_tty, "\01\01\01\01\01");
  1155. +     strcpy (wholist->w_next->w_tty, "~~~~~");
  1156. + #ifdef WHODEBUG
  1157. +     debugwholist ((struct who *) 0, (struct who *) 0);
  1158. + #endif WHODEBUG
  1159. + }
  1160. + /*
  1161. +  * Karl Kleinpaste, 26 Jan 1984.
  1162. +  * Watch /etc/utmp for login/logout changes.
  1163. +  */
  1164. + watch_login()
  1165. + {
  1166. +     int utmpfd, comparison, alldone, cnt;
  1167. +     struct utmp utmp;
  1168. +     struct who *wp, *wpnew;
  1169. +     struct varent *v;
  1170. +     char **vp, *cp;
  1171. +     time_t t, interval;
  1172. +     int    omask;
  1173. +     /* stop SIGINT, lest our login list get trashed. */
  1174. +     omask = sighold (SIGINT);
  1175. +     v = adrof ("watch");
  1176. +     if (v == (struct varent *) 0) {
  1177. +         sigsetmask(omask);
  1178. +         return;            /* no names to watch */
  1179. +     }
  1180. +     vp = v->vec;
  1181. +     cnt = blklen (vp);
  1182. +     if (cnt % 2) {            /* odd # args: 1st == # minutes. */
  1183. +         interval = (number (*vp)) ? getn (*vp++) : MAILINTVL;
  1184. +         cnt--;
  1185. +     }
  1186. +     time (&t);
  1187. +     if (t - watch_period < interval * 60) {
  1188. +         sigsetmask(omask);
  1189. +         return;            /* not long enough yet... */
  1190. +     }
  1191. +     watch_period = t;
  1192. +     if ((utmpfd = open ("/etc/utmp", 0)) < 0) {
  1193. +         printf ("/etc/utmp cannot be opened.  Please \"unset watch\".\n");
  1194. +         sigsetmask(omask);
  1195. +         return;
  1196. +     }
  1197. +     /*
  1198. +      * Read in the utmp file, sort the entries, and update existing
  1199. +      * entries or add new entries to the status list.
  1200. +      */
  1201. +     while (read (utmpfd, &utmp, sizeof utmp) == sizeof utmp) {
  1202. +         if (utmp.ut_name[0] == '\0' && utmp.ut_line[0] == '\0')
  1203. +             continue;    /* completely void entry */
  1204. +         wp = wholist;
  1205. +         while ((comparison = strncmp (wp->w_tty, utmp.ut_line, 8)) < 0)
  1206. +             wp = wp->w_next;    /* find that tty! */
  1207. +         if (comparison == 0) {        /* found the tty... */
  1208. +             if (utmp.ut_name[0] == '\0')
  1209. +                 wp->w_status = OFFLINE;
  1210. +             else            /* someone is logged in */
  1211. +                 if (strncmp (utmp.ut_name, wp->w_name, 8) == 0)
  1212. +                     wp->w_status = 0;    /* same guy */
  1213. +                 else {
  1214. +                     strncpy (wp->w_new, utmp.ut_name, 8);
  1215. +                     if (wp->w_name[0] == '\0')
  1216. +                         wp->w_status = ONLINE;
  1217. +                     else
  1218. +                         wp->w_status = CHANGED;
  1219. +                 }
  1220. +         } else {            /* new tty in utmp */
  1221. +             wpnew = (struct who *) calloc (1, sizeof *wpnew);
  1222. +             strncpy (wpnew->w_tty, utmp.ut_line, 8);
  1223. +             if (utmp.ut_name[0] == '\0')
  1224. +                 wpnew->w_status = OFFLINE;
  1225. +             else {
  1226. +                 strncpy (wpnew->w_new, utmp.ut_name, 8);
  1227. +                 wpnew->w_status = ONLINE;
  1228. +             }
  1229. + #ifdef WHODEBUG
  1230. +             debugwholist(wpnew, wp);
  1231. + #endif WHODEBUG
  1232. +             wpnew->w_next = wp;    /* link in a new 'who' */
  1233. +             wpnew->w_prev = wp->w_prev;
  1234. +             wpnew->w_prev->w_next = wpnew;
  1235. +             wp->w_prev = wpnew;    /* linked in now */
  1236. +         }
  1237. +     }
  1238. +     close (utmpfd);
  1239. +     /*
  1240. +      * The state of all logins is now known, so we can search
  1241. +      * the user's list of watchables to print the interesting ones.
  1242. +      */
  1243. +     for (alldone = 0; !alldone && *vp != (char *) 0 && **vp != '\0' &&
  1244. +             *(vp+1) != (char *) 0 && **(vp+1) != '\0';
  1245. +             vp += 2) {        /* args used in pairs... */
  1246. +         if (eq (*vp, "any") && eq (*(vp+1), "any"))
  1247. +             alldone++;
  1248. +         for (wp = wholist; wp != (struct who *) 0; wp = wp->w_next) {
  1249. +             if (wp->w_status & ANNOUNCE        ||
  1250. +                 (!eq (*vp, "any") && !eq (*vp, wp->w_name) &&
  1251. +                 !eq (*vp, wp->w_new))        ||
  1252. +                 (!eq (*(vp+1), wp->w_tty) && !eq (*(vp+1), "any")))
  1253. +                 continue;    /* entry doesn't qualify */
  1254. +                 /* already printed or not right one to print */
  1255. +             if ((wp->w_status & OFFLINE) &&
  1256. +                 (wp->w_name[0] != '\0')) {
  1257. +                 printf ("%s has logged off %s.\n",
  1258. +                     wp->w_name, wp->w_tty);
  1259. +                 wp->w_name[0] = '\0';
  1260. +                 wp->w_status |= ANNOUNCE;
  1261. +                 continue;
  1262. +             }
  1263. +             if (wp->w_status & ONLINE) {
  1264. +                 printf ("%s has logged on %s.\n",
  1265. +                     wp->w_new, wp->w_tty);
  1266. +                 strcpy (wp->w_name, wp->w_new);
  1267. +                 wp->w_status |= ANNOUNCE;
  1268. +                 continue;
  1269. +             }
  1270. +             if (wp->w_status & CHANGED) {
  1271. +                 printf ("%s has replaced %s on %s.\n",
  1272. +                     wp->w_new, wp->w_name, wp->w_tty);
  1273. +                 strcpy (wp->w_name, wp->w_new);
  1274. +                 wp->w_status |= ANNOUNCE;
  1275. +                 continue;
  1276. +             }
  1277. +         }
  1278. +     }
  1279. +     sigsetmask(omask);
  1280. + }
  1281. + #ifdef WHODEBUG
  1282. + debugwholist (new, wp)
  1283. + register struct who *new, *wp;
  1284. + {
  1285. +     register struct who *a;
  1286. +     a = wholist;
  1287. +     while (a != (struct who *) 0) {
  1288. +         printf ("%s/%s -> ", a->w_name, a->w_tty);
  1289. +         a = a->w_next;
  1290. +     }
  1291. +     printf ("NULL\n");
  1292. +     a = wholist;
  1293. +     printf ("backward: ");
  1294. +     while (a->w_next != (struct who *) 0)
  1295. +         a = a->w_next;
  1296. +     while (a != (struct who *) 0) {
  1297. +         printf ("%s/%s -> ", a->w_name, a->w_tty);
  1298. +         a = a->w_prev;
  1299. +     }
  1300. +     printf ("NULL\n");
  1301. +     if (new)
  1302. +         printf ("new: %s/%s\n", new->w_name, new->w_tty);
  1303. +     if (wp)
  1304. +         printf ("wp: %s/%s\n", wp->w_name, wp->w_tty);
  1305. + }
  1306. + #endif WHODEBUG
  1307. + /*
  1308. +  * kfk 21oct1983 -- add @ (time) and / ($cwd) in prompt.
  1309. +  * PWP 4/27/87 -- rearange for tcsh.
  1310. +  */
  1311. + printprompt ()
  1312. + {
  1313. +     register char *cp, *p, *z;
  1314. +     register char underlining = 0;
  1315. +     PromptBuf[0] = '\0';
  1316. +     p = PromptBuf;
  1317. +     if (whyles)
  1318. +     cp = value("prompt2");
  1319. +     else
  1320. +     cp = value("prompt");
  1321. +     for (; *cp; cp++) {
  1322. +     if (*cp == '%') {
  1323. +         cp++;
  1324. +         if (*cp == HIST || *cp == 'h') {
  1325. +         itoa(eventno + 1, buff);
  1326. +         for (z = buff; *z; z++)
  1327. +             *p++ = underlining | *z;
  1328. +         } else if (*cp == '@' || *cp == 't') {
  1329. +         struct tm *t;
  1330. +         long clock;
  1331. +         char ampm = 'a';
  1332. +         time (&clock);
  1333. +         t = localtime(&clock);
  1334. +         if (t->tm_hour >= 12) {
  1335. +             if (t->tm_hour > 12)
  1336. +             t->tm_hour -= 12;
  1337. +             ampm = 'p';
  1338. +         } else if (t->tm_hour == 0)
  1339. +             t->tm_hour = 12;
  1340. +         
  1341. +         itoa(t->tm_hour, buff);
  1342. +         *p++ = underlining | buff[0];
  1343. +         if (buff[1]) *p++ = underlining | buff[1];
  1344. +         *p++ = underlining | ':';
  1345. +         itoa(t->tm_min, buff);
  1346. +         if (buff[1]) {
  1347. +             *p++ = underlining | buff[0];
  1348. +             *p++ = underlining | buff[1];
  1349. +         } else {
  1350. +             *p++ = underlining | '0';
  1351. +             *p++ = underlining | buff[0];
  1352. +         }
  1353. +         *p++ = underlining | ampm;
  1354. +         *p++ = underlining | 'm';
  1355. +         } else if (*cp == 'M') {
  1356. +         for (z = getenv("HOST"); *z; z++)
  1357. +             *p++ = underlining | *z;
  1358. +         } else if (*cp == 'm') {
  1359. +         for (z = getenv("HOST"); *z && *z != '.'; z++)
  1360. +             *p++ = underlining | *z;
  1361. +         } else if (*cp == '/' || *cp == 'd') {
  1362. +         for (z = value("cwd"); *z; z++)
  1363. +             *p++ = underlining | *z;
  1364. +         } else if (*cp == '.' || *cp == 'c') {
  1365. +         strcpy (buff, value("cwd"));
  1366. +         if (!buff[1]) {    /* if CWD == / */
  1367. +             *p++ = underlining | buff[0];
  1368. +         } else {
  1369. +             if (strcmp(buff, value("home")) == 0) {
  1370. +             *p++ = underlining | '~';
  1371. +             } else {
  1372. +             for (z = buff; *z; z++) ; /* find the end */
  1373. +             while ((z > buff) && (*z != '/')) z--; /* back up */
  1374. +             if (*z == '/') z++;
  1375. +             while (*z)
  1376. +                 *p++ = underlining | *z++;
  1377. +             }
  1378. +         }
  1379. +         } else if (*cp == 'S' || *cp == 'U') { /* start standout */
  1380. +         underlining = 0200;
  1381. +         } else if (*cp == 's' || *cp == 'u') { /* end standout */
  1382. +         underlining = 0;
  1383. +         } else if (*cp == '%') {
  1384. +         *p++ = underlining | '%';
  1385. +         } else {
  1386. +         *p++ = underlining | '%';
  1387. +         *p++ = underlining | *cp;
  1388. +         }
  1389. +     } else {
  1390. +         *p++ = underlining | *cp;        /* normal character */
  1391. +     }
  1392. +     }
  1393. +     *p = '\0';
  1394. +     /*
  1395. +     cp = PromptBuf;
  1396. +     while (*cp)
  1397. +         putchar(*cp++ | QUOTE);
  1398. +     */
  1399. +     flush();
  1400. + }
  1401. + setalarm()
  1402. + {
  1403. +     struct varent *vp;
  1404. +     char *cp;
  1405. +     int alrm_time = 0;
  1406. +     long cl, sched_dif;
  1407. +     extern    struct    sched_event *sched_ptr;
  1408. +     if (vp = adrof("autologout"))
  1409. +     {
  1410. +         if (cp = vp->vec[0])
  1411. +             alrm_time = (atoi (cp) * 60);
  1412. +     }
  1413. +     if (sched_ptr) {
  1414. +         time(&cl);
  1415. +         sched_dif = sched_ptr->t_when - cl;
  1416. +         if ((alrm_time == 0) || (sched_dif < alrm_time))
  1417. +             alrm_time = ((int) sched_dif) + 1;
  1418. +     }
  1419. +     alarm (alrm_time);    /* Autologout ON */
  1420. + }
  1421.   #ifdef PROF
  1422.   done(i)
  1423.   #else
  1424. ***************
  1425. *** 915,938
  1426.       _exit(i);
  1427.   }
  1428.   
  1429. - printprompt()
  1430. - {
  1431. -     register char *cp;
  1432. -     if (!whyles) {
  1433. -         for (cp = value("prompt"); *cp; cp++)
  1434. -             if (*cp == HIST)
  1435. -                 printf("%d", eventno + 1);
  1436. -             else {
  1437. -                 if (*cp == '\\' && cp[1] == HIST)
  1438. -                     cp++;
  1439. -                 putchar(*cp | QUOTE);
  1440. -             }
  1441. -     } else
  1442. -         /* 
  1443. -          * Prompt for forward reading loop
  1444. -          * body content.
  1445. -          */
  1446. -         printf("? ");
  1447. -     flush();
  1448. - }
  1449.  
  1450. --- 1548,1550 -----
  1451.       _exit(i);
  1452.   }
  1453.   
  1454. *** sh.char.c    Sat Mar 29 07:37:20 1986
  1455. --- /usr/src/local/tcsh/sh.char.c    Mon Aug 17 23:30:38 1987
  1456. ***************
  1457. *** 60,66
  1458.       _META,        0,        _META,        _GLOB,
  1459.   
  1460.   /*    @        A        B        C    */
  1461. !     0,        _LET,        _LET,        _LET,
  1462.   
  1463.   /*    D        E        F        G    */
  1464.       _LET,        _LET,        _LET,        _LET,
  1465.  
  1466. --- 60,66 -----
  1467.       _META,        0,        _META,        _GLOB,
  1468.   
  1469.   /*    @        A        B        C    */
  1470. !     0,        _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_HEX|_UP,
  1471.   
  1472.   /*    D        E        F        G    */
  1473.       _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_UP,
  1474. ***************
  1475. *** 63,69
  1476.       0,        _LET,        _LET,        _LET,
  1477.   
  1478.   /*    D        E        F        G    */
  1479. !     _LET,        _LET,        _LET,        _LET,
  1480.   
  1481.   /*    H        I        J        K    */
  1482.       _LET,        _LET,        _LET,        _LET,
  1483.  
  1484. --- 63,69 -----
  1485.       0,        _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_HEX|_UP,
  1486.   
  1487.   /*    D        E        F        G    */
  1488. !     _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_UP,
  1489.   
  1490.   /*    H        I        J        K    */
  1491.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1492. ***************
  1493. *** 66,72
  1494.       _LET,        _LET,        _LET,        _LET,
  1495.   
  1496.   /*    H        I        J        K    */
  1497. !     _LET,        _LET,        _LET,        _LET,
  1498.   
  1499.   /*    L        M        N        O    */
  1500.       _LET,        _LET,        _LET,        _LET,
  1501.  
  1502. --- 66,72 -----
  1503.       _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_HEX|_UP,    _LET|_UP,
  1504.   
  1505.   /*    H        I        J        K    */
  1506. !     _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1507.   
  1508.   /*    L        M        N        O    */
  1509.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1510. ***************
  1511. *** 69,75
  1512.       _LET,        _LET,        _LET,        _LET,
  1513.   
  1514.   /*    L        M        N        O    */
  1515. !     _LET,        _LET,        _LET,        _LET,
  1516.   
  1517.   /*    P        Q        R        S    */
  1518.       _LET,        _LET,        _LET,        _LET,
  1519.  
  1520. --- 69,75 -----
  1521.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1522.   
  1523.   /*    L        M        N        O    */
  1524. !     _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1525.   
  1526.   /*    P        Q        R        S    */
  1527.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1528. ***************
  1529. *** 72,78
  1530.       _LET,        _LET,        _LET,        _LET,
  1531.   
  1532.   /*    P        Q        R        S    */
  1533. !     _LET,        _LET,        _LET,        _LET,
  1534.   
  1535.   /*    T        U        V        W    */
  1536.       _LET,        _LET,        _LET,        _LET,
  1537.  
  1538. --- 72,78 -----
  1539.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1540.   
  1541.   /*    P        Q        R        S    */
  1542. !     _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1543.   
  1544.   /*    T        U        V        W    */
  1545.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1546. ***************
  1547. *** 75,81
  1548.       _LET,        _LET,        _LET,        _LET,
  1549.   
  1550.   /*    T        U        V        W    */
  1551. !     _LET,        _LET,        _LET,        _LET,
  1552.   
  1553.   /*    X        Y        Z        [    */
  1554.       _LET,        _LET,        _LET,        _GLOB,
  1555.  
  1556. --- 75,81 -----
  1557.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1558.   
  1559.   /*    T        U        V        W    */
  1560. !     _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1561.   
  1562.   /*    X        Y        Z        [    */
  1563.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _GLOB,
  1564. ***************
  1565. *** 78,84
  1566.       _LET,        _LET,        _LET,        _LET,
  1567.   
  1568.   /*    X        Y        Z        [    */
  1569. !     _LET,        _LET,        _LET,        _GLOB,
  1570.   
  1571.   /*    \        ]        ^        _    */
  1572.       _ESC,        0,        0,        _LET,
  1573.  
  1574. --- 78,84 -----
  1575.       _LET|_UP,    _LET|_UP,    _LET|_UP,    _LET|_UP,
  1576.   
  1577.   /*    X        Y        Z        [    */
  1578. !     _LET|_UP,    _LET|_UP,    _LET|_UP,    _GLOB,
  1579.   
  1580.   /*    \        ]        ^        _    */
  1581.       _ESC,        0,        0,        _LET,
  1582. ***************
  1583. *** 84,90
  1584.       _ESC,        0,        0,        _LET,
  1585.   
  1586.   /*    `        a        b        c    */
  1587. !     _Q1|_GLOB,    _LET,        _LET,        _LET,
  1588.   
  1589.   /*    d        e        f        g    */
  1590.       _LET,        _LET,        _LET,        _LET,
  1591.  
  1592. --- 84,90 -----
  1593.       _ESC,        0,        0,        _LET,
  1594.   
  1595.   /*    `        a        b        c    */
  1596. !     _Q1|_GLOB,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,
  1597.   
  1598.   /*    d        e        f        g    */
  1599.       _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_LOW,
  1600. ***************
  1601. *** 87,93
  1602.       _Q1|_GLOB,    _LET,        _LET,        _LET,
  1603.   
  1604.   /*    d        e        f        g    */
  1605. !     _LET,        _LET,        _LET,        _LET,
  1606.   
  1607.   /*    h        i        j        k    */
  1608.       _LET,        _LET,        _LET,        _LET,
  1609.  
  1610. --- 87,93 -----
  1611.       _Q1|_GLOB,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,
  1612.   
  1613.   /*    d        e        f        g    */
  1614. !     _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_LOW,
  1615.   
  1616.   /*    h        i        j        k    */
  1617.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1618. ***************
  1619. *** 90,96
  1620.       _LET,        _LET,        _LET,        _LET,
  1621.   
  1622.   /*    h        i        j        k    */
  1623. !     _LET,        _LET,        _LET,        _LET,
  1624.   
  1625.   /*    l        m        n        o    */
  1626.       _LET,        _LET,        _LET,        _LET,
  1627.  
  1628. --- 90,96 -----
  1629.       _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_HEX|_LOW,    _LET|_LOW,
  1630.   
  1631.   /*    h        i        j        k    */
  1632. !     _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1633.   
  1634.   /*    l        m        n        o    */
  1635.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1636. ***************
  1637. *** 93,99
  1638.       _LET,        _LET,        _LET,        _LET,
  1639.   
  1640.   /*    l        m        n        o    */
  1641. !     _LET,        _LET,        _LET,        _LET,
  1642.   
  1643.   /*    p        q        r        s    */
  1644.       _LET,        _LET,        _LET,        _LET,
  1645.  
  1646. --- 93,99 -----
  1647.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1648.   
  1649.   /*    l        m        n        o    */
  1650. !     _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1651.   
  1652.   /*    p        q        r        s    */
  1653.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1654. ***************
  1655. *** 96,102
  1656.       _LET,        _LET,        _LET,        _LET,
  1657.   
  1658.   /*    p        q        r        s    */
  1659. !     _LET,        _LET,        _LET,        _LET,
  1660.   
  1661.   /*    t        u        v        w    */
  1662.       _LET,        _LET,        _LET,        _LET,
  1663.  
  1664. --- 96,102 -----
  1665.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1666.   
  1667.   /*    p        q        r        s    */
  1668. !     _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1669.   
  1670.   /*    t        u        v        w    */
  1671.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1672. ***************
  1673. *** 99,105
  1674.       _LET,        _LET,        _LET,        _LET,
  1675.   
  1676.   /*    t        u        v        w    */
  1677. !     _LET,        _LET,        _LET,        _LET,
  1678.   
  1679.   /*    x        y        z        {    */
  1680.       _LET,        _LET,        _LET,        _GLOB,
  1681.  
  1682. --- 99,105 -----
  1683.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1684.   
  1685.   /*    t        u        v        w    */
  1686. !     _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1687.   
  1688.   /*    x        y        z        {    */
  1689.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _GLOB,
  1690. ***************
  1691. *** 102,108
  1692.       _LET,        _LET,        _LET,        _LET,
  1693.   
  1694.   /*    x        y        z        {    */
  1695. !     _LET,        _LET,        _LET,        _GLOB,
  1696.   
  1697.   /*    |        }        ~        del    */
  1698.       _META,        0,        0,        0,
  1699.  
  1700. --- 102,108 -----
  1701.       _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _LET|_LOW,
  1702.   
  1703.   /*    x        y        z        {    */
  1704. !     _LET|_LOW,    _LET|_LOW,    _LET|_LOW,    _GLOB,
  1705.   
  1706.   /*    |        }        ~        del    */
  1707.       _META,        0,        0,        0,
  1708. *** sh.char.h    Sat Mar 29 07:37:14 1986
  1709. --- /usr/src/local/tcsh/sh.char.h    Mon Aug 17 23:28:06 1987
  1710. ***************
  1711. *** 24,29
  1712.   #define _DOL    0x80        /* $ */
  1713.   #define _DIG   0x100        /* 0-9 */
  1714.   #define _LET   0x200        /* a-z, A-Z, _ */
  1715.   
  1716.   #define cmap(c, bits)    (_cmap[(unsigned char)(c)] & (bits))
  1717.   
  1718.  
  1719. --- 24,32 -----
  1720.   #define _DOL    0x80        /* $ */
  1721.   #define _DIG   0x100        /* 0-9 */
  1722.   #define _LET   0x200        /* a-z, A-Z, _ */
  1723. + #define    _HEX   0x400        /* Hex digits */
  1724. + #define    _LOW   0x800        /* Lower case */
  1725. + #define    _UP   0x1000        /* Upper case */
  1726.   
  1727.   #define cmap(c, bits)    (_cmap[(unsigned char)(c)] & (bits))
  1728.   
  1729. ***************
  1730. *** 32,36
  1731.   #define isspnl(c)    cmap(c, _SP|_NL)
  1732.   #define ismeta(c)    cmap(c, _META)
  1733.   #define digit(c)    cmap(c, _DIG)
  1734.   #define letter(c)    cmap(c, _LET)
  1735.   #define alnum(c)    (digit(c) || letter(c))
  1736.  
  1737. --- 35,41 -----
  1738.   #define isspnl(c)    cmap(c, _SP|_NL)
  1739.   #define ismeta(c)    cmap(c, _META)
  1740.   #define digit(c)    cmap(c, _DIG)
  1741. + #define isdigit(c)    cmap(c, _DIG)
  1742.   #define letter(c)    cmap(c, _LET)
  1743.   #define isalpha(c)    cmap(c, _LET)
  1744.   #define islower(c)    cmap(c, _LOW)
  1745. ***************
  1746. *** 33,36
  1747.   #define ismeta(c)    cmap(c, _META)
  1748.   #define digit(c)    cmap(c, _DIG)
  1749.   #define letter(c)    cmap(c, _LET)
  1750.   #define alnum(c)    (digit(c) || letter(c))
  1751.  
  1752. --- 37,46 -----
  1753.   #define digit(c)    cmap(c, _DIG)
  1754.   #define isdigit(c)    cmap(c, _DIG)
  1755.   #define letter(c)    cmap(c, _LET)
  1756. + #define isalpha(c)    cmap(c, _LET)
  1757. + #define islower(c)    cmap(c, _LOW)
  1758. + #define isupper(c)    cmap(c, _UP)
  1759. + #define isxdigit(c)    cmap(c, _HEX)
  1760.   #define alnum(c)    (digit(c) || letter(c))
  1761.   #define toupper(c)    ((c)-'a'+'A')
  1762.   #define tolower(c)    ((c)-'A'+'a')
  1763. ***************
  1764. *** 34,36
  1765.   #define digit(c)    cmap(c, _DIG)
  1766.   #define letter(c)    cmap(c, _LET)
  1767.   #define alnum(c)    (digit(c) || letter(c))
  1768.  
  1769. --- 42,46 -----
  1770.   #define isupper(c)    cmap(c, _UP)
  1771.   #define isxdigit(c)    cmap(c, _HEX)
  1772.   #define alnum(c)    (digit(c) || letter(c))
  1773. + #define toupper(c)    ((c)-'a'+'A')
  1774. + #define tolower(c)    ((c)-'A'+'a')
  1775. *** sh.dir.c    Tue Jun 11 18:59:53 1985
  1776. --- /usr/src/local/tcsh/sh.dir.c    Mon Aug 17 19:58:48 1987
  1777. ***************
  1778. *** 230,235
  1779.       } else if (dp = dfind(*v)) {
  1780.           if (chdir(dp->di_name) < 0)
  1781.               Perror(dp->di_name);
  1782.       } else {
  1783.           register char *cp;
  1784.   
  1785.  
  1786. --- 230,240 -----
  1787.       } else if (dp = dfind(*v)) {
  1788.           if (chdir(dp->di_name) < 0)
  1789.               Perror(dp->di_name);
  1790. +         /*
  1791. +          * kfk - 10 Feb 1984 - added new "extraction style" pushd +n
  1792. +          */
  1793. +         if (adrof ("dextract"))
  1794. +             dextract (dp);
  1795.       } else {
  1796.           register char *cp;
  1797.   
  1798. ***************
  1799. *** 471,473
  1800.       if (printd)
  1801.           dodirs(fakev);
  1802.   }
  1803.  
  1804. --- 476,530 -----
  1805.       if (printd)
  1806.           dodirs(fakev);
  1807.   }
  1808. + /*
  1809. +  * getstakd - added by kfk 17 Jan 1984
  1810. +  * Support routine for the stack hack.  Finds nth directory in
  1811. +  * the directory stack, or finds last directory in stack.
  1812. +  */
  1813. + getstakd (s, cnt, callerr)
  1814. +     char *s;
  1815. +     int cnt, callerr;
  1816. + {
  1817. +     struct directory *dp;
  1818. +     dp = dcwd;
  1819. +     if (cnt < 0) {        /* < 0 ==> last dir requested. */
  1820. +         dp = dp->di_next;
  1821. +         if (dp == &dhead)
  1822. +             dp = dp->di_next;
  1823. +     } else {
  1824. +         while (cnt-- > 0) {
  1825. +             dp = dp->di_prev;
  1826. +             if (dp == &dhead)
  1827. +                 dp = dp->di_prev;
  1828. +             if (dp == dcwd) {
  1829. +                 if (callerr)
  1830. +                     error ("Not that many dir stack entries");
  1831. +                 else
  1832. +                     return;
  1833. +             }
  1834. +         }
  1835. +     }
  1836. +     strcpy (s, dp->di_name);
  1837. + }
  1838. + /*
  1839. +  * Karl Kleinpaste - 10 Feb 1984
  1840. +  * Added dextract(), which is used in pushd +n.
  1841. +  * Instead of just rotating the entire stack around, dextract()
  1842. +  * lets the user have the nth dir extracted from its current
  1843. +  * position, and pushes it onto the top.
  1844. +  */
  1845. + dextract(dp)
  1846. + struct directory *dp;
  1847. + {
  1848. +     if (dp == dcwd)
  1849. +         return;
  1850. +     dp->di_next->di_prev = dp->di_prev;
  1851. +     dp->di_prev->di_next = dp->di_next;
  1852. +     dp->di_next = dcwd->di_next;
  1853. +     dp->di_prev = dcwd;
  1854. +     dp->di_next->di_prev = dp;
  1855. +     dcwd->di_next = dp;
  1856. +  }
  1857. *** sh.err.c    Tue May 13 01:03:05 1986
  1858. --- /usr/src/local/tcsh/sh.err.c    Mon Aug 17 19:58:49 1987
  1859. ***************
  1860. *** 9,15
  1861.   #endif
  1862.   
  1863.   #include "sh.h"
  1864. ! #include <sys/ioctl.h>
  1865.   
  1866.   /*
  1867.    * C Shell
  1868.  
  1869. --- 9,15 -----
  1870.   #endif
  1871.   
  1872.   #include "sh.h"
  1873. ! /* #include <sys/ioctl.h> */
  1874.   
  1875.   /*
  1876.    * C Shell
  1877. ***************
  1878. *** 78,83
  1879.       btoeof();
  1880.   
  1881.       setq("status", onev, &shvhed);
  1882.       if (tpgrp > 0)
  1883.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&tpgrp);
  1884.       reset();        /* Unwind */
  1885.  
  1886. --- 78,84 -----
  1887.       btoeof();
  1888.   
  1889.       setq("status", onev, &shvhed);
  1890. + #ifdef BSDJOBS
  1891.       if (tpgrp > 0)
  1892.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&tpgrp);
  1893.   #endif
  1894. ***************
  1895. *** 80,85
  1896.       setq("status", onev, &shvhed);
  1897.       if (tpgrp > 0)
  1898.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&tpgrp);
  1899.       reset();        /* Unwind */
  1900.   }
  1901.   
  1902.  
  1903. --- 81,87 -----
  1904.   #ifdef BSDJOBS
  1905.       if (tpgrp > 0)
  1906.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&tpgrp);
  1907. + #endif
  1908.       reset();        /* Unwind */
  1909.   }
  1910.   
  1911. *** sh.exec.c    Thu Jun  6 13:15:32 1985
  1912. --- /usr/src/local/tcsh/sh.exec.c    Thu Sep 24 15:06:55 1987
  1913. ***************
  1914. *** 9,15
  1915.   #endif
  1916.   
  1917.   #include "sh.h"
  1918. ! #include <sys/dir.h>
  1919.   
  1920.   /*
  1921.    * C shell
  1922.  
  1923. --- 9,15 -----
  1924.   #endif
  1925.   
  1926.   #include "sh.h"
  1927. ! /* #include <sys/dir.h> */
  1928.   
  1929.   /*
  1930.    * C shell
  1931. ***************
  1932. *** 287,292
  1933.       char **pv;
  1934.       int hashval;
  1935.   
  1936.       havhash = 1;
  1937.       for (cnt = 0; cnt < sizeof xhash; cnt++)
  1938.           xhash[cnt] = 0;
  1939.  
  1940. --- 287,293 -----
  1941.       char **pv;
  1942.       int hashval;
  1943.   
  1944. +     tw_clear_comm_list();
  1945.       havhash = 1;
  1946.       for (cnt = 0; cnt < sizeof xhash; cnt++)
  1947.           xhash[cnt] = 0;
  1948. ***************
  1949. *** 298,303
  1950.           dirp = opendir(*pv);
  1951.           if (dirp == NULL)
  1952.               continue;
  1953.           if (fstat(dirp->dd_fd, &stb) < 0 || !isdir(stb)) {
  1954.               closedir(dirp);
  1955.               continue;
  1956.  
  1957. --- 299,305 -----
  1958.           dirp = opendir(*pv);
  1959.           if (dirp == NULL)
  1960.               continue;
  1961. + #ifdef COMMENT    /* this isn't needed.  opendir won't open non-dirs */
  1962.           if (fstat(dirp->dd_fd, &stb) < 0 || !isdir(stb)) {
  1963.               closedir(dirp);
  1964.               continue;
  1965. ***************
  1966. *** 302,307
  1967.               closedir(dirp);
  1968.               continue;
  1969.           }
  1970.           while ((dp = readdir(dirp)) != NULL) {
  1971.               if (dp->d_ino == 0)
  1972.                   continue;
  1973.  
  1974. --- 304,310 -----
  1975.               closedir(dirp);
  1976.               continue;
  1977.           }
  1978. + #endif
  1979.           while ((dp = readdir(dirp)) != NULL) {
  1980.               if (dp->d_ino == 0)
  1981.                   continue;
  1982. ***************
  1983. *** 331,336
  1984.               hits, misses, 100 * hits / (hits + misses));
  1985.   }
  1986.   #endif
  1987.   
  1988.   /*
  1989.    * Hash a command name.
  1990.  
  1991. --- 334,435 -----
  1992.               hits, misses, 100 * hits / (hits + misses));
  1993.   }
  1994.   #endif
  1995. + int
  1996. + iscommand(name)
  1997. +     char *name;
  1998. + {
  1999. +     char *sav;
  2000. +     register char *dp, **pv;
  2001. +     register struct varent *v;
  2002. +     bool slash = any('/', name);
  2003. +     int hashval, i;
  2004. +     v = adrof("path");
  2005. +     if (v == 0 || v->vec[0] == 0 || slash)
  2006. +         pv = justabs;
  2007. +     else
  2008. +         pv = v->vec;
  2009. +     sav = strspl("/", name);        /* / command name for postpending */
  2010. +     if (havhash)
  2011. +         hashval = hashname(name);
  2012. +     i = 0;
  2013. +     do {
  2014. +         if (!slash && pv[0][0] == '/' && havhash && (hashval & (1 << (i % 8))) == 0)
  2015. +             goto cont;
  2016. +         if (pv[0][0] == 0 || eq(pv[0], ".")) {    /* don't make ./xxx */
  2017. +             if (access(name, 1) == 0) {
  2018. +                 xfree(sav);
  2019. +                 return i+1;
  2020. +             }
  2021. +         } else {
  2022. +             dp = strspl(*pv, sav);
  2023. +             if (access(dp, 1) == 0) {
  2024. +                 xfree(sav);
  2025. +                 xfree(dp);
  2026. +                 return i+1;
  2027. +             }
  2028. +             xfree(dp);
  2029. +         }
  2030. + cont:
  2031. +         pv++;
  2032. +         i++;
  2033. +     } while (*pv);
  2034. +     xfree(sav);
  2035. +     return 0;
  2036. + }
  2037. + tellmewhat(lex)
  2038. +     struct wordent *lex;
  2039. + {
  2040. +     register char *cp;
  2041. +     register int i;
  2042. +     register struct biltins *bptr;
  2043. +     register struct wordent *sp = lex->next;
  2044. +     for (bptr = bfunc; bptr < &bfunc[nbfunc]; bptr++) {
  2045. + #ifdef    OUTDEF
  2046. +     for (bptr = bfunc; cp = bptr->bname; bptr++) {
  2047. + #endif
  2048. +     if (strcmp(sp->word, bptr->bname) == 0) {
  2049. +         prlex(lex);
  2050. +         printf("%s: is built in.\n", sp->word);
  2051. +         flush();
  2052. +         return;
  2053. +     }
  2054. +     }
  2055. +     while (*(sp->word) & 0200) (sp->word)++;
  2056. +     if (i = iscommand(strip(sp->word))) {
  2057. +     char *s1;
  2058. +     register char **pv;
  2059. +     register struct varent *v;
  2060. +     bool slash = any('/', sp->word);
  2061. +     v = adrof("path");
  2062. +     if (v == 0 || v->vec[0] == 0 || slash)
  2063. +         pv = justabs;
  2064. +     else
  2065. +         pv = v->vec;
  2066. +     while (--i) pv++;
  2067. +     if (pv[0][0] == 0 || eq(pv[0], ".")) {
  2068. +         prlex(lex);
  2069. +         return;
  2070. +     }
  2071. +     s1 = strspl(*pv, "/");
  2072. +     sp->word = strspl(s1, sp->word);
  2073. +     xfree(s1);
  2074. +     prlex(lex);
  2075. +     xfree(sp->word);
  2076. +     sp->word = (char *)0;
  2077. +     } else {
  2078. +     prlex(lex);
  2079. +     printf("%s: Command not found.\n", sp->word);
  2080. +     flush();
  2081. +     }
  2082. + }
  2083.   
  2084.   /*
  2085.    * Hash a command name.
  2086. *** sh.file.c    Sun May 18 23:01:20 1986
  2087. --- /usr/src/local/tcsh/sh.file.c    Mon Aug 17 19:21:52 1987
  2088. ***************
  2089. *** 174,179
  2090.       return (' ');
  2091.   }
  2092.   
  2093.   static struct winsize win;
  2094.   
  2095.   /*
  2096.  
  2097. --- 174,188 -----
  2098.       return (' ');
  2099.   }
  2100.   
  2101. + #ifndef    BSD4_3
  2102. + struct    winsize {
  2103. +     unsigned short    ws_row;
  2104. +     unsigned short    ws_col;
  2105. +     unsigned short    ws_xpixel;
  2106. +     unsigned short    ws_ypixel;
  2107. + };
  2108. + #endif
  2109.   static struct winsize win;
  2110.   
  2111.   /*
  2112. ***************
  2113. *** 185,190
  2114.   {
  2115.       register int i, rows, r, c, maxwidth = 0, columns;
  2116.   
  2117.       if (ioctl(SHOUT, TIOCGWINSZ, (char *)&win) < 0 || win.ws_col == 0)
  2118.           win.ws_col = 80;
  2119.       for (i = 0; i < count; i++)
  2120.  
  2121. --- 194,200 -----
  2122.   {
  2123.       register int i, rows, r, c, maxwidth = 0, columns;
  2124.   
  2125. + #ifdef    BSD4_3
  2126.       if (ioctl(SHOUT, TIOCGWINSZ, (char *)&win) < 0 || win.ws_col == 0)
  2127.   #endif
  2128.           win.ws_col = 80;
  2129. ***************
  2130. *** 186,191
  2131.       register int i, rows, r, c, maxwidth = 0, columns;
  2132.   
  2133.       if (ioctl(SHOUT, TIOCGWINSZ, (char *)&win) < 0 || win.ws_col == 0)
  2134.           win.ws_col = 80;
  2135.       for (i = 0; i < count; i++)
  2136.           maxwidth = maxwidth > (r = strlen(items[i])) ? maxwidth : r;
  2137.  
  2138. --- 196,202 -----
  2139.   
  2140.   #ifdef    BSD4_3
  2141.       if (ioctl(SHOUT, TIOCGWINSZ, (char *)&win) < 0 || win.ws_col == 0)
  2142. + #endif
  2143.           win.ws_col = 80;
  2144.       for (i = 0; i < count; i++)
  2145.           maxwidth = maxwidth > (r = strlen(items[i])) ? maxwidth : r;
  2146. *** sh.func.c    Tue May 13 01:03:48 1986
  2147. --- /usr/src/local/tcsh/sh.func.c    Thu Sep 24 15:08:48 1987
  2148. ***************
  2149. *** 9,15
  2150.   #endif
  2151.   
  2152.   #include "sh.h"
  2153. ! #include <sys/ioctl.h>
  2154.   
  2155.   /*
  2156.    * C shell
  2157.  
  2158. --- 9,15 -----
  2159.   #endif
  2160.   
  2161.   #include "sh.h"
  2162. ! /* #include <sys/ioctl.h> */
  2163.   
  2164.   /*
  2165.    * C shell
  2166. ***************
  2167. *** 175,181
  2168.       islogin();
  2169.       rechist();
  2170.       (void) signal(SIGTERM, parterm);
  2171. !     execl("/bin/login", "login", v[1], 0);
  2172.       untty();
  2173.       exit(1);
  2174.   }
  2175.  
  2176. --- 175,181 -----
  2177.       islogin();
  2178.       rechist();
  2179.       (void) signal(SIGTERM, parterm);
  2180. !     execl("/bin/login", "login", v[1], (char *) 0);
  2181.       untty();
  2182.       exit(1);
  2183.   }
  2184. ***************
  2185. *** 180,185
  2186.       exit(1);
  2187.   }
  2188.   
  2189.   #ifdef NEWGRP
  2190.   donewgrp(v)
  2191.       char **v;
  2192.  
  2193. --- 180,204 -----
  2194.       exit(1);
  2195.   }
  2196.   
  2197. + dolog()
  2198. + {
  2199. +     extern struct who *wholist;
  2200. +     extern time_t watch_period;
  2201. +     struct who *wp;
  2202. +     struct varent *v;
  2203. +     if ((v = adrof ("watch")) == (struct varent *) 0)
  2204. +         error ("No $watch variable set");
  2205. +     blkpr (v->vec);
  2206. +     printf ("\n");
  2207. +     watch_period = 0;
  2208. +     wp = wholist;
  2209. +     while (wp != (struct who *) 0) {
  2210. +         wp->w_name[0] = '\0';
  2211. +         wp = wp->w_next;
  2212. +     }
  2213. + }
  2214.   #ifdef NEWGRP
  2215.   donewgrp(v)
  2216.       char **v;
  2217. ***************
  2218. *** 188,195
  2219.       if (chkstop == 0 && setintr)
  2220.           panystop(0);
  2221.       (void) signal(SIGTERM, parterm);
  2222. !     execl("/bin/newgrp", "newgrp", v[1], 0);
  2223. !     execl("/usr/bin/newgrp", "newgrp", v[1], 0);
  2224.       untty();
  2225.       exit(1);
  2226.   }
  2227.  
  2228. --- 207,214 -----
  2229.       if (chkstop == 0 && setintr)
  2230.           panystop(0);
  2231.       (void) signal(SIGTERM, parterm);
  2232. !     execl("/bin/newgrp", "newgrp", v[1], (char *) 0);
  2233. !     execl("/usr/bin/newgrp", "newgrp", v[1], (char *) 0);
  2234.       untty();
  2235.       exit(1);
  2236.   }
  2237. ***************
  2238. *** 532,538
  2239.           bseek((off_t)0);
  2240.       do {
  2241.           if (intty && fseekp == feobp)
  2242. !             printf("? "), flush();
  2243.           aword[0] = 0;
  2244.           (void) getword(aword);
  2245.           switch (srchx(aword)) {
  2246.  
  2247. --- 551,557 -----
  2248.           bseek((off_t)0);
  2249.       do {
  2250.           if (intty && fseekp == feobp)
  2251. !             printprompt(); /* printf("? "), flush(); */
  2252.           aword[0] = 0;
  2253.           (void) getword(aword);
  2254.           switch (srchx(aword)) {
  2255. ***************
  2256. *** 866,872
  2257.       (void) umask(i);
  2258.   }
  2259.   
  2260.   struct limits {
  2261.       int    limconst;
  2262.       char    *limname;
  2263.  
  2264. --- 885,891 -----
  2265.       (void) umask(i);
  2266.   }
  2267.   
  2268. ! #ifndef OREO
  2269.   struct limits {
  2270.       int    limconst;
  2271.       char    *limname;
  2272. ***************
  2273. *** 1074,1079
  2274.       }
  2275.       return (0);
  2276.   }
  2277.   
  2278.   dosuspend()
  2279.   {
  2280.  
  2281. --- 1093,1099 -----
  2282.       }
  2283.       return (0);
  2284.   }
  2285. + #endif OREO
  2286.   
  2287.   #ifdef SVID
  2288.   extern struct termio termiob;
  2289. ***************
  2290. *** 1075,1080
  2291.       return (0);
  2292.   }
  2293.   
  2294.   dosuspend()
  2295.   {
  2296.       int ldisc, ctpgrp;
  2297.  
  2298. --- 1095,1104 -----
  2299.   }
  2300.   #endif OREO
  2301.   
  2302. + #ifdef SVID
  2303. + extern struct termio termiob;
  2304. + #endif SVID
  2305.   dosuspend()
  2306.   {
  2307.       int ldisc, ctpgrp;
  2308. ***************
  2309. *** 1087,1092
  2310.       (void) kill(0, SIGTSTP);
  2311.       /* the shell stops here */
  2312.       (void) signal(SIGTSTP, old);
  2313.       if (tpgrp != -1) {
  2314.   retry:
  2315.           (void) ioctl(FSHTTY, TIOCGPGRP, (char *)&ctpgrp);
  2316.  
  2317. --- 1111,1117 -----
  2318.       (void) kill(0, SIGTSTP);
  2319.       /* the shell stops here */
  2320.       (void) signal(SIGTSTP, old);
  2321. + #ifdef BSDJOBS
  2322.       if (tpgrp != -1) {
  2323.   retry:
  2324.           (void) ioctl(FSHTTY, TIOCGPGRP, (char *)&ctpgrp);
  2325. ***************
  2326. *** 1099,1104
  2327.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&shpgrp);
  2328.           (void) setpgrp(0, shpgrp);
  2329.       }
  2330.       (void) ioctl(FSHTTY, TIOCGETD, (char *)&oldisc);
  2331.       if (oldisc != NTTYDISC) {
  2332.           printf("Switching to new tty driver...\n");
  2333.  
  2334. --- 1124,1141 -----
  2335.           (void) ioctl(FSHTTY, TIOCSPGRP, (char *)&shpgrp);
  2336.           (void) setpgrp(0, shpgrp);
  2337.       }
  2338. + #endif BSDJOBS
  2339. + #ifdef SVID
  2340. +     (void) ioctl(FSHTTY, TCGETA, &termiob);
  2341. +     if (termiob.c_cc[VSWTCH] != CSWTCH) {
  2342. + #ifdef DEBUG
  2343. +         printf ("Setting ^Z...\n");
  2344. + #endif DEBUG
  2345. +         termiob.c_cc[VSWTCH] = CSWTCH;
  2346. +         (void) ioctl(FSHTTY, TCSETA, &termiob);
  2347. +     }
  2348. + #else SVID
  2349.       (void) ioctl(FSHTTY, TIOCGETD, (char *)&oldisc);
  2350.       if (oldisc != NTTYDISC) {
  2351.           printf("Switching to new tty driver...\n");
  2352. ***************
  2353. *** 1105,1110
  2354.           ldisc = NTTYDISC;
  2355.           (void) ioctl(FSHTTY, TIOCSETD, (char *)&ldisc);
  2356.       }
  2357.   }
  2358.   
  2359.   doeval(v)
  2360.  
  2361. --- 1142,1148 -----
  2362.           ldisc = NTTYDISC;
  2363.           (void) ioctl(FSHTTY, TIOCSETD, (char *)&ldisc);
  2364.       }
  2365. + #endif SVID
  2366.   }
  2367.   
  2368.   doeval(v)
  2369. ***************
  2370. *** 1146,1148
  2371.       if (reenter >= 2)
  2372.           error(NOSTR);
  2373.   }
  2374.  
  2375. --- 1184,1366 -----
  2376.       if (reenter >= 2)
  2377.           error(NOSTR);
  2378.   }
  2379. + /*
  2380. +  * kfk - added scheduled event functions
  2381. +  */
  2382. + struct sched_event *sched_ptr;
  2383. + dosched(v)
  2384. +     register char **v;
  2385. + {
  2386. +     register struct sched_event *tp, *tp1, *tp2;
  2387. +     long cur_time;
  2388. +     int count, hours, minutes, dif_hour, dif_min;
  2389. +     char *cp;
  2390. +     bool relative;        /* time specified as +hh:mm */
  2391. +     struct tm *ltp;
  2392. +     char *timeline;
  2393. +     char *ctime();
  2394. +     v++;
  2395. +     cp = *v++;
  2396. +     if (cp == (char *) 0) {
  2397. +         /* print list of scheduled events */
  2398. +         for (count = 1, tp = sched_ptr; tp; count++, tp = tp->t_next) {
  2399. +             timeline = ctime(&tp->t_when);
  2400. +             timeline[16] = '\0';
  2401. +             printf ("%6d\t%s\t", count, timeline);
  2402. +             blkpr (tp->t_lex);
  2403. +             printf ("\n");
  2404. +         }
  2405. +         return;
  2406. +     }
  2407. +     if (*cp == '-') {
  2408. +         /* remove item from list */
  2409. +         if (!sched_ptr)
  2410. +             error ("No scheduled events");
  2411. +         if (*v)
  2412. +             error ("Too many args for 'sched -<item#>'");
  2413. +         count = atoi (++cp);
  2414. +         if (count <= 0)
  2415. +             error ("Usage to delete: sched -<item#>");
  2416. +         tp = sched_ptr;
  2417. +         tp1 = 0;
  2418. +         while (--count) {
  2419. +             if (tp->t_next == 0)
  2420. +                 break;
  2421. +             else {
  2422. +                 tp1 = tp;
  2423. +                 tp = tp->t_next;
  2424. +             }
  2425. +         }
  2426. +         if (count)
  2427. +             error ("Not that many scheduled events");
  2428. +         if (tp1 == 0)
  2429. +             sched_ptr = tp->t_next;
  2430. +         else
  2431. +             tp1->t_next = tp->t_next;
  2432. +         blkfree (tp->t_lex);
  2433. +         xfree ((char *) tp);
  2434. +         return;
  2435. +     }
  2436. +     /* else, add an item to the list */
  2437. +     if (!*v)
  2438. +         error ("No command to run");
  2439. +     relative = 0;
  2440. +     if (!digit(*cp)) {        /* not abs. time */
  2441. +         if (*cp != '+')
  2442. +             error ("Usage: sched [+]hh:mm <command>");
  2443. +         cp++, relative++;
  2444. +     }
  2445. +     minutes = 0;
  2446. +     hours = atoi(cp);
  2447. +     while (*cp && *cp != ':' && *cp != 'a' && *cp != 'p')
  2448. +         cp++;
  2449. +     if (*cp && *cp == ':')
  2450. +         minutes = atoi(++cp);
  2451. +     if ((hours < 0) || (minutes < 0) ||
  2452. +         (hours > 23) || (minutes > 59))
  2453. +         error ("Invalid time for event");
  2454. +     while (*cp && *cp != 'p' && *cp != 'a')
  2455. +         cp++;
  2456. +     if (*cp && relative)
  2457. +         error ("Relative time inconsistent with am/pm");
  2458. +     if (*cp == 'p')
  2459. +         hours += 12;
  2460. +     time(&cur_time);
  2461. +     ltp = localtime(&cur_time);
  2462. +     if (relative) {
  2463. +         dif_hour = hours;
  2464. +         dif_min = minutes;
  2465. +     } else {
  2466. +         if ((dif_hour = hours - ltp->tm_hour) < 0)
  2467. +             dif_hour += 24;
  2468. +         if ((dif_min = minutes - ltp->tm_min) < 0) {
  2469. +             dif_min += 60;
  2470. +             if ((--dif_hour) < 0)
  2471. +                 dif_hour = 23;
  2472. +         }
  2473. +     }
  2474. +     tp = (struct sched_event *) calloc (1, sizeof *tp);
  2475. +     tp->t_when = cur_time - ltp->tm_sec + dif_hour*3600L + dif_min*60L;
  2476. +             /* use of tm_sec: get to beginning of minute. */
  2477. +     if (!sched_ptr || tp->t_when < sched_ptr->t_when) {
  2478. +         tp->t_next = sched_ptr;
  2479. +         sched_ptr = tp;
  2480. +     } else {
  2481. +         tp1 = sched_ptr->t_next;
  2482. +         tp2 = sched_ptr;
  2483. +         while (tp1 && tp->t_when >= tp1->t_when) {
  2484. +             tp2 = tp1;
  2485. +             tp1 = tp1->t_next;
  2486. +         }
  2487. +         tp->t_next = tp1;
  2488. +         tp2->t_next = tp;
  2489. +     }
  2490. +     tp->t_lex = saveblk(v);
  2491. + }
  2492. + /*
  2493. +  * Execute scheduled events
  2494. +  */
  2495. + sched_run()
  2496. + {
  2497. +     long    cur_time;
  2498. +     register struct sched_event *tp, *tp1;
  2499. +     struct wordent cmd, *nextword, *lastword;
  2500. +     struct command *t = (struct command *) 0;
  2501. +     char **v, *cp;
  2502. +     extern int GettingInput;
  2503. +     int    omask;
  2504. +     omask = sighold (SIGINT);
  2505. +        
  2506. +         if (GettingInput)
  2507. +         Cookedmode();
  2508. +     time(&cur_time);
  2509. +     tp = sched_ptr;
  2510. +     while (tp && tp->t_when < cur_time) {
  2511. +         err = NOSTR;
  2512. +         cmd.word = "";
  2513. +         lastword = &cmd;
  2514. +         v = tp->t_lex;
  2515. +         for (cp = *v; cp; cp = *++v) {
  2516. +             nextword = (struct wordent *) calloc (1, sizeof cmd);
  2517. +             nextword->word = savestr (cp);
  2518. +             lastword->next = nextword;
  2519. +             nextword->prev = lastword;
  2520. +             lastword = nextword;
  2521. +         }
  2522. +         lastword->next = &cmd;
  2523. +         cmd.prev = lastword;
  2524. +         tp1 = tp;
  2525. +         sched_ptr = tp = tp1->t_next;    /* looping termination cond: */
  2526. +         blkfree (tp1->t_lex);        /* straighten out in case of */
  2527. +         xfree ((char *) tp1);        /* command blow-up. */
  2528. +         /* expand aliases like process() does. */
  2529. +         alias (&cmd);
  2530. +         /* build a syntax tree for the command. */
  2531. +         t = syntax (cmd.next, &cmd, 0);
  2532. +         if (err)
  2533. +             error (err);
  2534. +         /* execute the parse tree. */
  2535. +         execute (t, -1);
  2536. +         /* done. free the lex list and parse tree. */
  2537. +         freelex (&cmd), freesyn (t);
  2538. +     }
  2539. +         if (GettingInput) {    /* PWP */
  2540. +         Rawmode();
  2541. +         ClearLines();    /* do a real refresh since something may */
  2542. +         ClearDisp();    /* have printed to the screen */
  2543. +         Refresh();
  2544. +     }
  2545. +     sigsetmask(omask);
  2546. + }
  2547. + /* kfk - end change */
  2548.