| 1 | /* Copyright (c) 1981 Regents of the University of California */ |
| 2 | /* sccs id: @(#)ex_temp.h 7.3 %G% */ |
| 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 |
| 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. |
| 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. |
| 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. |
| 29 | */ |
| 30 | #ifndef VMUNIX |
| 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 */ |
| 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 |
| 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. |
| 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 |
| 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 | */ |
| 67 | var bool hitin2; /* Last read hit was ibuff2 not ibuff */ |
| 68 | var bool ichang2; /* Have actually changed ibuff2 */ |
| 69 | var bool ichanged; /* Have actually changed ibuff */ |
| 70 | var short iblock; /* Temp file block number of ibuff (or -1) */ |
| 71 | var short iblock2; /* Temp file block number of ibuff2 (or -1) */ |
| 72 | var short ninbuf; /* Number useful chars left in input buffer */ |
| 73 | var short nleft; /* Number usable chars left in output buffer */ |
| 74 | var short oblock; /* Temp file block number of obuff (or -1) */ |
| 75 | #ifndef VMUNIX |
| 76 | var short tline; /* Current temp file ptr */ |
| 77 | #else |
| 78 | var int tline; |
| 79 | #endif |
| 80 | |
| 81 | var char ibuff[BUFSIZ]; |
| 82 | var char ibuff2[BUFSIZ]; |
| 83 | var char 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 */ |
| 100 | struct header { |
| 101 | time_t Time; /* Time temp file last updated */ |
| 102 | int Uid; |
| 103 | #ifndef VMUNIX |
| 104 | short Flines; /* Number of lines in file */ |
| 105 | #else |
| 106 | int Flines; |
| 107 | #endif |
| 108 | char Savedfile[FNSIZE]; /* The current file name */ |
| 109 | short Blocks[LBLKS]; /* Blocks where line pointers stashed */ |
| 110 | }; |
| 111 | var struct header H; |
| 112 | |
| 113 | #define uid H.Uid |
| 114 | #define flines H.Flines |
| 115 | #define savedfile H.Savedfile |
| 116 | #define blocks H.Blocks |