fix for portability on systems with big uids. THIS CHANGES TEMP
[unix-history] / usr / src / usr.bin / ex / ex.c
index b10ceb8..169612f 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/* Copyright (c) 1981 Regents of the University of California */
+static char *sccsid = "@(#)ex.c        7.1     %G%";
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -80,6 +81,7 @@ main(ac, av)
        bool ivis;
        bool itag = 0;
        bool fast = 0;
        bool ivis;
        bool itag = 0;
        bool fast = 0;
+       extern int onemt();
 #ifdef TRACE
        register char *tracef;
 #endif
 #ifdef TRACE
        register char *tracef;
 #endif
@@ -142,10 +144,8 @@ main(ac, av)
        ruptible = signal(SIGINT, SIG_IGN) == SIG_DFL;
        if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
                signal(SIGTERM, onhup);
        ruptible = signal(SIGINT, SIG_IGN) == SIG_DFL;
        if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
                signal(SIGTERM, onhup);
-#ifdef TIOCLGET
-       if (signal(SIGTSTP, SIG_IGN) == SIG_DFL)
-               signal(SIGTSTP, onsusp), dosusp++;
-#endif
+       if (signal(SIGEMT, SIG_IGN) == SIG_DFL)
+               signal(SIGEMT, onemt);
 
        /*
         * Initialize end of core pointers.
 
        /*
         * Initialize end of core pointers.
@@ -187,9 +187,11 @@ main(ac, av)
                                        tracef[9] = 0;
                        }
                        trace = fopen(tracef, "w");
                                        tracef[9] = 0;
                        }
                        trace = fopen(tracef, "w");
+#define tracbuf NULL
                        if (trace == NULL)
                                printf("Trace create error\n");
                        if (trace == NULL)
                                printf("Trace create error\n");
-                       setbuf(trace, tracbuf);
+                       else
+                               setbuf(trace, tracbuf);
                        break;
 
 #endif
                        break;
 
 #endif
@@ -225,10 +227,12 @@ main(ac, av)
                                defwind = 10*defwind + *cp - '0';
                        break;
 
                                defwind = 10*defwind + *cp - '0';
                        break;
 
+#ifdef CRYPT
                case 'x':
                        /* -x: encrypted mode */
                        xflag = 1;
                        break;
                case 'x':
                        /* -x: encrypted mode */
                        xflag = 1;
                        break;
+#endif
 
                default:
                        smerror("Unknown option %s\n", av[0]);
 
                default:
                        smerror("Unknown option %s\n", av[0]);
@@ -236,15 +240,23 @@ main(ac, av)
                }
                ac--, av++;
        }
                }
                ac--, av++;
        }
+
+#ifdef SIGTSTP
+       if (!hush && signal(SIGTSTP, SIG_IGN) == SIG_DFL)
+               signal(SIGTSTP, onsusp), dosusp++;
+#endif
+
        if (ac && av[0][0] == '+') {
                firstpat = &av[0][1];
                ac--, av++;
        }
 
        if (ac && av[0][0] == '+') {
                firstpat = &av[0][1];
                ac--, av++;
        }
 
+#ifdef CRYPT
        if(xflag){
                key = getpass(KEYPROMPT);
                kflag = crinit(key, perm);
        }
        if(xflag){
                key = getpass(KEYPROMPT);
                kflag = crinit(key, perm);
        }
+#endif
 
        /*
         * If we are doing a recover and no filename
 
        /*
         * If we are doing a recover and no filename
@@ -276,7 +288,6 @@ main(ac, av)
         * Initialize a temporary file (buffer) and
         * set up terminal environment.  Read user startup commands.
         */
         * Initialize a temporary file (buffer) and
         * set up terminal environment.  Read user startup commands.
         */
-       init();
        if (setexit() == 0) {
                setrupt();
                intty = isatty(0);
        if (setexit() == 0) {
                setrupt();
                intty = isatty(0);
@@ -291,7 +302,7 @@ main(ac, av)
                                setterm(cp);
                }
        }
                                setterm(cp);
                }
        }
