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