2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: vi.h,v 8.20 1993/11/22 10:01:40 bostic Exp $ (Berkeley) $Date: 1993/11/22 10:01:40 $
10 typedef struct _vikeys VIKEYS
;
12 /* Structure passed around to functions implementing vi commands. */
13 typedef struct _vicmdarg
{
14 #define vp_startzero buffer /* START ZERO OUT. */
15 CHAR_T buffer
; /* Buffer. */
16 CHAR_T character
; /* Character. */
17 u_long count
; /* Count. */
18 u_long count2
; /* Second count (only used by z). */
19 int key
; /* Command key. */
20 VIKEYS
const *kp
; /* VIKEYS structure. */
21 size_t klen
; /* Keyword length. */
24 * Historic vi allowed "dl" when the cursor was on the last column, deleting
25 * the last character, and similarly allowed "dw" when the cursor was on the
26 * last column of the file. It didn't allow "dh" when the cursor was on
27 * column 1, although these cases are not strictly analogous. The point is
28 * that some movements would succeed if they were associated with a motion
29 * command, and fail otherwise. This is part of the off-by-1 schizophrenia
30 * that plagued vi. Other examples are that "dfb" deleted everything up to
31 * and including the next 'b' character, but "d/b" only deleted everything
32 * up to the next 'b' character. While this implementation regularizes the
33 * interface to the extent possible, there are many special cases that can't
34 * be fixed. This is implemented by setting special flags per command so that
35 * the motion routines know what's really going on.
37 * Note, the VC_COMMASK flags are set per command, and therefore must have
38 * values not used the set of flags used by the VIKEYS structure below.
40 #define VC_C 0x0001 /* The 'c' command. */
41 #define VC_D 0x0002 /* The 'd' command. */
42 #define VC_SH 0x0004 /* The '>' command. */
43 #define VC_Y 0x0008 /* The 'y' command. */
44 #define VC_COMMASK 0x000f /* Mask for special flags. */
46 #define VC_BUFFER 0x0010 /* Buffer set. */
47 #define VC_C1SET 0x0020 /* Count 1 set. */
48 #define VC_C1RESET 0x0040 /* Reset the C1SET flag for dot commands. */
49 #define VC_C2SET 0x0080 /* Count 2 set. */
50 #define VC_LMODE 0x0100 /* Motion is line oriented. */
51 #define VC_ISDOT 0x0200 /* Command was the dot command. */
55 #define vp_endzero keyword /* END ZERO OUT. */
56 char *keyword
; /* Keyword. */
57 size_t kbuflen
; /* Keyword buffer length. */
60 /* Vi command structure. */
61 struct _vikeys
{ /* Underlying function. */
62 int (*func
) __P((SCR
*, EXF
*, VICMDARG
*, MARK
*, MARK
*, MARK
*));
64 #define V_DONTUSE1 0x000001 /* VC_C */
65 #define V_DONTUSE2 0x000002 /* VC_D */
66 #define V_DONTUSE3 0x000004 /* VC_SH */
67 #define V_DONTUSE4 0x000008 /* VC_Y */
68 #define V_ABS 0x000010 /* Absolute movement, set '' mark. */
69 #define V_CHAR 0x000020 /* Character (required, trailing). */
70 #define V_CNT 0x000040 /* Count (optional, leading). */
71 #define V_DOT 0x000080 /* On success, sets dot command. */
72 #define V_KEYNUM 0x000100 /* Cursor referenced number. */
73 #define V_KEYW 0x000200 /* Cursor referenced word. */
74 #define V_LMODE 0x000400 /* Motion is line oriented. */
75 #define V_MOTION 0x000800 /* Motion (required, trailing). */
76 #define V_MOVE 0x001000 /* Command defines movement. */
77 #define V_OBUF 0x002000 /* Buffer (optional, leading). */
78 #define V_RBUF 0x004000 /* Buffer (required, trailing). */
79 #define V_RCM 0x008000 /* Use relative cursor movment (RCM). */
80 #define V_RCM_SET 0x010000 /* RCM: set to current position. */
81 #define V_RCM_SETFNB 0x020000 /* RCM: set to first non-blank (FNB). */
82 #define V_RCM_SETLAST 0x040000 /* RCM: set to last character. */
83 #define V_RCM_SETLFNB 0x080000 /* RCM: set to FNB if line moved. */
84 #define V_RCM_SETNNB 0x100000 /* RCM: set to next non-blank. */
86 char *usage
; /* Usage line. */
87 char *help
; /* Help line. */
89 #define MAXVIKEY 126 /* List of vi commands. */
90 extern VIKEYS
const vikeys
[MAXVIKEY
+ 1];
92 /* Definition of a "word". */
93 #define inword(ch) (isalnum(ch) || (ch) == '_')
95 /* Character stream structure, prototypes. */
97 recno_t cs_lno
; /* Line. */
98 size_t cs_cno
; /* Column. */
99 char *cs_bp
; /* Buffer. */
100 size_t cs_len
; /* Length. */
101 int cs_ch
; /* Character. */
102 #define CS_EMP 1 /* Empty line. */
103 #define CS_EOF 2 /* End-of-file. */
104 #define CS_EOL 3 /* End-of-line. */
105 #define CS_SOF 4 /* Start-of-file. */
106 int cs_flags
; /* Return flags. */
109 int cs_bblank
__P((SCR
*, EXF
*, VCS
*));
110 int cs_fblank
__P((SCR
*, EXF
*, VCS
*));
111 int cs_fspace
__P((SCR
*, EXF
*, VCS
*));
112 int cs_init
__P((SCR
*, EXF
*, VCS
*));
113 int cs_next
__P((SCR
*, EXF
*, VCS
*));
114 int cs_prev
__P((SCR
*, EXF
*, VCS
*));
116 /* Vi private, per-screen memory. */
117 typedef struct _vi_private
{
118 VICMDARG sdot
; /* Saved dot, motion command. */
121 CHAR_T rlast
; /* Last 'r' command character. */
123 char *rep
; /* Input replay buffer. */
124 size_t rep_len
; /* Input replay buffer length. */
125 size_t rep_cnt
; /* Input replay buffer characters. */
127 CHAR_T inc_lastch
; /* Last increment character. */
128 long inc_lastval
; /* Last increment value. */
130 char *paragraph
; /* Paragraph search list. */
131 size_t paragraph_len
; /* Paragraph search list length. */
134 #define VIP(sp) ((VI_PRIVATE *)((sp)->vi_private))
136 /* Vi function prototypes. */
137 int txt_auto
__P((SCR
*, EXF
*, recno_t
, TEXT
*, size_t, TEXT
*));
138 int v_buildparagraph
__P((SCR
*));
139 int v_comment
__P((SCR
*, EXF
*));
140 int v_end
__P((SCR
*));
141 void v_eof
__P((SCR
*, EXF
*, MARK
*));
142 void v_eol
__P((SCR
*, EXF
*, MARK
*));
143 int v_exwrite
__P((void *, const char *, int));
144 int v_init
__P((SCR
*, EXF
*));
145 int v_isempty
__P((char *, size_t));
146 int v_msgflush
__P((SCR
*));
147 int v_ntext
__P((SCR
*, EXF
*, TEXTH
*, MARK
*,
148 const char *, const size_t, MARK
*, int, recno_t
, u_int
));
149 int v_optchange
__P((SCR
*, int));
150 int v_screen_copy
__P((SCR
*, SCR
*));
151 int v_screen_end
__P((SCR
*));
152 void v_sof
__P((SCR
*, MARK
*));
153 int vi
__P((SCR
*, EXF
*));
155 #define VIPROTO(type, name) \
156 type name __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, MARK *))
158 VIPROTO(int, v_again
);
160 VIPROTO(int, v_bottom
);
161 VIPROTO(int, v_cfirst
);
162 VIPROTO(int, v_Change
);
163 VIPROTO(int, v_change
);
166 VIPROTO(int, v_chrepeat
);
167 VIPROTO(int, v_chrrepeat
);
171 VIPROTO(int, v_Delete
);
172 VIPROTO(int, v_delete
);
173 VIPROTO(int, v_dollar
);
174 VIPROTO(int, v_down
);
176 VIPROTO(int, v_exit
);
177 VIPROTO(int, v_exmode
);
178 VIPROTO(int, v_filter
);
179 VIPROTO(int, v_first
);
180 VIPROTO(int, v_gomark
);
181 VIPROTO(int, v_home
);
182 VIPROTO(int, v_hpagedown
);
183 VIPROTO(int, v_hpageup
);
188 VIPROTO(int, v_increment
);
191 VIPROTO(int, v_join
);
192 VIPROTO(int, v_left
);
193 VIPROTO(int, v_lgoto
);
194 VIPROTO(int, v_linedown
);
195 VIPROTO(int, v_lineup
);
196 VIPROTO(int, v_mark
);
197 VIPROTO(int, v_match
);
198 VIPROTO(int, v_middle
);
199 VIPROTO(int, v_ncol
);
200 VIPROTO(int, v_pagedown
);
201 VIPROTO(int, v_pageup
);
202 VIPROTO(int, v_paragraphb
);
203 VIPROTO(int, v_paragraphf
);
206 VIPROTO(int, v_redraw
);
207 VIPROTO(int, v_Replace
);
208 VIPROTO(int, v_replace
);
209 VIPROTO(int, v_right
);
210 VIPROTO(int, v_screen
);
211 VIPROTO(int, v_searchb
);
212 VIPROTO(int, v_searchf
);
213 VIPROTO(int, v_searchN
);
214 VIPROTO(int, v_searchn
);
215 VIPROTO(int, v_searchw
);
216 VIPROTO(int, v_sectionb
);
217 VIPROTO(int, v_sectionf
);
218 VIPROTO(int, v_sentenceb
);
219 VIPROTO(int, v_sentencef
);
220 VIPROTO(int, v_shiftl
);
221 VIPROTO(int, v_shiftr
);
222 VIPROTO(int, v_status
);
223 VIPROTO(int, v_stop
);
224 VIPROTO(int, v_Subst
);
225 VIPROTO(int, v_subst
);
226 VIPROTO(int, v_switch
);
227 VIPROTO(int, v_tagpop
);
228 VIPROTO(int, v_tagpush
);
229 VIPROTO(int, v_ulcase
);
230 VIPROTO(int, v_Undo
);
231 VIPROTO(int, v_undo
);
233 VIPROTO(int, v_wordB
);
234 VIPROTO(int, v_wordb
);
235 VIPROTO(int, v_wordE
);
236 VIPROTO(int, v_worde
);
237 VIPROTO(int, v_wordW
);
238 VIPROTO(int, v_wordw
);
239 VIPROTO(int, v_Xchar
);
240 VIPROTO(int, v_xchar
);
241 VIPROTO(int, v_Yank
);
242 VIPROTO(int, v_yank
);
244 VIPROTO(int, v_zero
);