-/* 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"
* data base, grabbing of tty modes (at beginning
* and after escapes).
*
+ * ex_unix.c Routines for the ! command and its variations.
+ *
* ex_v*.c Visual/open mode routines... see ex_v.c for a
* guide to the overall organization.
*/
/*
* Main procedure. Process arguments and then
* transfer control to the main command processing loop
- * in the routine commands. We are entered as either "ex", "edit" or "vi"
- * and the distinction is made here. Actually, we are "vi" if
- * there is a 'v' in our name, and "edit" if there is a 'd' in our
- * name. For edit we just diddle options; for vi we actually
- * force an early visual command, setting the external initev so
- * the q command in visual doesn't give command mode.
+ * in the routine commands. We are entered as either "ex", "edit", "vi"
+ * or "view" and the distinction is made here. Actually, we are "vi" if
+ * there is a 'v' in our name, "view" is there is a 'w', and "edit" if
+ * there is a 'd' in our name. For edit we just diddle options;
+ * for vi we actually force an early visual command.
*/
main(ac, av)
register int ac;
bool ivis;
bool itag = 0;
bool fast = 0;
+ extern int onemt();
#ifdef TRACE
register char *tracef;
#endif
* get messed up if an interrupt comes in quickly.
*/
gTTY(1);
+#ifndef USG3TTY
normf = tty.sg_flags;
+#else
+ normf = tty;
+#endif
ppid = getpid();
/*
- * Defend against d's, v's, and a's in directories of
+ * Defend against d's, v's, w's, and a's in directories of
* path leading to our true name.
*/
av[0] = tailpath(av[0]);
- ivis = any('v', av[0]);
/*
- * For debugging take files out of . if name is a.out.
- * If a 'd' in our name, then set options for edit.
+ * Figure out how we were invoked: ex, edit, vi, view.
*/
-#ifndef VMUNIX
- if (av[0][0] == 'a')
- erpath = tailpath(erpath);
-#endif
- if (ivis) {
-#ifdef notdef
- options[BEAUTIFY].odefault = value(BEAUTIFY) = 1;
-#endif
- } else if (any('d', av[0])) {
+ ivis = any('v', av[0]); /* "vi" */
+ if (any('w', av[0])) /* "view" */
+ value(READONLY) = 1;
+ if (any('d', av[0])) { /* "edit" */
value(OPEN) = 0;
value(REPORT) = 1;
value(MAGIC) = 0;
}
+#ifndef VMUNIX
+ /*
+ * For debugging take files out of . if name is a.out.
+ */
+ if (av[0][0] == 'a')
+ erpath = tailpath(erpath);
+#endif
/*
* Open the error message file.
*/
ruptible = signal(SIGINT, SIG_IGN) == SIG_DFL;
if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
signal(SIGTERM, onhup);
+ if (signal(SIGEMT, SIG_IGN) == SIG_DFL)
+ signal(SIGEMT, onemt);
/*
* Initialize end of core pointers.
fast++;
} else switch (c) {
+ case 'R':
+ value(READONLY) = 1;
+ break;
+
#ifdef TRACE
case 'T':
if (av[0][2] == 0)
tracef[9] = 0;
}
trace = fopen(tracef, "w");
+#define tracbuf NULL
if (trace == NULL)
printf("Trace create error\n");
- setbuf(trace, tracbuf);
+ else
+ setbuf(trace, tracbuf);
break;
#endif
defwind = 10*defwind + *cp - '0';
break;
+#ifdef CRYPT
+ case 'x':
+ /* -x: encrypted mode */
+ xflag = 1;
+ break;
+#endif
+
default:
smerror("Unknown option %s\n", av[0]);
break;
}
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++;
}
+#ifdef CRYPT
+ if(xflag){
+ key = getpass(KEYPROMPT);
+ kflag = crinit(key, perm);
+ }
+#endif
+
/*
* If we are doing a recover and no filename
* was given, then execute an exrecover command with
* Initialize a temporary file (buffer) and
* set up terminal environment. Read user startup commands.
*/
- init();
if (setexit() == 0) {
setrupt();
intty = isatty(0);
value(PROMPT) = intty;
+ if (cp = getenv("SHELL"))
+ CP(shell, cp);
if (fast || !intty)
setterm("dumb");
else {
gettmode();
- if ((cp = getenv("TERM")) != 0)
+ if ((cp = getenv("TERM")) != 0 && *cp)
setterm(cp);
}
}
- if (setexit() == 0 && !fast && intty)
- if (globp = getenv("EXINIT"))
+ if (setexit() == 0 && !fast && intty) {
+ if ((globp = getenv("EXINIT")) && *globp)
commands(1,1);
- else if ((cp = getenv("HOME")) != 0)
- source(strcat(strcpy(genbuf, cp), "/.exrc"), 1);
+ else {
+ globp = 0;
+ 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
* 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;
for (i = 0; i <= 'z'-'a'+1; i++)
names[i] = 1;
anymarks = 0;
-}
-
-/*
- * 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()
-{
-
- 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();
+#ifdef CRYPT
+ if(xflag) {
+ xtflag = 1;
+ makekey(key, tperm);
+ }
#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
-}
-
-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;
-{
-
- _exit(i);
-}
-#endif
-
/*
* Return last component of unix path name p.
*/