1 /* $NetBSD: ex_util.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 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 ";
19 __RCSID("$NetBSD: ex_util.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
26 #include <bitstring.h>
34 #include "../common/common.h"
38 * Create an EX command structure.
40 * PUBLIC: void ex_cinit __P((SCR *, EXCMD *, int, int, db_recno_t, db_recno_t, int));
43 ex_cinit(SCR
*sp
, EXCMD
*cmdp
, int cmd_id
, int naddr
, db_recno_t lno1
, db_recno_t lno2
, int force
)
45 memset(cmdp
, 0, sizeof(EXCMD
));
46 cmdp
->cmd
= &cmds
[cmd_id
];
47 cmdp
->addrcnt
= naddr
;
48 cmdp
->addr1
.lno
= lno1
;
49 cmdp
->addr2
.lno
= lno2
;
50 cmdp
->addr1
.cno
= cmdp
->addr2
.cno
= 1;
52 cmdp
->iflags
|= E_C_FORCE
;
53 (void)argv_init(sp
, cmdp
);
58 * Return a line from the file.
60 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
63 ex_getline(SCR
*sp
, FILE *fp
, size_t *lenp
)
71 for (errno
= 0, off
= 0, p
= exp
->ibp
;;) {
72 if (off
>= exp
->ibp_len
) {
73 BINC_RETC(sp
, exp
->ibp
, exp
->ibp_len
, off
+ 1);
76 if ((ch
= getc(fp
)) == EOF
&& !feof(fp
)) {
84 if (ch
== EOF
|| ch
== '\n') {
85 if (ch
== EOF
&& !off
)
98 * Check for more files to edit.
100 * PUBLIC: int ex_ncheck __P((SCR *, int));
103 ex_ncheck(SCR
*sp
, int force
)
109 * Historic practice: quit! or two quit's done in succession
110 * (where ZZ counts as a quit) didn't check for other files.
112 if (!force
&& sp
->ccnt
!= sp
->q_ccnt
+ 1 &&
113 sp
->cargv
!= NULL
&& sp
->cargv
[1] != NULL
) {
114 sp
->q_ccnt
= sp
->ccnt
;
116 for (ap
= sp
->cargv
+ 1; *ap
!= NULL
; ++ap
);
118 "167|%zd more files to edit", (ap
- sp
->cargv
) - 1);
127 * Init the screen for ex.
129 * PUBLIC: int ex_init __P((SCR *));
138 if (gp
->scr_screen(sp
, SC_EX
))
140 (void)gp
->scr_attr(sp
, SA_ALTERNATE
, 0);
142 sp
->rows
= O_VAL(sp
, O_LINES
);
143 sp
->cols
= O_VAL(sp
, O_COLUMNS
);
146 F_SET(sp
, SC_EX
| SC_SCR_EX
);
152 * Display a few common ex and vi error messages.
154 * PUBLIC: void ex_wemsg __P((SCR *, const CHAR_T *, exm_t));
157 ex_wemsg(SCR
* sp
, const CHAR_T
*p
, exm_t which
)
162 if (p
) INT2CHAR(sp
, p
, STRLEN(p
), np
, nlen
);
164 ex_emsg(sp
, np
, which
);
169 * Display a few common ex and vi error messages.
171 * PUBLIC: void ex_emsg __P((SCR *, const char *, exm_t));
174 ex_emsg(SCR
*sp
, const char *p
, exm_t which
)
178 msgq(sp
, M_ERR
, "168|Buffer %s is empty", p
);
181 msgq_str(sp
, M_ERR
, p
,
182 "144|%s: expanded into too many file names");
186 "Command failed, buffer is locked");
190 "283|The %s command requires the ex terminal interface", p
);
194 "272|That form of %s requires the ex terminal interface",
200 "274|Command failed, no file read in yet.");
203 "173|The %s command requires that a file have already been read in", p
);
206 msgq(sp
, M_ERR
, "171|No previous buffer to execute");
209 msgq(sp
, M_ERR
, "172|No previous regular expression");
212 msgq(sp
, M_ERR
, "230|This screen may not be suspended");
216 "290|The %s command is not supported when the secure edit option is set", p
);
220 "284|That form of %s is not supported when the secure edit option is set", p
);
223 msgq(sp
, M_ERR
, "174|Usage: %s", p
);