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.25 1996/12/05 14:20:28 bostic Exp $ (Berkeley) $Date: 1996/12/05 14:20:28 $";
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, recno_t, recno_t, int));
37 ex_cinit(sp
, cmdp
, cmd_id
, naddr
, lno1
, lno2
, force
)
40 int cmd_id
, force
, naddr
;
43 memset(cmdp
, 0, sizeof(EXCMD
));
44 cmdp
->cmd
= &cmds
[cmd_id
];
45 cmdp
->addrcnt
= naddr
;
46 cmdp
->addr1
.lno
= lno1
;
47 cmdp
->addr2
.lno
= lno2
;
48 cmdp
->addr1
.cno
= cmdp
->addr2
.cno
= 1;
50 cmdp
->iflags
|= E_C_FORCE
;
51 (void)argv_init(sp
, cmdp
);
56 * Return a line from the file.
58 * PUBLIC: int ex_getline __P((SCR *, FILE *, size_t *));
61 ex_getline(sp
, fp
, lenp
)
72 for (errno
= 0, off
= 0, p
= exp
->ibp
;;) {
73 if (off
>= exp
->ibp_len
) {
74 BINC_RET(sp
, exp
->ibp
, exp
->ibp_len
, off
+ 1);
77 if ((ch
= getc(fp
)) == EOF
&& !feof(fp
)) {
85 if (ch
== EOF
|| ch
== '\n') {
86 if (ch
== EOF
&& !off
)
99 * Check for more files to edit.
101 * PUBLIC: int ex_ncheck __P((SCR *, int));
112 * Historic practice: quit! or two quit's done in succession
113 * (where ZZ counts as a quit) didn't check for other files.
115 if (!force
&& sp
->ccnt
!= sp
->q_ccnt
+ 1 &&
116 sp
->cargv
!= NULL
&& sp
->cargv
[1] != NULL
) {
117 sp
->q_ccnt
= sp
->ccnt
;
119 for (ap
= sp
->cargv
+ 1; *ap
!= NULL
; ++ap
);
121 "167|%d more files to edit", (ap
- sp
->cargv
) - 1);
130 * Init the screen for ex.
132 * PUBLIC: int ex_init __P((SCR *));
142 if (gp
->scr_screen(sp
, SC_EX
))
144 (void)gp
->scr_attr(sp
, SA_ALTERNATE
, 0);
146 sp
->rows
= O_VAL(sp
, O_LINES
);
147 sp
->cols
= O_VAL(sp
, O_COLUMNS
);
150 F_SET(sp
, SC_EX
| SC_SCR_EX
);
156 * Display a few common ex and vi error messages.
158 * PUBLIC: void ex_emsg __P((SCR *, char *, exm_t));
161 ex_emsg(sp
, p
, 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
);