Skip to content
Newer
Older
100644 128 lines (106 sloc) 4.09 KB
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
1 /* session.h */
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5 /* This file contains macros, tyepdefs, and extern declarations pertaining to
6 * session files. This includes the session file format, block cacheing,
7 * and block allocation.
8 */
9
10 /*----------------------------------------------------------------------------*/
11 /* compile-time configurable constants */
12
13 #ifndef BLKSIZE
14 # define BLKSIZE 2048 /* default block size */
15 #endif
16
17 #ifndef BLKHASH
18 # define BLKHASH 61 /* default hash factor (a prime number) */
19 #endif
20
21 #ifndef BLKCACHE
22 # define BLKCACHE 20 /* default size of block cache */
23 #endif
24
25 #ifndef BLKGROW
26 # define BLKGROW 8 /* default amount by which block table grows */
27 #endif
28
29 /*----------------------------------------------------------------------------*/
30 /* session file format */
31
32 #define SESSION_MAGIC 0x0200DEADL
33 #define SESSION_MAGIC_BYTESWAPPED 0xADDE0002L
34
35 /* These data types are used to represent physical and logical block numbers.
36 * BLKNO is a physical block number; it is used to compute an offset into the
37 * session file. LBLKNO is a logical block number; it is an index into a
38 * blklist block for a given buffer. DON'T CONFUSE ONE FOR THE OTHER.
39 */
40 typedef COUNT BLKNO;
41 typedef COUNT LBLKNO;
42 typedef _COUNT_ _BLKNO_;
43 typedef _COUNT_ _LBLKNO_;
44 typedef enum { SES_NEW, SES_SUPER, SES_SUPER2, SES_BUFINFO, SES_BLKLIST, SES_CHARS } BLKTYPE;
45
46 typedef union
47 {
48 struct
49 {
50 long magic; /* file type code: 0x0200DEAD */
51 long inuse; /* in-use flag */
52 COUNT blksize; /* bytes per block */
53 BLKNO next; /* super2 block that continues buf[] */
54 BLKNO buf[1]; /* where each buffer is described */
55 } super;
56
57 struct
58 {
59 BLKNO next; /* super2 block that continues buf[] */
60 BLKNO buf[1]; /* continuation of super.buf[] */
61 } super2;
62
63 struct
64 {
65 long changes; /* change counter */
66 long prevloc; /* where last change was made */
67 long reserved; /* nothing yet; always 0 */
68 BLKNO first; /* first text block list */
69 short checksum; /* checksum of this block */
70 char name[1]; /* buffer name */
71 } bufinfo;
72
73 struct
74 {
75 BLKNO next; /* ref to next block of BLKNO values */
97d8998 @mbert Import Elvis 2.1_4 (written by Steve Kirkendall)
authored Dec 10, 2011
76 struct blki_s
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
77 {
78 BLKNO blkno; /* which block stores next CHARs */
79 COUNT nchars; /* number of CHARs used in the block */
80 COUNT nlines; /* number of '\n' CHARs in the block */
81 } blk[1]; /* list of blocks in this buffer */
82 } blklist;
83
84 struct
85 {
86 CHAR chars[1]; /* the bytes themselves */
87 } chars;
88
89 short sumshorts[BLKSIZE / sizeof(short)]; /* for calculating checksum */
90
91 char sizetester[BLKSIZE]; /* forces BLK to be prefered size */
92 } BLK;
93
94 #define SES_MAXSUPER ((o_blksize - (int)(((BLK *)0)->super.buf)) / sizeof(BLKNO))
95 #define SES_MAXSUPER2 ((o_blksize - (int)(((BLK *)0)->super2.buf)) / sizeof(BLKNO))
96 #define SES_MAXBUFINFO (o_blksize - (int)(((BLK *)0)->bufinfo.name))
97 #define SES_MAXBLKLIST ((o_blksize - (int)(((BLK *)0)->blklist.blk)) / sizeof(((BLK *)0)->blklist.blk[0]))
98 #define SES_MAXCHARS (o_blksize / sizeof(CHAR))
99
100
101 /*----------------------------------------------------------------------------*/
102 /* low-level session file access functions */
103
104 BEGIN_EXTERNC
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
105 extern void sesopen P_((ELVBOOL force));
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
106 extern void sesclose P_((void));
107 extern BLK *sesblk P_((_BLKNO_));
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
108 extern void sesunlock P_((_BLKNO_ blkno, ELVBOOL forwrite));
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
109 extern void sesflush P_((_BLKNO_ blkno));
110 extern void sessync P_((void));
111 END_EXTERNC
112 #ifdef DEBUG_SESSION
113 # define seslock(b,f,t) _seslock(__FILE__, __LINE__, b, f, t)
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored Dec 10, 2011
114 # define sesalloc(b,t) _sesalloc(__FILE__, __LINE__, b, t)
115 # define sesfree(b) _sesfree(__FILE__, __LINE__, b)
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
116 BEGIN_EXTERNC
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
117 extern BLKNO _seslock P_((char *file, int line, _BLKNO_ blkno, ELVBOOL forwrite, BLKTYPE blktype));
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored Dec 10, 2011
118 extern BLKNO _sesalloc P_((char *file, int line, _BLKNO_ blkno, BLKTYPE blktype));
119 extern void _sesfree P_((char *file, int line, _BLKNO_ blkno));
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
120 END_EXTERNC
121 #else
122 BEGIN_EXTERNC
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
123 extern BLKNO seslock P_((_BLKNO_ blkno, ELVBOOL forwrite, BLKTYPE blktype));
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored Dec 10, 2011
124 extern BLKNO sesalloc P_((_BLKNO_ blkno, BLKTYPE blktype));
125 extern void sesfree P_((_BLKNO_ blkno));
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
126 END_EXTERNC
127 #endif
Something went wrong with that request. Please try again.