date and time created 94/04/13 10:27:13 by eric
[unix-history] / usr / src / usr.bin / ex / ex_temp.h
CommitLineData
2791ff57 1/*-
eb035710
KB
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
2791ff57
KB
4 *
5 * %sccs.include.proprietary.c%
edf71f48 6 *
eb035710 7 * @(#)ex_temp.h 8.1 (Berkeley) %G%
edf71f48
DF
8 */
9
c37501ec
MH
10/*
11 * The editor uses a temporary file for files being edited, in a structure
12 * similar to that of ed. The first block of the file is used for a header
13 * block which guides recovery after editor/system crashes.
14 * Lines are represented in core by a pointer into the temporary file which
44232d5b
MH
15 * is packed into 16 bits (32 on VMUNIX). All but the low bit index the temp
16 * file; the last is used by global commands. The parameters below control
17 * how much the other bits are shifted left before they index the temp file.
c37501ec
MH
18 * Larger shifts give more slop in the temp file but allow larger files
19 * to be edited.
20 *
21 * The editor does not garbage collect the temporary file. When a new
22 * file is edited, the temporary file is rather discarded and a new one
23 * created for the new file. Garbage collection would be rather complicated
24 * in ex because of the general undo, and in any case would require more
25 * work when throwing lines away because marks would have be carefully
26 * checked before reallocating temporary file space. Said another way,
27 * each time you create a new line in the temporary file you get a unique
28 * number back, and this is a property used by marks.
29 *
30 * The following temp file parameters allow 256k bytes in the temporary
31 * file. By changing to the numbers in comments you can get 512k.
44232d5b
MH
32 * For VMUNIX you get more than you could ever want.
33 * VMUNIX uses long (32 bit) integers giving much more
34 * space in the temp file and no waste. This doubles core
35 * requirements but allows files of essentially unlimited size to be edited.
c37501ec 36 */
44232d5b 37#ifndef VMUNIX
c37501ec
MH
38#define BLKMSK 0777 /* 01777 */
39#define BNDRY 8 /* 16 */
40#define INCRMT 0200 /* 0100 */
41#define LBTMSK 0770 /* 0760 */
42#define NMBLKS 506 /* 1018 */
43#define OFFBTS 7 /* 6 */
44#define OFFMSK 0177 /* 077 */
45#define SHFT 2 /* 3 */
44232d5b
MH
46#else
47#define BLKMSK 077777
48#define BNDRY 2
49#define INCRMT 02000
50#define LBTMSK 01776
51#define NMBLKS 077770
52#define OFFBTS 10
53#define OFFMSK 01777
54#define SHFT 0
55#endif
c37501ec
MH
56
57/*
58 * The editor uses three buffers into the temporary file (ed uses two
59 * and is very similar). These are two read buffers and one write buffer.
44232d5b
MH
60 * Basically, the editor deals with the file as a sequence of BUFSIZ character
61 * blocks. Each block contains some number of lines (and lines
c37501ec
MH
62 * can run across block boundaries.
63 *
64 * New lines are written into the last block in the temporary file
65 * which is in core as obuf. When a line is needed which isn't in obuf,
66 * then it is brought into an input buffer. As there are two, the choice
67 * is to take the buffer into which the last read (of the two) didn't go.
68 * Thus this is a 2 buffer LRU replacement strategy. Measurement
69 * shows that this saves roughly 25% of the buffer reads over a one
70 * input buffer strategy. Since the editor (on our VAX over 1 week)
71 * spends (spent) roughly 30% of its time in the system read routine,
72 * this can be a big help.
73 */
cb3ac212
MH
74var bool hitin2; /* Last read hit was ibuff2 not ibuff */
75var bool ichang2; /* Have actually changed ibuff2 */
76var bool ichanged; /* Have actually changed ibuff */
77var short iblock; /* Temp file block number of ibuff (or -1) */
78var short iblock2; /* Temp file block number of ibuff2 (or -1) */
79var short ninbuf; /* Number useful chars left in input buffer */
80var short nleft; /* Number usable chars left in output buffer */
81var short oblock; /* Temp file block number of obuff (or -1) */
44232d5b 82#ifndef VMUNIX
cb3ac212 83var short tline; /* Current temp file ptr */
44232d5b 84#else
cb3ac212 85var int tline;
44232d5b 86#endif
c37501ec 87
cb3ac212
MH
88var char ibuff[BUFSIZ];
89var char ibuff2[BUFSIZ];
90var char obuff[BUFSIZ];
c37501ec
MH
91
92/*
93 * Structure of the descriptor block which resides
94 * in the first block of the temporary file and is
95 * the guiding light for crash recovery.
96 *
97 * As the Blocks field below implies, there are temporary file blocks
98 * devoted to (some) image of the incore array of pointers into the temp
99 * file. Thus, to recover from a crash we use these indices to get the
100 * line pointers back, and then use the line pointers to get the text back.
101 * Except for possible lost lines due to sandbagged I/O, the entire
102 * file (at the time of the last editor "sync") can be recovered from
103 * the temp file.
104 */
105
106/* This definition also appears in expreserve.c... beware */
107struct header {
108 time_t Time; /* Time temp file last updated */
7e9c0d40 109 int Uid;
44232d5b 110#ifndef VMUNIX
c37501ec 111 short Flines; /* Number of lines in file */
44232d5b
MH
112#else
113 int Flines;
114#endif
c37501ec
MH
115 char Savedfile[FNSIZE]; /* The current file name */
116 short Blocks[LBLKS]; /* Blocks where line pointers stashed */
299f2784 117};
cb3ac212 118var struct header H;
c37501ec
MH
119
120#define uid H.Uid
121#define flines H.Flines
122#define savedfile H.Savedfile
123#define blocks H.Blocks