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