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
[] = "$Id: ex_util.c,v 10.32 2001/06/25 15:19:21 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:21 $";
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((SCR *, EXCMD *, int, int, db_recno_t, db_recno_t, int));
37 ex_cinit(SCR
*sp
, EXCMD
*cmdp
, int cmd_id
, int naddr
, db_recno_t lno1
, db_recno_t lno2
, int force
)
39 memset(cmdp
, 0, sizeof(EXCMD
));
40 cmdp
->cmd
= &cmds
[cmd_id
];
41 cmdp
->addrcnt
= naddr
;
42 cmdp
->addr1
.lno
= lno1
;
43 cmdp
->addr2
.lno
= lno2
;
44 cmdp
->addr1
.cno
= cmdp
->addr2
.cno
= 1;
46 cmdp
->iflags
|= E_C_FORCE
;
47 (void)argv_init(sp
, cmdp
);
52 * Return a line from the file.
54 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
57 ex_getline(SCR
*sp
, FILE *fp
, size_t *lenp
)
65 for (errno
= 0, off
= 0, p
= exp
->ibp
;;) {
66 if (off
* sizeof(CHAR_T
) >= exp
->ibp_len
) {
67 BINC_RETW(sp
, exp
->ibp
, exp
->ibp_len
, off
+ 1);
70 if ((ch
= getc(fp
)) == EOF
&& !feof(fp
)) {
78 if (ch
== EOF
|| ch
== '\n') {
79 if (ch
== EOF
&& !off
)
92 * Check for more files to edit.
94 * PUBLIC: int ex_ncheck __P((SCR *, int));
97 ex_ncheck(SCR
*sp
, int force
)
103 * Historic practice: quit! or two quit's done in succession
104 * (where ZZ counts as a quit) didn't check for other files.
106 if (!force
&& sp
->ccnt
!= sp
->q_ccnt
+ 1 &&
107 sp
->cargv
!= NULL
&& sp
->cargv
[1] != NULL
) {
108 sp
->q_ccnt
= sp
->ccnt
;
110 for (ap
= sp
->cargv
+ 1; *ap
!= NULL
; ++ap
);
112 "167|%d more files to edit", (ap
- sp
->cargv
) - 1);
121 * Init the screen for ex.
123 * PUBLIC: int ex_init __P((SCR *));
132 if (gp
->scr_screen(sp
, SC_EX
))
134 (void)gp
->scr_attr(sp
, SA_ALTERNATE
, 0);
136 sp
->rows
= O_VAL(sp
, O_LINES
);
137 sp
->cols
= O_VAL(sp
, O_COLUMNS
);
140 F_SET(sp
, SC_EX
| SC_SCR_EX
);
146 * Display a few common ex and vi error messages.
148 * PUBLIC: void ex_wemsg __P((SCR *, CHAR_T *, exm_t));
151 ex_wemsg(SCR
* sp
, CHAR_T
*p
, exm_t which
)
156 if (p
) INT2CHAR(sp
, p
, STRLEN(p
), np
, nlen
);
158 ex_emsg(sp
, np
, which
);
163 * Display a few common ex and vi error messages.
165 * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t));
168 ex_emsg(SCR
*sp
, char *p
, exm_t which
)
172 msgq(sp
, M_ERR
, "168|Buffer %s is empty", p
);
175 msgq_str(sp
, M_ERR
, p
,
176 "144|%s: expanded into too many file names");
180 "Command failed, buffer is locked");
184 "283|The %s command requires the ex terminal interface", p
);
188 "272|That form of %s requires the ex terminal interface",
194 "274|Command failed, no file read in yet.");
197 "173|The %s command requires that a file have already been read in", p
);
200 msgq(sp
, M_ERR
, "171|No previous buffer to execute");
203 msgq(sp
, M_ERR
, "172|No previous regular expression");
206 msgq(sp
, M_ERR
, "230|This screen may not be suspended");
210 "290|The %s command is not supported when the secure edit option is set", p
);
214 "284|That form of %s is not supported when the secure edit option is set", p
);
217 msgq(sp
, M_ERR
, "174|Usage: %s", p
);