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.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
24 #include "../common/common.h"
28 * Create an EX command structure.
30 * PUBLIC: void ex_cinit(SCR *, EXCMD *, int, int, recno_t, recno_t, int);
33 ex_cinit(SCR *sp, EXCMD *cmdp, int cmd_id, int naddr, recno_t lno1, recno_t lno2, int force)
35 memset(cmdp, 0, sizeof(EXCMD));
36 cmdp->cmd = &cmds[cmd_id];
37 cmdp->addrcnt = naddr;
38 cmdp->addr1.lno = lno1;
39 cmdp->addr2.lno = lno2;
40 cmdp->addr1.cno = cmdp->addr2.cno = 1;
42 cmdp->iflags |= E_C_FORCE;
43 (void)argv_init(sp, cmdp);
48 * Return a line from the file.
50 * PUBLIC: int ex_getline(SCR *, FILE *, size_t *);
53 ex_getline(SCR *sp, FILE *fp, size_t *lenp)
61 for (errno = 0, off = 0, p = exp->ibp;;) {
62 if (off >= exp->ibp_len) {
63 BINC_RETC(sp, exp->ibp, exp->ibp_len, off + 1);
66 if ((ch = getc(fp)) == EOF && !feof(fp)) {
74 if (ch == EOF || ch == '\n') {
75 if (ch == EOF && !off)
88 * Check for more files to edit.
90 * PUBLIC: int ex_ncheck(SCR *, int);
93 ex_ncheck(SCR *sp, int force)
99 * Historic practice: quit! or two quit's done in succession
100 * (where ZZ counts as a quit) didn't check for other files.
102 if (!force && sp->ccnt != sp->q_ccnt + 1 &&
103 sp->cargv != NULL && sp->cargv[1] != NULL) {
104 sp->q_ccnt = sp->ccnt;
106 for (ap = sp->cargv + 1; *ap != NULL; ++ap);
108 "167|%d more files to edit", (int)(ap - sp->cargv) - 1);
117 * Init the screen for ex.
119 * PUBLIC: int ex_init(SCR *);
128 if (gp->scr_screen(sp, SC_EX))
130 (void)gp->scr_attr(sp, SA_ALTERNATE, 0);
132 sp->rows = O_VAL(sp, O_LINES);
133 sp->cols = O_VAL(sp, O_COLUMNS);
136 F_SET(sp, SC_EX | SC_SCR_EX);
142 * Display a few common ex and vi error messages.
144 * PUBLIC: void ex_wemsg(SCR *, CHAR_T *, exm_t);
147 ex_wemsg(SCR* sp, CHAR_T *p, exm_t which)
152 if (p) INT2CHAR(sp, p, STRLEN(p), np, nlen);
154 ex_emsg(sp, np, which);
159 * Display a few common ex and vi error messages.
161 * PUBLIC: void ex_emsg(SCR *, char *, exm_t);
164 ex_emsg(SCR *sp, char *p, exm_t which)
168 msgq(sp, M_ERR, "168|Buffer %s is empty", p);
171 msgq_str(sp, M_ERR, p,
172 "144|%s: expanded into too many file names");
176 "283|The %s command requires the ex terminal interface", p);
180 "272|That form of %s requires the ex terminal interface",
186 "274|Command failed, no file read in yet.");
189 "173|The %s command requires that a file have already been read in", p);
192 msgq(sp, M_ERR, "171|No previous buffer to execute");
195 msgq(sp, M_ERR, "172|No previous regular expression");
198 msgq(sp, M_ERR, "230|This screen may not be suspended");
202 "290|The %s command is not supported when the secure edit option is set", p);
206 "284|That form of %s is not supported when the secure edit option is set", p);
209 msgq(sp, M_ERR, "174|Usage: %s", p);