Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / vi / v_util.c
blobbe0750339b27eaf6423b1fd95c24b99a1fa7a65e
1 /* $NetBSD: v_util.c,v 1.1.1.2 2008/05/18 14:31:47 aymeric Exp $ */
3 /*-
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
14 #ifndef lint
15 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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/time.h>
22 #include <bitstring.h>
23 #include <ctype.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
30 #include "../common/common.h"
31 #include "vi.h"
34 * v_eof --
35 * Vi end-of-file error.
37 * PUBLIC: void v_eof __P((SCR *, MARK *));
39 void
40 v_eof(SCR *sp, 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(SCR *sp, MARK *mp)
65 size_t len;
67 if (mp == NULL)
68 v_emsg(sp, NULL, VIM_EOL);
69 else {
70 if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
71 return;
72 if (mp->cno == len - 1)
73 v_emsg(sp, NULL, VIM_EOL);
74 else
75 msgq(sp, M_BERR, "196|Movement past the end-of-line");
80 * v_nomove --
81 * Vi no cursor movement error.
83 * PUBLIC: void v_nomove __P((SCR *));
85 void
86 v_nomove(SCR *sp)
88 msgq(sp, M_BERR, "197|No cursor movement made");
92 * v_sof --
93 * Vi start-of-file error.
95 * PUBLIC: void v_sof __P((SCR *, MARK *));
97 void
98 v_sof(SCR *sp, MARK *mp)
100 if (mp == NULL || mp->lno == 1)
101 msgq(sp, M_BERR, "198|Already at the beginning of the file");
102 else
103 msgq(sp, M_BERR, "199|Movement past the beginning of the file");
107 * v_sol --
108 * Vi start-of-line error.
110 * PUBLIC: void v_sol __P((SCR *));
112 void
113 v_sol(SCR *sp)
115 msgq(sp, M_BERR, "200|Already in the first column");
119 * v_isempty --
120 * Return if the line contains nothing but white-space characters.
122 * PUBLIC: int v_isempty __P((CHAR_T *, size_t));
125 v_isempty(CHAR_T *p, size_t len)
127 for (; len--; ++p)
128 if (!isblank(*p))
129 return (0);
130 return (1);
134 * v_emsg --
135 * Display a few common vi messages.
137 * PUBLIC: void v_emsg __P((SCR *, const char *, vim_t));
139 void
140 v_emsg(SCR *sp, const char *p, vim_t which)
142 switch (which) {
143 case VIM_COMBUF:
144 msgq(sp, M_ERR,
145 "201|Buffers should be specified before the command");
146 break;
147 case VIM_EMPTY:
148 msgq(sp, M_BERR, "209|The file is empty");
149 break;
150 case VIM_EOF:
151 msgq(sp, M_BERR, "202|Already at end-of-file");
152 break;
153 case VIM_EOL:
154 msgq(sp, M_BERR, "203|Already at end-of-line");
155 break;
156 case VIM_NOCOM:
157 case VIM_NOCOM_B:
158 msgq(sp,
159 which == VIM_NOCOM_B ? M_BERR : M_ERR,
160 "204|%s isn't a vi command", p);
161 break;
162 case VIM_WRESIZE:
163 msgq(sp, M_ERR, "Window resize interrupted text input mode");
164 break;
165 case VIM_USAGE:
166 msgq(sp, M_ERR, "205|Usage: %s", p);
167 break;