1 /* $NetBSD: ex_util.c,v 1.2 2008/12/05 22:51:42 christos Exp $ */
4 * Copyright (c) 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 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";
18 #include <sys/types.h>
19 #include <sys/queue.h>
22 #include <bitstring.h>
30 #include "../common/common.h"
34 * Create an EX command structure.
36 * PUBLIC: void ex_cinit __P((SCR *, EXCMD *, int, int, db_recno_t, db_recno_t, int));
39 ex_cinit(SCR
*sp
, EXCMD
*cmdp
, int cmd_id
, int naddr
, db_recno_t lno1
, db_recno_t lno2
, int force
)
41 memset(cmdp
, 0, sizeof(EXCMD
));
42 cmdp
->cmd
= &cmds
[cmd_id
];
43 cmdp
->addrcnt
= naddr
;
44 cmdp
->addr1
.lno
= lno1
;
45 cmdp
->addr2
.lno
= lno2
;
46 cmdp
->addr1
.cno
= cmdp
->addr2
.cno
= 1;
48 cmdp
->iflags
|= E_C_FORCE
;
49 (void)argv_init(sp
, cmdp
);
54 * Return a line from the file.
56 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
59 ex_getline(SCR
*sp
, FILE *fp
, size_t *lenp
)
67 for (errno
= 0, off
= 0, p
= exp
->ibp
;;) {
68 if (off
>= exp
->ibp_len
) {
69 BINC_RETC(sp
, exp
->ibp
, exp
->ibp_len
, off
+ 1);
72 if ((ch
= getc(fp
)) == EOF
&& !feof(fp
)) {
80 if (ch
== EOF
|| ch
== '\n') {
81 if (ch
== EOF
&& !off
)
94 * Check for more files to edit.
96 * PUBLIC: int ex_ncheck __P((SCR *, int));
99 ex_ncheck(SCR
*sp
, int force
)
105 * Historic practice: quit! or two quit's done in succession
106 * (where ZZ counts as a quit) didn't check for other files.
108 if (!force
&& sp
->ccnt
!= sp
->q_ccnt
+ 1 &&
109 sp
->cargv
!= NULL
&& sp
->cargv
[1] != NULL
) {
110 sp
->q_ccnt
= sp
->ccnt
;
112 for (ap
= sp
->cargv
+ 1; *ap
!= NULL
; ++ap
);
114 "167|%zd more files to edit", (ap
- sp
->cargv
) - 1);
123 * Init the screen for ex.
125 * PUBLIC: int ex_init __P((SCR *));
134 if (gp
->scr_screen(sp
, SC_EX
))
136 (void)gp
->scr_attr(sp
, SA_ALTERNATE
, 0);
138 sp
->rows
= O_VAL(sp
, O_LINES
);
139 sp
->cols
= O_VAL(sp
, O_COLUMNS
);
142 F_SET(sp
, SC_EX
| SC_SCR_EX
);
148 * Display a few common ex and vi error messages.
150 * PUBLIC: void ex_wemsg __P((SCR *, CHAR_T *, exm_t));
153 ex_wemsg(SCR
* sp
, const CHAR_T
*p
, exm_t which
)
158 if (p
) INT2CHAR(sp
, p
, STRLEN(p
), np
, nlen
);
160 ex_emsg(sp
, np
, which
);
165 * Display a few common ex and vi error messages.
167 * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t));
170 ex_emsg(SCR
*sp
, const char *p
, exm_t which
)
174 msgq(sp
, M_ERR
, "168|Buffer %s is empty", p
);
177 msgq_str(sp
, M_ERR
, p
,
178 "144|%s: expanded into too many file names");
182 "Command failed, buffer is locked");
186 "283|The %s command requires the ex terminal interface", p
);
190 "272|That form of %s requires the ex terminal interface",
196 "274|Command failed, no file read in yet.");
199 "173|The %s command requires that a file have already been read in", p
);
202 msgq(sp
, M_ERR
, "171|No previous buffer to execute");
205 msgq(sp
, M_ERR
, "172|No previous regular expression");
208 msgq(sp
, M_ERR
, "230|This screen may not be suspended");
212 "290|The %s command is not supported when the secure edit option is set", p
);
216 "284|That form of %s is not supported when the secure edit option is set", p
);
219 msgq(sp
, M_ERR
, "174|Usage: %s", p
);