Undo command now needs a last executed count
[nvi.git] / vi / vi.h
blobeb668afc1316806e063ef7412ea7ec4ce19c267f
1 /*-
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.22 1994/01/08 13:54:29 bostic Exp $ (Berkeley) $Date: 1994/01/08 13:54:29 $
8 */
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. */
53 u_int flags;
55 #define vp_endzero keyword /* END ZERO OUT. */
56 char *keyword; /* Keyword. */
57 size_t kbuflen; /* Keyword buffer length. */
58 } VICMDARG;
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. */
85 u_long flags;
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. */
96 typedef struct _vcs {
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. */
107 } VCS;
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. */
119 VICMDARG sdotmotion;
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. */
133 u_long u_ccnt; /* Undo command count. */
134 } VI_PRIVATE;
136 #define VIP(sp) ((VI_PRIVATE *)((sp)->vi_private))
138 /* Vi function prototypes. */
139 int txt_auto __P((SCR *, EXF *, recno_t, TEXT *, size_t, TEXT *));
140 int v_buildparagraph __P((SCR *));
141 int v_end __P((SCR *));
142 void v_eof __P((SCR *, EXF *, MARK *));
143 void v_eol __P((SCR *, EXF *, MARK *));
144 int v_exwrite __P((void *, const char *, int));
145 int v_init __P((SCR *, EXF *));
146 int v_isempty __P((char *, size_t));
147 int v_msgflush __P((SCR *));
148 int v_ntext __P((SCR *, EXF *, TEXTH *, MARK *,
149 const char *, const size_t, MARK *, int, recno_t, u_int));
150 int v_optchange __P((SCR *, int));
151 int v_screen_copy __P((SCR *, SCR *));
152 int v_screen_end __P((SCR *));
153 void v_sof __P((SCR *, MARK *));
154 int vi __P((SCR *, EXF *));
156 #define VIPROTO(type, name) \
157 type name __P((SCR *, EXF *, VICMDARG *, MARK *, MARK *, MARK *))
159 VIPROTO(int, v_again);
160 VIPROTO(int, v_at);
161 VIPROTO(int, v_bottom);
162 VIPROTO(int, v_cfirst);
163 VIPROTO(int, v_Change);
164 VIPROTO(int, v_change);
165 VIPROTO(int, v_chF);
166 VIPROTO(int, v_chf);
167 VIPROTO(int, v_chrepeat);
168 VIPROTO(int, v_chrrepeat);
169 VIPROTO(int, v_chT);
170 VIPROTO(int, v_cht);
171 VIPROTO(int, v_cr);
172 VIPROTO(int, v_Delete);
173 VIPROTO(int, v_delete);
174 VIPROTO(int, v_dollar);
175 VIPROTO(int, v_down);
176 VIPROTO(int, v_ex);
177 VIPROTO(int, v_exit);
178 VIPROTO(int, v_exmode);
179 VIPROTO(int, v_filter);
180 VIPROTO(int, v_first);
181 VIPROTO(int, v_gomark);
182 VIPROTO(int, v_home);
183 VIPROTO(int, v_hpagedown);
184 VIPROTO(int, v_hpageup);
185 VIPROTO(int, v_iA);
186 VIPROTO(int, v_ia);
187 VIPROTO(int, v_iI);
188 VIPROTO(int, v_ii);
189 VIPROTO(int, v_increment);
190 VIPROTO(int, v_iO);
191 VIPROTO(int, v_io);
192 VIPROTO(int, v_join);
193 VIPROTO(int, v_left);
194 VIPROTO(int, v_lgoto);
195 VIPROTO(int, v_linedown);
196 VIPROTO(int, v_lineup);
197 VIPROTO(int, v_mark);
198 VIPROTO(int, v_match);
199 VIPROTO(int, v_middle);
200 VIPROTO(int, v_ncol);
201 VIPROTO(int, v_pagedown);
202 VIPROTO(int, v_pageup);
203 VIPROTO(int, v_paragraphb);
204 VIPROTO(int, v_paragraphf);
205 VIPROTO(int, v_Put);
206 VIPROTO(int, v_put);
207 VIPROTO(int, v_redraw);
208 VIPROTO(int, v_Replace);
209 VIPROTO(int, v_replace);
210 VIPROTO(int, v_right);
211 VIPROTO(int, v_screen);
212 VIPROTO(int, v_searchb);
213 VIPROTO(int, v_searchf);
214 VIPROTO(int, v_searchN);
215 VIPROTO(int, v_searchn);
216 VIPROTO(int, v_searchw);
217 VIPROTO(int, v_sectionb);
218 VIPROTO(int, v_sectionf);
219 VIPROTO(int, v_sentenceb);
220 VIPROTO(int, v_sentencef);
221 VIPROTO(int, v_shiftl);
222 VIPROTO(int, v_shiftr);
223 VIPROTO(int, v_status);
224 VIPROTO(int, v_stop);
225 VIPROTO(int, v_Subst);
226 VIPROTO(int, v_subst);
227 VIPROTO(int, v_switch);
228 VIPROTO(int, v_tagpop);
229 VIPROTO(int, v_tagpush);
230 VIPROTO(int, v_ulcase);
231 VIPROTO(int, v_Undo);
232 VIPROTO(int, v_undo);
233 VIPROTO(int, v_up);
234 VIPROTO(int, v_wordB);
235 VIPROTO(int, v_wordb);
236 VIPROTO(int, v_wordE);
237 VIPROTO(int, v_worde);
238 VIPROTO(int, v_wordW);
239 VIPROTO(int, v_wordw);
240 VIPROTO(int, v_Xchar);
241 VIPROTO(int, v_xchar);
242 VIPROTO(int, v_Yank);
243 VIPROTO(int, v_yank);
244 VIPROTO(int, v_z);
245 VIPROTO(int, v_zero);