1b8ba871bSPeter Wemm /*-
2b8ba871bSPeter Wemm * Copyright (c) 1992, 1993, 1994
3b8ba871bSPeter Wemm * The Regents of the University of California. All rights reserved.
4b8ba871bSPeter Wemm * Copyright (c) 1992, 1993, 1994, 1995, 1996
5b8ba871bSPeter Wemm * Keith Bostic. All rights reserved.
6b8ba871bSPeter Wemm *
7b8ba871bSPeter Wemm * See the LICENSE file for redistribution information.
8b8ba871bSPeter Wemm */
9b8ba871bSPeter Wemm
10b8ba871bSPeter Wemm #include "config.h"
11b8ba871bSPeter Wemm
12b8ba871bSPeter Wemm #include <sys/types.h>
13b8ba871bSPeter Wemm #include <sys/queue.h>
14b8ba871bSPeter Wemm #include <sys/time.h>
15b8ba871bSPeter Wemm
16b8ba871bSPeter Wemm #include <bitstring.h>
17b8ba871bSPeter Wemm #include <ctype.h>
18b8ba871bSPeter Wemm #include <limits.h>
19b8ba871bSPeter Wemm #include <stdio.h>
20b8ba871bSPeter Wemm #include <stdlib.h>
21b8ba871bSPeter Wemm #include <string.h>
22b8ba871bSPeter Wemm #include <unistd.h>
23b8ba871bSPeter Wemm
24b8ba871bSPeter Wemm #include "../common/common.h"
25b8ba871bSPeter Wemm #include "vi.h"
26b8ba871bSPeter Wemm
27b8ba871bSPeter Wemm /*
28b8ba871bSPeter Wemm * v_eof --
29b8ba871bSPeter Wemm * Vi end-of-file error.
30b8ba871bSPeter Wemm *
31*c271fa92SBaptiste Daroussin * PUBLIC: void v_eof(SCR *, MARK *);
32b8ba871bSPeter Wemm */
33b8ba871bSPeter Wemm void
v_eof(SCR * sp,MARK * mp)34f0957ccaSPeter Wemm v_eof(SCR *sp, MARK *mp)
35b8ba871bSPeter Wemm {
36b8ba871bSPeter Wemm recno_t lno;
37b8ba871bSPeter Wemm
38b8ba871bSPeter Wemm if (mp == NULL)
39b8ba871bSPeter Wemm v_emsg(sp, NULL, VIM_EOF);
40b8ba871bSPeter Wemm else {
41b8ba871bSPeter Wemm if (db_last(sp, &lno))
42b8ba871bSPeter Wemm return;
43b8ba871bSPeter Wemm if (mp->lno >= lno)
44b8ba871bSPeter Wemm v_emsg(sp, NULL, VIM_EOF);
45b8ba871bSPeter Wemm else
46b8ba871bSPeter Wemm msgq(sp, M_BERR, "195|Movement past the end-of-file");
47b8ba871bSPeter Wemm }
48b8ba871bSPeter Wemm }
49b8ba871bSPeter Wemm
50b8ba871bSPeter Wemm /*
51b8ba871bSPeter Wemm * v_eol --
52b8ba871bSPeter Wemm * Vi end-of-line error.
53b8ba871bSPeter Wemm *
54*c271fa92SBaptiste Daroussin * PUBLIC: void v_eol(SCR *, MARK *);
55b8ba871bSPeter Wemm */
56b8ba871bSPeter Wemm void
v_eol(SCR * sp,MARK * mp)57f0957ccaSPeter Wemm v_eol(SCR *sp, MARK *mp)
58b8ba871bSPeter Wemm {
59b8ba871bSPeter Wemm size_t len;
60b8ba871bSPeter Wemm
61b8ba871bSPeter Wemm if (mp == NULL)
62b8ba871bSPeter Wemm v_emsg(sp, NULL, VIM_EOL);
63b8ba871bSPeter Wemm else {
64b8ba871bSPeter Wemm if (db_get(sp, mp->lno, DBG_FATAL, NULL, &len))
65b8ba871bSPeter Wemm return;
66b8ba871bSPeter Wemm if (mp->cno == len - 1)
67b8ba871bSPeter Wemm v_emsg(sp, NULL, VIM_EOL);
68b8ba871bSPeter Wemm else
69b8ba871bSPeter Wemm msgq(sp, M_BERR, "196|Movement past the end-of-line");
70b8ba871bSPeter Wemm }
71b8ba871bSPeter Wemm }
72b8ba871bSPeter Wemm
73b8ba871bSPeter Wemm /*
74b8ba871bSPeter Wemm * v_nomove --
75b8ba871bSPeter Wemm * Vi no cursor movement error.
76b8ba871bSPeter Wemm *
77*c271fa92SBaptiste Daroussin * PUBLIC: void v_nomove(SCR *);
78b8ba871bSPeter Wemm */
79b8ba871bSPeter Wemm void
v_nomove(SCR * sp)80f0957ccaSPeter Wemm v_nomove(SCR *sp)
81b8ba871bSPeter Wemm {
82b8ba871bSPeter Wemm msgq(sp, M_BERR, "197|No cursor movement made");
83b8ba871bSPeter Wemm }
84b8ba871bSPeter Wemm
85b8ba871bSPeter Wemm /*
86b8ba871bSPeter Wemm * v_sof --
87b8ba871bSPeter Wemm * Vi start-of-file error.
88b8ba871bSPeter Wemm *
89*c271fa92SBaptiste Daroussin * PUBLIC: void v_sof(SCR *, MARK *);
90b8ba871bSPeter Wemm */
91b8ba871bSPeter Wemm void
v_sof(SCR * sp,MARK * mp)92f0957ccaSPeter Wemm v_sof(SCR *sp, MARK *mp)
93b8ba871bSPeter Wemm {
94b8ba871bSPeter Wemm if (mp == NULL || mp->lno == 1)
95b8ba871bSPeter Wemm msgq(sp, M_BERR, "198|Already at the beginning of the file");
96b8ba871bSPeter Wemm else
97b8ba871bSPeter Wemm msgq(sp, M_BERR, "199|Movement past the beginning of the file");
98b8ba871bSPeter Wemm }
99b8ba871bSPeter Wemm
100b8ba871bSPeter Wemm /*
101b8ba871bSPeter Wemm * v_sol --
102b8ba871bSPeter Wemm * Vi start-of-line error.
103b8ba871bSPeter Wemm *
104*c271fa92SBaptiste Daroussin * PUBLIC: void v_sol(SCR *);
105b8ba871bSPeter Wemm */
106b8ba871bSPeter Wemm void
v_sol(SCR * sp)107f0957ccaSPeter Wemm v_sol(SCR *sp)
108b8ba871bSPeter Wemm {
109b8ba871bSPeter Wemm msgq(sp, M_BERR, "200|Already in the first column");
110b8ba871bSPeter Wemm }
111b8ba871bSPeter Wemm
112b8ba871bSPeter Wemm /*
113b8ba871bSPeter Wemm * v_isempty --
114b8ba871bSPeter Wemm * Return if the line contains nothing but white-space characters.
115b8ba871bSPeter Wemm *
116*c271fa92SBaptiste Daroussin * PUBLIC: int v_isempty(CHAR_T *, size_t);
117b8ba871bSPeter Wemm */
118b8ba871bSPeter Wemm int
v_isempty(CHAR_T * p,size_t len)119f0957ccaSPeter Wemm v_isempty(CHAR_T *p, size_t len)
120b8ba871bSPeter Wemm {
121b8ba871bSPeter Wemm for (; len--; ++p)
122b8ba871bSPeter Wemm if (!isblank(*p))
123b8ba871bSPeter Wemm return (0);
124b8ba871bSPeter Wemm return (1);
125b8ba871bSPeter Wemm }
126b8ba871bSPeter Wemm
127b8ba871bSPeter Wemm /*
128b8ba871bSPeter Wemm * v_emsg --
129b8ba871bSPeter Wemm * Display a few common vi messages.
130b8ba871bSPeter Wemm *
131*c271fa92SBaptiste Daroussin * PUBLIC: void v_emsg(SCR *, char *, vim_t);
132b8ba871bSPeter Wemm */
133b8ba871bSPeter Wemm void
v_emsg(SCR * sp,char * p,vim_t which)134f0957ccaSPeter Wemm v_emsg(SCR *sp, char *p, vim_t which)
135b8ba871bSPeter Wemm {
136b8ba871bSPeter Wemm switch (which) {
137b8ba871bSPeter Wemm case VIM_COMBUF:
138b8ba871bSPeter Wemm msgq(sp, M_ERR,
139b8ba871bSPeter Wemm "201|Buffers should be specified before the command");
140b8ba871bSPeter Wemm break;
141b8ba871bSPeter Wemm case VIM_EMPTY:
142b8ba871bSPeter Wemm msgq(sp, M_BERR, "209|The file is empty");
143b8ba871bSPeter Wemm break;
144b8ba871bSPeter Wemm case VIM_EOF:
145b8ba871bSPeter Wemm msgq(sp, M_BERR, "202|Already at end-of-file");
146b8ba871bSPeter Wemm break;
147b8ba871bSPeter Wemm case VIM_EOL:
148b8ba871bSPeter Wemm msgq(sp, M_BERR, "203|Already at end-of-line");
149b8ba871bSPeter Wemm break;
150b8ba871bSPeter Wemm case VIM_NOCOM:
151b8ba871bSPeter Wemm case VIM_NOCOM_B:
152b8ba871bSPeter Wemm msgq(sp,
153b8ba871bSPeter Wemm which == VIM_NOCOM_B ? M_BERR : M_ERR,
154b8ba871bSPeter Wemm "204|%s isn't a vi command", p);
155b8ba871bSPeter Wemm break;
156b8ba871bSPeter Wemm case VIM_WRESIZE:
157b8ba871bSPeter Wemm msgq(sp, M_ERR, "Window resize interrupted text input mode");
158b8ba871bSPeter Wemm break;
159b8ba871bSPeter Wemm case VIM_USAGE:
160b8ba871bSPeter Wemm msgq(sp, M_ERR, "205|Usage: %s", p);
161b8ba871bSPeter Wemm break;
162b8ba871bSPeter Wemm }
163b8ba871bSPeter Wemm }
164