the script used to extract a release
[nvi.git] / vi / v_util.c
blob3372f28b99d6c4e4aafe11f6f2a53766100acbf2
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.13 2000/07/14 14:29:25 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:25 $";
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(sp, mp)
39 SCR *sp;
40 MARK *mp;
42 db_recno_t lno;
44 if (mp == NULL)
45 v_emsg(sp, NULL, VIM_EOF);
46 else {
47 if (db_last(sp, &lno))
48 return;
49 if (mp->lno >= lno)
50 v_emsg(sp, NULL, VIM_EOF);
51 else
52 msgq(sp, M_BERR, "195|Movement past the end-of-file");
57 * v_eol --
58 * Vi end-of-line error.
60 * PUBLIC: void v_eol __P((SCR *, MARK *));
62 void
63 v_eol(sp, mp)
64 SCR *sp;
65 MARK *mp;
67 size_t len;
69 if (mp == NULL)
70 v_emsg(sp, NULL, VIM_EOL);
71 else {
72 if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
73 return;
74 if (mp->cno == len - 1)
75 v_emsg(sp, NULL, VIM_EOL);
76 else
77 msgq(sp, M_BERR, "196|Movement past the end-of-line");
82 * v_nomove --
83 * Vi no cursor movement error.
85 * PUBLIC: void v_nomove __P((SCR *));
87 void
88 v_nomove(sp)
89 SCR *sp;
91 msgq(sp, M_BERR, "197|No cursor movement made");
95 * v_sof --
96 * Vi start-of-file error.
98 * PUBLIC: void v_sof __P((SCR *, MARK *));
100 void
101 v_sof(sp, mp)
102 SCR *sp;
103 MARK *mp;
105 if (mp == NULL || mp->lno == 1)
106 msgq(sp, M_BERR, "198|Already at the beginning of the file");
107 else
108 msgq(sp, M_BERR, "199|Movement past the beginning of the file");
112 * v_sol --
113 * Vi start-of-line error.
115 * PUBLIC: void v_sol __P((SCR *));
117 void
118 v_sol(sp)
119 SCR *sp;
121 msgq(sp, M_BERR, "200|Already in the first column");
125 * v_isempty --
126 * Return if the line contains nothing but white-space characters.
128 * PUBLIC: int v_isempty __P((CHAR_T *, size_t));
131 v_isempty(p, len)
132 CHAR_T *p;
133 size_t len;
135 for (; len--; ++p)
136 if (!isblank(*p))
137 return (0);
138 return (1);
142 * v_emsg --
143 * Display a few common vi messages.
145 * PUBLIC: void v_emsg __P((SCR *, char *, vim_t));
147 void
148 v_emsg(sp, p, which)
149 SCR *sp;
150 char *p;
151 vim_t which;
153 switch (which) {
154 case VIM_COMBUF:
155 msgq(sp, M_ERR,
156 "201|Buffers should be specified before the command");
157 break;
158 case VIM_EMPTY:
159 msgq(sp, M_BERR, "209|The file is empty");
160 break;
161 case VIM_EOF:
162 msgq(sp, M_BERR, "202|Already at end-of-file");
163 break;
164 case VIM_EOL:
165 msgq(sp, M_BERR, "203|Already at end-of-line");
166 break;
167 case VIM_NOCOM:
168 case VIM_NOCOM_B:
169 msgq(sp,
170 which == VIM_NOCOM_B ? M_BERR : M_ERR,
171 "204|%s isn't a vi command", p);
172 break;
173 case VIM_WRESIZE:
174 msgq(sp, M_ERR, "Window resize interrupted text input mode");
175 break;
176 case VIM_USAGE:
177 msgq(sp, M_ERR, "205|Usage: %s", p);
178 break;