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