1 /* $NetBSD: v_at.c,v 1.4 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 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 ";
19 __RCSID("$NetBSD: v_at.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
32 #include "../common/common.h"
39 * PUBLIC: int v_at __P((SCR *, VICMD *));
42 v_at(SCR
*sp
, VICMD
*vp
)
55 * Historically, [@*]<carriage-return> and [@*][@*] executed the most
56 * recently executed buffer in ex mode. In vi mode, only @@ repeated
57 * the last buffer. We change historic practice and make @* work from
58 * vi mode as well, it's simpler and more consistent.
60 * My intent is that *[buffer] will, in the future, pass the buffer to
61 * whatever interpreter is loaded.
63 name
= F_ISSET(vp
, VC_BUFFER
) ? vp
->buffer
: '@';
64 if (name
== '@' || name
== '*') {
65 if (!F_ISSET(sp
, SC_AT_SET
)) {
66 ex_emsg(sp
, NULL
, EXM_NOPREVBUF
);
73 CBNAME(sp
, cbp
, name
);
75 ex_emsg(sp
, (char *)KEY_NAME(sp
, name
), EXM_EMPTYBUF
);
83 * The buffer is executed in vi mode, while in vi mode, so simply
84 * push it onto the terminal queue and continue.
87 * Historic practice is that if the buffer was cut in line mode,
88 * <newlines> were appended to each line as it was pushed onto
89 * the stack. If the buffer was cut in character mode, <newlines>
90 * were appended to all lines but the last one.
93 * Historic practice is that execution of an @ buffer could be
94 * undone by a single 'u' command, i.e. the changes were grouped
95 * together. We don't get this right; I'm waiting for the new DB
96 * logging code to be available.
98 TAILQ_FOREACH_REVERSE(tp
, &cbp
->textq
, _texth
, q
) {
99 static CHAR_T nl
[] = { '\n', 0 };
100 if (((F_ISSET(cbp
, CB_LMODE
) ||
101 TAILQ_NEXT(tp
, q
) != NULL
) &&
102 v_event_push(sp
, NULL
, nl
, 1, 0)) ||
103 v_event_push(sp
, NULL
, tp
->lb
, tp
->len
, 0))
109 * If any count was supplied, it applies to the first command in the
112 if (F_ISSET(vp
, VC_C1SET
)) {
113 len
= snprintf(nbuf
, sizeof(nbuf
), "%lu", vp
->count
);
114 CHAR2INT(sp
, nbuf
, len
, wp
, wlen
);
115 MEMCPYW(wbuf
, wp
, wlen
);
116 if (v_event_push(sp
, NULL
, wp
, wlen
, 0))