-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec.h
53 lines (47 loc) · 2.3 KB
/
rec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define SEARCHSZ 41 /* max size of search string */
#define MAXTEMP 2048 /* max of temp file size (in cells) */
#define TEMPSZ ((MAXTEMP+7)/8) /* temp table size (in bytes) */
#define POOLSZ 50 /* number of lines in cache */
#define XTEMP 1 /* line is in tmp file */
#define XNOEOLN 2 /* no end of line */
struct index { /* out of core line descriptor */
long seek; /* seek in file */
short len; /* length of line */
unsigned poolindex :8; /* index in pool or NOINDEX */
unsigned flags :8; /* is in tmp file */
};
struct map { /* pool cell descriptor */
short busy; /* cell busy */
int index; /* index in lindex */
long time; /* time of last access */
};
typedef struct { /* in core line descriptor */
char *ptr; /* pointer to string */
short len; /* length of string */
short oldlen; /* length before mod */
unsigned mod :8; /* line is modified */
unsigned noeoln :8; /* no end of line */
} LINE;
typedef struct {
struct index *lindex; /* out of core line descriptors */
struct map map [POOLSZ]; /* line pool */
LINE pool [POOLSZ]; /* in core line descriptors */
char tmap [TEMPSZ]; /* temp file map */
long nindex; /* number of indexes malloc'ed */
long size; /* length of file in bytes */
short fd; /* file descriptor */
short bakfd; /* bak file descriptor */
short tfd; /* temp file descriptor */
int len; /* length of file in lines */
short broken; /* there are broken lines */
} REC;
REC *RecOpen (int fd, int wmode);
void RecClose (REC *r);
int RecSave (REC *r, char *filename);
void RecBreak (REC *r);
LINE *RecGet (REC *r, int n);
void RecPut (LINE *p, int newlen);
void RecDelChar (REC *r, int line, int off);
void RecInsChar (REC *r, int line, int off, int sym);
void RecInsLine (REC *r, int n);
void RecDelLine (REC *r, int n);