1 /* $OpenBSD: def.h,v 1.124 2012/06/14 17:21:22 lum Exp $ */
3 /* This file is in the public domain. */
6 * This file is the general header file for all parts
7 * of the Mg display editor. It contains all of the
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.
13 #include "sysdef.h" /* Order is critical. */
17 typedef int (*PF)(int, int); /* generally useful type */
22 #define NFILEN 1024 /* Length, file name. */
23 #define NBUFN NFILEN /* Length, buffer name. */
24 #define NLINE 256 /* Length, line. */
25 #define PBMODES 4 /* modes per buffer */
26 #define NKBDM 256 /* Length, keyboard macro. */
27 #define NPAT 80 /* Length, pattern. */
28 #define HUGE 1000 /* A rather large number. */
29 #define NSRCH 128 /* Undoable search commands. */
30 #define NXNAME 64 /* Length, extended command. */
31 #define NKNAME 20 /* Length, key names. */
32 #define NTIME 50 /* Length, timestamp string. */
36 #define FALSE 0 /* False, no, bad, etc. */
37 #define TRUE 1 /* True, yes, good, etc. */
38 #define ABORT 2 /* Death, ^G, abort, etc. */
40 #define KCLEAR 2 /* clear echo area */
43 * These flag bits keep track of
44 * some aspects of the last command. The CFCPCN
45 * flag controls goal column setting. The CFKILL
46 * flag controls the clearing versus appending
47 * of data in the kill buffer.
49 #define CFCPCN 0x0001 /* Last command was C-P, C-N */
50 #define CFKILL 0x0002 /* Last command was a kill */
51 #define CFINS 0x0004 /* Last command was self-insert */
56 #define FIOSUC 0 /* Success. */
57 #define FIOFNF 1 /* File not found. */
58 #define FIOEOF 2 /* End of file. */
59 #define FIOERR 3 /* Error. */
60 #define FIOLONG 4 /* long line partially read */
61 #define FIODIR 5 /* File is a directory */
66 #define DIOSUC 0 /* Success. */
67 #define DIOEOF 1 /* End of file. */
68 #define DIOERR 2 /* Error. */
73 #define CNONE 0 /* Unknown color. */
74 #define CTEXT 1 /* Text color. */
75 #define CMODE 2 /* Mode line color. */
78 * Flags for keyboard invoked functions.
80 #define FFUNIV 1 /* universal argument */
81 #define FFNEGARG 2 /* negative only argument */
82 #define FFOTHARG 4 /* other argument */
83 #define FFARG 7 /* any argument */
84 #define FFRAND 8 /* Called by other function */
89 #define EFFUNC 0x0001 /* Autocomplete functions. */
90 #define EFBUF 0x0002 /* Autocomplete buffers. */
91 #define EFFILE 0x0004 /* " files (maybe someday) */
92 #define EFAUTO 0x0007 /* Some autocompletion on */
93 #define EFNEW 0x0008 /* New prompt. */
94 #define EFCR 0x0010 /* Echo CR at end; last read. */
95 #define EFDEF 0x0020 /* buffer contains default args */
96 #define EFNUL 0x0040 /* Null Minibuffer OK */
99 * Direction of insert into kill ring
102 #define KFORW 0x01 /* forward insert into kill ring */
103 #define KBACK 0x02 /* Backwards insert into kill ring */
104 #define KREG 0x04 /* This is a region-based kill */
109 * This structure holds the starting position
110 * (as a line/offset pair) and the number of characters in a
111 * region of a buffer. This makes passing the specification
112 * of a region around a little bit easier.
115 struct line *r_linep; /* Origin line address. */
116 int r_offset; /* Origin line offset. */
117 int r_lineno; /* Origin line number */
118 RSIZE r_size; /* Length in characters. */
123 * All text is kept in circularly linked
124 * lists of "line" structures. These begin at the
125 * header line (which is the blank line beyond the
126 * end of the buffer). This line is pointed to by
127 * the "buffer" structure. Each line contains the number of
128 * bytes in the line (the "used" size), the size
129 * of the text array, and the text. The end of line
130 * is not stored as a byte; it's implied. Future
131 * additions will include update hints, and a
132 * list of marks into the line.
135 struct line *l_fp; /* Link to the next line */
136 struct line *l_bp; /* Link to the previous line */
137 int l_size; /* Allocated size */
138 int l_used; /* Used size */
139 char *l_text; /* Content of the line */
143 * The rationale behind these macros is that you
144 * could (with some editing, like changing the type of a line
145 * link from a "struct line *" to a "REFLINE", and fixing the commands
146 * like file reading that break the rules) change the actual
147 * storage representation of lines to use something fancy on
148 * machines with small address spaces.
150 #define lforw(lp) ((lp)->l_fp)
151 #define lback(lp) ((lp)->l_bp)
152 #define lgetc(lp, n) (CHARMASK((lp)->l_text[(n)]))
153 #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
154 #define llength(lp) ((lp)->l_used)
155 #define ltext(lp) ((lp)->l_text)
158 * All repeated structures are kept as linked lists of structures.
159 * All of these start with a LIST structure (except lines, which
160 * have their own abstraction). This will allow for
161 * later conversion to generic list manipulation routines should
162 * I decide to do that. It does mean that there are four extra
163 * bytes per window. I feel that this is an acceptable price,
164 * considering that there are usually only one or two windows.
169 struct buffer *x_bp; /* l_bp is used by struct line */
176 * Usual hack - to keep from uglifying the code with lotsa
177 * references through the union, we #define something for it.
179 #define l_next l_p.l_nxt
182 * There is a window structure allocated for
183 * every active display window. The windows are kept in a
184 * big list, in top to bottom screen order, with the listhead at
185 * "wheadp". Each window contains its own values of dot and mark.
186 * The flag field contains some bits that are set by commands
187 * to guide redisplay; although this is a bit of a compromise in
188 * terms of decoupling, the full blown redisplay is just too
189 * expensive to run for every input character.
192 struct list w_list; /* List header */
193 struct buffer *w_bufp; /* Buffer displayed in window */
194 struct line *w_linep; /* Top line in the window */
195 struct line *w_dotp; /* Line containing "." */
196 struct line *w_markp; /* Line containing "mark" */
197 int w_doto; /* Byte offset for "." */
198 int w_marko; /* Byte offset for "mark" */
199 int w_toprow; /* Origin 0 top row of window */
200 int w_ntrows; /* # of rows of text in window */
201 int w_frame; /* #lines to reframe by. */
202 char w_rflag; /* Redisplay Flags. */
203 char w_flag; /* Flags. */
204 struct line *w_wrapline;
205 int w_dotline; /* current line number of dot */
206 int w_markline; /* current line number of mark */
208 #define w_wndp w_list.l_p.l_wp
209 #define w_name w_list.l_name
212 * Window redisplay flags are set by command processors to
213 * tell the display system what has happened to the buffer
214 * mapped by the window. Setting "WFFULL" is always a safe thing
215 * to do, but it may do more work than is necessary. Always try
216 * to set the simplest action that achieves the required update.
217 * Because commands set bits in the "w_flag", update will see
218 * all change flags, and do the most general one.
220 #define WFFRAME 0x01 /* Force reframe. */
221 #define WFMOVE 0x02 /* Movement from line to line. */
222 #define WFEDIT 0x04 /* Editing within a line. */
223 #define WFFULL 0x08 /* Do a full display. */
224 #define WFMODE 0x10 /* Update mode line. */
229 #define WNONE 0x00 /* No special window options. */
230 #define WEPHEM 0x01 /* Window is ephemeral. */
233 TAILQ_HEAD(undoq, undo_rec);
236 * Text is kept in buffers. A buffer header, described
237 * below, exists for every buffer in the system. The buffers are
238 * kept in a big list, so that commands that search for a buffer by
239 * name can find the buffer header. There is a safe store for the
240 * dot and mark in the header, but this is only valid if the buffer
241 * is not being displayed (that is, if "b_nwnd" is 0). The text for
242 * the buffer is kept in a circularly linked list of lines, with
243 * a pointer to the header line in "b_headp".
246 struct list b_list; /* buffer list pointer */
247 struct buffer *b_altb; /* Link to alternate buffer */
248 struct line *b_dotp; /* Link to "." line structure */
249 struct line *b_markp; /* ditto for mark */
250 struct line *b_headp; /* Link to the header line */
251 struct maps_s *b_modes[PBMODES]; /* buffer modes */
252 int b_doto; /* Offset of "." in above line */
253 int b_marko; /* ditto for the "mark" */
254 short b_nmodes; /* number of non-fundamental modes */
255 char b_nwnd; /* Count of windows on buffer */
256 char b_flag; /* Flags */
257 char b_fname[NFILEN]; /* File name */
258 char b_cwd[NFILEN]; /* working directory */
259 struct fileinfo b_fi; /* File attributes */
260 struct undoq b_undo; /* Undo actions list */
261 int b_undopos; /* Where we were during last undo */
262 struct undo_rec *b_undoptr;
263 int b_dotline; /* Line number of dot */
264 int b_markline; /* Line number of mark */
265 int b_lines; /* Number of lines in file */
267 #define b_bufp b_list.l_p.x_bp
268 #define b_bname b_list.l_name
270 /* Some helper macros, in case they ever change to functions */
271 #define bfirstlp(buf) (lforw((buf)->b_headp))
272 #define blastlp(buf) (lback((buf)->b_headp))
274 #define BFCHG 0x01 /* Changed. */
275 #define BFBAK 0x02 /* Need to make a backup. */
277 #define BFNOTAB 0x04 /* no tab mode */
279 #define BFOVERWRITE 0x08 /* overwrite mode */
280 #define BFREADONLY 0x10 /* read only mode */
281 #define BFDIRTY 0x20 /* Buffer was modified elsewhere */
282 #define BFIGNDIRTY 0x40 /* Ignore modifications */
284 * This structure holds information about recent actions for the Undo command.
287 TAILQ_ENTRY(undo_rec) next;
295 struct region region;
308 void ttmove(int, int);
312 void ttinsl(int, int, int);
313 void ttdell(int, int, int);
314 void ttwindow(int, int);
315 void ttnowindow(void);
319 volatile sig_atomic_t winch_flag;
330 int charswaiting(void);
334 int changedir(int, int);
335 int showcwdir(int, int);
336 int getcwdir(char *, size_t);
339 struct buffer *dired_(char *);
342 int fileinsert(int, int);
343 int filevisit(int, int);
344 int filevisitalt(int, int);
345 int filevisitro(int, int);
346 int poptofile(int, int);
347 struct buffer *findbuffer(char *);
349 int insertfile(char *, char *, int);
350 int filewrite(int, int);
351 int filesave(int, int);
352 int buffsave(struct buffer *);
353 int makebkfile(int, int);
354 int writeout(FILE **, struct buffer *, char *);
355 void upmodes(struct buffer *);
356 size_t xbasename(char *, const char *, size_t);
359 struct line *lalloc(int);
360 int lrealloc(struct line *, int);
361 void lfree(struct line *);
363 int linsert_str(const char *, int);
364 int linsert(int, int);
365 int lnewline_at(struct line *, int);
367 int ldelete(RSIZE, int);
368 int ldelnewline(void);
369 int lreplace(RSIZE, char *);
370 char * linetostr(const struct line *);
375 int kinsert(int, int);
377 int kchunk(char *, RSIZE, int);
378 int killline(int, int);
382 struct mgwin *new_window(struct buffer *);
383 void free_window(struct mgwin *);
384 int reposition(int, int);
385 int redraw(int, int);
386 int do_redraw(int, int, int);
387 int nextwind(int, int);
388 int prevwind(int, int);
389 int onlywind(int, int);
390 int splitwind(int, int);
391 int enlargewind(int, int);
392 int shrinkwind(int, int);
393 int delwind(int, int);
396 int togglereadonly(int, int);
397 struct buffer *bfind(const char *, int);
398 int poptobuffer(int, int);
399 int killbuffer(struct buffer *);
400 int killbuffer_cmd(int, int);
401 int savebuffers(int, int);
402 int listbuffers(int, int);
403 int addlinef(struct buffer *, char *, ...);
404 #define addline(bp, text) addlinef(bp, "%s", text)
406 int bclear(struct buffer *);
407 int showbuffer(struct buffer *, struct mgwin *, int);
408 int augbname(char *, const char *, size_t);
409 struct mgwin *popbuf(struct buffer *, int);
410 int bufferinsert(int, int);
411 int usebuffer(int, int);
412 int notmodified(int, int);
413 int popbuftop(struct buffer *, int);
414 int getbufcwd(char *, size_t);
415 int checkdirty(struct buffer *);
418 int vtresize(int, int, int);
422 int linenotoggle(int, int);
426 int eyorn(const char *);
427 int eyesno(const char *);
428 void ewprintf(const char *fmt, ...);
429 char *ereply(const char *, char *, size_t, ...);
430 char *eread(const char *, char *, size_t, int, ...);
431 int getxtra(struct list *, struct list *, int, int);
432 void free_file_list(struct list *);
435 int ffropen(FILE **, const char *, struct buffer *);
436 void ffstat(FILE *, struct buffer *);
437 int ffwopen(FILE **, const char *, struct buffer *);
438 int ffclose(FILE *, struct buffer *);
439 int ffputbuf(FILE *, struct buffer *);
440 int ffgetline(FILE *, char *, int, int *);
441 int fbackupfile(const char *);
442 char *adjustname(const char *, int);
443 char *startupfile(char *);
444 int copy(char *, char *);
445 struct list *make_file_list(char *);
446 int fisdir(const char *);
447 int fchecktime(struct buffer *);
448 int fupdstat(struct buffer *);
449 int backuptohomedir(int, int);
450 int toggleleavetmp(int, int);
453 int do_meta(int, int);
458 int rescan(int, int);
459 int universal_argument(int, int);
460 int digit_argument(int, int);
461 int negative_argument(int, int);
462 int selfinsert(int, int);
473 char *getkeyname(char *, size_t, int);
476 int gotobol(int, int);
477 int backchar(int, int);
478 int gotoeol(int, int);
479 int forwchar(int, int);
480 int gotobob(int, int);
481 int gotoeob(int, int);
482 int forwline(int, int);
483 int backline(int, int);
485 int getgoal(struct line *);
486 int forwpage(int, int);
487 int backpage(int, int);
488 int forw1page(int, int);
489 int back1page(int, int);
490 int pagenext(int, int);
492 int setmark(int, int);
493 int clearmark(int, int);
494 int swapmark(int, int);
495 int gotoline(int, int);
498 int showcpos(int, int);
500 int twiddle(int, int);
501 int openline(int, int);
502 int newline(int, int);
503 int deblank(int, int);
504 int justone(int, int);
505 int delwhite(int, int);
506 int delleadwhite(int, int);
507 int deltrailwhite(int, int);
508 int lfindent(int, int);
509 int indent(int, int);
510 int forwdel(int, int);
511 int backdel(int, int);
512 int space_to_tabstop(int, int);
513 int backtoindent(int, int);
514 int joinline(int, int);
517 int findtag(int, int);
518 int poptag(int, int);
519 int tagsvisit(int, int);
520 int curtoken(int, int, char *);
523 int cssymbol(int, int);
524 int csdefinition(int, int);
525 int csfuncalled(int, int);
526 int cscallerfuncs(int, int);
527 int csfindtext(int, int);
528 int csegrep(int, int);
529 int csfindfile(int, int);
530 int csfindinc(int, int);
531 int csnextfile(int, int);
532 int csnextmatch(int, int);
533 int csprevfile(int, int);
534 int csprevmatch(int, int);
535 int cscreatelist(int, int);
538 int insert(int, int);
539 int bindtokey(int, int);
540 int localbind(int, int);
541 int redefine_key(int, int);
542 int unbindtokey(int, int);
543 int localunbind(int, int);
544 int extend(int, int);
545 int evalexpr(int, int);
546 int evalbuffer(int, int);
547 int evalfile(int, int);
548 int load(const char *);
552 int desckey(int, int);
553 int wallchart(int, int);
554 int help_help(int, int);
555 int apropos_command(int, int);
558 int gotobop(int, int);
559 int gotoeop(int, int);
560 int fillpara(int, int);
561 int killpara(int, int);
562 int fillword(int, int);
563 int setfillcol(int, int);
566 int backword(int, int);
567 int forwword(int, int);
568 int upperword(int, int);
569 int lowerword(int, int);
570 int capword(int, int);
571 int delfword(int, int);
572 int delbword(int, int);
576 int killregion(int, int);
577 int copyregion(int, int);
578 int lowerregion(int, int);
579 int upperregion(int, int);
580 int prefixregion(int, int);
581 int setprefix(int, int);
582 int region_get_data(struct region *, char *, int);
583 void region_put_data(const char *, int);
584 int markbuffer(int, int);
585 int piperegion(int, int);
588 int forwsearch(int, int);
589 int backsearch(int, int);
590 int searchagain(int, int);
591 int forwisearch(int, int);
592 int backisearch(int, int);
593 int queryrepl(int, int);
596 int readpattern(char *);
599 int spawncli(int, int);
602 void ttykeymapinit(void);
603 void ttykeymaptidy(void);
606 int showmatch(int, int);
609 int showversion(int, int);
612 int definemacro(int, int);
613 int finishmacro(int, int);
614 int executemacro(int, int);
617 int indentmode(int, int);
618 int fillmode(int, int);
619 int blinkparen(int, int);
621 int notabmode(int, int);
623 int overwrite_mode(int, int);
624 int set_default_mode(int,int);
628 int re_forwsearch(int, int);
629 int re_backsearch(int, int);
630 int re_searchagain(int, int);
631 int re_queryrepl(int, int);
632 int replstr(int, int);
633 int setcasefold(int, int);
634 int delmatchlines(int, int);
635 int delnonmatchlines(int, int);
636 int cntmatchlines(int, int);
637 int cntnonmatchlines(int, int);
641 void free_undo_record(struct undo_rec *);
642 int undo_dump(int, int);
643 int undo_enabled(void);
644 int undo_enable(int, int);
645 int undo_add_boundary(int, int);
646 void undo_add_modified(void);
647 int undo_add_insert(struct line *, int, int);
648 int undo_add_delete(struct line *, int, int, int);
649 int undo_boundary_enable(int, int);
650 int undo_add_change(struct line *, int, int);
654 int auto_execute(int, int);
655 PF *find_autoexec(const char *);
656 int add_autoexec(const char *, const char *);
660 int cc_brace(int, int);
661 int cc_char(int, int);
662 int cc_tab(int, int);
663 int cc_indent(int, int);
664 int cc_lfindent(int, int);
667 int next_error(int, int);
668 int globalwdtoggle(int, int);
669 int compile(int, int);
674 extern struct buffer *bheadp;
675 extern struct buffer *curbp;
676 extern struct mgwin *curwp;
677 extern struct mgwin *wheadp;
692 extern int defb_nmodes;
693 extern int defb_flag;
695 extern char *keystrings[];
696 extern char pat[NPAT];
698 extern char prompt[];
699 #endif /* !NO_DPROMPT */
707 int rptcount; /* successive invocation count */