Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* vi.h */ |
2 | ||
3 | /* Author: | |
4 | * Steve Kirkendall | |
5 | * 14407 SW Teal Blvd. #C | |
6 | * Beaverton, OR 97005 | |
7 | * kirkenda@cs.pdx.edu | |
8 | */ | |
9 | ||
08746e8b | 10 | #define VERSION "ELVIS 1.7, by Steve Kirkendall (30 December 1992)" |
15637ed4 RG |
11 | #define COPYING "This version of ELVIS is freely redistributable." |
12 | ||
13 | #include <errno.h> | |
08746e8b AM |
14 | #if TOS |
15 | # ifndef __GNUC__ | |
16 | # define ENOENT (-AEFILNF) | |
17 | # endif | |
15637ed4 RG |
18 | #endif |
19 | ||
20 | #if TOS || VMS | |
21 | # include <types.h> | |
22 | # define O_RDONLY 0 | |
23 | # define O_WRONLY 1 | |
24 | # define O_RDWR 2 | |
25 | # ifdef __GNUC__ | |
26 | # define S_IJDIR S_IFDIR | |
27 | # endif | |
28 | #else | |
29 | # if OSK | |
30 | # include <modes.h> | |
31 | # define O_RDONLY S_IREAD | |
32 | # define O_WRONLY S_IWRITE | |
33 | # define O_RDWR (S_IREAD | S_IWRITE) | |
34 | # define ENOENT E_PNNF | |
35 | # define sprintf Sprintf | |
36 | # else | |
08746e8b AM |
37 | # if !AMIGA |
38 | # include <sys/types.h> | |
39 | # endif | |
40 | # if COH_286 | |
15637ed4 RG |
41 | # include <sys/fcntl.h> |
42 | # else | |
43 | # include <fcntl.h> | |
44 | # endif | |
45 | # endif | |
46 | #endif | |
47 | ||
48 | #ifndef O_BINARY | |
49 | # define O_BINARY 0 | |
50 | #endif | |
51 | ||
52 | #include "curses.h" | |
53 | ||
54 | #include <signal.h> | |
08746e8b AM |
55 | #ifdef __STDC__ |
56 | # include <stdio.h> /* for [v]sprintf prototype */ | |
57 | # include <string.h> /* for str* prototypes */ | |
58 | # include <stdlib.h> /* for atoi, system, malloc, free */ | |
59 | # include <stdarg.h> /* for vararg definitions */ | |
60 | # if ANY_UNIX | |
61 | # include <unistd.h> /* for read, write, ... prototypes */ | |
62 | # include <sys/wait.h> /* for wait prototype */ | |
63 | # endif | |
64 | #endif | |
15637ed4 RG |
65 | |
66 | /*------------------------------------------------------------------------*/ | |
67 | /* Miscellaneous constants. */ | |
68 | ||
69 | #define INFINITY 2000000001L /* a very large integer */ | |
70 | #define LONGKEY 10 /* longest possible raw :map key */ | |
71 | #ifndef MAXRCLEN | |
72 | # define MAXRCLEN 1000 /* longest possible :@ command */ | |
73 | #endif | |
74 | ||
75 | /*------------------------------------------------------------------------*/ | |
76 | /* These describe how temporary files are divided into blocks */ | |
77 | ||
78 | #define MAXBLKS (BLKSIZE / sizeof(unsigned short)) | |
79 | typedef union | |
80 | { | |
81 | char c[BLKSIZE]; /* for text blocks */ | |
82 | unsigned short n[MAXBLKS]; /* for the header block */ | |
83 | } | |
84 | BLK; | |
85 | ||
86 | /*------------------------------------------------------------------------*/ | |
87 | /* These are used manipulate BLK buffers. */ | |
88 | ||
89 | extern BLK hdr; /* buffer for the header block */ | |
08746e8b AM |
90 | extern BLK *blkget P_((int)); /* given index into hdr.c[], reads block */ |
91 | extern BLK *blkadd P_((int)); /* inserts a new block into hdr.c[] */ | |
15637ed4 RG |
92 | |
93 | /*------------------------------------------------------------------------*/ | |
94 | /* These are used to keep track of various flags */ | |
95 | extern struct _viflags | |
96 | { | |
97 | short file; /* file flags */ | |
98 | } | |
99 | viflags; | |
100 | ||
101 | /* file flags */ | |
102 | #define NEWFILE 0x0001 /* the file was just created */ | |
103 | #define READONLY 0x0002 /* the file is read-only */ | |
104 | #define HADNUL 0x0004 /* the file contained NUL characters */ | |
105 | #define MODIFIED 0x0008 /* the file has been modified, but not saved */ | |
106 | #define NOFILE 0x0010 /* no name is known for the current text */ | |
107 | #define ADDEDNL 0x0020 /* newlines were added to the file */ | |
108 | #define HADBS 0x0040 /* backspace chars were lost from the file */ | |
109 | #define UNDOABLE 0x0080 /* file has been modified */ | |
110 | #define NOTEDITED 0x0100 /* the :file command has been used */ | |
111 | ||
112 | /* macros used to set/clear/test flags */ | |
113 | #define setflag(x,y) viflags.x |= y | |
114 | #define clrflag(x,y) viflags.x &= ~y | |
115 | #define tstflag(x,y) (viflags.x & y) | |
116 | #define initflags() viflags.file = 0; | |
117 | ||
118 | /* The options */ | |
119 | extern char o_autoindent[1]; | |
120 | extern char o_autoprint[1]; | |
121 | extern char o_autotab[1]; | |
122 | extern char o_autowrite[1]; | |
123 | extern char o_columns[3]; | |
124 | extern char o_directory[30]; | |
125 | extern char o_edcompatible[1]; | |
126 | extern char o_equalprg[80]; | |
127 | extern char o_errorbells[1]; | |
128 | extern char o_exrefresh[1]; | |
129 | extern char o_ignorecase[1]; | |
130 | extern char o_keytime[3]; | |
131 | extern char o_keywordprg[80]; | |
132 | extern char o_lines[3]; | |
133 | extern char o_list[1]; | |
134 | extern char o_number[1]; | |
135 | extern char o_readonly[1]; | |
136 | extern char o_remap[1]; | |
137 | extern char o_report[3]; | |
138 | extern char o_scroll[3]; | |
139 | extern char o_shell[60]; | |
140 | extern char o_shiftwidth[3]; | |
141 | extern char o_sidescroll[3]; | |
142 | extern char o_sync[1]; | |
143 | extern char o_tabstop[3]; | |
144 | extern char o_term[30]; | |
145 | extern char o_flash[1]; | |
146 | extern char o_warn[1]; | |
147 | extern char o_wrapscan[1]; | |
148 | ||
149 | #ifndef CRUNCH | |
150 | extern char o_beautify[1]; | |
151 | extern char o_exrc[1]; | |
152 | extern char o_mesg[1]; | |
153 | extern char o_more[1]; | |
08746e8b | 154 | extern char o_nearscroll[3]; |
15637ed4 RG |
155 | extern char o_novice[1]; |
156 | extern char o_prompt[1]; | |
157 | extern char o_taglength[3]; | |
08746e8b | 158 | extern char o_tags[256]; |
15637ed4 RG |
159 | extern char o_terse[1]; |
160 | extern char o_window[3]; | |
161 | extern char o_wrapmargin[3]; | |
162 | extern char o_writeany[1]; | |
163 | #endif | |
164 | ||
165 | #ifndef NO_ERRLIST | |
166 | extern char o_cc[30]; | |
167 | extern char o_make[30]; | |
168 | #endif | |
169 | ||
170 | #ifndef NO_CHARATTR | |
171 | extern char o_charattr[1]; | |
172 | #endif | |
173 | ||
174 | #ifndef NO_DIGRAPH | |
175 | extern char o_digraph[1]; | |
176 | extern char o_flipcase[80]; | |
177 | #endif | |
178 | ||
179 | #ifndef NO_SENTENCE | |
180 | extern char o_hideformat[1]; | |
181 | #endif | |
182 | ||
183 | #ifndef NO_EXTENSIONS | |
184 | extern char o_inputmode[1]; | |
185 | extern char o_ruler[1]; | |
186 | #endif | |
187 | ||
188 | #ifndef NO_MAGIC | |
189 | extern char o_magic[1]; | |
190 | #endif | |
191 | ||
192 | #ifndef NO_MODELINES | |
193 | extern char o_modelines[1]; | |
194 | #endif | |
195 | ||
196 | #ifndef NO_SENTENCE | |
197 | extern char o_paragraphs[30]; | |
198 | extern char o_sections[30]; | |
199 | #endif | |
200 | ||
201 | #if MSDOS | |
202 | extern char o_pcbios[1]; | |
203 | #endif | |
204 | ||
205 | #ifndef NO_SHOWMATCH | |
206 | extern char o_showmatch[1]; | |
207 | #endif | |
208 | ||
209 | #ifndef NO_SHOWMODE | |
210 | extern char o_smd[1]; | |
211 | #endif | |
212 | ||
08746e8b AM |
213 | #ifndef NO_TAGSTACK |
214 | extern char o_tagstack[1]; | |
215 | #endif | |
216 | ||
15637ed4 RG |
217 | /*------------------------------------------------------------------------*/ |
218 | /* These help support the single-line multi-change "undo" -- shift-U */ | |
219 | ||
220 | extern char U_text[BLKSIZE]; | |
221 | extern long U_line; | |
222 | ||
223 | /*------------------------------------------------------------------------*/ | |
224 | /* These are used to refer to places in the text */ | |
225 | ||
226 | typedef long MARK; | |
227 | #define markline(x) (long)((x) / BLKSIZE) | |
228 | #define markidx(x) (int)((x) & (BLKSIZE - 1)) | |
229 | #define MARK_UNSET ((MARK)0) | |
230 | #define MARK_FIRST ((MARK)BLKSIZE) | |
231 | #define MARK_LAST ((MARK)(nlines * BLKSIZE)) | |
08746e8b | 232 | #define MARK_EOF ((MARK)((nlines + 1) * BLKSIZE)) |
15637ed4 RG |
233 | #define MARK_AT_LINE(x) ((MARK)(x) * BLKSIZE) |
234 | ||
235 | #define NMARKS 29 | |
236 | extern MARK mark[NMARKS]; /* marks a-z, plus mark ' and two temps */ | |
237 | extern MARK cursor; /* mark where line is */ | |
238 | ||
239 | /*------------------------------------------------------------------------*/ | |
240 | /* These are used to keep track of the current & previous files. */ | |
241 | ||
242 | extern long origtime; /* modification date&time of the current file */ | |
243 | extern char origname[256]; /* name of the current file */ | |
244 | extern char prevorig[256]; /* name of the preceding file */ | |
245 | extern long prevline; /* line number from preceding file */ | |
246 | ||
247 | /*------------------------------------------------------------------------*/ | |
248 | /* misc housekeeping variables & functions */ | |
249 | ||
08746e8b AM |
250 | extern int tmpfd; /* fd used to access the tmp file */ |
251 | extern int tmpnum; /* counter used to generate unique filenames */ | |
252 | extern long lnum[MAXBLKS]; /* last line# of each block */ | |
253 | extern long nlines; /* number of lines in the file */ | |
254 | extern char args[BLKSIZE]; /* file names given on the command line */ | |
255 | extern int argno; /* the current element of args[] */ | |
256 | extern int nargs; /* number of filenames in args */ | |
257 | extern long changes; /* counts changes, to prohibit short-cuts */ | |
258 | extern int significant; /* boolean: was a *REAL* change made? */ | |
259 | extern int exitcode; /* 0=not updated, 1=overwritten, else error */ | |
260 | extern BLK tmpblk; /* a block used to accumulate changes */ | |
261 | extern long topline; /* file line number of top line */ | |
262 | extern int leftcol; /* column number of left col */ | |
15637ed4 RG |
263 | #define botline (topline + LINES - 2) |
264 | #define rightcol (leftcol + COLS - (*o_number ? 9 : 1)) | |
08746e8b AM |
265 | extern int physcol; /* physical column number that cursor is on */ |
266 | extern int physrow; /* physical row number that cursor is on */ | |
267 | extern int exwrote; /* used to detect verbose ex commands */ | |
268 | extern int doingdot; /* boolean: are we doing the "." command? */ | |
269 | extern int doingglobal; /* boolean: are doing a ":g" command? */ | |
270 | extern long rptlines; /* number of lines affected by a command */ | |
271 | extern char *rptlabel; /* description of how lines were affected */ | |
272 | extern char *fetchline P_((long)); /* read a given line from tmp file */ | |
273 | extern char *parseptrn P_((REG char *)); /* isolate a regexp in a line */ | |
274 | extern MARK paste P_((MARK, int, int)); /* paste from cut buffer to a given point */ | |
275 | extern char *wildcard P_((char *)); /* expand wildcards in filenames */ | |
276 | extern MARK input P_((MARK, MARK, int, int)); /* inserts characters from keyboard */ | |
277 | extern char *linespec P_((REG char *, MARK *)); /* finds the end of a /regexp/ string */ | |
15637ed4 RG |
278 | #define ctrl(ch) ((ch)&037) |
279 | #ifndef NO_RECYCLE | |
08746e8b AM |
280 | extern long allocate P_((void)); /* allocate a free block of the tmp file */ |
281 | #endif | |
282 | extern SIGTYPE trapint P_((int)); /* trap handler for SIGINT */ | |
283 | extern SIGTYPE deathtrap P_((int)); /* trap handler for deadly signals */ | |
284 | extern void blkdirty P_((BLK *)); /* marks a block as being "dirty" */ | |
285 | extern void blksync P_((void)); /* forces all "dirty" blocks to disk */ | |
286 | extern void blkinit P_((void)); /* resets the block cache to "empty" state */ | |
287 | extern void beep P_((void)); /* rings the terminal's bell */ | |
288 | extern void exrefresh P_((void)); /* writes text to the screen */ | |
289 | #ifdef __STDC__ | |
290 | extern void msg (char *, ...); /* writes a printf-style message to the screen */ | |
291 | #else | |
292 | extern void msg (); /* writes a printf-style message to the screen */ | |
293 | #endif | |
294 | extern void endmsgs P_((void)); /* if "manymsgs" is set, then scroll up 1 line */ | |
295 | extern void garbage P_((void)); /* reclaims any garbage blocks */ | |
296 | extern void redraw P_((MARK, int)); /* updates the screen after a change */ | |
297 | extern void resume_curses P_((int)); /* puts the terminal in "cbreak" mode */ | |
298 | extern void beforedo P_((int)); /* saves current revision before a new change */ | |
299 | extern void afterdo P_((void)); /* marks end of a beforedo() change */ | |
300 | extern void abortdo P_((void)); /* like "afterdo()" followed by "undo()" */ | |
301 | extern int undo P_((void)); /* restores file to previous undo() */ | |
302 | extern void dumpkey P_((int, int)); /* lists key mappings to the screen */ | |
303 | extern void mapkey P_((char *, char *, int, char *)); /* defines a new key mapping */ | |
304 | extern void redrawrange P_((long, long, long)); /* records clues from modify.c */ | |
305 | extern void cut P_((MARK, MARK)); /* saves text in a cut buffer */ | |
306 | extern void delete P_((MARK, MARK)); /* deletes text */ | |
307 | extern void add P_((MARK, char *)); /* adds text */ | |
308 | extern void change P_((MARK, MARK, char *));/* deletes text, and then adds other text */ | |
309 | extern void cutswitch P_((void)); /* updates cut buffers when we switch files */ | |
310 | extern void do_digraph P_((int, char [])); /* defines or lists digraphs */ | |
311 | extern void exstring P_((char *, int, int));/* execute a string as EX commands */ | |
312 | extern void dumpopts P_((int)); /* display current option settings on the screen */ | |
313 | extern void setopts P_((char *)); /* assign new values to options */ | |
314 | extern void saveopts P_((int)); /* save current option values to a given fd */ | |
315 | extern void savedigs P_((int)); /* save current non-standard digraphs to fd */ | |
316 | extern void savecolor P_((int)); /* save current color settings (if any) to fd */ | |
317 | extern void cutname P_((int)); /* select cut buffer for next cut/paste */ | |
318 | extern void initopts P_((void)); /* initialize options */ | |
319 | extern void cutend P_((void)); /* free all cut buffers & delete temp files */ | |
320 | extern int storename P_((char *)); /* stamp temp file with pathname of text file */ | |
321 | extern int tmpstart P_((char *)); /* load a text file into edit buffer */ | |
322 | extern int tmpsave P_((char *, int)); /* write edit buffer out to text file */ | |
323 | extern int tmpend P_((int)); /* call tmpsave(), and then tmpabort */ | |
324 | extern int tmpabort P_((int)); /* abandon the current edit buffer */ | |
325 | extern void savemaps P_((int, int)); /* write current :map or :ab commands to fd */ | |
326 | extern int ansicolor P_((int, int)); /* emit ANSI color command to terminal */ | |
327 | extern int filter P_((MARK, MARK, char *, int)); /* I/O though another program */ | |
328 | extern int getkey P_((int)); /* return a keystroke, interpretting maps */ | |
329 | extern int vgets P_((int, char *, int)); /* read a single line from keyboard */ | |
330 | extern int doexrc P_((char *)); /* execute a string as a sequence of EX commands */ | |
331 | extern int cb2str P_((int, char *, unsigned));/* return a string containing cut buffer's contents */ | |
332 | extern int ansiquit P_((void)); /* neutralize previous ansicolor() call */ | |
333 | extern int ttyread P_((char *, int, int)); /* read from keyboard with optional timeout */ | |
334 | extern int tgetent P_((char *, char *)); /* start termcap */ | |
335 | extern int tgetnum P_((char *)); /* get a termcap number */ | |
336 | extern int tgetflag P_((char *)); /* get a termcap boolean */ | |
337 | extern int getsize P_((int)); /* determine how big the screen is */ | |
338 | extern int endcolor P_((void)); /* used during color output */ | |
339 | extern int getabkey P_((int, char *, int));/* like getkey(), but also does abbreviations */ | |
340 | extern int idx2col P_((MARK, REG char *, int)); /* returns column# of a given MARK */ | |
341 | extern int cutneeds P_((BLK *)); /* returns bitmap of blocks needed to hold cutbuffer text */ | |
342 | extern void execmap P_((int, char *, int)); /* replaces "raw" keys with "mapped" keys */ | |
15637ed4 | 343 | #ifndef CRUNCH |
08746e8b | 344 | extern int wset; /* boolean: has the "window" size been set? */ |
15637ed4 RG |
345 | #endif |
346 | ||
347 | /*------------------------------------------------------------------------*/ | |
348 | /* macros that are used as control structures */ | |
349 | ||
350 | #define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0) | |
351 | #define ChangeText BeforeAfter(beforedo(FALSE),afterdo()) | |
352 | ||
353 | extern int bavar; /* used only in BeforeAfter macros */ | |
354 | ||
355 | /*------------------------------------------------------------------------*/ | |
356 | /* These are the movement commands. Each accepts a mark for the starting */ | |
357 | /* location & number and returns a mark for the destination. */ | |
358 | ||
08746e8b AM |
359 | extern MARK m_updnto P_((MARK, long, int)); /* k j G */ |
360 | extern MARK m_right P_((MARK, long, int, int)); /* h */ | |
361 | extern MARK m_left P_((MARK, long)); /* l */ | |
362 | extern MARK m_tocol P_((MARK, long, int)); /* | */ | |
363 | extern MARK m_front P_((MARK, long)); /* ^ */ | |
364 | extern MARK m_rear P_((MARK, long)); /* $ */ | |
365 | extern MARK m_fword P_((MARK, long, int, int)); /* w */ | |
366 | extern MARK m_bword P_((MARK, long, int)); /* b */ | |
367 | extern MARK m_eword P_((MARK, long, int)); /* e */ | |
368 | extern MARK m_paragraph P_((MARK, long, int)); /* { } [[ ]] */ | |
369 | extern MARK m_match P_((MARK, long)); /* % */ | |
15637ed4 | 370 | #ifndef NO_SENTENCE |
08746e8b | 371 | extern MARK m_sentence P_((MARK, long, int)); /* ( ) */ |
15637ed4 | 372 | #endif |
08746e8b | 373 | extern MARK m_tomark P_((MARK, long, int)); /* 'm */ |
15637ed4 | 374 | #ifndef NO_EXTENSIONS |
08746e8b | 375 | extern MARK m_wsrch P_((char *, MARK, int)); /* ^A */ |
15637ed4 | 376 | #endif |
08746e8b AM |
377 | extern MARK m_nsrch P_((MARK, long, int)); /* n */ |
378 | extern MARK m_fsrch P_((MARK, char *)); /* /regexp */ | |
379 | extern MARK m_bsrch P_((MARK, char *)); /* ?regexp */ | |
15637ed4 | 380 | #ifndef NO_CHARSEARCH |
08746e8b AM |
381 | extern MARK m__ch P_((MARK, long, int)); /* ; , */ |
382 | extern MARK m_fch P_((MARK, long, int)); /* f */ | |
383 | extern MARK m_tch P_((MARK, long, int)); /* t */ | |
384 | extern MARK m_Fch P_((MARK, long, int)); /* F */ | |
385 | extern MARK m_Tch P_((MARK, long, int)); /* T */ | |
15637ed4 | 386 | #endif |
08746e8b AM |
387 | extern MARK m_row P_((MARK, long, int)); /* H L M */ |
388 | extern MARK m_z P_((MARK, long, int)); /* z */ | |
389 | extern MARK m_scroll P_((MARK, long, int)); /* ^B ^F ^E ^Y ^U ^D */ | |
15637ed4 RG |
390 | |
391 | /* Some stuff that is used by movement functions... */ | |
392 | ||
08746e8b | 393 | extern MARK adjmove P_((MARK, REG MARK, int)); /* a helper fn, used by move fns */ |
15637ed4 RG |
394 | |
395 | /* This macro is used to set the default value of cnt */ | |
396 | #define DEFAULT(val) if (cnt < 1) cnt = (val) | |
397 | ||
398 | /* These are used to minimize calls to fetchline() */ | |
399 | extern int plen; /* length of the line */ | |
400 | extern long pline; /* line number that len refers to */ | |
401 | extern long pchgs; /* "changes" level that len refers to */ | |
402 | extern char *ptext; /* text of previous line, if valid */ | |
08746e8b AM |
403 | extern void pfetch P_((long)); |
404 | extern char digraph P_((int, int)); | |
15637ed4 RG |
405 | |
406 | /* This is used to build a MARK that corresponds to a specific point in the | |
407 | * line that was most recently pfetch'ed. | |
408 | */ | |
409 | #define buildmark(text) (MARK)(BLKSIZE * pline + (int)((text) - ptext)) | |
410 | ||
411 | ||
412 | /*------------------------------------------------------------------------*/ | |
413 | /* These are used to handle EX commands. */ | |
414 | ||
08746e8b AM |
415 | #define CMD_NULL 0 /* NOT A VALID COMMAND */ |
416 | #define CMD_ABBR 1 /* "define an abbreviation" */ | |
417 | #define CMD_ARGS 2 /* "show me the args" */ | |
418 | #define CMD_APPEND 3 /* "insert lines after this line" */ | |
419 | #define CMD_AT 4 /* "execute a cut buffer's contents via EX" */ | |
420 | #define CMD_BANG 5 /* "run a single shell command" */ | |
421 | #define CMD_CC 6 /* "run `cc` and then do CMD_ERRLIST" */ | |
422 | #define CMD_CD 7 /* "change directories" */ | |
423 | #define CMD_CHANGE 8 /* "change some lines" */ | |
424 | #define CMD_COLOR 9 /* "change the default colors" */ | |
425 | #define CMD_COPY 10 /* "copy the selected text to a given place" */ | |
426 | #define CMD_DELETE 11 /* "delete the selected text" */ | |
427 | #define CMD_DIGRAPH 12 /* "add a digraph, or display them all" */ | |
428 | #define CMD_EDIT 13 /* "switch to a different file" */ | |
429 | #define CMD_EQUAL 14 /* "display a line number" */ | |
430 | #define CMD_ERRLIST 15 /* "locate the next error in a list" */ | |
431 | #define CMD_FILE 16 /* "show the file's status" */ | |
432 | #define CMD_GLOBAL 17 /* "globally search & do a command" */ | |
433 | #define CMD_INSERT 18 /* "insert lines before the current line" */ | |
434 | #define CMD_JOIN 19 /* "join the selected line & the one after" */ | |
435 | #define CMD_LIST 20 /* "print lines, making control chars visible" */ | |
436 | #define CMD_MAKE 21 /* "run `make` and then do CMD_ERRLIST" */ | |
437 | #define CMD_MAP 22 /* "adjust the keyboard map" */ | |
438 | #define CMD_MARK 23 /* "mark this line" */ | |
439 | #define CMD_MKEXRC 24 /* "make a .exrc file" */ | |
440 | #define CMD_MOVE 25 /* "move the selected text to a given place" */ | |
441 | #define CMD_NEXT 26 /* "switch to next file in args" */ | |
442 | #define CMD_NUMBER 27 /* "print lines from the file w/ line numbers" */ | |
443 | #define CMD_POP 28 /* "pop a position off the tagstack" */ | |
444 | #define CMD_PRESERVE 29 /* "act as though vi crashed" */ | |
445 | #define CMD_PREVIOUS 30 /* "switch to the previous file in args" */ | |
446 | #define CMD_PRINT 31 /* "print the selected text" */ | |
447 | #define CMD_PUT 32 /* "insert any cut lines before this line" */ | |
448 | #define CMD_QUIT 33 /* "quit without writing the file" */ | |
449 | #define CMD_READ 34 /* "append the given file after this line */ | |
450 | #define CMD_RECOVER 35 /* "recover file after vi crashes" - USE -r FLAG */ | |
451 | #define CMD_REWIND 36 /* "rewind to first file" */ | |
452 | #define CMD_SET 37 /* "set a variable's value" */ | |
453 | #define CMD_SHELL 38 /* "run some lines through a command" */ | |
454 | #define CMD_SHIFTL 39 /* "shift lines left" */ | |
455 | #define CMD_SHIFTR 40 /* "shift lines right" */ | |
456 | #define CMD_SOURCE 41 /* "interpret a file's contents as ex commands" */ | |
457 | #define CMD_STOP 42 /* same as CMD_SUSPEND */ | |
458 | #define CMD_SUBAGAIN 43 /* "repeat the previous substitution" */ | |
459 | #define CMD_SUBSTITUTE 44 /* "substitute text in this line" */ | |
460 | #define CMD_SUSPEND 45 /* "suspend the vi session" */ | |
461 | #define CMD_TR 46 /* "transliterate chars in the selected lines" */ | |
462 | #define CMD_TAG 47 /* "go to a particular tag" */ | |
463 | #define CMD_UNABBR 48 /* "remove an abbreviation definition" */ | |
464 | #define CMD_UNDO 49 /* "undo the previous command" */ | |
465 | #define CMD_UNMAP 50 /* "remove a key sequence map */ | |
466 | #define CMD_VERSION 51 /* "describe which version this is" */ | |
467 | #define CMD_VGLOBAL 52 /* "apply a cmd to lines NOT containing an RE" */ | |
468 | #define CMD_VISUAL 53 /* "go into visual mode" */ | |
469 | #define CMD_WQUIT 54 /* "write this file out (any case) & quit" */ | |
470 | #define CMD_WRITE 55 /* "write the selected(?) text to a given file" */ | |
471 | #define CMD_XIT 56 /* "write this file out (if modified) & quit" */ | |
472 | #define CMD_YANK 57 /* "copy the selected text into the cut buffer" */ | |
473 | #define CMD_DEBUG 58 /* access to internal data structures */ | |
474 | #define CMD_VALIDATE 59 /* check for internal consistency */ | |
15637ed4 RG |
475 | typedef int CMD; |
476 | ||
08746e8b AM |
477 | extern void ex P_((void)); |
478 | extern void vi P_((void)); | |
479 | extern void doexcmd P_((char *)); | |
15637ed4 | 480 | |
08746e8b AM |
481 | extern void cmd_append P_((MARK, MARK, CMD, int, char *)); |
482 | extern void cmd_args P_((MARK, MARK, CMD, int, char *)); | |
15637ed4 | 483 | #ifndef NO_AT |
08746e8b | 484 | extern void cmd_at P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 485 | #endif |
08746e8b | 486 | extern void cmd_cd P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 487 | #ifndef NO_COLOR |
08746e8b | 488 | extern void cmd_color P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 489 | #endif |
08746e8b | 490 | extern void cmd_delete P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 491 | #ifndef NO_DIGRAPH |
08746e8b | 492 | extern void cmd_digraph P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 493 | #endif |
08746e8b | 494 | extern void cmd_edit P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 495 | #ifndef NO_ERRLIST |
08746e8b | 496 | extern void cmd_errlist P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 497 | #endif |
08746e8b AM |
498 | extern void cmd_file P_((MARK, MARK, CMD, int, char *)); |
499 | extern void cmd_global P_((MARK, MARK, CMD, int, char *)); | |
500 | extern void cmd_join P_((MARK, MARK, CMD, int, char *)); | |
501 | extern void cmd_mark P_((MARK, MARK, CMD, int, char *)); | |
15637ed4 | 502 | #ifndef NO_ERRLIST |
08746e8b | 503 | extern void cmd_make P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 504 | #endif |
08746e8b | 505 | extern void cmd_map P_((MARK, MARK, CMD, int, char *)); |
15637ed4 | 506 | #ifndef NO_MKEXRC |
08746e8b AM |
507 | extern void cmd_mkexrc P_((MARK, MARK, CMD, int, char *)); |
508 | #endif | |
509 | extern void cmd_next P_((MARK, MARK, CMD, int, char *)); | |
510 | #ifndef NO_TAGSTACK | |
511 | extern void cmd_pop P_((MARK, MARK, CMD, int, char *)); | |
512 | #endif | |
513 | extern void cmd_print P_((MARK, MARK, CMD, int, char *)); | |
514 | extern void cmd_put P_((MARK, MARK, CMD, int, char *)); | |
515 | extern void cmd_read P_((MARK, MARK, CMD, int, char *)); | |
516 | extern void cmd_set P_((MARK, MARK, CMD, int, char *)); | |
517 | extern void cmd_shell P_((MARK, MARK, CMD, int, char *)); | |
518 | extern void cmd_shift P_((MARK, MARK, CMD, int, char *)); | |
519 | extern void cmd_source P_((MARK, MARK, CMD, int, char *)); | |
520 | extern void cmd_substitute P_((MARK, MARK, CMD, int, char *)); | |
521 | extern void cmd_tag P_((MARK, MARK, CMD, int, char *)); | |
522 | extern void cmd_undo P_((MARK, MARK, CMD, int, char *)); | |
523 | extern void cmd_version P_((MARK, MARK, CMD, int, char *)); | |
524 | extern void cmd_write P_((MARK, MARK, CMD, int, char *)); | |
525 | extern void cmd_xit P_((MARK, MARK, CMD, int, char *)); | |
526 | extern void cmd_move P_((MARK, MARK, CMD, int, char *)); | |
15637ed4 | 527 | #ifdef DEBUG |
08746e8b AM |
528 | extern void cmd_debug P_((MARK, MARK, CMD, int, char *)); |
529 | extern void cmd_validate P_((MARK, MARK, CMD, int, char *)); | |
15637ed4 RG |
530 | #endif |
531 | #ifdef SIGTSTP | |
08746e8b | 532 | extern void cmd_suspend P_((MARK, MARK, CMD, int, char *)); |
15637ed4 RG |
533 | #endif |
534 | ||
535 | /*----------------------------------------------------------------------*/ | |
536 | /* These are used to handle VI commands */ | |
537 | ||
08746e8b AM |
538 | extern MARK v_1ex P_((MARK, char *)); /* : */ |
539 | extern MARK v_mark P_((MARK, long, int)); /* m */ | |
540 | extern MARK v_quit P_((void)); /* Q */ | |
541 | extern MARK v_redraw P_((void)); /* ^L ^R */ | |
542 | extern MARK v_ulcase P_((MARK, long)); /* ~ */ | |
543 | extern MARK v_undo P_((MARK)); /* u */ | |
544 | extern MARK v_xchar P_((MARK, long, int)); /* x X */ | |
545 | extern MARK v_replace P_((MARK, long, int));/* r */ | |
546 | extern MARK v_overtype P_((MARK)); /* R */ | |
547 | extern MARK v_selcut P_((MARK, long, int)); /* " */ | |
548 | extern MARK v_paste P_((MARK, long, int)); /* p P */ | |
549 | extern MARK v_yank P_((MARK, MARK)); /* y Y */ | |
550 | extern MARK v_delete P_((MARK, MARK)); /* d D */ | |
551 | extern MARK v_join P_((MARK, long)); /* J */ | |
552 | extern MARK v_insert P_((MARK, long, int)); /* a A i I o O */ | |
553 | extern MARK v_change P_((MARK, MARK)); /* c C */ | |
554 | extern MARK v_subst P_((MARK, long)); /* s */ | |
555 | extern MARK v_lshift P_((MARK, MARK)); /* < */ | |
556 | extern MARK v_rshift P_((MARK, MARK)); /* > */ | |
557 | extern MARK v_reformat P_((MARK, MARK)); /* = */ | |
558 | extern MARK v_filter P_((MARK, MARK)); /* ! */ | |
559 | extern MARK v_status P_((void)); /* ^G */ | |
560 | extern MARK v_switch P_((void)); /* ^^ */ | |
561 | extern MARK v_tag P_((char *, MARK, long)); /* ^] */ | |
562 | extern MARK v_xit P_((MARK, long, int)); /* ZZ */ | |
563 | extern MARK v_undoline P_((MARK)); /* U */ | |
564 | extern MARK v_again P_((MARK, MARK)); /* & */ | |
15637ed4 | 565 | #ifndef NO_EXTENSIONS |
08746e8b AM |
566 | extern MARK v_keyword P_((char *, MARK, long)); /* K */ |
567 | extern MARK v_increment P_((char *, MARK, long)); /* * */ | |
15637ed4 RG |
568 | #endif |
569 | #ifndef NO_ERRLIST | |
08746e8b | 570 | extern MARK v_errlist P_((MARK)); /* * */ |
15637ed4 RG |
571 | #endif |
572 | #ifndef NO_AT | |
08746e8b | 573 | extern MARK v_at P_((MARK, long, int)); /* @ */ |
15637ed4 RG |
574 | #endif |
575 | #ifdef SIGTSTP | |
08746e8b | 576 | extern MARK v_suspend P_((void)); /* ^Z */ |
15637ed4 RG |
577 | #endif |
578 | #ifndef NO_POPUP | |
08746e8b AM |
579 | extern MARK v_popup P_((MARK, MARK)); /* \ */ |
580 | #endif | |
581 | #ifndef NO_TAGSTACK | |
582 | extern MARK v_pop P_((MARK, long, int)); /* ^T */ | |
15637ed4 RG |
583 | #endif |
584 | ||
585 | /*----------------------------------------------------------------------*/ | |
586 | /* These flags describe the quirks of the individual visual commands */ | |
587 | #define NO_FLAGS 0x00 | |
588 | #define MVMT 0x01 /* this is a movement command */ | |
589 | #define PTMV 0x02 /* this can be *part* of a movement command */ | |
590 | #define FRNT 0x04 /* after move, go to front of line */ | |
591 | #define INCL 0x08 /* include last char when used with c/d/y */ | |
592 | #define LNMD 0x10 /* use line mode of c/d/y */ | |
593 | #define NCOL 0x20 /* this command can't change the column# */ | |
594 | #define NREL 0x40 /* this is "non-relative" -- set the '' mark */ | |
595 | #define SDOT 0x80 /* set the "dot" variables, for the "." cmd */ | |
08746e8b AM |
596 | #define FINL 0x100 /* final testing, more strict! */ |
597 | #define NWRP 0x200 /* no line-wrap (used for 'w' and 'W') */ | |
15637ed4 | 598 | #ifndef NO_VISIBLE |
08746e8b | 599 | # define VIZ 0x400 /* commands which can be used with 'v' */ |
15637ed4 RG |
600 | #else |
601 | # define VIZ 0 | |
602 | #endif | |
603 | ||
604 | /* This variable is zeroed before a command executes, and later ORed with the | |
605 | * command's flags after the command has been executed. It is used to force | |
606 | * certain flags to be TRUE for *some* invocations of a particular command. | |
607 | * For example, "/regexp/+offset" forces the LNMD flag, and sometimes a "p" | |
608 | * or "P" command will force FRNT. | |
609 | */ | |
610 | extern int force_flags; | |
611 | ||
612 | /*----------------------------------------------------------------------*/ | |
613 | /* These describe what mode we're in */ | |
614 | ||
615 | #define MODE_EX 1 /* executing ex commands */ | |
616 | #define MODE_VI 2 /* executing vi commands */ | |
617 | #define MODE_COLON 3 /* executing an ex command from vi mode */ | |
618 | #define MODE_QUIT 4 | |
619 | extern int mode; | |
620 | ||
621 | #define WHEN_VICMD 1 /* getkey: we're reading a VI command */ | |
622 | #define WHEN_VIINP 2 /* getkey: we're in VI's INPUT mode */ | |
623 | #define WHEN_VIREP 4 /* getkey: we're in VI's REPLACE mode */ | |
624 | #define WHEN_EX 8 /* getkey: we're in EX mode */ | |
625 | #define WHEN_MSG 16 /* getkey: we're at a "more" prompt */ | |
626 | #define WHEN_POPUP 32 /* getkey: we're in the pop-up menu */ | |
627 | #define WHEN_REP1 64 /* getkey: we're getting a single char for 'r' */ | |
628 | #define WHEN_CUT 128 /* getkey: we're getting a cut buffer name */ | |
629 | #define WHEN_MARK 256 /* getkey: we're getting a mark name */ | |
630 | #define WHEN_CHAR 512 /* getkey: we're getting a destination for f/F/t/T */ | |
631 | #define WHEN_INMV 4096 /* in input mode, interpret the key in VICMD mode */ | |
632 | #define WHEN_FREE 8192 /* free the keymap after doing it once */ | |
633 | #define WHENMASK (WHEN_VICMD|WHEN_VIINP|WHEN_VIREP|WHEN_REP1|WHEN_CUT|WHEN_MARK|WHEN_CHAR) | |
634 | ||
635 | #ifndef NO_VISIBLE | |
636 | extern MARK V_from; | |
637 | extern int V_linemd; | |
08746e8b | 638 | extern MARK v_start P_((MARK m, long cnt, int cmd)); |
15637ed4 RG |
639 | #endif |
640 | ||
641 | #ifdef DEBUG | |
642 | # define malloc(size) dbmalloc(size, __FILE__, __LINE__) | |
643 | # define free(ptr) dbfree(ptr, __FILE__, __LINE__) | |
08746e8b AM |
644 | # define checkmem() dbcheckmem(__FILE__, __LINE__) |
645 | extern char *dbmalloc P_((int, char *, int)); | |
646 | #else | |
647 | # define checkmem() | |
15637ed4 | 648 | #endif |