source: trunk/minix/commands/elvis/vi.h@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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