home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3447 / def.h < prev   
Encoding:
C/C++ Source or Header  |  1991-06-07  |  19.6 KB  |  491 lines

  1. /*
  2.  *     Common header file.
  3.  *
  4.  * This file is the general header file for all parts
  5.  * of the 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. #define LINT_ARGS   1           /* enable lint type checking */
  13. #include        "stdio.h"
  14.  
  15. #define BACKUP  1           /* Make backup file.            */
  16. #define RUNCHK  1           /* Do additional checking at run time */
  17.  
  18. #ifndef    uchar
  19. #define uchar   unsigned    char
  20. #endif
  21.  
  22. #ifndef    uint
  23. #define uint    unsigned    int 
  24. #endif
  25.  
  26. #ifndef    ushort
  27. #define ushort  unsigned    short
  28. #endif
  29.  
  30. #ifndef    ulong
  31. #define ulong   unsigned    long
  32. #endif
  33.  
  34. /* these defines are reserved for handling data values from the buffer */
  35. #define     D8  uchar       /* this had better be a 8 bit quantity */
  36. #define     D16 ushort      /* this had better be a 16 bit quantity */
  37. #define     D32 ulong       /* this had better be a 32 bit quantity */
  38.  
  39. /* this define is reserved for the address of a location in the buffer */
  40. #define     A32 long        /* this is a 32 bit address into the buffer */
  41.  
  42. #define     bool char       /* used for boolean values      */
  43. #define     bits char       /* used for boolean bit flags   */
  44.  
  45. /*
  46.  *      MS-DOS system header file.
  47.  */
  48. #if    MSDOS
  49. #define LARGE   1           /* Large model.         */
  50. #endif
  51. #define PCC 1               /* "[]" won't work.     */
  52. #define GOOD    0           /* Indicate hunkydoryhood   */
  53.  
  54. /*
  55.  * Macros used by the buffer name making code.
  56.  * Start at the end of the file name, scan to the left
  57.  * until BDC1 (or BDC2, if defined) is reached. The buffer
  58.  * name starts just to the right of that location, and
  59.  * stops at end of string (or at the next BDC3 character,
  60.  * if defined). BDC2 and BDC3 are mainly for VMS.
  61.  */
  62. #define BDC1    ':'         /* Buffer names.        */
  63. #define BDC2    '/'         /* Buffer names. jam    */
  64.  
  65. #ifdef UNIX
  66. #define PATHCHR ':'
  67. #define    SEPCHAR '/'
  68. #else
  69. #define PATHCHR ';'
  70. #define    SEPCHAR 0x5c    /* this is a \ char */
  71. #endif
  72.  
  73. /*
  74.  *      Digital ANSI terminal header file
  75.  */
  76. #define GOSLING 0           /* Compile in fancy display.    */
  77. #ifdef MSDOS
  78. #define    ANSI    1            /* send ANSI escape codes */
  79. #endif
  80.  
  81. #define NROW    25          /* Rows.for boot    */
  82. #define NCOL    80          /* Columns.         */
  83.  
  84. #define CUSTOMIZE                       /* compile switch for extended key
  85.                                            binding in extend.c           */
  86. #define COSMETIC                        /* cosmetic screen stuff on 
  87.                                            insert off screen             */
  88. #ifdef MSDOS
  89. #define WANG_CHARACTER_SCREEN 0xf0000000L
  90. #endif
  91. /*
  92.  * Table sizes, etc.
  93.  */
  94. #define NSHASH  31          /* Symbol table hash size.      */
  95. #define NFILEN  80          /* Length, file name.           */
  96. #define NBUFN   13          /* Length, buffer name.     */
  97. #define NFILE   12          /* Length, file name.  */ /* krw */
  98. #define NLINE   80          /* Length, line.      pvr   */
  99. #define NKBDM   256         /* Length, keyboard macro.      */
  100. #define NMSG    512         /* Length, message buffer.      */
  101. #define NPAT    80          /* Length, pattern.             */
  102. #define HUGE    1000        /* A rather large number.       */
  103. #define NSRCH   128         /* Undoable search commands.    */
  104. #define NXNAME  64          /* Length, extended command.    */
  105. #define NBLOCK  16          /* Line block chunk size        */
  106. #define MAXPOS  0x7FFFFFFF  /* Maximum positive long value  */
  107.  
  108. /*
  109.  * Universal.
  110.  */
  111. #define FALSE   0                       /* False, no, bad, etc.         */
  112. #define TRUE    1                       /* True, yes, good, etc.        */
  113. #define ABORT   2                       /* Death, ^G, abort, etc.       */
  114.  
  115. /*
  116.  * These flag bits keep track of
  117.  * some aspects of the last command.
  118.  * The CFKILL flag controls the clearing versus appending
  119.  * of data in the kill buffer.
  120.  */
  121. #define CFKILL  0x0002                  /* Last command was a kill      */
  122.  
  123. /*
  124.  * File I/O.
  125.  */
  126. #define FIOSUC  0                       /* Success.                     */
  127. #define FIOFNF  1                       /* File not found.              */
  128. #define FIOEOF  2                       /* End of file.                 */
  129. #define FIOERR  3                       /* Error.                       */
  130.  
  131. /*
  132.  * Directory I/O.
  133.  */
  134. #define DIOSUC  0                       /* Success.                     */
  135. #define DIOEOF  1                       /* End of file.                 */
  136. #define DIOERR  2                       /* Error.                       */
  137.  
  138. /*
  139.  * Display colors.
  140.  */
  141. #define CNONE   0                       /* Unknown color.               */
  142. #define CTEXT   1                       /* Text color.                  */
  143. #define CMODE   2                       /* Mode line color.             */
  144.  
  145. /*
  146.  * Flags for "eread".
  147.  */
  148. #define EFNEW   0x0001                  /* New prompt.                  */
  149. #define EFAUTO  0x0002                  /* Autocompletion enabled.      */
  150. #define EFCR    0x0004                  /* Echo CR at end; last read.   */
  151.  
  152. /*
  153.  * Keys are represented inside using an 11 bit
  154.  * keyboard code. The transformation between the keys on
  155.  * the keyboard and 11 bit code is done by terminal specific
  156.  * code in the "kbd.c" file. The actual character is stored
  157.  * in 8 bits (DEC multinationals work); there is also a control
  158.  * flag KCTRL, a meta flag KMETA, and a control-X flag KCTLX.
  159.  * ASCII control characters are always represented using the
  160.  * KCTRL form. Although the C0 control set is free, it is
  161.  * reserved for C0 controls because it makes the communication
  162.  * between "getkey" and "getkbd" easier. The funny keys get
  163.  * mapped into the C1 control area.
  164.  */
  165. #define NKEYS   2048                    /* 11 bit code.                 */
  166.  
  167. #define METACH  0x1B                    /* M- prefix,   Control-[, ESC  */
  168. #define CTMECH  0x1C                    /* C-M- prefix, Control-\       */
  169. #define EXITCH  0x1D                    /* Exit level,  Control-]       */
  170. #define CTRLCH  0x1E                    /* C- prefix,   Control-^       */
  171. #define HELPCH  0x1F                    /* Help key,    Control-_       */
  172.  
  173. #define KCHAR   0x00FF                  /* The basic character code.    */
  174. #define KCTRL   0x0100                  /* Control flag.                */
  175. #define KMETA   0x0200                  /* Meta flag.                   */
  176. #define KCTLX   0x0400                  /* Control-X flag.              */
  177.  
  178. #define KFIRST  0x0080                  /* First special.       fitz    */
  179. #define KLAST   0x00F3                  /* Last special.                */
  180.  
  181. #define KRANDOM 0x0080                  /* A "no key" code.             */
  182.  
  183. /*
  184. *    This causes the key sequence ESC [ <key> to be delevered as
  185. *    KCTRL | KMETA | KCTLX | <key>.   This allows VT100 function keys
  186. *    to be bound. 
  187. */
  188. #define    VT100KEY
  189.  
  190. /*
  191.  *    These define the column used in the help (wallchart) function 
  192.  */
  193. #define    HFUNCCOL    3
  194. #define    HKEY        32
  195. #define    HKEYCODE    50
  196. #define    HENDCOL     55
  197.  
  198. /*
  199.  * These flags, and the macros below them,
  200.  * make up a do-it-yourself set of "ctype" macros that
  201.  * understand the DEC multinational set, and let me ask
  202.  * a slightly different set of questions.
  203.  */
  204. #define _W      0x01                    /* Word.                        */
  205. #define _U      0x02                    /* Upper case letter.           */
  206. #define _L      0x04                    /* Lower case letter.           */
  207. #define _C      0x08                    /* Control.                     */
  208.  
  209. #define ISCTRL(c)       ((cinfo[(c)]&_C)!=0)
  210. #define ISUPPER(c)      ((cinfo[(c)]&_U)!=0)
  211. #define ISLOWER(c)      ((cinfo[(c)]&_L)!=0)
  212. #define TOUPPER(c)      ((c)-0x20)
  213. #define TOLOWER(c)      ((c)+0x20)
  214.  
  215. #define BUF_SIZE(wp)    (wp -> w_bufp -> b_linep -> l_bp -> l_file_offset + \
  216.                         wp -> w_bufp -> b_linep -> l_bp -> l_used)
  217. #define BUF_START(wp)   (wp -> w_bufp -> b_linep -> l_fp -> l_file_offset)
  218. #define DOT_POS(wp)     (wp -> w_dotp -> l_file_offset + wp -> w_doto)
  219. #define MARK_POS(wp)    (wp -> w_markp -> l_file_offset + wp -> w_marko)
  220. #define DOT_CHAR(wp)    (wp -> w_dotp -> l_text[wp -> w_doto])
  221. #define WIND_POS(wp)    (wp -> w_linep -> l_file_offset + wp -> w_loff)
  222. #define R_TYPE(wp)      (wp -> w_fmt_ptr -> r_type)
  223. #define R_SIZE(wp)      (wp -> w_fmt_ptr -> r_size)
  224. #define R_UNITS(wp)     (wp -> w_fmt_ptr -> r_units)
  225. #define R_BYTES(wp)     (wp -> w_fmt_ptr -> r_bytes)
  226. #define R_ALIGN(wp)     (wp -> w_fmt_ptr -> r_align)
  227. #define R_B_PER_U(wp)   (wp -> w_fmt_ptr -> r_b_per_u)
  228. #define R_CHR_PER_U(wp) (wp -> w_fmt_ptr -> r_chr_per_u)
  229. #define R_FLAGS(wp)     (wp -> w_fmt_ptr -> r_flags)
  230. #define R_UNIT_FMT(wp)  (wp -> w_fmt_ptr -> r_unit_fmt)
  231. #define R_POS_FMT(wp)   (wp -> w_fmt_ptr -> r_pos_fmt)
  232. #define R_BYTE_FMT(wp)   (wp -> w_fmt_ptr -> r_byte_fmt)
  233. #define R_POSITIONS(wp) (wp -> w_fmt_ptr -> r_positions)
  234.  
  235. /*
  236.  * The symbol table links editing functions
  237.  * to names. Entries in the key map point at the symbol
  238.  * table entry. A reference count is kept, but it is
  239.  * probably next to useless right now. The old type code,
  240.  * which was not being used and probably not right
  241.  * anyway, is all gone.
  242.  */
  243. typedef struct  SYMBOL {
  244.         struct  SYMBOL *s_symp;         /* Hash chain.                  */
  245.         short   s_nkey;                 /* Count of keys bound here.    */
  246.         char    *s_name;                /* Name.            */
  247.         int     (*s_funcp)();           /* Function.                    */
  248.         bits    s_modify;               /* modify bit */
  249. }       SYMBOL;
  250.  
  251. /*
  252. *   These are the legal values for 's_modify' and 'k_modify'
  253. */
  254. #define SMOD    0x01            /* command modifies the buffer  */
  255. #define SSIZE   0x02            /* command changes buffer size  */
  256. #define SSRCH   0x04            /* command valid in search  */
  257. #define SRPLC   0x08            /* command valid in replace */
  258. #define SBOUND  0x10            /* key was bound bu user or rc file */
  259.  
  260. /*
  261.  * There is a window structure allocated for
  262.  * every active display window. The windows are kept in a
  263.  * big list, in top to bottom screen order, with the listhead at
  264.  * "wheadp". Each window contains its own values of dot and mark.
  265.  * The flag field contains some bits that are set by commands
  266.  * to guide redisplay; although this is a bit of a compromise in
  267.  * terms of decoupling, the full blown redisplay is just too
  268.  * expensive to run for every input character.
  269.  */
  270. typedef struct  WINDOW {
  271.         struct  WINDOW *w_wndp;         /* Next window                  */
  272.         struct  BUFFER *w_bufp;         /* Buffer displayed in window   */
  273.         struct  LINE *w_linep;          /* Top line in the window       */
  274.         int     w_loff;                 /* Offset into line for start pvr  */
  275.         struct  LINE *w_dotp;           /* Line containing "."          */
  276.         int     w_doto;                 /* Offset into line for "." */
  277.         struct  LINE *w_markp;          /* Line containing "mark"       */
  278.         int     w_marko;                /* Byte offset for "mark"       */
  279.         char    w_unit_offset;          /* Byte offset for "." into unit pvr */
  280.         char    w_toprow;               /* Origin 0 top row of window   */
  281.         char    w_ntrows;               /* # of rows of text in window  */
  282.         bits    w_flag;                 /* Flags.                       */
  283.         char    w_disp_shift;           /* Display byte shift; 0-3  pvr */
  284.         bool    w_intel_mode;           /* Display byte swaped.     pvr */
  285.         struct  ROW_FMT *w_fmt_ptr;     /* Pointer to display format pvr */
  286. }       WINDOW;
  287.  
  288. /*
  289.  * Window flags are set by command processors to
  290.  * tell the display system what has happened to the buffer
  291.  * mapped by the window. Setting "WFHARD" is always a safe thing
  292.  * to do, but it may do more work than is necessary. Always try
  293.  * to set the simplest action that achieves the required update.
  294.  * Because commands set bits in the "w_flag", update will see
  295.  * all change flags, and do the most general one.
  296.  */
  297. #define WFFORCE 0x01                    /* Force reframe.               */
  298. #define WFMOVE  0x02                    /* Movement from line to line.  */
  299. #define WFEDIT  0x04                    /* Editing within a line.       */
  300. #define WFHARD  0x08                    /* Better to a full display.    */
  301. #define WFMODE  0x10                    /* Update mode line.        */
  302. /*
  303. *   This structure contains how a row is constructed.   pvr
  304. */
  305.  
  306. typedef struct  ROW_FMT {
  307.     uchar   r_type;     /* format type nibbles          */
  308.     uchar   r_size;     /* format size: must be 0,1,3,7,15, etc */
  309.     uchar   r_units;    /* number of units per window row: must be 1,2,4,8,16*/
  310.     uchar   r_bytes;    /* number of bytes per window row: must be 1,2,4,8,16*/
  311.     uchar   r_align;    /* number of bytes per align row: must be 1,2,4,8,16*/
  312.     uchar   r_b_per_u;  /* number of bytes per unit: must be 1,2,4,8,16 */
  313.     uchar   r_chr_per_u; /* displayed chars per unit     */
  314.     bits    r_flags;    /* flags controlling format     */
  315.     char    *r_unit_fmt; /* print format for unit */
  316.     char    *r_pos_fmt; /* print format for buffer position, always a long */
  317.     char    *r_byte_fmt; /* print format for bytes */
  318.     uchar   *r_positions; /* list of unit positions   */
  319.     struct ROW_FMT *r_srch_fmt; /* pointer to search display format */
  320.     } ROW_FMT;
  321.  
  322. /* legal values for 'r_size'  (values significant; used as bit mask) pvr */
  323.  
  324. #define BYTES   0x00        /* Display as byte; 8 bits  */
  325. #define WORDS   0x01        /* Display as word;    16 bits  */
  326. #define DWORDS  0x03        /* Display as doubles; 32 bits  */
  327.  
  328. /* legal values for 'r_type'   pvr */
  329. #define ASCII   0x10        /* Display as ascii     */
  330. #define OCTAL   0x20        /* Display as octal values  */
  331. #define DECIMAL 0x30        /* Display as decimal values    */
  332. #define HEX     0x40        /* Display as hex values    */
  333. #define BINARY  0x50        /* Display as binary values */
  334. #define EBCDIC  0x60        /* Display as ebcdic        */
  335. #define TEXT    0x70        /* Display as normal text   */
  336.  
  337. /*
  338.  * Text is kept in buffers. A buffer header, described
  339.  * below, exists for every buffer in the system. The buffers are
  340.  * kept in a big list, so that commands that search for a buffer by
  341.  * name can find the buffer header. There is a safe store for the
  342.  * dot and mark in the header, but this is only valid if the buffer
  343.  * is not being displayed (that is, if "b_nwnd" is 0). The text for
  344.  * the buffer is kept in a circularly linked list of lines, with
  345.  * a pointer to the header line in "b_linep".
  346.  */
  347. typedef struct  BUFFER {
  348.     bits    buf_type;       /* Type of buffer       */
  349.     struct  BUFFER *b_bufp; /* Link to next BUFFER          */
  350.     struct  LINE *b_dotp;   /* Link to "." LINE structure   */
  351.     int     b_doto;         /* Offset of "." in above LINE  */
  352.     char    b_unit_offset;  /* Offset into unit for "." pvr */
  353.     struct  LINE *b_markp;  /* The same as the above two,   */
  354.     int     b_marko;        /* but for the "mark"       */
  355.     struct  LINE *b_linep;  /* Link to the header LINE      */
  356.     char    b_nwnd;         /* Count of windows on buffer   */
  357.     bits    b_flag;         /* Flags            */
  358.     A32     b_begin_addr;   /* File address of begining of buffer */
  359.     A32     b_end_addr;     /* File address of end of buffer */
  360.     A32     b_file_size;    /* Size of file */
  361.     char    b_fname[NFILEN]; /* File name                    */
  362.     char    b_bname[NBUFN];  /* Buffer name                  */
  363. }   BUFFER;
  364.  
  365. /* Values for 'buf_type' */
  366. #define BFILE   0x00            /* Buffer contains a file   */
  367. #define BDISK   0x01            /* Buffer points to a disk  */
  368. #define BMEMORY 0x02            /* Buffer points to memory  */
  369. #define INMEM   0x04            /* File is entirely in memory */
  370.  
  371. /* Values for 'b_flag' */
  372.  
  373. #define BFCHG   0x01            /* Changed.         */
  374. #define BFBAK   0x02                    /* Need to make a backup.       */
  375. #define BFBAD   0x04                    /* may be trashed alloc error?  */
  376. #define BFSAV   0x08                    /* saved buffer from save-region */
  377. #define BFNWL   0x10                    /* append newline to this buffer */
  378. #define BFVIEW  0x20                    /* read only (jam)               */
  379. #define BFLINK  0x40            /* Linked mode    pvr        */
  380. #define BFSLOCK 0x80            /* Lock buffer size   pvr    */
  381. /*
  382.  * This structure holds the starting position
  383.  * (as a line/offset pair) and the number of characters in a
  384.  * region of a buffer. This makes passing the specification
  385.  * of a region around a little bit easier.
  386.  * There have been some complaints that the short in this
  387.  * structure is wrong; that a long would be more appropriate.
  388.  * I'll await more comments from the folks with the little
  389.  * machines; I have a VAX, and everything fits.
  390.  */
  391. typedef struct  reg {
  392.         struct  LINE *r_linep;          /* Origin LINE address.         */
  393.         int     r_offset;               /* Origin LINE offset.          */
  394.         int     r_size;                 /* Length in characters.        */
  395. }       REGION;
  396.  
  397. /*
  398.  * All text is kept in circularly linked
  399.  * lists of "LINE" structures. These begin at the
  400.  * header line (which is the blank line beyond the
  401.  * end of the buffer). This line is pointed to by
  402.  * the "BUFFER". Each line contains a the number of
  403.  * bytes in the line (the "used" size), the size
  404.  * of the text array, and the text. The end of line
  405.  * is not stored as a byte; it's implied. Future
  406.  * additions will include update hints, and a
  407.  * list of marks into the line.
  408.  */
  409. typedef struct  LINE {
  410.     struct  LINE *l_fp;       /* Link to the next line        */
  411.     struct  LINE *l_bp;       /* Link to the previous line    */
  412.     A32     l_file_offset;        /* Offset from begining of file pvr */
  413.     int     l_size;           /* Allocated size           */
  414.     int     l_used;           /* Used size            */
  415. #if     PCC
  416.     char    l_text[1];        /* A bunch of characters.       */
  417. #else
  418.     char    l_text[];         /* A bunch of characters.       */
  419. #endif
  420. }      LINE;
  421.  
  422. /*
  423.  * The rationale behind these macros is that you
  424.  * could (with some editing, like changing the type of a line
  425.  * link from a "LINE *" to a "REFLINE", and fixing the commands
  426.  * like file reading that break the rules) change the actual
  427.  * storage representation of lines to use something fancy on
  428.  * machines with small address spaces.
  429.  */
  430. #define lforw(lp)       ((lp)->l_fp)
  431. #define lback(lp)       ((lp)->l_bp)
  432. #define lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  433. #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
  434. #define llength(lp)     ((lp)->l_used)
  435.  
  436. /*
  437.  * Externals.
  438.  */
  439. extern  int     thisflag;
  440. extern  int     lastflag;
  441. extern  int     curgoal;
  442. extern  int     epresf;
  443. extern  int     sgarbf;
  444. extern  WINDOW  *curwp;
  445. extern  BUFFER  *curbp;
  446. extern  WINDOW  *wheadp;
  447. extern  BUFFER  *bheadp;
  448. extern  BUFFER  *blistp;
  449. extern  short   kbdm[];
  450. extern  short   *kbdmip;
  451. extern  short   *kbdmop;
  452. extern  char    pat[];
  453. extern  SYMBOL  *symbol[];
  454. extern  SYMBOL  *binding[];
  455. extern  BUFFER  *bfind();
  456. extern  BUFFER  *bcreate();
  457. extern  WINDOW  *wpopup();
  458. extern  LINE    *lalloc();
  459. extern  int     nrow;
  460. extern  int     ncol;
  461. extern  char    version[];
  462. extern  int     ttrow;
  463. extern  int     ttcol;
  464. extern  int     tceeol;
  465. extern  int     tcinsl;
  466. extern  int     tcdell;
  467. extern  char    cinfo[];
  468. extern  SYMBOL  *symlookup();
  469. extern  int     nmsg;
  470. extern  int     curmsgf;
  471. extern  int     newmsgf;
  472. extern  char    msg[];
  473.  
  474. /* jam
  475.  */
  476. extern  char    *okmsg;
  477. extern  int     insert_mode;
  478. extern  int     extend_buf;  
  479. extern  int     flush_num;
  480. extern  int     auto_update;
  481. extern  int     flush_count;
  482. extern  int     rowb;
  483. extern  char    file_off_bad;
  484.  
  485. /*
  486.  * Standard I/O.
  487.  */
  488. extern  char    *malloc();
  489. extern  char    *strcpy();
  490. extern  char    *strcat();
  491.