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