tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_util.c
blob13eb586043963db448a769a84d10788d72728b97
1 /* $NetBSD: v_util.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
2 /*-
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #ifndef lint
14 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 ";
15 #endif /* not lint */
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
21 #include <bitstring.h>
22 #include <ctype.h>
23 #include <limits.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
29 #include "../common/common.h"
30 #include "vi.h"
33 * v_eof --
34 * Vi end-of-file error.
36 * PUBLIC: void v_eof __P((SCR *, MARK *));
38 void
39 v_eof(SCR *sp, MARK *mp)
41 db_recno_t lno;
43 if (mp == NULL)
44 v_emsg(sp, NULL, VIM_EOF);
45 else {
46 if (db_last(sp, &lno))
47 return;
48 if (mp->lno >= lno)
49 v_emsg(sp, NULL, VIM_EOF);
50 else
51 msgq(sp, M_BERR, "195|Movement past the end-of-file");
56 * v_eol --
57 * Vi end-of-line error.
59 * PUBLIC: void v_eol __P((SCR *, MARK *));
61 void
62 v_eol(SCR *sp, MARK *mp)
64 size_t len;
66 if (mp == NULL)
67 v_emsg(sp, NULL, VIM_EOL);
68 else {
69 if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
70 return;
71 if (mp->cno == len - 1)
72 v_emsg(sp, NULL, VIM_EOL);
73 else
74 msgq(sp, M_BERR, "196|Movement past the end-of-line");
79 * v_nomove --
80 * Vi no cursor movement error.
82 * PUBLIC: void v_nomove __P((SCR *));
84 void
85 v_nomove(SCR *sp)
87 msgq(sp, M_BERR, "197|No cursor movement made");
91 * v_sof --
92 * Vi start-of-file error.
94 * PUBLIC: void v_sof __P((SCR *, MARK *));
96 void
97 v_sof(SCR *sp, MARK *mp)
99 if (mp == NULL || mp->lno == 1)
100 msgq(sp, M_BERR, "198|Already at the beginning of the file");
101 else
102 msgq(sp, M_BERR, "199|Movement past the beginning of the file");
106 * v_sol --
107 * Vi start-of-line error.
109 * PUBLIC: void v_sol __P((SCR *));
111 void
112 v_sol(SCR *sp)
114 msgq(sp, M_BERR, "200|Already in the first column");
118 * v_isempty --
119 * Return if the line contains nothing but white-space characters.
121 * PUBLIC: int v_isempty __P((CHAR_T *, size_t));
124 v_isempty(CHAR_T *p, size_t len)
126 for (; len--; ++p)
127 if (!ISBLANK((UCHAR_T)*p))
128 return (0);
129 return (1);
133 * v_emsg --
134 * Display a few common vi messages.
136 * PUBLIC: void v_emsg __P((SCR *, const char *, vim_t));
138 void
139 v_emsg(SCR *sp, const char *p, vim_t which)
141 switch (which) {
142 case VIM_COMBUF:
143 msgq(sp, M_ERR,
144 "201|Buffers should be specified before the command");
145 break;
146 case VIM_EMPTY:
147 msgq(sp, M_BERR, "209|The file is empty");
148 break;
149 case VIM_EOF:
150 msgq(sp, M_BERR, "202|Already at end-of-file");
151 break;
152 case VIM_EOL:
153 msgq(sp, M_BERR, "203|Already at end-of-line");
154 break;
155 case VIM_NOCOM:
156 case VIM_NOCOM_B:
157 msgq(sp,
158 which == VIM_NOCOM_B ? M_BERR : M_ERR,
159 "204|%s isn't a vi command", p);
160 break;
161 case VIM_WRESIZE:
162 msgq(sp, M_ERR, "Window resize interrupted text input mode");
163 break;
164 case VIM_USAGE:
165 msgq(sp, M_ERR, "205|Usage: %s", p);
166 break;