|
|
1.1 root 1: /* vi.h */
2:
3: /* Author:
4: * Steve Kirkendall
5: * 16820 SW Tallac Way
6: * Beaverton, OR 97006
7: * [email protected], or ...uunet!tektronix!psueea!jove!kirkenda
8: */
9:
10:
11: /* This is the header file for my version of vi. */
12:
13: #define VERSION "ELVIS 1.4, by Steve Kirkendall"
14: #define COPYING "This version of ELVIS is freely redistributable."
15:
16: #include <errno.h>
17: extern int errno;
18: #if TOS
19: #define ENOENT (-AEFILNF)
20: #endif
21:
22: #if TOS
23: # include <types.h>
24: # define O_RDONLY 0
25: # define O_WRONLY 1
26: # define O_RDWR 2
27: #else
28: # if OSK
29: # include <modes.h>
30: # define O_RDONLY S_IREAD
31: # define O_WRONLY S_IWRITE
32: # define O_RDWR (S_IREAD | S_IWRITE)
33: # define ENOENT E_PNNF
34: # else
35: # include <sys/types.h>
36: # if COHERENT
37: # include <sys/fcntl.h>
38: # else
39: # include <fcntl.h>
40: # endif
41: # endif
42: #endif
43:
44: #ifndef O_BINARY
45: # define O_BINARY 0
46: #endif
47:
48: #include "curses.h"
49:
50: /*------------------------------------------------------------------------*/
51: /* Miscellaneous constants. */
52:
53: #define INFINITY 2000000001L /* a very large integer */
54: #define LONGKEY 10 /* longest possible raw :map key */
55: #ifndef MAXRCLEN
56: # define MAXRCLEN 1000 /* longest possible .exrc file */
57: #endif
58:
59: /*------------------------------------------------------------------------*/
60: /* These describe how temporary files are divided into blocks */
61:
62: #define BLKSIZE 1024 /* size of blocks */
63: #define MAXBLKS (BLKSIZE / sizeof(unsigned short))
64: typedef union
65: {
66: char c[BLKSIZE]; /* for text blocks */
67: unsigned short n[MAXBLKS]; /* for the header block */
68: }
69: BLK;
70:
71: /*------------------------------------------------------------------------*/
72: /* These are used manipulate BLK buffers. */
73:
74: extern BLK hdr; /* buffer for the header block */
75: extern BLK *blkget(); /* given index into hdr.c[], reads block */
76: extern BLK *blkadd(); /* inserts a new block into hdr.c[] */
77:
78: /*------------------------------------------------------------------------*/
79: /* These are used to keep track of various flags */
80: extern struct _viflags
81: {
82: short file; /* file flags */
83: }
84: viflags;
85:
86: /* file flags */
87: #define NEWFILE 0x0001 /* the file was just created */
88: #define READONLY 0x0002 /* the file is read-only */
89: #define HADNUL 0x0004 /* the file contained NUL characters */
90: #define MODIFIED 0x0008 /* the file has been modified */
91: #define NOFILE 0x0010 /* no name is known for the current text */
92: #define ADDEDNL 0x0020 /* newlines were added to the file */
93:
94: /* macros used to set/clear/test flags */
95: #define setflag(x,y) viflags.x |= y
96: #define clrflag(x,y) viflags.x &= ~y
97: #define tstflag(x,y) (viflags.x & y)
98: #define initflags() viflags.file = 0;
99:
100: /* The options */
101: extern char o_autoindent[1];
102: extern char o_autoprint[1];
103: extern char o_autowrite[1];
104: #ifndef NO_ERRLIST
105: extern char o_cc[30];
106: #endif
107: #ifndef NO_CHARATTR
108: extern char o_charattr[1];
109: #endif
110: extern char o_columns[3];
111: extern char o_digraph[1];
112: extern char o_directory[30];
113: extern char o_edcompatible[1];
114: extern char o_errorbells[1];
115: extern char o_exrefresh[1];
116: #ifndef NO_DIGRAPH
117: extern char o_flipcase[80];
118: #endif
119: #ifndef NO_SENTENCE
120: extern char o_hideformat[1];
121: #endif
122: extern char o_ignorecase[1];
123: #ifndef NO_EXTENSIONS
124: extern char o_inputmode[1];
125: #endif
126: extern char o_keytime[3];
127: extern char o_keywordprg[80];
128: extern char o_lines[3];
129: extern char o_list[1];
130: #ifndef NO_MAGIC
131: extern char o_magic[1];
132: #endif
133: #ifndef NO_ERRLIST
134: extern char o_make[30];
135: #endif
136: #ifndef NO_MODELINE
137: extern char o_modeline[1];
138: #endif
139: #ifndef NO_SENTENCE
140: extern char o_paragraphs[30];
141: #endif
142: #if MSDOS
143: extern char o_pcbios[1];
144: #endif
145: extern char o_readonly[1];
146: extern char o_report[3];
147: extern char o_scroll[3];
148: #ifndef NO_SENTENCE
149: extern char o_sections[30];
150: #endif
151: extern char o_shell[60];
152: #ifndef NO_SHOWMATCH
153: extern char o_showmatch[1];
154: #endif
155: #ifndef NO_SHOWMODE
156: extern char o_smd[1];
157: #endif
158: extern char o_shiftwidth[3];
159: extern char o_sidescroll[3];
160: extern char o_sync[1];
161: extern char o_tabstop[3];
162: extern char o_term[30];
163: extern char o_vbell[1];
164: extern char o_warn[1];
165: extern char o_wrapmargin[3];
166: extern char o_wrapscan[1];
167:
168: /*------------------------------------------------------------------------*/
169: /* These help support the single-line multi-change "undo" -- shift-U */
170:
171: extern char U_text[BLKSIZE];
172: extern long U_line;
173:
174: /*------------------------------------------------------------------------*/
175: /* These are used to refer to places in the text */
176:
177: typedef long MARK;
178: #define markline(x) (long)((x) / BLKSIZE)
179: #define markidx(x) (int)((x) & (BLKSIZE - 1))
180: #define MARK_UNSET ((MARK)0)
181: #define MARK_FIRST ((MARK)BLKSIZE)
182: #define MARK_LAST ((MARK)(nlines * BLKSIZE))
183: #define MARK_AT_LINE(x) ((MARK)((x) * BLKSIZE))
184:
185: #define NMARKS 29
186: extern MARK mark[NMARKS]; /* marks a-z, plus mark ' and two temps */
187: extern MARK cursor; /* mark where line is */
188:
189: /*------------------------------------------------------------------------*/
190: /* These are used to keep track of the current & previous files. */
191:
192: extern long origtime; /* modification date&time of the current file */
193: extern char origname[256]; /* name of the current file */
194: extern char prevorig[256]; /* name of the preceding file */
195: extern long prevline; /* line number from preceding file */
196:
197: /*------------------------------------------------------------------------*/
198: /* misc housekeeping variables & functions */
199:
200: extern int tmpfd; /* fd used to access the tmp file */
201: extern long lnum[MAXBLKS]; /* last line# of each block */
202: extern long nlines; /* number of lines in the file */
203: extern char args[BLKSIZE]; /* file names given on the command line */
204: extern int argno; /* the current element of args[] */
205: extern int nargs; /* number of filenames in args */
206: extern long changes; /* counts changes, to prohibit short-cuts */
207: extern int significant; /* boolean: was a *REAL* change made? */
208: extern int mustredraw; /* boolean: force total redraw of screen? */
209: extern BLK tmpblk; /* a block used to accumulate changes */
210: extern long topline; /* file line number of top line */
211: extern int leftcol; /* column number of left col */
212: #define botline (topline + LINES - 2)
213: #define rightcol (leftcol + COLS - 1)
214: extern int physcol; /* physical column number that cursor is on */
215: extern int physrow; /* physical row number that cursor is on */
216: extern int exwrote; /* used to detect verbose ex commands */
217: extern int doingdot; /* boolean: are we doing the "." command? */
218: extern int doingglobal; /* boolean: are doing a ":g" command? */
219: extern long rptlines; /* number of lines affected by a command */
220: extern char *rptlabel; /* description of how lines were affected */
221: extern char *fetchline(); /* read a given line from tmp file */
222: extern char *parseptrn(); /* isolate a regexp in a line */
223: extern MARK paste(); /* paste from cut buffer to a given point */
224: extern char *wildcard(); /* expand wildcards in filenames */
225: extern MARK input(); /* inserts characters from keyboard */
226: extern char *linespec(); /* finds the end of a /regexp/ string */
227: #define ctrl(ch) ((ch)&037)
228: #ifndef NO_RECYCLE
229: extern long allocate(); /* allocate a free block of the tmp file */
230: #endif
231: extern int trapint(); /* trap handler for SIGINT */
232: extern void blkdirty(); /* marks a block as being "dirty" */
233: extern void blkflush(); /* writes a single dirty block to the disk */
234: extern void blksync(); /* forces all "dirty" blocks to disk */
235: extern void blkinit(); /* resets the block cache to "empty" state */
236: extern void beep(); /* rings the terminal's bell */
237: extern void exrefresh(); /* writes text to the screen */
238: extern void msg(); /* writes a printf-style message to the screen */
239: extern void reset_msg(); /* resets the "manymsgs" flag */
240: extern void endmsgs(); /* if "manymsgs" is set, then scroll up 1 line */
241: extern void garbage(); /* reclaims any garbage blocks */
242: extern void redraw(); /* updates the screen after a change */
243: extern void resume_curses();/* puts the terminal in "cbreak" mode */
244: extern void beforedo(); /* saves current revision before a new change */
245: extern void afterdo(); /* marks end of a beforedo() change */
246: extern void abortdo(); /* like "afterdo()" followed by "undo()" */
247: extern int undo(); /* restores file to previous undo() */
248: extern void dumpkey(); /* lists key mappings to the screen */
249: extern void mapkey(); /* defines a new key mapping */
250: extern void savekeys(); /* lists key mappings to a file */
251: extern void redrawrange(); /* records clues from modify.c */
252: extern void cut(); /* saves text in a cut buffer */
253: extern void delete(); /* deletes text */
254: extern void add(); /* adds text */
255: extern void change(); /* deletes text, and then adds other text */
256: extern void cutswitch(); /* updates cut buffers when we switch files */
257: extern void do_abbr(); /* defines or lists abbreviations */
258: extern void do_digraph(); /* defines or lists digraphs */
259: extern void exstring(); /* execute a string as EX commands */
260: extern void dumpopts();
261: extern void setopts();
262: extern void saveopts();
263: #ifndef NO_DIGRAPH
264: extern void savedigs();
265: #endif
266: #ifndef NO_ABBR
267: extern void saveabbr();
268: #endif
269: extern void cutname();
270: extern void cutname();
271: extern void initopts();
272: extern void cutend();
273:
274: /*------------------------------------------------------------------------*/
275: /* macros that are used as control structures */
276:
277: #define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0)
278: #define ChangeText BeforeAfter(beforedo(FALSE),afterdo())
279:
280: extern int bavar; /* used only in BeforeAfter macros */
281:
282: /*------------------------------------------------------------------------*/
283: /* These are the movement commands. Each accepts a mark for the starting */
284: /* location & number and returns a mark for the destination. */
285:
286: extern MARK m_updnto(); /* k j G */
287: extern MARK m_right(); /* h */
288: extern MARK m_left(); /* l */
289: extern MARK m_tocol(); /* | */
290: extern MARK m_front(); /* ^ */
291: extern MARK m_rear(); /* $ */
292: extern MARK m_fword(); /* w */
293: extern MARK m_bword(); /* b */
294: extern MARK m_eword(); /* e */
295: extern MARK m_fWord(); /* W */
296: extern MARK m_bWord(); /* B */
297: extern MARK m_eWord(); /* E */
298: extern MARK m_fparagraph(); /* } */
299: extern MARK m_bparagraph(); /* { */
300: extern MARK m_fsection(); /* ]] */
301: extern MARK m_bsection(); /* [[ */
302: extern MARK m_match(); /* % */
303: #ifndef NO_SENTENCE
304: extern MARK m_fsentence(); /* ) */
305: extern MARK m_bsentence(); /* ( */
306: #endif
307: extern MARK m_tomark(); /* 'm */
308: extern MARK m_nsrch(); /* n */
309: extern MARK m_Nsrch(); /* N */
310: extern MARK m_fsrch(); /* /regexp */
311: extern MARK m_bsrch(); /* ?regexp */
312: #ifndef NO_CHARSEARCH
313: extern MARK m__ch(); /* ; , */
314: extern MARK m_fch(); /* f */
315: extern MARK m_tch(); /* t */
316: extern MARK m_Fch(); /* F */
317: extern MARK m_Tch(); /* T */
318: #endif
319: extern MARK m_row(); /* H L M */
320: extern MARK m_z(); /* z */
321: extern MARK m_scroll(); /* ^B ^F ^E ^Y ^U ^D */
322:
323: /* Some stuff that is used by movement functions... */
324:
325: extern MARK adjmove(); /* a helper fn, used by move fns */
326:
327: /* This macro is used to set the default value of cnt */
328: #define DEFAULT(val) if (cnt < 1) cnt = (val)
329:
330: /* These are used to minimize calls to fetchline() */
331: extern int plen; /* length of the line */
332: extern long pline; /* line number that len refers to */
333: extern long pchgs; /* "changes" level that len refers to */
334: extern char *ptext; /* text of previous line, if valid */
335: extern void pfetch();
336: extern char digraph();
337:
338: /* This is used to build a MARK that corresponds to a specific point in the
339: * line that was most recently pfetch'ed.
340: */
341: #define buildmark(text) (MARK)(BLKSIZE * pline + (int)((text) - ptext))
342:
343:
344: /*------------------------------------------------------------------------*/
345: /* These are used to handle EX commands. */
346:
347: #define CMD_NULL 0 /* NOT A VALID COMMAND */
348: #define CMD_ABBR 1 /* "define an abbreviation" */
349: #define CMD_ARGS 2 /* "show me the args" */
350: #define CMD_APPEND 3 /* "insert lines after this line" */
351: #define CMD_AT 4 /* "execute a cut buffer's contents via EX" */
352: #define CMD_BANG 5 /* "run a single shell command" */
353: #define CMD_CC 6 /* "run `cc` and then do CMD_ERRLIST" */
354: #define CMD_CD 7 /* "change directories" */
355: #define CMD_CHANGE 8 /* "change some lines" */
356: #define CMD_COPY 9 /* "copy the selected text to a given place" */
357: #define CMD_DELETE 10 /* "delete the selected text" */
358: #define CMD_DIGRAPH 11 /* "add a digraph, or display them all" */
359: #define CMD_EDIT 12 /* "switch to a different file" */
360: #define CMD_EQUAL 13 /* "display a line number" */
361: #define CMD_ERRLIST 14 /* "locate the next error in a list" */
362: #define CMD_FILE 15 /* "show the file's status" */
363: #define CMD_GLOBAL 16 /* "globally search & do a command" */
364: #define CMD_INSERT 17 /* "insert lines before the current line" */
365: #define CMD_JOIN 18 /* "join the selected line & the one after" */
366: #define CMD_LIST 19 /* "print lines, making control chars visible" */
367: #define CMD_MAKE 20 /* "run `make` and then do CMD_ERRLIST" */
368: #define CMD_MAP 21 /* "adjust the keyboard map" */
369: #define CMD_MARK 22 /* "mark this line" */
370: #define CMD_MKEXRC 23 /* "make a .exrc file" */
371: #define CMD_MOVE 24 /* "move the selected text to a given place" */
372: #define CMD_NEXT 25 /* "switch to next file in args" */
373: #define CMD_NUMBER 26 /* "print lines from the file w/ line numbers" */
374: #define CMD_PRESERVE 27 /* "act as though vi crashed" */
375: #define CMD_PREVIOUS 28 /* "switch to the previous file in args" */
376: #define CMD_PRINT 29 /* "print the selected text" */
377: #define CMD_PUT 30 /* "insert any cut lines before this line" */
378: #define CMD_QUIT 31 /* "quit without writing the file" */
379: #define CMD_READ 32 /* "append the given file after this line */
380: #define CMD_RECOVER 33 /* "recover file after vi crashes" - USE -r FLAG */
381: #define CMD_REWIND 34 /* "rewind to first file" */
382: #define CMD_SET 35 /* "set a variable's value" */
383: #define CMD_SHELL 36 /* "run some lines through a command" */
384: #define CMD_SHIFTL 37 /* "shift lines left" */
385: #define CMD_SHIFTR 38 /* "shift lines right" */
386: #define CMD_SOURCE 39 /* "interpret a file's contents as ex commands" */
387: #define CMD_STOP 40 /* same as CMD_SUSPEND */
388: #define CMD_SUBAGAIN 41 /* "repeat the previous substitution" */
389: #define CMD_SUBSTITUTE 42 /* "substitute text in this line" */
390: #define CMD_SUSPEND 43 /* "suspend the vi session" */
391: #define CMD_TR 44 /* "transliterate chars in the selected lines" */
392: #define CMD_TAG 45 /* "go to a particular tag" */
393: #define CMD_UNABBR 46 /* "remove an abbreviation definition" */
394: #define CMD_UNDO 47 /* "undo the previous command" */
395: #define CMD_UNMAP 48 /* "remove a key sequence map */
396: #define CMD_VERSION 49 /* "describe which version this is" */
397: #define CMD_VGLOBAL 50 /* "apply a cmd to lines NOT containing an RE" */
398: #define CMD_VISUAL 51 /* "go into visual mode" */
399: #define CMD_WQUIT 52 /* "write this file out (any case) & quit" */
400: #define CMD_WRITE 53 /* "write the selected(?) text to a given file" */
401: #define CMD_XIT 54 /* "write this file out (if modified) & quit" */
402: #define CMD_YANK 55 /* "copy the selected text into the cut buffer" */
403: #ifdef DEBUG
404: # define CMD_DEBUG 56 /* access to internal data structures */
405: # define CMD_VALIDATE 57 /* check for internal consistency */
406: #endif
407: typedef int CMD;
408:
409: extern void ex();
410: extern void vi();
411: extern void doexcmd();
412:
413: #ifndef NO_ABBR
414: extern void cmd_abbr();
415: #endif
416: extern void cmd_append();
417: extern void cmd_args();
418: #ifndef NO_AT
419: extern void cmd_at();
420: #endif
421: extern void cmd_cd();
422: extern void cmd_delete();
423: #ifndef NO_DIGRAPH
424: extern void cmd_digraph();
425: #endif
426: extern void cmd_edit();
427: #ifndef NO_ERRLIST
428: extern void cmd_errlist();
429: #endif
430: extern void cmd_file();
431: extern void cmd_global();
432: extern void cmd_join();
433: extern void cmd_mark();
434: #ifndef NO_ERRLIST
435: extern void cmd_make();
436: #endif
437: extern void cmd_map();
438: #ifndef NO_MKEXRC
439: extern void cmd_mkexrc();
440: #endif
441: extern void cmd_next();
442: extern void cmd_print();
443: extern void cmd_put();
444: extern void cmd_read();
445: extern void cmd_set();
446: extern void cmd_shell();
447: extern void cmd_shift();
448: extern void cmd_source();
449: extern void cmd_substitute();
450: extern void cmd_tag();
451: extern void cmd_undo();
452: extern void cmd_version();
453: extern void cmd_visual();
454: extern void cmd_write();
455: extern void cmd_xit();
456: extern void cmd_move();
457: #ifdef DEBUG
458: extern void cmd_debug();
459: extern void cmd_validate();
460: #endif
461:
462: /*----------------------------------------------------------------------*/
463: /* These are used to handle VI commands */
464:
465: extern MARK v_1ex(); /* : */
466: extern MARK v_mark(); /* m */
467: extern MARK v_quit(); /* Q */
468: extern MARK v_redraw(); /* ^L ^R */
469: extern MARK v_ulcase(); /* ~ */
470: extern MARK v_undo(); /* u */
471: extern MARK v_xchar(); /* x */
472: extern MARK v_Xchar(); /* X */
473: extern MARK v_replace(); /* r */
474: extern MARK v_overtype(); /* R */
475: extern MARK v_selcut(); /* " */
476: extern MARK v_paste(); /* p P */
477: extern MARK v_yank(); /* y Y */
478: extern MARK v_delete(); /* d D */
479: extern MARK v_join(); /* J */
480: extern MARK v_insert(); /* a A i I o O */
481: extern MARK v_change(); /* c C */
482: extern MARK v_subst(); /* s */
483: extern MARK v_lshift(); /* < */
484: extern MARK v_rshift(); /* > */
485: extern MARK v_filter(); /* ! */
486: extern MARK v_status(); /* ^G */
487: extern MARK v_switch(); /* ^^ */
488: extern MARK v_tag(); /* ^] */
489: extern MARK v_xit(); /* ZZ */
490: extern MARK v_undoline(); /* U */
491: extern MARK v_again(); /* & */
492: #ifndef NO_EXTENSIONS
493: extern MARK v_keyword(); /* ^K */
494: extern MARK v_increment(); /* * */
495: #endif
496: #ifndef NO_ERRLIST
497: extern MARK v_errlist(); /* * */
498: #endif
499: #ifndef NO_AT
500: extern MARK v_at(); /* @ */
501: #endif
502:
503: /*----------------------------------------------------------------------*/
504: /* These describe what mode we're in */
505:
506: #define MODE_EX 1 /* executing ex commands */
507: #define MODE_VI 2 /* executing vi commands */
508: #define MODE_COLON 3 /* executing an ex command from vi mode */
509: #define MODE_QUIT 4
510: extern int mode;
511:
512: #define WHEN_VICMD 1 /* getkey: we're reading a VI command */
513: #define WHEN_VIINP 2 /* getkey: we're in VI's INPUT mode */
514: #define WHEN_VIREP 4 /* getkey: we're in VI's REPLACE mode */
515: #define WHEN_EX 8 /* getkey: we're in EX mode */
516: #define WHEN_MSG 16 /* getkey: we're at a "more" prompt */
517: #define WHEN_INMV 256 /* in input mode, interpret the key in VICMD mode */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.