rework ARGS structures as part of ex parser rework
[nvi.git] / ex / ex_util.c
blobf30081cc83849beb2eaec8a4348f2460c2434997
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.3 1993/11/13 18:02:32 bostic Exp $ (Berkeley) $Date: 1993/11/13 18:02:32 $";
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(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 */