rework initial error handling -- since we check for any screens on
[nvi.git] / vi / v_util.c
blob5521d04dcacf7f79ae5327a5646f411608c110d9
1 /*-
2 * Copyright (c) 1992, 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: v_util.c,v 8.5 1993/11/15 09:15:36 bostic Exp $ (Berkeley) $Date: 1993/11/15 09:15:36 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <ctype.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
19 #include "vi.h"
20 #include "vcmd.h"
23 * v_eof --
24 * Vi end-of-file error.
26 void
27 v_eof(sp, ep, mp)
28 SCR *sp;
29 EXF *ep;
30 MARK *mp;
32 u_long lno;
34 if (mp == NULL)
35 msgq(sp, M_BERR, "Already at end-of-file.");
36 else {
37 if (file_lline(sp, ep, &lno))
38 return;
39 if (mp->lno >= lno)
40 msgq(sp, M_BERR, "Already at end-of-file.");
41 else
42 msgq(sp, M_BERR,
43 "Movement past the end-of-file.");
48 * v_eol --
49 * Vi end-of-line error.
51 void
52 v_eol(sp, ep, mp)
53 SCR *sp;
54 EXF *ep;
55 MARK *mp;
57 size_t len;
59 if (mp == NULL)
60 msgq(sp, M_BERR, "Already at end-of-line.");
61 else {
62 if (file_gline(sp, ep, mp->lno, &len) == NULL) {
63 GETLINE_ERR(sp, mp->lno);
64 return;
66 if (mp->cno == len - 1)
67 msgq(sp, M_BERR, "Already at end-of-line.");
68 else
69 msgq(sp, M_BERR, "Movement past the end-of-line.");
74 * v_sof --
75 * Vi start-of-file error.
77 void
78 v_sof(sp, mp)
79 SCR *sp;
80 MARK *mp;
82 if (mp == NULL || mp->lno == 1)
83 msgq(sp, M_BERR, "Already at the beginning of the file.");
84 else
85 msgq(sp, M_BERR, "Movement past the beginning of the file.");
89 * v_isempty --
90 * Return if the line contains nothing but white-space characters.
92 int
93 v_isempty(p, len)
94 char *p;
95 size_t len;
97 for (; len--; ++p)
98 if (!isblank(*p))
99 return (0);
100 return (1);