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