rename O_DIRECTORY to O_TMP_DIRECTORY to avoid conflict with open option
[nvi.git] / vi / v_at.c
blob9f9e83d32b2dbf3cf4947526747c9916bf374e66
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: v_at.c,v 10.11 2001/06/25 15:19:30 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:30 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <limits.h>
23 #include <stdio.h>
25 #include "../common/common.h"
26 #include "vi.h"
29 * v_at -- @
30 * Execute a buffer.
32 * PUBLIC: int v_at __P((SCR *, VICMD *));
34 int
35 v_at(SCR *sp, VICMD *vp)
37 CB *cbp;
38 CHAR_T name;
39 TEXT *tp;
40 size_t len;
41 char nbuf[20];
42 CHAR_T wbuf[20];
43 CHAR_T *wp;
44 size_t wlen;
47 * !!!
48 * Historically, [@*]<carriage-return> and [@*][@*] executed the most
49 * recently executed buffer in ex mode. In vi mode, only @@ repeated
50 * the last buffer. We change historic practice and make @* work from
51 * vi mode as well, it's simpler and more consistent.
53 * My intent is that *[buffer] will, in the future, pass the buffer to
54 * whatever interpreter is loaded.
56 name = F_ISSET(vp, VC_BUFFER) ? vp->buffer : '@';
57 if (name == '@' || name == '*') {
58 if (!F_ISSET(sp, SC_AT_SET)) {
59 ex_emsg(sp, NULL, EXM_NOPREVBUF);
60 return (1);
62 name = sp->at_lbuf;
64 F_SET(sp, SC_AT_SET);
66 CBNAME(sp, cbp, name);
67 if (cbp == NULL) {
68 ex_emsg(sp, KEY_NAME(sp, name), EXM_EMPTYBUF);
69 return (1);
72 /* Save for reuse. */
73 sp->at_lbuf = name;
76 * The buffer is executed in vi mode, while in vi mode, so simply
77 * push it onto the terminal queue and continue.
79 * !!!
80 * Historic practice is that if the buffer was cut in line mode,
81 * <newlines> were appended to each line as it was pushed onto
82 * the stack. If the buffer was cut in character mode, <newlines>
83 * were appended to all lines but the last one.
85 * XXX
86 * Historic practice is that execution of an @ buffer could be
87 * undone by a single 'u' command, i.e. the changes were grouped
88 * together. We don't get this right; I'm waiting for the new DB
89 * logging code to be available.
91 for (tp = cbp->textq.cqh_last;
92 tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) {
93 static CHAR_T nl[] = { '\n', 0 };
94 if ((F_ISSET(cbp, CB_LMODE) ||
95 tp->q.cqe_next != (void *)&cbp->textq) &&
96 v_event_push(sp, NULL, nl, 1, 0) ||
97 v_event_push(sp, NULL, tp->lb, tp->len, 0))
98 return (1);
102 * !!!
103 * If any count was supplied, it applies to the first command in the
104 * at buffer.
106 if (F_ISSET(vp, VC_C1SET)) {
107 len = snprintf(nbuf, sizeof(nbuf), "%lu", vp->count);
108 CHAR2INT(sp, nbuf, len, wp, wlen);
109 MEMCPYW(wbuf, wp, wlen);
110 if (v_event_push(sp, NULL, wp, wlen, 0))
111 return (1);
113 return (0);