1 /* $NetBSD: ex_util.c,v 1.2 2013/11/22 15:52:05 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.
14 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 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
21 #include <bitstring.h>
29 #include "../common/common.h"
33 * Create an EX command structure.
35 * PUBLIC: void ex_cinit __P((SCR *, EXCMD *, int, int, db_recno_t, db_recno_t, int));
38 ex_cinit(SCR
*sp
, EXCMD
*cmdp
, int cmd_id
, int naddr
, db_recno_t lno1
, db_recno_t lno2
, int force
)
40 memset(cmdp
, 0, sizeof(EXCMD
));
41 cmdp
->cmd
= &cmds
[cmd_id
];
42 cmdp
->addrcnt
= naddr
;
43 cmdp
->addr1
.lno
= lno1
;
44 cmdp
->addr2
.lno
= lno2
;
45 cmdp
->addr1
.cno
= cmdp
->addr2
.cno
= 1;
47 cmdp
->iflags
|= E_C_FORCE
;
48 (void)argv_init(sp
, cmdp
);
53 * Return a line from the file.
55 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
58 ex_getline(SCR
*sp
, FILE *fp
, size_t *lenp
)
66 for (errno
= 0, off
= 0, p
= exp
->ibp
;;) {
67 if (off
>= exp
->ibp_len
) {
68 BINC_RETC(sp
, exp
->ibp
, exp
->ibp_len
, off
+ 1);
71 if ((ch
= getc(fp
)) == EOF
&& !feof(fp
)) {
79 if (ch
== EOF
|| ch
== '\n') {
80 if (ch
== EOF
&& !off
)
93 * Check for more files to edit.
95 * PUBLIC: int ex_ncheck __P((SCR *, int));
98 ex_ncheck(SCR
*sp
, int force
)
104 * Historic practice: quit! or two quit's done in succession
105 * (where ZZ counts as a quit) didn't check for other files.
107 if (!force
&& sp
->ccnt
!= sp
->q_ccnt
+ 1 &&
108 sp
->cargv
!= NULL
&& sp
->cargv
[1] != NULL
) {
109 sp
->q_ccnt
= sp
->ccnt
;
111 for (ap
= sp
->cargv
+ 1; *ap
!= NULL
; ++ap
);
113 "167|%zd more files to edit", (ap
- sp
->cargv
) - 1);
122 * Init the screen for ex.
124 * PUBLIC: int ex_init __P((SCR *));
133 if (gp
->scr_screen(sp
, SC_EX
))
135 (void)gp
->scr_attr(sp
, SA_ALTERNATE
, 0);
137 sp
->rows
= O_VAL(sp
, O_LINES
);
138 sp
->cols
= O_VAL(sp
, O_COLUMNS
);
141 F_SET(sp
, SC_EX
| SC_SCR_EX
);
147 * Display a few common ex and vi error messages.
149 * PUBLIC: void ex_wemsg __P((SCR *, const CHAR_T *, exm_t));
152 ex_wemsg(SCR
* sp
, const CHAR_T
*p
, exm_t which
)
157 if (p
) INT2CHAR(sp
, p
, STRLEN(p
), np
, nlen
);
159 ex_emsg(sp
, np
, which
);
164 * Display a few common ex and vi error messages.
166 * PUBLIC: void ex_emsg __P((SCR *, const char *, exm_t));
169 ex_emsg(SCR
*sp
, const char *p
, exm_t which
)
173 msgq(sp
, M_ERR
, "168|Buffer %s is empty", p
);
176 msgq_str(sp
, M_ERR
, p
,
177 "144|%s: expanded into too many file names");
181 "Command failed, buffer is locked");
185 "283|The %s command requires the ex terminal interface", p
);
189 "272|That form of %s requires the ex terminal interface",
195 "274|Command failed, no file read in yet.");
198 "173|The %s command requires that a file have already been read in", p
);
201 msgq(sp
, M_ERR
, "171|No previous buffer to execute");
204 msgq(sp
, M_ERR
, "172|No previous regular expression");
207 msgq(sp
, M_ERR
, "230|This screen may not be suspended");
211 "290|The %s command is not supported when the secure edit option is set", p
);
215 "284|That form of %s is not supported when the secure edit option is set", p
);
218 msgq(sp
, M_ERR
, "174|Usage: %s", p
);