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