1: /*************************************************************************
2: * This program is copyright (C) 1985, 1986 by Jonathan Payne. It is *
3: * provided to you without charge for use only on a licensed Unix *
4: * system. You may copy JOVE provided that this notice is included with *
5: * the copy. You may not sell copies of this program or versions *
6: * modified for use on microcomputer systems, unless the copies are *
7: * included with a Unix system distribution and the source is provided. *
8: *************************************************************************/
9:
10: /* This algorithm is just like the VI and ED ones. There are several
11: differences though. The first is that I don't just have THREE or TWO
12: incore blocks of the tmp file. Instead there is a buffer cache of NBUF
13: buffers (64 on VM machines and the normal 3 on smaller ones). Each block
14: is stored in LRU order and in a hash table by block #. When a block is
15: requested it can quickly be looked up in the hash table. If it's not
16: there the LRU block is used. If it finds that the LRU block is dirty it
17: syncs the whole tmp file, i.e., does all the pending writes. This works
18: really well on floppy disk systems, like the IBM PC, if the blocks are
19: sorted first.
20:
21: The constants below are sorta hard to grok because they are in disguise,
22: but the basic idea is this: The tmp file is allocated in chunks of
23: BNDRY/2 (or is it BNDRY? I can't remember) characters. New lines are
24: added to the end of the tmp file. The file is not garbage collected
25: because that would be too painful. As a result, commands like Yank and
26: Kill are really easy. Basically all we do is make copies of the disk
27: addresses of the lines. It's fast--very. So, putline(buf) writes BUF to
28: the disk and returns a new disk address. Getline(addr, buf) is the
29: opposite of putline(). Lines do NOT cross block bounderies (as in VI and
30: ED) so that accessing the contents of lines can be much faster. Pointers
31: to offsets into disk buffers are returned instead of copying the contents
32: into local arrays and then using them. This cut down on the amount of
33: copying a great deal, at the expense of less efficiency. But it's not a
34: big deal, really. Incrementing the logical disk pointer by INCRMT is
35: like incrementing the physical disk pointer by a block. The lower bit is
36: left alone, so JOVE uses that to mark lines as needing redisplay done to
37: them. */
38:
39: #ifndef VMUNIX
40:
41: #if BUFSIZ == 512
42: # define BLKMSK 01777
43: # define BNDRY 16
44: # define INCRMT 0100
45: # define LBTMSK 0760
46: # define NMBLKS 1018
47: # define OFFBTS 6
48: # define OFFMSK 077
49: # define SHFT 3
50: #else
51: # define BLKMSK 0777
52: # define BNDRY 16
53: # define INCRMT 0200
54: # define LBTMSK 01760
55: # define NMBLKS 506
56: # define OFFBTS 7
57: # define OFFMSK 0177
58: # define SHFT 3
59: #endif
60:
61: #else
62:
63: #define BLKMSK 077777
64: #define BNDRY 2
65: #define INCRMT 02000
66: #define LBTMSK 01776
67: #define NMBLKS 077770
68: #define OFFBTS 10
69: #define OFFMSK 01777
70: #define SHFT 0
71:
72: #endif VMUNIX
73:
74: extern int nleft, /* Number of good characters left in current block */
75: tmpfd;
76: extern disk_line
77: tline; /* Pointer to end of tmp file */
78:
79: extern char *tfname;
Defined macros
BNDRY
defined in line
64; used 1 times
SHFT
defined in line
70; used 3 times
Usage of this include