xref: /onnv-gate/usr/src/cmd/vi/port/ex_temp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
27*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate  * The editor uses a temporary file for files being edited, in a structure
30*0Sstevel@tonic-gate  * similar to that of ed.  The first block of the file is used for a header
31*0Sstevel@tonic-gate  * block which guides recovery after editor/system crashes.
32*0Sstevel@tonic-gate  * Lines are represented in core by a pointer into the temporary file which
33*0Sstevel@tonic-gate  * is packed into 16 bits (32 on VMUNIX).  All but the low bit index the temp
34*0Sstevel@tonic-gate  * file; the last is used by global commands.  The parameters below control
35*0Sstevel@tonic-gate  * how much the other bits are shifted left before they index the temp file.
36*0Sstevel@tonic-gate  * Larger shifts give more slop in the temp file but allow larger files
37*0Sstevel@tonic-gate  * to be edited.
38*0Sstevel@tonic-gate  *
39*0Sstevel@tonic-gate  * The editor does not garbage collect the temporary file.  When a new
40*0Sstevel@tonic-gate  * file is edited, the temporary file is rather discarded and a new one
41*0Sstevel@tonic-gate  * created for the new file.  Garbage collection would be rather complicated
42*0Sstevel@tonic-gate  * in ex because of the general undo, and in any case would require more
43*0Sstevel@tonic-gate  * work when throwing lines away because marks would have be carefully
44*0Sstevel@tonic-gate  * checked before reallocating temporary file space.  Said another way,
45*0Sstevel@tonic-gate  * each time you create a new line in the temporary file you get a unique
46*0Sstevel@tonic-gate  * number back, and this is a property used by marks.
47*0Sstevel@tonic-gate  *
48*0Sstevel@tonic-gate  * The following temp file parameters allow 256k bytes in the temporary
49*0Sstevel@tonic-gate  * file.  By changing to the numbers in comments you can get 512k.
50*0Sstevel@tonic-gate  * For VMUNIX you get more than you could ever want.
51*0Sstevel@tonic-gate  * VMUNIX uses long (32 bit) integers giving much more
52*0Sstevel@tonic-gate  * space in the temp file and no waste.  This doubles core
53*0Sstevel@tonic-gate  * requirements but allows files of essentially unlimited size to be edited.
54*0Sstevel@tonic-gate  */
55*0Sstevel@tonic-gate #ifndef VMUNIX
56*0Sstevel@tonic-gate #define	BLKMSK	0777		/* 01777 */
57*0Sstevel@tonic-gate #define	BNDRY	8		/* 16 */
58*0Sstevel@tonic-gate #define	INCRMT	0200		/* 0100 */
59*0Sstevel@tonic-gate #define	LBTMSK	0770		/* 0760 */
60*0Sstevel@tonic-gate #define	NMBLKS	506		/* 1018 */
61*0Sstevel@tonic-gate #define	OFFBTS	7		/* 6 */
62*0Sstevel@tonic-gate #define	OFFMSK	0177		/* 077 */
63*0Sstevel@tonic-gate #define	SHFT	2		/* 3 */
64*0Sstevel@tonic-gate #else
65*0Sstevel@tonic-gate #define	BLKMSK	077777
66*0Sstevel@tonic-gate #define	BNDRY	2
67*0Sstevel@tonic-gate #define	INCRMT	04000		/* 02000 */
68*0Sstevel@tonic-gate #define	LBTMSK	03776		/* 01776 */
69*0Sstevel@tonic-gate #define	NMBLKS	077770
70*0Sstevel@tonic-gate #define	OFFBTS	11		/* 10 */
71*0Sstevel@tonic-gate #define	OFFMSK	03777		/* 01777 */
72*0Sstevel@tonic-gate #define	SHFT	0
73*0Sstevel@tonic-gate #endif
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate  * The editor uses three buffers into the temporary file (ed uses two
77*0Sstevel@tonic-gate  * and is very similar).  These are two read buffers and one write buffer.
78*0Sstevel@tonic-gate  * Basically, the editor deals with the file as a sequence of BUFSIZE character
79*0Sstevel@tonic-gate  * blocks.  Each block contains some number of lines (and lines
80*0Sstevel@tonic-gate  * can run across block boundaries.
81*0Sstevel@tonic-gate  *
82*0Sstevel@tonic-gate  * New lines are written into the last block in the temporary file
83*0Sstevel@tonic-gate  * which is in core as obuf.  When a line is needed which isn't in obuf,
84*0Sstevel@tonic-gate  * then it is brought into an input buffer.  As there are two, the choice
85*0Sstevel@tonic-gate  * is to take the buffer into which the last read (of the two) didn't go.
86*0Sstevel@tonic-gate  * Thus this is a 2 buffer LRU replacement strategy.  Measurement
87*0Sstevel@tonic-gate  * shows that this saves roughly 25% of the buffer reads over a one
88*0Sstevel@tonic-gate  * input buffer strategy.  Since the editor (on our VAX over 1 week)
89*0Sstevel@tonic-gate  * spends (spent) roughly 30% of its time in the system read routine,
90*0Sstevel@tonic-gate  * this can be a big help.
91*0Sstevel@tonic-gate  */
92*0Sstevel@tonic-gate var bool	hitin2;		/* Last read hit was ibuff2 not ibuff */
93*0Sstevel@tonic-gate var bool	ichang2;	/* Have actually changed ibuff2 */
94*0Sstevel@tonic-gate var bool	ichanged;	/* Have actually changed ibuff */
95*0Sstevel@tonic-gate var short	iblock;		/* Temp file block number of ibuff (or -1) */
96*0Sstevel@tonic-gate var short	iblock2;	/* Temp file block number of ibuff2 (or -1) */
97*0Sstevel@tonic-gate var short	ninbuf;		/* Number useful chars left in input buffer */
98*0Sstevel@tonic-gate var short	nleft;		/* Number usable chars left in output buffer */
99*0Sstevel@tonic-gate var short	oblock;		/* Temp file block number of obuff (or -1) */
100*0Sstevel@tonic-gate #ifndef VMUNIX
101*0Sstevel@tonic-gate var short	tline;		/* Current temp file ptr */
102*0Sstevel@tonic-gate #else
103*0Sstevel@tonic-gate var int	tline;
104*0Sstevel@tonic-gate #endif
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate var unsigned char	ibuff[BUFSIZE];
107*0Sstevel@tonic-gate var unsigned char	ibuff2[BUFSIZE];
108*0Sstevel@tonic-gate var unsigned char	obuff[BUFSIZE];
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate /*
111*0Sstevel@tonic-gate  * Structure of the descriptor block which resides
112*0Sstevel@tonic-gate  * in the first block of the temporary file and is
113*0Sstevel@tonic-gate  * the guiding light for crash recovery.
114*0Sstevel@tonic-gate  *
115*0Sstevel@tonic-gate  * As the Blocks field below implies, there are temporary file blocks
116*0Sstevel@tonic-gate  * devoted to (some) image of the incore array of pointers into the temp
117*0Sstevel@tonic-gate  * file.  Thus, to recover from a crash we use these indices to get the
118*0Sstevel@tonic-gate  * line pointers back, and then use the line pointers to get the text back.
119*0Sstevel@tonic-gate  * Except for possible lost lines due to sandbagged I/O, the entire
120*0Sstevel@tonic-gate  * file (at the time of the last editor "sync") can be recovered from
121*0Sstevel@tonic-gate  * the temp file.
122*0Sstevel@tonic-gate  */
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate /* This definition also appears in expreserve.c... beware */
125*0Sstevel@tonic-gate struct 	header {
126*0Sstevel@tonic-gate 	time_t	Time;			/* Time temp file last updated */
127*0Sstevel@tonic-gate 	int	Uid;
128*0Sstevel@tonic-gate #ifndef VMUNIX
129*0Sstevel@tonic-gate 	short	Flines;			/* Number of lines in file */
130*0Sstevel@tonic-gate #else
131*0Sstevel@tonic-gate 	int	Flines;
132*0Sstevel@tonic-gate #endif
133*0Sstevel@tonic-gate 	unsigned char	Savedfile[FNSIZE];	/* The current file name */
134*0Sstevel@tonic-gate 	short	Blocks[LBLKS];		/* Blocks where line pointers stashed */
135*0Sstevel@tonic-gate 	short 	encrypted;		/* Encrypted temp file flag */
136*0Sstevel@tonic-gate };
137*0Sstevel@tonic-gate var struct 	header H;
138*0Sstevel@tonic-gate 
139*0Sstevel@tonic-gate #define	uid		H.Uid
140*0Sstevel@tonic-gate #define	flines		H.Flines
141*0Sstevel@tonic-gate #define	savedfile	H.Savedfile
142*0Sstevel@tonic-gate #define	blocks		H.Blocks
143