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) 05/31/85 7 */ 8 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 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. 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. 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. 35 */ 36 #ifndef VMUNIX 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 */ 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 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. 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 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 */ 73 var bool hitin2; /* Last read hit was ibuff2 not ibuff */ 74 var bool ichang2; /* Have actually changed ibuff2 */ 75 var bool ichanged; /* Have actually changed ibuff */ 76 var short iblock; /* Temp file block number of ibuff (or -1) */ 77 var short iblock2; /* Temp file block number of ibuff2 (or -1) */ 78 var short ninbuf; /* Number useful chars left in input buffer */ 79 var short nleft; /* Number usable chars left in output buffer */ 80 var short oblock; /* Temp file block number of obuff (or -1) */ 81 #ifndef VMUNIX 82 var short tline; /* Current temp file ptr */ 83 #else 84 var int tline; 85 #endif 86 87 var char ibuff[BUFSIZ]; 88 var char ibuff2[BUFSIZ]; 89 var char obuff[BUFSIZ]; 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 */ 106 struct header { 107 time_t Time; /* Time temp file last updated */ 108 int Uid; 109 #ifndef VMUNIX 110 short Flines; /* Number of lines in file */ 111 #else 112 int Flines; 113 #endif 114 char Savedfile[FNSIZE]; /* The current file name */ 115 short Blocks[LBLKS]; /* Blocks where line pointers stashed */ 116 }; 117 var struct header H; 118 119 #define uid H.Uid 120 #define flines H.Flines 121 #define savedfile H.Savedfile 122 #define blocks H.Blocks 123