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