Annotation of src/usr.bin/mg/def.h, Revision 1.6
1.6 ! niklas 1: /* $OpenBSD$ */
! 2:
1.1 deraadt 3: /*
4: * This file is the general header file for all parts
1.4 millert 5: * of the Mg display editor. It contains all of the
1.1 deraadt 6: * general definitions and macros. It also contains some
7: * conditional compilation flags. All of the per-system and
8: * per-terminal definitions are in special header files.
9: * The most common reason to edit this file would be to zap
10: * the definition of CVMVAS or BACKUP.
11: */
1.4 millert 12: #include "sysdef.h" /* Order is critical. */
1.1 deraadt 13: #include "ttydef.h"
14: #include "chrdef.h"
15:
16: /*
17: * If your system and/or compiler does not support the "void" type
18: * then define NO_VOID_TYPE in sysdef.h. In the absence of some
19: * other definition for VOID, the default in that case will be to
20: * turn it into an int, which works with most compilers that don't
21: * support void. In the absence of any definition of VOID or
22: * NO_VOID_TYPE, the default is to assume void is supported, which
23: * should be the case for most modern C compilers.
24: */
25:
26: #ifdef NO_VOID_TYPE
1.4 millert 27: #undef VOID
28: #define VOID int /* Default for no void is int */
1.1 deraadt 29: #else
30: #ifndef VOID
1.4 millert 31: #define VOID void /* Just use normal void */
32: #endif /* VOID */
33: #endif /* NO_VOID_TYPE */
1.1 deraadt 34:
35: #ifdef NO_MACRO
36: #ifndef NO_STARTUP
1.4 millert 37: #define NO_STARTUP /* NO_MACRO implies NO_STARTUP */
1.1 deraadt 38: #endif
39: #endif
40:
1.5 millert 41: typedef int (*PF)(); /* generally useful type */
1.1 deraadt 42:
43: /*
44: * Table sizes, etc.
45: */
1.4 millert 46: #define NFILEN 80 /* Length, file name. */
47: #define NBUFN 24 /* Length, buffer name. */
48: #define NLINE 256 /* Length, line. */
49: #define PBMODES 4 /* modes per buffer */
50: #define NKBDM 256 /* Length, keyboard macro. */
51: #define NPAT 80 /* Length, pattern. */
52: #define HUGE 1000 /* A rather large number. */
53: #define NSRCH 128 /* Undoable search commands. */
54: #define NXNAME 64 /* Length, extended command. */
55: #define NKNAME 20 /* Length, key names */
1.1 deraadt 56: /*
57: * Universal.
58: */
1.4 millert 59: #define FALSE 0 /* False, no, bad, etc. */
60: #define TRUE 1 /* True, yes, good, etc. */
61: #define ABORT 2 /* Death, ^G, abort, etc. */
1.1 deraadt 62:
1.4 millert 63: #define KPROMPT 2 /* keyboard prompt */
1.1 deraadt 64:
65: /*
66: * These flag bits keep track of
67: * some aspects of the last command. The CFCPCN
68: * flag controls goal column setting. The CFKILL
69: * flag controls the clearing versus appending
70: * of data in the kill buffer.
71: */
1.4 millert 72: #define CFCPCN 0x0001 /* Last command was C-P, C-N */
73: #define CFKILL 0x0002 /* Last command was a kill */
74: #define CFINS 0x0004 /* Last command was self-insert */
1.1 deraadt 75:
76: /*
77: * File I/O.
78: */
1.4 millert 79: #define FIOSUC 0 /* Success. */
80: #define FIOFNF 1 /* File not found. */
81: #define FIOEOF 2 /* End of file. */
82: #define FIOERR 3 /* Error. */
83: #define FIOLONG 4 /* long line partially read */
1.1 deraadt 84:
85: /*
86: * Directory I/O.
87: */
1.4 millert 88: #define DIOSUC 0 /* Success. */
89: #define DIOEOF 1 /* End of file. */
90: #define DIOERR 2 /* Error. */
1.1 deraadt 91:
92: /*
93: * Display colors.
94: */
1.4 millert 95: #define CNONE 0 /* Unknown color. */
96: #define CTEXT 1 /* Text color. */
97: #define CMODE 2 /* Mode line color. */
98:
99: /*
100: * Flags for keyboard involked functions.
101: */
102: #define FFUNIV 1 /* universal argument */
103: #define FFNEGARG 2 /* negitive only argument */
104: #define FFOTHARG 4 /* other argument */
105: #define FFARG 7 /* any argument */
106: #define FFRAND 8 /* Called by other function */
1.1 deraadt 107:
108: /*
109: * Flags for "eread".
110: */
1.4 millert 111: #define EFFUNC 0x0001 /* Autocomplete functions. */
112: #define EFBUF 0x0002 /* Autocomplete buffers. */
113: #define EFFILE 0x0004 /* " files (maybe someday) */
114: #define EFAUTO 0x0007 /* Some autocompleteion on */
115: #define EFNEW 0x0008 /* New prompt. */
116: #define EFCR 0x0010 /* Echo CR at end; last read. */
1.1 deraadt 117:
118: /*
119: * Flags for "ldelete"/"kinsert"
120: */
121: #define KNONE 0
122: #define KFORW 1
123: #define KBACK 2
124:
125: /*
126: * All text is kept in circularly linked
127: * lists of "LINE" structures. These begin at the
128: * header line (which is the blank line beyond the
129: * end of the buffer). This line is pointed to by
130: * the "BUFFER". Each line contains a the number of
131: * bytes in the line (the "used" size), the size
132: * of the text array, and the text. The end of line
133: * is not stored as a byte; it's implied. Future
134: * additions will include update hints, and a
135: * list of marks into the line.
136: */
1.4 millert 137: typedef struct LINE {
138: struct LINE *l_fp; /* Link to the next line */
139: struct LINE *l_bp; /* Link to the previous line */
140: int l_size; /* Allocated size */
141: int l_used; /* Used size */
1.1 deraadt 142: #ifndef ZEROARRAY
1.4 millert 143: char l_text[1]; /* A bunch of chars. */
1.1 deraadt 144: #else
1.4 millert 145: char l_text[]; /* A bunch of chars. */
1.1 deraadt 146: #endif
1.4 millert 147: } LINE;
1.1 deraadt 148:
149: /*
150: * The rationale behind these macros is that you
151: * could (with some editing, like changing the type of a line
152: * link from a "LINE *" to a "REFLINE", and fixing the commands
153: * like file reading that break the rules) change the actual
154: * storage representation of lines to use something fancy on
155: * machines with small address spaces.
156: */
157: #define lforw(lp) ((lp)->l_fp)
158: #define lback(lp) ((lp)->l_bp)
159: #define lgetc(lp, n) (CHARMASK((lp)->l_text[(n)]))
160: #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
161: #define llength(lp) ((lp)->l_used)
162: #define ltext(lp) ((lp)->l_text)
163:
164: /*
165: * All repeated structures are kept as linked lists of structures.
166: * All of these start with a LIST structure (except lines, which
167: * have their own abstraction). This will allow for
168: * later conversion to generic list manipulation routines should
169: * I decide to do that. it does mean that there are four extra
170: * bytes per window. I feel that this is an acceptable price,
171: * considering that there are usually only one or two windows.
172: */
173: typedef struct LIST {
174: union {
1.4 millert 175: struct MGWIN *l_wp;
176: struct BUFFER *x_bp; /* l_bp is used by LINE */
177: struct LIST *l_nxt;
1.1 deraadt 178: } l_p;
1.4 millert 179: char *l_name;
1.1 deraadt 180: } LIST;
1.4 millert 181:
1.1 deraadt 182: /*
183: * Usual hack - to keep from uglifying the code with lotsa
184: * references through the union, we #define something for it.
185: */
186: #define l_next l_p.l_nxt
187:
188: /*
189: * There is a window structure allocated for
190: * every active display window. The windows are kept in a
191: * big list, in top to bottom screen order, with the listhead at
192: * "wheadp". Each window contains its own values of dot and mark.
193: * The flag field contains some bits that are set by commands
194: * to guide redisplay; although this is a bit of a compromise in
195: * terms of decoupling, the full blown redisplay is just too
196: * expensive to run for every input character.
197: */
1.4 millert 198: typedef struct MGWIN {
199: LIST w_list; /* List header */
200: struct BUFFER *w_bufp; /* Buffer displayed in window */
201: struct LINE *w_linep; /* Top line in the window */
202: struct LINE *w_dotp; /* Line containing "." */
203: struct LINE *w_markp; /* Line containing "mark" */
204: int w_doto; /* Byte offset for "." */
205: int w_marko; /* Byte offset for "mark" */
206: char w_toprow; /* Origin 0 top row of window */
207: char w_ntrows; /* # of rows of text in window */
208: char w_force; /* If NZ, forcing row. */
209: char w_flag; /* Flags. */
210: } MGWIN;
1.1 deraadt 211: #define w_wndp w_list.l_p.l_wp
212: #define w_name w_list.l_name
213:
214: /*
215: * Window flags are set by command processors to
216: * tell the display system what has happened to the buffer
217: * mapped by the window. Setting "WFHARD" is always a safe thing
218: * to do, but it may do more work than is necessary. Always try
219: * to set the simplest action that achieves the required update.
220: * Because commands set bits in the "w_flag", update will see
221: * all change flags, and do the most general one.
222: */
1.4 millert 223: #define WFFORCE 0x01 /* Force reframe. */
224: #define WFMOVE 0x02 /* Movement from line to line. */
225: #define WFEDIT 0x04 /* Editing within a line. */
226: #define WFHARD 0x08 /* Better to a full display. */
227: #define WFMODE 0x10 /* Update mode line. */
1.1 deraadt 228:
229: /*
230: * Text is kept in buffers. A buffer header, described
231: * below, exists for every buffer in the system. The buffers are
232: * kept in a big list, so that commands that search for a buffer by
233: * name can find the buffer header. There is a safe store for the
234: * dot and mark in the header, but this is only valid if the buffer
235: * is not being displayed (that is, if "b_nwnd" is 0). The text for
236: * the buffer is kept in a circularly linked list of lines, with
237: * a pointer to the header line in "b_linep".
238: */
1.4 millert 239: typedef struct BUFFER {
240: LIST b_list; /* buffer list pointer */
241: struct BUFFER *b_altb; /* Link to alternate buffer */
242: struct LINE *b_dotp; /* Link to "." LINE structure */
243: struct LINE *b_markp; /* ditto for mark */
244: struct LINE *b_linep; /* Link to the header LINE */
245: struct MAPS_S *b_modes[PBMODES]; /* buffer modes */
246: int b_doto; /* Offset of "." in above LINE */
247: int b_marko; /* ditto for the "mark" */
248: short b_nmodes; /* number of non-fundamental modes */
249: char b_nwnd; /* Count of windows on buffer */
250: char b_flag; /* Flags */
251: char b_fname[NFILEN];/* File name */
252: struct fileinfo b_fi; /* File attributes */
253: } BUFFER;
1.1 deraadt 254: #define b_bufp b_list.l_p.x_bp
255: #define b_bname b_list.l_name
256:
1.4 millert 257: #define BFCHG 0x01 /* Changed. */
258: #define BFBAK 0x02 /* Need to make a backup. */
1.1 deraadt 259: #ifdef NOTAB
1.4 millert 260: #define BFNOTAB 0x04 /* no tab mode */
1.1 deraadt 261: #endif
1.4 millert 262: #define BFOVERWRITE 0x08 /* overwrite mode */
1.1 deraadt 263:
264: /*
265: * This structure holds the starting position
266: * (as a line/offset pair) and the number of characters in a
267: * region of a buffer. This makes passing the specification
268: * of a region around a little bit easier.
269: */
1.4 millert 270: typedef struct {
271: struct LINE *r_linep; /* Origin LINE address. */
272: int r_offset; /* Origin LINE offset. */
273: RSIZE r_size; /* Length in characters. */
274: } REGION;
275:
276: /*
277: * Prototypes.
278: */
279:
1.5 millert 280: /* tty.c X */
281: VOID ttinit __P((void));
282: VOID ttreinit __P((void));
283: VOID tttidy __P((void));
284: VOID ttmove __P((int, int));
285: VOID tteeol __P((void));
286: VOID tteeop __P((void));
287: VOID ttbeep __P((void));
288: VOID ttinsl __P((int, int, int));
289: VOID ttdell __P((int, int, int));
290: VOID ttwindow __P((int, int));
291: VOID ttnowindow __P((void));
292: VOID ttcolor __P((int));
293: VOID ttresize __P((void));
1.4 millert 294:
295: /* ttyio.c */
1.5 millert 296: VOID ttopen __P((void));
297: int ttraw __P((void));
298: VOID ttclose __P((void));
299: int ttcooked __P((void));
300: int ttputc __P((int));
301: VOID ttflush __P((void));
302: int ttgetc __P((void));
303: int ttwait __P((void));
304: VOID setttysize __P((void));
305: int typeahead __P((void));
1.4 millert 306:
307: /* dir.c */
1.5 millert 308: VOID dirinit __P((VOID));
309: int changedir __P((int, int));
310: int showcwdir __P((int, int));
1.4 millert 311:
312: /* dired.c */
1.5 millert 313: int dired __P((int, int));
314: int d_otherwindow __P((int, int));
315: int d_undel __P((int, int));
316: int d_undelbak __P((int, int));
317: int d_findfile __P((int, int));
318: int d_ffotherwindow __P((int, int));
319: int d_expunge __P((int, int));
320: int d_copy __P((int, int));
321: int d_del __P((int, int));
322: int d_rename __P((int, int));
323:
324: /* file.c X */
325: int fileinsert __P((int, int));
326: int filevisit __P((int, int));
327: int poptofile __P((int, int));
328: BUFFER *findbuffer __P((char *));
329: int readin __P((char *));
330: int insertfile __P((char *, char *, int));
331: VOID makename __P((char *, char *));
332: int filewrite __P((int, int));
333: int filesave __P((int, int));
334: int buffsave __P((BUFFER *));
335: int makebkfile __P((int, int));
336: int writeout __P((BUFFER *, char *));
337: VOID upmodes __P((BUFFER *));
338:
339: /* line.c X */
340: LINE *lalloc __P((int));
341: LINE *lallocx __P((int));
342: VOID lfree __P((LINE *));
343: VOID lchange __P((int));
344: int linsert __P((int, int));
345: int lnewline __P((void));
346: int ldelete __P((RSIZE, int));
347: int ldelnewline __P((void));
348: int lreplace __P((RSIZE, char *, int));
349: VOID kdelete __P((void));
350: int kinsert __P((int, int));
351: int kremove __P((int));
352:
353: /* window.c X */
354: int reposition __P((int, int));
355: int refresh __P((int, int));
356: int nextwind __P((int, int));
357: int prevwind __P((int, int));
358: int onlywind __P((int, int));
359: int splitwind __P((int, int));
360: int enlargewind __P((int, int));
361: int shrinkwind __P((int, int));
362: int delwind __P((int, int));
363: MGWIN *wpopup __P((void));
1.4 millert 364:
365: /* buffer.c */
1.5 millert 366: BUFFER *bfind __P((char *, int));
367: int poptobuffer __P((int, int));
368: int killbuffer __P((int, int));
369: int savebuffers __P((int, int));
370: int listbuffers __P((int, int));
371: int addline __P((BUFFER *, char *));
372: int anycb __P((int));
373: int bclear __P((BUFFER *));
374: int showbuffer __P((BUFFER *, MGWIN *, int));
375: MGWIN *popbuf __P((BUFFER *));
376: int bufferinsert __P((int, int));
377: int usebuffer __P((int, int));
378: int notmodified __P((int, int));
379: int popbuftop __P((BUFFER *));
1.4 millert 380:
381: /* display.c */
1.5 millert 382: VOID vtinit __P((void));
383: VOID vttidy __P((void));
384: VOID update __P((void));
385:
386: /* echo.c X */
387: VOID eerase __P((void));
388: int eyorn __P((char *));
389: int eyesno __P((char *));
390: VOID ewprintf __P((const char *fmt, ...));
391: int ereply __P((const char *, char *, int, ...));
392: int eread __P((const char *, char *, int, int, ...));
393: int getxtra __P((LIST *, LIST *, int, int));
1.4 millert 394:
395: /* fileio.c */
1.5 millert 396: int ffropen __P((char *, BUFFER *));
397: int ffwopen __P((char *, BUFFER *));
398: int ffclose __P((BUFFER *));
399: int ffputbuf __P((BUFFER *));
400: int ffgetline __P((char *, int, int *));
401: int fbackupfile __P((char *));
402: char *adjustname __P((char *));
403: char *startupfile __P((char *));
404: int copy __P((char *, char *));
405: BUFFER *dired_ __P((char *));
406: int d_makename __P((LINE *, char *));
407: LIST *make_file_list __P((char *, int));
1.4 millert 408:
1.5 millert 409: /* keymap.c X */
410: int complete_function __P((char *, int));
1.4 millert 411: LIST *complete_function_list __P((char *, int));
412:
1.5 millert 413: /* kbd.c X */
414: int do_meta __P((int, int));
415: int bsmap __P((int, int));
416: VOID ungetkey __P((int));
417: int getkey __P((int));
418: int doin __P((void));
419: int rescan __P((int, int));
420: int universal_argument __P((int, int));
421: int digit_argument __P((int, int));
422: int negative_argument __P((int, int));
423: int selfinsert __P((int, int));
424: int quote __P((int, int));
1.4 millert 425:
426: /* main.c */
1.5 millert 427: int ctrlg __P((int, int));
428: int quit __P((int, int));
1.4 millert 429:
430: /* ttyio.c */
1.5 millert 431: VOID panic __P((char *));
1.4 millert 432:
433: /* cinfo.c */
1.5 millert 434: char *keyname __P((char *, int));
1.4 millert 435:
436: /* basic.c */
1.5 millert 437: int gotobol __P((int, int));
438: int backchar __P((int, int));
439: int gotoeol __P((int, int));
440: int forwchar __P((int, int));
441: int gotobob __P((int, int));
442: int gotoeob __P((int, int));
443: int forwline __P((int, int));
444: int backline __P((int, int));
445: VOID setgoal __P((void));
446: int getgoal __P((LINE *));
447: int forwpage __P((int, int));
448: int backpage __P((int, int));
449: int forw1page __P((int, int));
450: int back1page __P((int, int));
451: int pagenext __P((int, int));
452: VOID isetmark __P((VOID));
453: int setmark __P((int, int));
454: int swapmark __P((int, int));
455: int gotoline __P((int, int));
456:
457: /* random.c X */
458: int showcpos __P((int, int));
459: int getcolpos __P((void));
460: int twiddle __P((int, int));
461: int openline __P((int, int));
462: int newline __P((int, int));
463: int deblank __P((int, int));
464: int justone __P((int, int));
465: int delwhite __P((int, int));
466: int indent __P((int, int));
467: int forwdel __P((int, int));
468: int backdel __P((int, int));
469: int killline __P((int, int));
470: int yank __P((int, int));
471: int space_to_tabstop __P((int, int));
472:
473: /* extend.c X */
474: int insert __P((int, int));
475: int bindtokey __P((int, int));
476: int localbind __P((int, int));
477: int define_key __P((int, int));
478: int unbindtokey __P((int, int));
479: int localunbind __P((int, int));
480: int extend __P((int, int));
481: int evalexpr __P((int, int));
482: int evalbuffer __P((int, int));
483: int evalfile __P((int, int));
484: int load __P((char *));
485: int excline __P((char *));
486:
487: /* help.c X */
488: int desckey __P((int, int));
489: int wallchart __P((int, int));
490: int help_help __P((int, int));
491: int apropos_command __P((int, int));
492:
493: /* paragraph.c X */
494: int gotobop __P((int, int));
495: int gotoeop __P((int, int));
496: int fillpara __P((int, int));
497: int killpara __P((int, int));
498: int fillword __P((int, int));
499: int setfillcol __P((int, int));
500:
501: /* word.c X */
502: int backword __P((int, int));
503: int forwword __P((int, int));
504: int upperword __P((int, int));
505: int lowerword __P((int, int));
506: int capword __P((int, int));
507: int delfword __P((int, int));
508: int delbword __P((int, int));
509: int inword __P((void));
510:
511: /* region.c X */
512: int killregion __P((int, int));
513: int copyregion __P((int, int));
514: int lowerregion __P((int, int));
515: int upperregion __P((int, int));
516: int prefixregion __P((int, int));
517: int setprefix __P((int, int));
518:
519: /* search.c X */
520: int forwsearch __P((int, int));
521: int backsearch __P((int, int));
522: int searchagain __P((int, int));
523: int forwisearch __P((int, int));
524: int backisearch __P((int, int));
525: int queryrepl __P((int, int));
526: int forwsrch __P((void));
527: int backsrch __P((void));
528: int readpattern __P((char *));
529:
530: /* spawn.c X */
531: int spawncli __P((int, int));
532:
533: /* ttykbd.c X */
534: void ttykeymapinit __P((void));
535: void ttykeymaptidy __P((void));
536:
537: /* match.c X */
538: int showmatch __P((int, int));
539:
540: /* version.c X */
541: int showversion __P((int, int));
542:
543: #ifndef NO_MACRO
544: /* macro.c X */
545: int definemacro __P((int, int));
546: int finishmacro __P((int, int));
547: int executemacro __P((int, int));
548: #endif /* !NO_MACRO */
549:
550: /* modes.c X */
551: int indentmode __P((int, int));
552: int fillmode __P((int, int));
553: int blinkparen __P((int, int));
554: #ifdef NOTAB
555: int notabmode __P((int, int));
556: #endif /* NOTAB */
557: int overwrite __P((int, int));
558: int set_default_mode __P((int,int));
559:
560: #ifdef REGEX
561: /* re_search.c X */
562: int re_forwsearch __P((int, int));
563: int re_backsearch __P((int, int));
564: int re_searchagain __P((int, int));
565: int re_queryrepl __P((int, int));
566: int setcasefold __P((int, int));
567: int delmatchlines __P((int, int));
568: int delnonmatchlines __P((int, int));
569: int cntmatchlines __P((int, int));
570: int cntnonmatchlines __P((int, int));
571: #endif /* REGEX */
1.1 deraadt 572:
573: /*
574: * Externals.
575: */
1.5 millert 576: extern BUFFER *bheadp;
577: extern BUFFER *curbp;
578: extern MGWIN *curwp;
579: extern MGWIN *wheadp;
580: extern int thisflag;
581: extern int lastflag;
582: extern int curgoal;
583: extern int epresf;
584: extern int sgarbf;
585: extern int mode;
586: extern int nrow;
587: extern int ncol;
588: extern int ttrow;
589: extern int ttcol;
590: extern int tttop;
591: extern int ttbot;
592: extern int tthue;
593: extern int nmaps;
594: extern int nfunct;
595: extern int defb_nmodes;
596: extern int defb_flag;
597: extern char cinfo[];
598: extern char *keystrings[];
599: extern char pat[];
600: #ifndef NO_DPROMPT
601: extern char prompt[];
602: extern char *promptp;
603: #endif /* !NO_DPROMPT */
604:
605: /*
606: * Globals.
607: */
608: int tceeol;
609: int tcinsl;
610: int tcdell;
611: