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