2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid[] = "@(#)ex_util.c 10.23 (Berkeley) 6/19/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
28 #include "../common/common.h"
32 * Create an EX command structure.
34 * PUBLIC: void ex_cinit __P((EXCMD *,
35 * PUBLIC: int, int, recno_t, recno_t, int, ARGS **));
38 ex_cinit(cmdp, cmd_id, naddr, lno1, lno2, force, ap)
40 int cmd_id, force, naddr;
44 memset(cmdp, 0, sizeof(EXCMD));
45 cmdp->cmd = &cmds[cmd_id];
46 cmdp->addrcnt = naddr;
47 cmdp->addr1.lno = lno1;
48 cmdp->addr2.lno = lno2;
49 cmdp->addr1.cno = cmdp->addr2.cno = 1;
51 cmdp->iflags |= E_C_FORCE;
53 if ((cmdp->argv = ap) != NULL)
59 * Add an argument to an EX command structure.
61 * PUBLIC: void ex_cadd __P((EXCMD *, ARGS *, char *, size_t));
64 ex_cadd(cmdp, ap, arg, len)
70 cmdp->argv[cmdp->argc] = ap;
73 cmdp->argv[++cmdp->argc] = NULL;
78 * Return a line from the file.
80 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
83 ex_getline(sp, fp, lenp)
94 for (errno = 0, off = 0, p = exp->ibp;;) {
95 if (off >= exp->ibp_len) {
96 BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1);
99 if ((ch = getc(fp)) == EOF && !feof(fp)) {
100 if (errno == EINTR) {
107 if (ch == EOF || ch == '\n') {
108 if (ch == EOF && !off)
121 * Check for more files to edit.
123 * PUBLIC: int ex_ncheck __P((SCR *, int));
134 * Historic practice: quit! or two quit's done in succession
135 * (where ZZ counts as a quit) didn't check for other files.
137 if (!force && sp->ccnt != sp->q_ccnt + 1 &&
138 sp->cargv != NULL && sp->cargv[1] != NULL) {
139 sp->q_ccnt = sp->ccnt;
141 for (ap = sp->cargv + 1; *ap != NULL; ++ap);
143 "167|%d more files to edit", (ap - sp->cargv) - 1);
152 * Init the screen for ex.
154 * PUBLIC: int ex_init __P((SCR *));
164 if (gp->scr_screen(sp, SC_EX))
166 (void)gp->scr_attr(sp, SA_ALTERNATE, 0);
168 sp->rows = O_VAL(sp, O_LINES);
169 sp->cols = O_VAL(sp, O_COLUMNS);
172 F_SET(sp, SC_EX | SC_SCR_EX);
178 * Display a few common ex and vi error messages.
180 * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t));
183 ex_emsg(sp, p, which)
190 msgq(sp, M_ERR, "168|Buffer %s is empty", p);
193 msgq_str(sp, M_ERR, p,
194 "144|%s: expanded into too many file names");
198 "283|The %s command requires the ex terminal interface", p);
202 "272|That form of %s requires the ex terminal interface",
208 "274|Command failed, no file read in yet.");
211 "173|The %s command requires that a file have already been read in", p);
214 msgq(sp, M_ERR, "171|No previous buffer to execute");
217 msgq(sp, M_ERR, "172|No previous regular expression");
220 msgq(sp, M_ERR, "230|This screen may not be suspended");
224 "290|The %s command is not supported when the secure edit option is set", p);
228 "284|That form of %s is not supported when the secure edit option is set", p);
231 msgq(sp, M_ERR, "174|Usage: %s", p);