update to 1.01
[nvi.git] / ex / ex_util.c
blobdf9d9f0f027934cee2b77675cac51bf2960a51f2
1 /*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_util.c,v 8.4 1993/12/09 19:42:50 bostic Exp $ (Berkeley) $Date: 1993/12/09 19:42:50 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vi.h"
19 #include "excmd.h"
22 * ex_getline --
23 * Return a line from the terminal.
25 int
26 ex_getline(sp, fp, lenp)
27 SCR *sp;
28 FILE *fp;
29 size_t *lenp;
31 EX_PRIVATE *exp;
32 size_t off;
33 int ch;
34 char *p;
36 exp = EXP(sp);
37 for (off = 0, p = exp->ibp;; ++off) {
38 ch = getc(fp);
39 if (off >= exp->ibp_len) {
40 BINC_RET(sp, exp->ibp, exp->ibp_len, off + 1);
41 p = exp->ibp + off;
43 if (ch == EOF || ch == '\n') {
44 if (ch == EOF && !off)
45 return (1);
46 *lenp = off;
47 return (0);
49 *p++ = ch;
51 /* NOTREACHED */