split is "sp", not "s"
[nvi.git] / ex / ex_at.c
blob5d85309a418e31c29390a79fb0d0518a48d600aa
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.16 1994/01/09 14:20:53 bostic Exp $ (Berkeley) $Date: 1994/01/09 14:20:53 $";
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 CBNAME(sp, cbp, name);
51 if (cbp == NULL) {
52 msgq(sp, M_ERR, "Buffer %s is empty.", charname(sp, name));
53 return (1);
56 /* Save for reuse. */
57 exp->at_lbuf = name;
58 exp->at_lbuf_set = 1;
61 * If the buffer was cut in line mode or had portions of more
62 * than one line, <newlines> are appended to each line as it
63 * is pushed onto the stack.
65 tp = cbp->textq.cqh_last;
66 lmode = F_ISSET(cbp, CB_LMODE) || tp->q.cqe_prev != (void *)&cbp->textq;
67 for (; tp != (void *)&cbp->textq; tp = tp->q.cqe_prev)
68 if ((lmode || tp->q.cqe_prev != (void *)&cbp->textq) &&
69 term_push(sp, "\n", 1, 0, 0) ||
70 term_push(sp, tp->lb, tp->len, 0, CH_QUOTED))
71 return (1);
72 return (0);