-       if (setexit() == 0 && !fast && intty)
+       if (setexit() == 0 && !fast && intty) {
                if ((globp = getenv("EXINIT")) && *globp)
                        commands(1,1);
                else {
                if ((globp = getenv("EXINIT")) && *globp)
                        commands(1,1);
                else {
@@ -299,6 +310,15 @@ main(ac, av)
                        if ((cp = getenv("HOME")) != 0 && *cp)
                                source(strcat(strcpy(genbuf, cp), "/.exrc"), 1);
                }
                        if ((cp = getenv("HOME")) != 0 && *cp)
                                source(strcat(strcpy(genbuf, cp), "/.exrc"), 1);
                }
+               /*
+                * Allow local .exrc too.  This loses if . is $HOME,
+                * but nobody should notice unless they do stupid things
+                * like putting a version command in .exrc.  Besides,
+                * they should be using EXINIT, not .exrc, right?
+                */
+               source(".exrc", 1);
+       }
+       init(); /* moved after prev 2 chunks to fix directory option */
 
        /*
         * Initial processing.  Handle tag, recover, and file argument
 
        /*
         * Initial processing.  Handle tag, recover, and file argument
@@ -345,6 +365,7 @@ main(ac, av)
         * If you quit out of a 'vi' command by doing Q or ^\,
         * you also fall through to here.
         */
         * If you quit out of a 'vi' command by doing Q or ^\,
         * you also fall through to here.
         */
+       seenprompt = 1;
        ungetchar(0);
        globp = 0;
        initev = 0;
        ungetchar(0);
        globp = 0;
        initev = 0;
@@ -370,136 +391,17 @@ init()
        undkind = UNDNONE;
        chng = 0;
        edited = 0;
        undkind = UNDNONE;
        chng = 0;
        edited = 0;
-#ifdef USG
-       signal (SIGHUP, SIG_IGN);
-#endif
-#ifdef USG3TTY
-#ifndef USG
-       signal (SIGHUP, SIG_IGN);
-#endif
-#endif
        for (i = 0; i <= 'z'-'a'+1; i++)
                names[i] = 1;
        anymarks = 0;
        for (i = 0; i <= 'z'-'a'+1; i++)
                names[i] = 1;
        anymarks = 0;
+#ifdef CRYPT
         if(xflag) {
                 xtflag = 1;
                 makekey(key, tperm);
         }
         if(xflag) {
                 xtflag = 1;
                 makekey(key, tperm);
         }
-}
-
-/*
- * When a hangup occurs our actions are similar to a preserve
- * command.  If the buffer has not been [Modified], then we do
- * nothing but remove the temporary files and exit.
- * Otherwise, we sync the temp file and then attempt a preserve.
- * If the preserve succeeds, we unlink our temp files.
- * If the preserve fails, we leave the temp files as they are
- * as they are a backup even without preservation if they
- * are not removed.
- */
-onhup()
-{
-
-       /*
-        * USG tty driver can send multiple HUP's!!
-        */
-       signal(SIGINT, SIG_IGN);
-       signal(SIGHUP, SIG_IGN);
-       if (chng == 0) {
-               cleanup(1);
-               exit(0);
-       }
-       if (setexit() == 0) {
-               if (preserve()) {
-                       cleanup(1);
-                       exit(0);
-               }
-       }
-       exit(1);
-}
-
-/*
- * An interrupt occurred.  Drain any output which
- * is still in the output buffering pipeline.
- * Catch interrupts again.  Unless we are in visual
- * reset the output state (out of -nl mode, e.g).
- * Then like a normal error (with the \n before Interrupt
- * suppressed in visual mode).
- */
-onintr()
-{
-
-#ifndef CBREAK
-       signal(SIGINT, onintr);
-#else
-       signal(SIGINT, inopen ? vintr : onintr);
-#endif
-       draino();
-       if (!inopen) {
-               pstop();
-               setlastchar('\n');
-#ifdef CBREAK
-       }
-#else
-       } else
-               vraw();
-#endif
-       error("\nInterrupt" + inopen);
-}
-
-/*
- * If we are interruptible, enable interrupts again.
- * In some critical sections we turn interrupts off,
- * but not very often.
- */
-setrupt()
-{
-
-       if (ruptible) {
-#ifndef CBREAK
-               signal(SIGINT, onintr);
-#else
-               signal(SIGINT, inopen ? vintr : onintr);
 #endif
 #endif
-#ifdef TIOCLGET
-               if (dosusp)
-                       signal(SIGTSTP, onsusp);
-#endif
-       }
-}
-
-preserve()
-{
-
-       synctmp();
-       pid = fork();
-       if (pid < 0)
-               return (0);
-       if (pid == 0) {
-               close(0);
-               dup(tfile);
-               execl(EXPRESERVE, "expreserve", (char *) 0);
-               exit(1);
-       }
-       waitfor();
-       if (rpid == pid && status == 0)
-               return (1);
-       return (0);
 }
 
 }
 
-#ifndef V6
-exit(i)
-       int i;
-{
-
-# ifdef TRACE
-       if (trace)
-               fclose(trace);
-# endif
-       _exit(i);
-}
-#endif
-
 /*
  * Return last component of unix path name p.
  */
 /*
  * Return last component of unix path name p.
  */