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