lint
[nvi.git] / ex / ex_at.c
blob4abd22fc59defd007b2c8c5eb21e69795d8add25
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_at.c,v 8.15 1993/12/22 13:15:47 bostic Exp $ (Berkeley) $Date: 1993/12/22 13:15:47 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <ctype.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vi.h"
19 #include "excmd.h"
22 * ex_at -- :@[@ | buffer]
23 * :*[* | buffer]
25 * Execute the contents of the buffer.
27 int
28 ex_at(sp, ep, cmdp)
29 SCR *sp;
30 EXF *ep;
31 EXCMDARG *cmdp;
33 CB *cbp;
34 EX_PRIVATE *exp;
35 TEXT *tp;
36 int name, lmode;
38 exp = EXP(sp);
40 /* Historically, @@ and ** execute the last buffer. */
41 name = cmdp->buffer;
42 if (name == cmdp->cmd->name[0]) {
43 if (!exp->at_lbuf_set) {
44 msgq(sp, M_ERR, "No previous buffer to execute.");
45 return (1);
47 name = exp->at_lbuf;
50 CBEMPTY(sp, cbp, name);
52 /* Save for reuse. */
53 exp->at_lbuf = name;
54 exp->at_lbuf_set = 1;
57 * If the buffer was cut in line mode or had portions of more
58 * than one line, <newlines> are appended to each line as it
59 * is pushed onto the stack.
61 tp = cbp->textq.cqh_last;
62 lmode = F_ISSET(cbp, CB_LMODE) || tp->q.cqe_prev != (void *)&cbp->textq;
63 for (; tp != (void *)&cbp->textq; tp = tp->q.cqe_prev)
64 if ((lmode || tp->q.cqe_prev != (void *)&cbp->textq) &&
65 term_push(sp, "\n", 1, 0, 0) ||
66 term_push(sp, tp->lb, tp->len, 0, CH_QUOTED))
67 return (1);
68 return (0);