lingt
[nvi.git] / common / exf.h
blobe7472e409e81ef422e900698ee6fd2d6253de04b
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: exf.h,v 8.19 1993/12/10 12:20:41 bostic Exp $ (Berkeley) $Date: 1993/12/10 12:20:41 $
8 */
9 /* Undo direction. */
10 enum udirection { UBACKWARD, UFORWARD };
13 * exf --
14 * The file structure.
16 struct _exf {
17 int refcnt; /* Reference count. */
19 /* Underlying database state. */
20 DB *db; /* File db structure. */
21 char *c_lp; /* Cached line. */
22 size_t c_len; /* Cached line length. */
23 recno_t c_lno; /* Cached line number. */
24 recno_t c_nlines; /* Cached lines in the file. */
26 DB *log; /* Log db structure. */
27 char *l_lp; /* Log buffer. */
28 size_t l_len; /* Log buffer length. */
29 recno_t l_high; /* Log last + 1 record number. */
30 recno_t l_cur; /* Log current record number. */
31 MARK l_cursor; /* Log cursor position. */
32 enum udirection lundo; /* Last undo direction. */
34 LIST_HEAD(_markh, _mark) marks; /* Linked list of file MARK's. */
37 * Paths for the recovery mail file and the vi recovery file and
38 * a file descriptor for the former. We keep a file descriptor
39 * to the recovery file open and locked, while the file is in use.
40 * This allows the recovery option to distinguish between files
41 * that are live, and those that should be recovered.
43 * F_RCV_ON is set as long as we believe that the file is recoverable.
44 * This doesn't mean that any initialization has been done, however.
45 * If F_RCV_NORM is not set and rcv_path and rcv_mpath are not NULL,
46 * they are unlinked on file exit. If not NULL they are free'd on file
47 * exit. On file exit, if rcv_fd is not -1, it is closed.
49 #define RCV_PERIOD 120 /* Sync every two minutes. */
50 char *rcv_path; /* Recover file name. */
51 char *rcv_mpath; /* Recover mail file name. */
52 int rcv_fd; /* Locked mail file descriptor. */
54 #define F_FIRSTMODIFY 0x001 /* File not yet modified. */
55 #define F_MODIFIED 0x002 /* File is currently dirty. */
56 #define F_MULTILOCK 0x004 /* Multiple processes running, lock. */
57 #define F_NOLOG 0x008 /* Logging turned off. */
58 #define F_RCV_ALRM 0x010 /* File needs to be synced. */
59 #define F_RCV_NORM 0x020 /* Don't delete recovery files. */
60 #define F_RCV_ON 0x040 /* Recovery is possible. */
61 #define F_UNDO 0x080 /* No change since last undo. */
62 u_int flags;
65 /* Flags to file_write(). */
66 #define FS_ALL 0x01 /* Write the entire file. */
67 #define FS_APPEND 0x02 /* Append to the file. */
68 #define FS_FORCE 0x04 /* Force is set. */
69 #define FS_POSSIBLE 0x08 /* Force could be set. */
71 #define GETLINE_ERR(sp, lno) { \
72 msgq((sp), M_ERR, \
73 "Error: %s/%d: unable to retrieve line %u.", \
74 tail(__FILE__), __LINE__, (lno)); \
77 /* FREF routines. */
78 FREF *file_add __P((SCR *, FREF *, CHAR_T *, int));
79 FREF *file_first __P((SCR *));
80 FREF *file_next __P((SCR *, FREF *));
81 FREF *file_prev __P((SCR *, FREF *));
82 FREF *file_unedited __P((SCR *));
84 /* EXF routines. */
85 int file_end __P((SCR *, EXF *, int));
86 int file_init __P((SCR *, FREF *, char *, int));
87 int file_write __P((SCR *, EXF *, MARK *, MARK *, char *, int));
89 /* Recovery routines. */
90 void rcv_hup __P((void));
91 int rcv_init __P((SCR *, EXF *));
92 int rcv_list __P((SCR *));
93 int rcv_read __P((SCR *, char *));
94 int rcv_sync __P((SCR *, EXF *));
95 void rcv_term __P((void));
96 int rcv_tmp __P((SCR *, EXF *, char *));
98 /* DB interface routines */
99 int file_aline __P((SCR *, EXF *, int, recno_t, char *, size_t));
100 int file_dline __P((SCR *, EXF *, recno_t));
101 char *file_gline __P((SCR *, EXF *, recno_t, size_t *));
102 int file_iline __P((SCR *, EXF *, recno_t, char *, size_t));
103 int file_lline __P((SCR *, EXF *, recno_t *));
104 char *file_rline __P((SCR *, EXF *, recno_t, size_t *));
105 int file_sline __P((SCR *, EXF *, recno_t, char *, size_t));