xref: /illumos-gate/usr/src/cmd/vi/port/ex_temp.h (revision 55fea89d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1981 Regents of the University of California */
277c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.7	*/
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * The editor uses a temporary file for files being edited, in a structure
307c478bd9Sstevel@tonic-gate  * similar to that of ed.  The first block of the file is used for a header
317c478bd9Sstevel@tonic-gate  * block which guides recovery after editor/system crashes.
327c478bd9Sstevel@tonic-gate  * Lines are represented in core by a pointer into the temporary file which
337c478bd9Sstevel@tonic-gate  * is packed into 16 bits (32 on VMUNIX).  All but the low bit index the temp
347c478bd9Sstevel@tonic-gate  * file; the last is used by global commands.  The parameters below control
357c478bd9Sstevel@tonic-gate  * how much the other bits are shifted left before they index the temp file.
367c478bd9Sstevel@tonic-gate  * Larger shifts give more slop in the temp file but allow larger files
377c478bd9Sstevel@tonic-gate  * to be edited.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * The editor does not garbage collect the temporary file.  When a new
407c478bd9Sstevel@tonic-gate  * file is edited, the temporary file is rather discarded and a new one
417c478bd9Sstevel@tonic-gate  * created for the new file.  Garbage collection would be rather complicated
427c478bd9Sstevel@tonic-gate  * in ex because of the general undo, and in any case would require more
437c478bd9Sstevel@tonic-gate  * work when throwing lines away because marks would have be carefully
447c478bd9Sstevel@tonic-gate  * checked before reallocating temporary file space.  Said another way,
457c478bd9Sstevel@tonic-gate  * each time you create a new line in the temporary file you get a unique
467c478bd9Sstevel@tonic-gate  * number back, and this is a property used by marks.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * The following temp file parameters allow 256k bytes in the temporary
497c478bd9Sstevel@tonic-gate  * file.  By changing to the numbers in comments you can get 512k.
507c478bd9Sstevel@tonic-gate  * For VMUNIX you get more than you could ever want.
517c478bd9Sstevel@tonic-gate  * VMUNIX uses long (32 bit) integers giving much more
527c478bd9Sstevel@tonic-gate  * space in the temp file and no waste.  This doubles core
537c478bd9Sstevel@tonic-gate  * requirements but allows files of essentially unlimited size to be edited.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #ifndef VMUNIX
567c478bd9Sstevel@tonic-gate #define	BLKMSK	0777		/* 01777 */
577c478bd9Sstevel@tonic-gate #define	BNDRY	8		/* 16 */
587c478bd9Sstevel@tonic-gate #define	INCRMT	0200		/* 0100 */
597c478bd9Sstevel@tonic-gate #define	LBTMSK	0770		/* 0760 */
607c478bd9Sstevel@tonic-gate #define	NMBLKS	506		/* 1018 */
617c478bd9Sstevel@tonic-gate #define	OFFBTS	7		/* 6 */
627c478bd9Sstevel@tonic-gate #define	OFFMSK	0177		/* 077 */
637c478bd9Sstevel@tonic-gate #define	SHFT	2		/* 3 */
647c478bd9Sstevel@tonic-gate #else
657c478bd9Sstevel@tonic-gate #define	BLKMSK	077777
667c478bd9Sstevel@tonic-gate #define	BNDRY	2
677c478bd9Sstevel@tonic-gate #define	INCRMT	04000		/* 02000 */
687c478bd9Sstevel@tonic-gate #define	LBTMSK	03776		/* 01776 */
697c478bd9Sstevel@tonic-gate #define	NMBLKS	077770
707c478bd9Sstevel@tonic-gate #define	OFFBTS	11		/* 10 */
717c478bd9Sstevel@tonic-gate #define	OFFMSK	03777		/* 01777 */
727c478bd9Sstevel@tonic-gate #define	SHFT	0
737c478bd9Sstevel@tonic-gate #endif
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * The editor uses three buffers into the temporary file (ed uses two
777c478bd9Sstevel@tonic-gate  * and is very similar).  These are two read buffers and one write buffer.
787c478bd9Sstevel@tonic-gate  * Basically, the editor deals with the file as a sequence of BUFSIZE character
797c478bd9Sstevel@tonic-gate  * blocks.  Each block contains some number of lines (and lines
807c478bd9Sstevel@tonic-gate  * can run across block boundaries.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * New lines are written into the last block in the temporary file
837c478bd9Sstevel@tonic-gate  * which is in core as obuf.  When a line is needed which isn't in obuf,
847c478bd9Sstevel@tonic-gate  * then it is brought into an input buffer.  As there are two, the choice
857c478bd9Sstevel@tonic-gate  * is to take the buffer into which the last read (of the two) didn't go.
867c478bd9Sstevel@tonic-gate  * Thus this is a 2 buffer LRU replacement strategy.  Measurement
877c478bd9Sstevel@tonic-gate  * shows that this saves roughly 25% of the buffer reads over a one
887c478bd9Sstevel@tonic-gate  * input buffer strategy.  Since the editor (on our VAX over 1 week)
897c478bd9Sstevel@tonic-gate  * spends (spent) roughly 30% of its time in the system read routine,
907c478bd9Sstevel@tonic-gate  * this can be a big help.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate var bool	hitin2;		/* Last read hit was ibuff2 not ibuff */
937c478bd9Sstevel@tonic-gate var bool	ichang2;	/* Have actually changed ibuff2 */
947c478bd9Sstevel@tonic-gate var bool	ichanged;	/* Have actually changed ibuff */
957c478bd9Sstevel@tonic-gate var short	iblock;		/* Temp file block number of ibuff (or -1) */
967c478bd9Sstevel@tonic-gate var short	iblock2;	/* Temp file block number of ibuff2 (or -1) */
977c478bd9Sstevel@tonic-gate var short	ninbuf;		/* Number useful chars left in input buffer */
987c478bd9Sstevel@tonic-gate var short	nleft;		/* Number usable chars left in output buffer */
997c478bd9Sstevel@tonic-gate var short	oblock;		/* Temp file block number of obuff (or -1) */
1007c478bd9Sstevel@tonic-gate #ifndef VMUNIX
1017c478bd9Sstevel@tonic-gate var short	tline;		/* Current temp file ptr */
1027c478bd9Sstevel@tonic-gate #else
1037c478bd9Sstevel@tonic-gate var int	tline;
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate var unsigned char	ibuff[BUFSIZE];
1077c478bd9Sstevel@tonic-gate var unsigned char	ibuff2[BUFSIZE];
1087c478bd9Sstevel@tonic-gate var unsigned char	obuff[BUFSIZE];
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Structure of the descriptor block which resides
1127c478bd9Sstevel@tonic-gate  * in the first block of the temporary file and is
1137c478bd9Sstevel@tonic-gate  * the guiding light for crash recovery.
1147c478bd9Sstevel@tonic-gate  *
1157c478bd9Sstevel@tonic-gate  * As the Blocks field below implies, there are temporary file blocks
1167c478bd9Sstevel@tonic-gate  * devoted to (some) image of the incore array of pointers into the temp
1177c478bd9Sstevel@tonic-gate  * file.  Thus, to recover from a crash we use these indices to get the
1187c478bd9Sstevel@tonic-gate  * line pointers back, and then use the line pointers to get the text back.
1197c478bd9Sstevel@tonic-gate  * Except for possible lost lines due to sandbagged I/O, the entire
1207c478bd9Sstevel@tonic-gate  * file (at the time of the last editor "sync") can be recovered from
1217c478bd9Sstevel@tonic-gate  * the temp file.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* This definition also appears in expreserve.c... beware */
1257c478bd9Sstevel@tonic-gate struct 	header {
1267c478bd9Sstevel@tonic-gate 	time_t	Time;			/* Time temp file last updated */
1277c478bd9Sstevel@tonic-gate 	int	Uid;
1287c478bd9Sstevel@tonic-gate #ifndef VMUNIX
1297c478bd9Sstevel@tonic-gate 	short	Flines;			/* Number of lines in file */
1307c478bd9Sstevel@tonic-gate #else
1317c478bd9Sstevel@tonic-gate 	int	Flines;
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 	unsigned char	Savedfile[FNSIZE];	/* The current file name */
1347c478bd9Sstevel@tonic-gate 	short	Blocks[LBLKS];		/* Blocks where line pointers stashed */
1357c478bd9Sstevel@tonic-gate 	short 	encrypted;		/* Encrypted temp file flag */
136*55fea89dSDan Cross };
1377c478bd9Sstevel@tonic-gate var struct 	header H;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	uid		H.Uid
1407c478bd9Sstevel@tonic-gate #define	flines		H.Flines
1417c478bd9Sstevel@tonic-gate #define	savedfile	H.Savedfile
1427c478bd9Sstevel@tonic-gate #define	blocks		H.Blocks
143