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