Annotation of src/usr.bin/mg/def.h, Revision 1.10
1.10 ! art 1: /* $OpenBSD: def.h,v 1.9 2001/05/03 20:40:22 art Exp $ */
1.6 niklas 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.7 art 46: #define NFILEN 1024 /* Length, file name. */
47: #define NBUFN NFILEN /* Length, buffer name. */
1.4 millert 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));
1.9 art 303: int ttwait __P((int));
1.5 millert 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: int filewrite __P((int, int));
332: int filesave __P((int, int));
333: int buffsave __P((BUFFER *));
334: int makebkfile __P((int, int));
335: int writeout __P((BUFFER *, char *));
336: VOID upmodes __P((BUFFER *));
337:
338: /* line.c X */
339: LINE *lalloc __P((int));
340: LINE *lallocx __P((int));
341: VOID lfree __P((LINE *));
342: VOID lchange __P((int));
343: int linsert __P((int, int));
344: int lnewline __P((void));
345: int ldelete __P((RSIZE, int));
346: int ldelnewline __P((void));
347: int lreplace __P((RSIZE, char *, int));
348: VOID kdelete __P((void));
349: int kinsert __P((int, int));
350: int kremove __P((int));
351:
352: /* window.c X */
353: int reposition __P((int, int));
354: int refresh __P((int, int));
355: int nextwind __P((int, int));
356: int prevwind __P((int, int));
357: int onlywind __P((int, int));
358: int splitwind __P((int, int));
359: int enlargewind __P((int, int));
360: int shrinkwind __P((int, int));
361: int delwind __P((int, int));
362: MGWIN *wpopup __P((void));
1.4 millert 363:
364: /* buffer.c */
1.5 millert 365: BUFFER *bfind __P((char *, int));
366: int poptobuffer __P((int, int));
367: int killbuffer __P((int, int));
368: int savebuffers __P((int, int));
369: int listbuffers __P((int, int));
370: int addline __P((BUFFER *, char *));
371: int anycb __P((int));
372: int bclear __P((BUFFER *));
373: int showbuffer __P((BUFFER *, MGWIN *, int));
374: MGWIN *popbuf __P((BUFFER *));
375: int bufferinsert __P((int, int));
376: int usebuffer __P((int, int));
377: int notmodified __P((int, int));
378: int popbuftop __P((BUFFER *));
1.4 millert 379:
380: /* display.c */
1.5 millert 381: VOID vtinit __P((void));
382: VOID vttidy __P((void));
383: VOID update __P((void));
384:
385: /* echo.c X */
386: VOID eerase __P((void));
387: int eyorn __P((char *));
388: int eyesno __P((char *));
389: VOID ewprintf __P((const char *fmt, ...));
390: int ereply __P((const char *, char *, int, ...));
391: int eread __P((const char *, char *, int, int, ...));
392: int getxtra __P((LIST *, LIST *, int, int));
1.4 millert 393:
394: /* fileio.c */
1.5 millert 395: int ffropen __P((char *, BUFFER *));
396: int ffwopen __P((char *, BUFFER *));
397: int ffclose __P((BUFFER *));
398: int ffputbuf __P((BUFFER *));
399: int ffgetline __P((char *, int, int *));
400: int fbackupfile __P((char *));
401: char *adjustname __P((char *));
402: char *startupfile __P((char *));
403: int copy __P((char *, char *));
404: BUFFER *dired_ __P((char *));
405: int d_makename __P((LINE *, char *));
1.8 art 406: LIST *make_file_list __P((char *));
1.4 millert 407:
1.5 millert 408: /* keymap.c X */
409: int complete_function __P((char *, int));
1.4 millert 410: LIST *complete_function_list __P((char *, int));
411:
1.5 millert 412: /* kbd.c X */
413: int do_meta __P((int, int));
414: int bsmap __P((int, int));
415: VOID ungetkey __P((int));
416: int getkey __P((int));
417: int doin __P((void));
418: int rescan __P((int, int));
419: int universal_argument __P((int, int));
420: int digit_argument __P((int, int));
421: int negative_argument __P((int, int));
422: int selfinsert __P((int, int));
423: int quote __P((int, int));
1.4 millert 424:
425: /* main.c */
1.5 millert 426: int ctrlg __P((int, int));
427: int quit __P((int, int));
1.4 millert 428:
429: /* ttyio.c */
1.5 millert 430: VOID panic __P((char *));
1.4 millert 431:
432: /* cinfo.c */
1.5 millert 433: char *keyname __P((char *, int));
1.4 millert 434:
435: /* basic.c */
1.5 millert 436: int gotobol __P((int, int));
437: int backchar __P((int, int));
438: int gotoeol __P((int, int));
439: int forwchar __P((int, int));
440: int gotobob __P((int, int));
441: int gotoeob __P((int, int));
442: int forwline __P((int, int));
443: int backline __P((int, int));
444: VOID setgoal __P((void));
445: int getgoal __P((LINE *));
446: int forwpage __P((int, int));
447: int backpage __P((int, int));
448: int forw1page __P((int, int));
449: int back1page __P((int, int));
450: int pagenext __P((int, int));
451: VOID isetmark __P((VOID));
452: int setmark __P((int, int));
453: int swapmark __P((int, int));
454: int gotoline __P((int, int));
455:
456: /* random.c X */
457: int showcpos __P((int, int));
458: int getcolpos __P((void));
459: int twiddle __P((int, int));
460: int openline __P((int, int));
461: int newline __P((int, int));
462: int deblank __P((int, int));
463: int justone __P((int, int));
464: int delwhite __P((int, int));
465: int indent __P((int, int));
466: int forwdel __P((int, int));
467: int backdel __P((int, int));
468: int killline __P((int, int));
469: int yank __P((int, int));
470: int space_to_tabstop __P((int, int));
471:
472: /* extend.c X */
473: int insert __P((int, int));
474: int bindtokey __P((int, int));
475: int localbind __P((int, int));
476: int define_key __P((int, int));
477: int unbindtokey __P((int, int));
478: int localunbind __P((int, int));
479: int extend __P((int, int));
480: int evalexpr __P((int, int));
481: int evalbuffer __P((int, int));
482: int evalfile __P((int, int));
483: int load __P((char *));
484: int excline __P((char *));
485:
486: /* help.c X */
487: int desckey __P((int, int));
488: int wallchart __P((int, int));
489: int help_help __P((int, int));
490: int apropos_command __P((int, int));
491:
492: /* paragraph.c X */
493: int gotobop __P((int, int));
494: int gotoeop __P((int, int));
495: int fillpara __P((int, int));
496: int killpara __P((int, int));
497: int fillword __P((int, int));
498: int setfillcol __P((int, int));
499:
500: /* word.c X */
501: int backword __P((int, int));
502: int forwword __P((int, int));
503: int upperword __P((int, int));
504: int lowerword __P((int, int));
505: int capword __P((int, int));
506: int delfword __P((int, int));
507: int delbword __P((int, int));
508: int inword __P((void));
509:
510: /* region.c X */
511: int killregion __P((int, int));
512: int copyregion __P((int, int));
513: int lowerregion __P((int, int));
514: int upperregion __P((int, int));
515: int prefixregion __P((int, int));
516: int setprefix __P((int, int));
517:
518: /* search.c X */
519: int forwsearch __P((int, int));
520: int backsearch __P((int, int));
521: int searchagain __P((int, int));
522: int forwisearch __P((int, int));
523: int backisearch __P((int, int));
524: int queryrepl __P((int, int));
525: int forwsrch __P((void));
526: int backsrch __P((void));
527: int readpattern __P((char *));
528:
529: /* spawn.c X */
530: int spawncli __P((int, int));
531:
532: /* ttykbd.c X */
533: void ttykeymapinit __P((void));
534: void ttykeymaptidy __P((void));
535:
536: /* match.c X */
537: int showmatch __P((int, int));
538:
539: /* version.c X */
540: int showversion __P((int, int));
541:
542: #ifndef NO_MACRO
543: /* macro.c X */
544: int definemacro __P((int, int));
545: int finishmacro __P((int, int));
546: int executemacro __P((int, int));
547: #endif /* !NO_MACRO */
548:
549: /* modes.c X */
550: int indentmode __P((int, int));
551: int fillmode __P((int, int));
552: int blinkparen __P((int, int));
553: #ifdef NOTAB
554: int notabmode __P((int, int));
555: #endif /* NOTAB */
556: int overwrite __P((int, int));
557: int set_default_mode __P((int,int));
558:
559: #ifdef REGEX
560: /* re_search.c X */
561: int re_forwsearch __P((int, int));
562: int re_backsearch __P((int, int));
563: int re_searchagain __P((int, int));
564: int re_queryrepl __P((int, int));
565: int setcasefold __P((int, int));
566: int delmatchlines __P((int, int));
567: int delnonmatchlines __P((int, int));
568: int cntmatchlines __P((int, int));
569: int cntnonmatchlines __P((int, int));
570: #endif /* REGEX */
1.1 deraadt 571:
572: /*
573: * Externals.
574: */
1.5 millert 575: extern BUFFER *bheadp;
576: extern BUFFER *curbp;
577: extern MGWIN *curwp;
578: extern MGWIN *wheadp;
579: extern int thisflag;
580: extern int lastflag;
581: extern int curgoal;
582: extern int epresf;
583: extern int sgarbf;
584: extern int mode;
585: extern int nrow;
586: extern int ncol;
587: extern int ttrow;
588: extern int ttcol;
589: extern int tttop;
590: extern int ttbot;
591: extern int tthue;
592: extern int nmaps;
593: extern int nfunct;
594: extern int defb_nmodes;
595: extern int defb_flag;
596: extern char cinfo[];
597: extern char *keystrings[];
598: extern char pat[];
599: #ifndef NO_DPROMPT
600: extern char prompt[];
601: extern char *promptp;
602: #endif /* !NO_DPROMPT */
603:
604: /*
605: * Globals.
606: */
607: int tceeol;
608: int tcinsl;
609: int tcdell;
610: