use ISBLANK to test whether CHAR_T represents a blank
[nvi.git] / vi / v_util.c
blob8445e2a0112b6d4502d562f2a70da61ac47695a9
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: v_util.c,v 10.14 2001/06/25 15:19:36 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:36 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
28 #include "../common/common.h"
29 #include "vi.h"
32 * v_eof --
33 * Vi end-of-file error.
35 * PUBLIC: void v_eof __P((SCR *, MARK *));
37 void
38 v_eof(SCR *sp, MARK *mp)
40 db_recno_t lno;
42 if (mp == NULL)
43 v_emsg(sp, NULL, VIM_EOF);
44 else {
45 if (db_last(sp, &lno))
46 return;
47 if (mp->lno >= lno)
48 v_emsg(sp, NULL, VIM_EOF);
49 else
50 msgq(sp, M_BERR, "195|Movement past the end-of-file");
55 * v_eol --
56 * Vi end-of-line error.
58 * PUBLIC: void v_eol __P((SCR *, MARK *));
60 void
61 v_eol(SCR *sp, MARK *mp)
63 size_t len;
65 if (mp == NULL)
66 v_emsg(sp, NULL, VIM_EOL);
67 else {
68 if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
69 return;
70 if (mp->cno == len - 1)
71 v_emsg(sp, NULL, VIM_EOL);
72 else
73 msgq(sp, M_BERR, "196|Movement past the end-of-line");
78 * v_nomove --
79 * Vi no cursor movement error.
81 * PUBLIC: void v_nomove __P((SCR *));
83 void
84 v_nomove(SCR *sp)
86 msgq(sp, M_BERR, "197|No cursor movement made");
90 * v_sof --
91 * Vi start-of-file error.
93 * PUBLIC: void v_sof __P((SCR *, MARK *));
95 void
96 v_sof(SCR *sp, MARK *mp)
98 if (mp == NULL || mp->lno == 1)
99 msgq(sp, M_BERR, "198|Already at the beginning of the file");
100 else
101 msgq(sp, M_BERR, "199|Movement past the beginning of the file");
105 * v_sol --
106 * Vi start-of-line error.
108 * PUBLIC: void v_sol __P((SCR *));
110 void
111 v_sol(SCR *sp)
113 msgq(sp, M_BERR, "200|Already in the first column");
117 * v_isempty --
118 * Return if the line contains nothing but white-space characters.
120 * PUBLIC: int v_isempty __P((CHAR_T *, size_t));
123 v_isempty(CHAR_T *p, size_t len)
125 for (; len--; ++p)
126 if (!ISBLANK(*p))
127 return (0);
128 return (1);
132 * v_emsg --
133 * Display a few common vi messages.
135 * PUBLIC: void v_emsg __P((SCR *, char *, vim_t));
137 void
138 v_emsg(SCR *sp, char *p, vim_t which)
140 switch (which) {
141 case VIM_COMBUF:
142 msgq(sp, M_ERR,
143 "201|Buffers should be specified before the command");
144 break;
145 case VIM_EMPTY:
146 msgq(sp, M_BERR, "209|The file is empty");
147 break;
148 case VIM_EOF:
149 msgq(sp, M_BERR, "202|Already at end-of-file");
150 break;
151 case VIM_EOL:
152 msgq(sp, M_BERR, "203|Already at end-of-line");
153 break;
154 case VIM_NOCOM:
155 case VIM_NOCOM_B:
156 msgq(sp,
157 which == VIM_NOCOM_B ? M_BERR : M_ERR,
158 "204|%s isn't a vi command", p);
159 break;
160 case VIM_WRESIZE:
161 msgq(sp, M_ERR, "Window resize interrupted text input mode");
162 break;
163 case VIM_USAGE:
164 msgq(sp, M_ERR, "205|Usage: %s", p);
165 break;