* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)ex_cmds.c 7.10 (Berkeley) %G%";
#define nochng() lchng = chng
* Main loop for command mode command decoding.
* A few commands are executed here, but main function
* is to strip command addresses, do a little address oriented
* processing and call command routines to do the real work.
commands(noprompt
, exitoneof
)
bool noprompt
, exitoneof
;
* ended up at zero, advance to one if there is a such.
* If autoprint or trailing print flags,
* print the line at the specified offset
* before the next command.
lchng
!= chng
&& value(AUTOPRINT
) && !inglobal
&& !inopen
&& endline
) {
addr1
= addr2
= dot
+ poffset
;
if (addr1
< one
|| addr1
> dol
)
error("Offset out-of-bounds|Offset after command too large");
* Print prompt if appropriate.
* If not in global flush output first to prevent
* going into pfast mode unreasonably.
if (!hush
&& value(PROMPT
) && !globp
&& !noprompt
&& endline
) {
* Degenerate addresses yield ".".
* Set command name for special character commands.
* If called via : escape from open or visual, limit
* the set of available commands here to save work below.
if (c
=='\n' || c
=='\r' || c
==CTRL(d
) || c
==EOF
) {
ignore(append(gettty
, addr2
));
if (savedfile
[0] == '/' || !value(WARN
))
error("Home directory unknown");
tailprim("change", 2, 1);
ignore(append(gettty
, addr1
- 1));
* Caution: dp and dl have special meaning already.
tail(peekchar() == 'x' ? "ex" : "edit");
ignore(append(gettty
, addr2
- 1));
if (dot
== zero
&& dol
> zero
)
if (given
< 2 && addr2
!= dol
)
serror("Mark what?|%s requires following letter", Command
);
error("Bad mark|Mark must specify a letter");
names
[c
- 'a'] = *addr2
&~ 01;
error("Preserve failed!");
error("File preserved.");
if (CL
&& span() > LINES
) {
error("No write@since last chage (:rewind! overrides)");
if (savedfile
[0] == 0 && dol
== zero
)
if (inopen
&& endline
&& addr1
> zero
&& addr1
< dol
)
* Caution: 2nd char cannot be c, g, or r
* because these have meaning to substitute.
unixwt(1, unixex("-i", (char *) 0, 0, 0));
error("Old tty driver|Not using new tty driver/shell");
printf("@(#) Version 3.7, %G%."+5);
tail(c
== 'q' ? "wq" : "write");
if (skipwh() && peekchar() == '!') {
if (UP
!= NOSTR
&& c
== '\n' && !inglobal
)
error("At EOF|At end-of-file");
printf("%d", lineno(addr2
));
unixwt(1, unixex("-c", uxb
, 0, 0));
vclrech(1); /* vcontin(0); */
for (cnt
= 1; peekchar() == c
; cnt
++)
* Chtty sys call at UCB may cause a
* input which was a tty to suddenly be
error("What?|Unknown command character '%c'", c
);