home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / uemacs / part1 / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  10.7 KB  |  343 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Common header file.
  4.  * Version:    29
  5.  * Last edit:    14-Feb-86
  6.  * By:        rex::conroy
  7.  *        decvax!decwrl!dec-rhea!dec-rex!conroy
  8.  * 
  9.  * This file is the general header file for all parts
  10.  * of the MicroEMACS display editor. It contains all of the
  11.  * general definitions and macros. It also contains some
  12.  * conditional compilation flags. All of the per-system and
  13.  * per-terminal definitions are in special header files.
  14.  * The most common reason to edit this file would be to zap
  15.  * the definition of CVMVAS or BACKUP.
  16.  */
  17. #include    "sysdef.h"        /* Order is critical.        */
  18. #include    "ttydef.h"
  19. #include    <stdio.h>
  20.  
  21. #define    CVMVAS    1            /* C-V, M-V work in pages.    */
  22. #define    BACKUP    0            /* Make backup file.        */
  23.  
  24. /*
  25.  * Table sizes, etc.
  26.  */
  27. #define    NSHASH    31            /* Symbol table hash size.    */
  28. #define    NFILEN    80            /* Length, file name.        */
  29. #define    NBUFN    16            /* Length, buffer name.        */
  30. #define    NLINE    256            /* Length, line.        */
  31. #define    NKBDM    256            /* Length, keyboard macro.    */
  32. #define NMSG    512            /* Length, message buffer.    */
  33. #define    NPAT    80            /* Length, pattern.        */
  34. #define    HUGE    1000            /* A rather large number.    */
  35. #define NSRCH    128            /* Undoable search commands.    */
  36. #define    NXNAME    64            /* Length, extended command.    */
  37.  
  38. /*
  39.  * Universal.
  40.  */
  41. #define    FALSE    0            /* False, no, bad, etc.        */
  42. #define    TRUE    1            /* True, yes, good, etc.    */
  43. #define    ABORT    2            /* Death, ^G, abort, etc.    */
  44.  
  45. /*
  46.  * These flag bits keep track of
  47.  * some aspects of the last command. The CFCPCN
  48.  * flag controls goal column setting. The CFKILL
  49.  * flag controls the clearing versus appending
  50.  * of data in the kill buffer.
  51.  */
  52. #define    CFCPCN    0x0001            /* Last command was C-P, C-N    */
  53. #define    CFKILL    0x0002            /* Last command was a kill    */
  54.  
  55. /*
  56.  * File I/O.
  57.  */
  58. #define    FIOSUC    0            /* Success.            */
  59. #define    FIOFNF    1            /* File not found.        */
  60. #define    FIOEOF    2            /* End of file.            */
  61. #define    FIOERR    3            /* Error.            */
  62.  
  63. /*
  64.  * Directory I/O.
  65.  */
  66. #define    DIOSUC    0            /* Success.            */
  67. #define    DIOEOF    1            /* End of file.            */
  68. #define    DIOERR    2            /* Error.            */
  69.  
  70. /*
  71.  * Display colors.
  72.  */
  73. #define    CNONE    0            /* Unknown color.        */
  74. #define    CTEXT    1            /* Text color.            */
  75. #define    CMODE    2            /* Mode line color.        */
  76.  
  77. /*
  78.  * Flags for "eread".
  79.  */
  80. #define    EFNEW    0x0001            /* New prompt.            */
  81. #define    EFAUTO    0x0002            /* Autocompletion enabled.    */
  82. #define    EFCR    0x0004            /* Echo CR at end; last read.    */
  83.  
  84. /*
  85.  * Keys are represented inside using an 11 bit
  86.  * keyboard code. The transformation between the keys on
  87.  * the keyboard and 11 bit code is done by terminal specific
  88.  * code in the "kbd.c" file. The actual character is stored
  89.  * in 8 bits (DEC multinationals work); there is also a control
  90.  * flag KCTRL, a meta flag KMETA, and a control-X flag KCTLX.
  91.  * ASCII control characters are always represented using the
  92.  * KCTRL form. Although the C0 control set is free, it is
  93.  * reserved for C0 controls because it makes the communication
  94.  * between "getkey" and "getkbd" easier. The funny keys get
  95.  * mapped into the C1 control area.
  96.  */
  97. #define    NKEYS    2048            /* 11 bit code.            */
  98.  
  99. #define    METACH    0x1B            /* M- prefix,   Control-[, ESC    */
  100. #define    CTMECH    0x1C            /* C-M- prefix, Control-\    */
  101. #define    EXITCH    0x1D            /* Exit level,  Control-]    */
  102. #define    CTRLCH    0x1E            /* C- prefix,    Control-^    */
  103. #define    HELPCH    0x1F            /* Help key,    Control-_    */
  104.  
  105. #define    KCHAR    0x00FF            /* The basic character code.    */
  106. #define    KCTRL    0x0100            /* Control flag.        */
  107. #define    KMETA    0x0200            /* Meta flag.            */
  108. #define    KCTLX    0x0400            /* Control-X flag.        */
  109.  
  110. #define    KFIRST    0x0080            /* First special.        */
  111. #define    KLAST    0x009F            /* Last special.        */
  112.  
  113. #define    KRANDOM    0x0080            /* A "no key" code.        */
  114. #define    K01    0x0081            /* Use these names to define    */
  115. #define    K02    0x0082            /* the special keys on your    */
  116. #define    K03    0x0083            /* terminal.            */
  117. #define    K04    0x0084
  118. #define    K05    0x0085
  119. #define    K06    0x0086
  120. #define    K07    0x0087
  121. #define    K08    0x0088
  122. #define    K09    0x0089
  123. #define    K0A    0x008A
  124. #define    K0B    0x008B
  125. #define    K0C    0x008C
  126. #define    K0D    0x008D
  127. #define    K0E    0x008E
  128. #define    K0F    0x008F
  129. #define    K10    0x0090
  130. #define    K11    0x0091
  131. #define    K12    0x0092
  132. #define    K13    0x0093
  133. #define    K14    0x0094
  134. #define    K15    0x0095
  135. #define    K16    0x0096
  136. #define    K17    0x0097
  137. #define    K18    0x0098
  138. #define    K19    0x0099
  139. #define    K1A    0x009A
  140. #define    K1B    0x009B
  141. #define    K1C    0x009C
  142. #define    K1D    0x009D
  143. #define    K1E    0x009E
  144. #define    K1F    0x009F
  145.  
  146. /*
  147.  * These flags, and the macros below them,
  148.  * make up a do-it-yourself set of "ctype" macros that
  149.  * understand the DEC multinational set, and let me ask
  150.  * a slightly different set of questions.
  151.  */
  152. #define    _W    0x01            /* Word.            */
  153. #define    _U    0x02            /* Upper case letter.        */
  154. #define    _L    0x04            /* Lower case letter.        */
  155. #define    _C    0x08            /* Control.            */
  156.  
  157. #define    ISWORD(c)    ((cinfo[(c)]&_W)!=0)
  158. #define    ISCTRL(c)    ((cinfo[(c)]&_C)!=0)
  159. #define    ISUPPER(c)    ((cinfo[(c)]&_U)!=0)
  160. #define    ISLOWER(c)    ((cinfo[(c)]&_L)!=0)
  161. #define    TOUPPER(c)    ((c)-0x20)
  162. #define    TOLOWER(c)    ((c)+0x20)
  163.  
  164. /*
  165.  * The symbol table links editing functions
  166.  * to names. Entries in the key map point at the symbol
  167.  * table entry. A reference count is kept, but it is
  168.  * probably next to useless right now. The old type code,
  169.  * which was not being used and probably not right
  170.  * anyway, is all gone.
  171.  */
  172. typedef    struct    SYMBOL {
  173.     struct    SYMBOL *s_symp;        /* Hash chain.            */
  174.     short    s_nkey;            /* Count of keys bound here.    */
  175.     char    *s_name;        /* Name.            */
  176.     int    (*s_funcp)();        /* Function.            */
  177. }    SYMBOL;
  178.  
  179. /*
  180.  * There is a window structure allocated for
  181.  * every active display window. The windows are kept in a
  182.  * big list, in top to bottom screen order, with the listhead at
  183.  * "wheadp". Each window contains its own values of dot and mark.
  184.  * The flag field contains some bits that are set by commands
  185.  * to guide redisplay; although this is a bit of a compromise in
  186.  * terms of decoupling, the full blown redisplay is just too
  187.  * expensive to run for every input character. 
  188.  */
  189. typedef    struct    WINDOW {
  190.     struct    WINDOW *w_wndp;        /* Next window            */
  191.     struct    BUFFER *w_bufp;        /* Buffer displayed in window    */
  192.     struct    LINE *w_linep;        /* Top line in the window    */
  193.     struct    LINE *w_dotp;        /* Line containing "."        */
  194.     short    w_doto;            /* Byte offset for "."        */
  195.     struct    LINE *w_markp;        /* Line containing "mark"    */
  196.     short    w_marko;        /* Byte offset for "mark"    */
  197.     char    w_toprow;        /* Origin 0 top row of window    */
  198.     char    w_ntrows;        /* # of rows of text in window    */
  199.     char    w_force;        /* If NZ, forcing row.        */
  200.     char    w_flag;            /* Flags.            */
  201. }    WINDOW;
  202.  
  203. /*
  204.  * Window flags are set by command processors to
  205.  * tell the display system what has happened to the buffer
  206.  * mapped by the window. Setting "WFHARD" is always a safe thing
  207.  * to do, but it may do more work than is necessary. Always try
  208.  * to set the simplest action that achieves the required update.
  209.  * Because commands set bits in the "w_flag", update will see
  210.  * all change flags, and do the most general one.
  211.  */
  212. #define    WFFORCE    0x01            /* Force reframe.        */
  213. #define    WFMOVE    0x02            /* Movement from line to line.    */
  214. #define    WFEDIT    0x04            /* Editing within a line.    */
  215. #define    WFHARD    0x08            /* Better to a full display.    */
  216. #define    WFMODE    0x10            /* Update mode line.        */
  217.  
  218. /*
  219.  * Text is kept in buffers. A buffer header, described
  220.  * below, exists for every buffer in the system. The buffers are
  221.  * kept in a big list, so that commands that search for a buffer by
  222.  * name can find the buffer header. There is a safe store for the
  223.  * dot and mark in the header, but this is only valid if the buffer
  224.  * is not being displayed (that is, if "b_nwnd" is 0). The text for
  225.  * the buffer is kept in a circularly linked list of lines, with
  226.  * a pointer to the header line in "b_linep".
  227.  */
  228. typedef    struct    BUFFER {
  229.     struct    BUFFER *b_bufp;        /* Link to next BUFFER        */
  230.     struct    LINE *b_dotp;        /* Link to "." LINE structure    */
  231.     short    b_doto;            /* Offset of "." in above LINE    */
  232.     struct    LINE *b_markp;        /* The same as the above two,    */
  233.     short    b_marko;        /* but for the "mark"        */
  234.     struct    LINE *b_linep;        /* Link to the header LINE    */
  235.     char    b_nwnd;            /* Count of windows on buffer    */
  236.     char    b_flag;            /* Flags            */
  237.     char    b_fname[NFILEN];    /* File name            */
  238.     char    b_bname[NBUFN];        /* Buffer name            */
  239. }    BUFFER;
  240.  
  241. #define    BFCHG    0x01            /* Changed.            */
  242. #define    BFBAK    0x02            /* Need to make a backup.    */
  243.  
  244. /*
  245.  * This structure holds the starting position
  246.  * (as a line/offset pair) and the number of characters in a
  247.  * region of a buffer. This makes passing the specification
  248.  * of a region around a little bit easier.
  249.  * There have been some complaints that the short in this
  250.  * structure is wrong; that a long would be more appropriate.
  251.  * I'll awat more comments from the folks with the little
  252.  * machines; I have a VAX, and everything fits.
  253.  */
  254. typedef    struct    {
  255.     struct    LINE *r_linep;        /* Origin LINE address.        */
  256.     short    r_offset;        /* Origin LINE offset.        */
  257.     short    r_size;            /* Length in characters.    */
  258. }    REGION;
  259.  
  260. /*
  261.  * All text is kept in circularly linked
  262.  * lists of "LINE" structures. These begin at the
  263.  * header line (which is the blank line beyond the
  264.  * end of the buffer). This line is pointed to by
  265.  * the "BUFFER". Each line contains a the number of
  266.  * bytes in the line (the "used" size), the size
  267.  * of the text array, and the text. The end of line
  268.  * is not stored as a byte; it's implied. Future
  269.  * additions will include update hints, and a
  270.  * list of marks into the line.
  271.  */
  272. typedef    struct    LINE {
  273.     struct    LINE *l_fp;        /* Link to the next line    */
  274.     struct    LINE *l_bp;        /* Link to the previous line    */
  275.     short    l_size;            /* Allocated size        */
  276.     short    l_used;            /* Used size            */
  277. #if    PCC
  278.     char    l_text[1];        /* A bunch of characters.    */
  279. #else
  280.     char    l_text[];        /* A bunch of characters.    */
  281. #endif
  282. }    LINE;
  283.  
  284. /*
  285.  * The rationale behind these macros is that you
  286.  * could (with some editing, like changing the type of a line
  287.  * link from a "LINE *" to a "REFLINE", and fixing the commands
  288.  * like file reading that break the rules) change the actual
  289.  * storage representation of lines to use something fancy on
  290.  * machines with small address spaces.
  291.  */
  292. #define    lforw(lp)    ((lp)->l_fp)
  293. #define    lback(lp)    ((lp)->l_bp)
  294. #define    lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  295. #define    lputc(lp, n, c)    ((lp)->l_text[(n)]=(c))
  296. #define    llength(lp)    ((lp)->l_used)
  297.  
  298. /*
  299.  * Externals.
  300.  */
  301. extern    int    thisflag;
  302. extern    int    lastflag;
  303. extern    int    curgoal;
  304. extern    int    epresf;
  305. extern    int    sgarbf;
  306. extern    WINDOW    *curwp;
  307. extern    BUFFER    *curbp;
  308. extern    WINDOW    *wheadp;
  309. extern    BUFFER    *bheadp;
  310. extern    BUFFER    *blistp;
  311. extern    short    kbdm[];
  312. extern    short    *kbdmip;
  313. extern    short    *kbdmop;
  314. extern    char    pat[];
  315. extern    SYMBOL    *symbol[];
  316. extern    SYMBOL    *binding[];
  317. extern    BUFFER    *bfind();
  318. extern    BUFFER    *bcreate();
  319. extern    WINDOW    *wpopup();
  320. extern    LINE    *lalloc();
  321. extern  int    nrow;
  322. extern  int    ncol;
  323. extern    char    *version[];
  324. extern    int    ttrow;
  325. extern    int    ttcol;
  326. extern    int    tceeol;
  327. extern    int    tcinsl;
  328. extern    int    tcdell;
  329. extern    char    cinfo[];
  330. extern    char    *keystrings[];
  331. extern    SYMBOL    *symlookup();
  332. extern    int    nmsg;
  333. extern    int    curmsgf;
  334. extern    int    newmsgf;
  335. extern    char    msg[];
  336.  
  337. /*
  338.  * Standard I/O.
  339.  */
  340. extern    char    *malloc();
  341. extern    char    *strcpy();
  342. extern    char    *strcat();
  343.