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