Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / vi / v_at.c
blobcf3385ed891e4366c336e44b9305437a47eb9e09
1 /* $NetBSD: v_at.c,v 1.2 2008/12/05 22:51:43 christos Exp $ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <ctype.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <string.h>
28 #include "../common/common.h"
29 #include "vi.h"
32 * v_at -- @
33 * Execute a buffer.
35 * PUBLIC: int v_at __P((SCR *, VICMD *));
37 int
38 v_at(SCR *sp, VICMD *vp)
40 CB *cbp;
41 CHAR_T name;
42 TEXT *tp;
43 size_t len;
44 char nbuf[20];
45 CHAR_T wbuf[20];
46 const CHAR_T *wp;
47 size_t wlen;
50 * !!!
51 * Historically, [@*]<carriage-return> and [@*][@*] executed the most
52 * recently executed buffer in ex mode. In vi mode, only @@ repeated
53 * the last buffer. We change historic practice and make @* work from
54 * vi mode as well, it's simpler and more consistent.
56 * My intent is that *[buffer] will, in the future, pass the buffer to
57 * whatever interpreter is loaded.
59 name = F_ISSET(vp, VC_BUFFER) ? vp->buffer : '@';
60 if (name == '@' || name == '*') {
61 if (!F_ISSET(sp, SC_AT_SET)) {
62 ex_emsg(sp, NULL, EXM_NOPREVBUF);
63 return (1);
65 name = sp->at_lbuf;
67 F_SET(sp, SC_AT_SET);
69 CBNAME(sp, cbp, name);
70 if (cbp == NULL) {
71 ex_emsg(sp, (char *)KEY_NAME(sp, name), EXM_EMPTYBUF);
72 return (1);
75 /* Save for reuse. */
76 sp->at_lbuf = name;
79 * The buffer is executed in vi mode, while in vi mode, so simply
80 * push it onto the terminal queue and continue.
82 * !!!
83 * Historic practice is that if the buffer was cut in line mode,
84 * <newlines> were appended to each line as it was pushed onto
85 * the stack. If the buffer was cut in character mode, <newlines>
86 * were appended to all lines but the last one.
88 * XXX
89 * Historic practice is that execution of an @ buffer could be
90 * undone by a single 'u' command, i.e. the changes were grouped
91 * together. We don't get this right; I'm waiting for the new DB
92 * logging code to be available.
94 for (tp = cbp->textq.cqh_last;
95 tp != (void *)&cbp->textq; tp = tp->q.cqe_prev) {
96 static CHAR_T nl[] = { '\n', 0 };
97 if (((F_ISSET(cbp, CB_LMODE) ||
98 tp->q.cqe_next != (void *)&cbp->textq) &&
99 v_event_push(sp, NULL, nl, 1, 0)) ||
100 v_event_push(sp, NULL, tp->lb, tp->len, 0))
101 return (1);
105 * !!!
106 * If any count was supplied, it applies to the first command in the
107 * at buffer.
109 if (F_ISSET(vp, VC_C1SET)) {
110 len = snprintf(nbuf, sizeof(nbuf), "%lu", vp->count);
111 CHAR2INT(sp, nbuf, len, wp, wlen);
112 MEMCPYW(wbuf, wp, wlen);
113 if (v_event_push(sp, NULL, wp, wlen, 0))
114 return (1);
116 return (0);