Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 7u83 1
/*
2
 * This code contains changes by
3
 *      Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
4
 *
5
 * Conditions 1, 2, and 4 and the no-warranty notice below apply
6
 * to these changes.
7
 *
8
 *
9
 * Copyright (c) 1980, 1993
10
 * 	The Regents of the University of California.  All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgement:
22
 * 	This product includes software developed by the University of
23
 * 	California, Berkeley and its contributors.
24
 * 4. Neither the name of the University nor the names of its contributors
25
 *    may be used to endorse or promote products derived from this software
26
 *    without specific prior written permission.
27
 *
28
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
 * SUCH DAMAGE.
39
 *
40
 *
41
 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
42
 *
43
 * Redistribution and use in source and binary forms, with or without
44
 * modification, are permitted provided that the following conditions
45
 * are met:
46
 *   Redistributions of source code and documentation must retain the
47
 *    above copyright notice, this list of conditions and the following
48
 *    disclaimer.
49
 *   Redistributions in binary form must reproduce the above copyright
50
 *    notice, this list of conditions and the following disclaimer in the
51
 *    documentation and/or other materials provided with the distribution.
52
 *   All advertising materials mentioning features or use of this software
53
 *    must display the following acknowledgement:
54
 *      This product includes software developed or owned by Caldera
55
 *      International, Inc.
56
 *   Neither the name of Caldera International, Inc. nor the names of
57
 *    other contributors may be used to endorse or promote products
58
 *    derived from this software without specific prior written permission.
59
 *
60
 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
61
 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
62
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
63
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64
 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
65
 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
66
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
68
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
69
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
71
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72
 *
73
 *	from ex_temp.h	7.4 (Berkeley) 5/31/85
74
 *
75
 *	@(#)ex_temp.h	1.8 (gritter) 1/26/02
76
 */
77
 
78
/*
79
 * The editor uses a temporary file for files being edited, in a structure
80
 * similar to that of ed.  The first block of the file is used for a header
81
 * block which guides recovery after editor/system crashes.
82
 * Lines are represented in core by a pointer into the temporary file which
83
 * is packed into 16 bits (32 on VMUNIX).  All but the low bit index the temp
84
 * file; the last is used by global commands.  The parameters below control
85
 * how much the other bits are shifted left before they index the temp file.
86
 * Larger shifts give more slop in the temp file but allow larger files
87
 * to be edited.
88
 *
89
 * The editor does not garbage collect the temporary file.  When a new
90
 * file is edited, the temporary file is rather discarded and a new one
91
 * created for the new file.  Garbage collection would be rather complicated
92
 * in ex because of the general undo, and in any case would require more
93
 * work when throwing lines away because marks would have be carefully
94
 * checked before reallocating temporary file space.  Said another way,
95
 * each time you create a new line in the temporary file you get a unique
96
 * number back, and this is a property used by marks.
97
 *
98
 * The following temp file parameters allow 256k bytes in the temporary
99
 * file.  By changing to the numbers in comments you can get 512k.
100
 * For VMUNIX you get more than you could ever want.
101
 * VMUNIX uses long (32 bit) integers giving much more
102
 * space in the temp file and no waste.  This doubles core
103
 * requirements but allows files of essentially unlimited size to be edited.
104
 */
105
#ifndef VMUNIX
106
#define	BLKMSK	0777		/* 01777 */
107
#define	BNDRY	8		/* 16 */
108
#define	INCRMT	0200		/* 0100 */
109
#define	LBTMSK	0770		/* 0760 */
110
#define	NMBLKS	506		/* 1018 */
111
#define	OFFBTS	7		/* 6 */
112
#define	OFFMSK	0177		/* 077 */
113
#define	SHFT	2		/* 3 */
114
#else
115
#ifdef	LARGEF
116
#define	BLKMSK	017777777777
117
#else
118
#define	BLKMSK	077777
119
#endif
120
#define	BNDRY	2
121
#define	INCRMT	02000
122
#define	LBTMSK	01776
123
#ifdef	LARGEF
124
#define	NMBLKS	017777777770
125
#else
126
#define	NMBLKS	077770
127
#endif
128
#define	OFFBTS	10
129
#define	OFFMSK	01777
130
#define	SHFT	0
131
#endif
132
 
133
/*
134
 * The editor uses three buffers into the temporary file (ed uses two
135
 * and is very similar).  These are two read buffers and one write buffer.
136
 * Basically, the editor deals with the file as a sequence of BUFSIZ character
137
 * blocks.  Each block contains some number of lines (and lines
138
 * can run across block boundaries.
139
 *
140
 * New lines are written into the last block in the temporary file
141
 * which is in core as obuf.  When a line is needed which isn't in obuf,
142
 * then it is brought into an input buffer.  As there are two, the choice
143
 * is to take the buffer into which the last read (of the two) didn't go.
144
 * Thus this is a 2 buffer LRU replacement strategy.  Measurement
145
 * shows that this saves roughly 25% of the buffer reads over a one
146
 * input buffer strategy.  Since the editor (on our VAX over 1 week)
147
 * spends (spent) roughly 30% of its time in the system read routine,
148
 * this can be a big help.
149
 */
150
var bool	hitin2;		/* Last read hit was ibuff2 not ibuff */
151
var bool	ichang2;	/* Have actually changed ibuff2 */
152
var bool	ichanged;	/* Have actually changed ibuff */
153
var bloc	iblock;		/* Temp file block number of ibuff (or -1) */
154
var bloc	iblock2;	/* Temp file block number of ibuff2 (or -1) */
155
var bloc	ninbuf;		/* Number useful chars left in input buffer */
156
var bloc	nleft;		/* Number usable chars left in output buffer */
157
var bloc	oblock;		/* Temp file block number of obuff (or -1) */
158
var bbloc	tline;		/* Current temp file ptr */
159
 
160
var char	ibuff[BUFSIZ];
161
var char	ibuff2[BUFSIZ];
162
var char	obuff[BUFSIZ];
163
 
164
/*
165
 * Structure of the descriptor block which resides
166
 * in the first block of the temporary file and is
167
 * the guiding light for crash recovery.
168
 *
169
 * As the Blocks field below implies, there are temporary file blocks
170
 * devoted to (some) image of the incore array of pointers into the temp
171
 * file.  Thus, to recover from a crash we use these indices to get the
172
 * line pointers back, and then use the line pointers to get the text back.
173
 * Except for possible lost lines due to sandbagged I/O, the entire
174
 * file (at the time of the last editor "sync") can be recovered from
175
 * the temp file.
176
 */
177
 
178
/* This definition also appears in expreserve.c... beware */
179
struct 	header {
180
	time_t	Time;			/* Time temp file last updated */
181
	uid_t	Uid;
182
	bbloc	Flines;			/* Number of lines in file */
183
	char	Savedfile[FNSIZE];	/* The current file name */
184
	bloc	Blocks[LBLKS];		/* Blocks where line pointers stashed */
185
}; 
186
var struct 	header H;
187
 
188
#define	uid		H.Uid
189
#define	flines		H.Flines
190
#define	savedfile	H.Savedfile
191
#define	blocks		H.Blocks