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