This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / usr.bin / vi / exf.h
CommitLineData
1e64b3ba
JH
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)exf.h 8.20 (Berkeley) 12/28/93
34 */
35 /* Undo direction. */
36/*
37 * exf --
38 * The file structure.
39 */
40struct _exf {
41 int refcnt; /* Reference count. */
42
43 /* Underlying database state. */
44 DB *db; /* File db structure. */
45 char *c_lp; /* Cached line. */
46 size_t c_len; /* Cached line length. */
47 recno_t c_lno; /* Cached line number. */
48 recno_t c_nlines; /* Cached lines in the file. */
49
50 DB *log; /* Log db structure. */
51 char *l_lp; /* Log buffer. */
52 size_t l_len; /* Log buffer length. */
53 recno_t l_high; /* Log last + 1 record number. */
54 recno_t l_cur; /* Log current record number. */
55 MARK l_cursor; /* Log cursor position. */
56 enum direction lundo; /* Last undo direction. */
57
58 LIST_HEAD(_markh, _mark) marks; /* Linked list of file MARK's. */
59
60 /*
61 * Paths for the recovery mail file and the vi recovery file and
62 * a file descriptor for the former. We keep a file descriptor
63 * to the recovery file open and locked, while the file is in use.
64 * This allows the recovery option to distinguish between files
65 * that are live, and those that should be recovered.
66 *
67 * F_RCV_ON is set as long as we believe that the file is recoverable.
68 * This doesn't mean that any initialization has been done, however.
69 * If F_RCV_NORM is not set and rcv_path and rcv_mpath are not NULL,
70 * they are unlinked on file exit. If not NULL they are free'd on file
71 * exit. On file exit, if rcv_fd is not -1, it is closed.
72 */
73#define RCV_PERIOD 120 /* Sync every two minutes. */
74 char *rcv_path; /* Recover file name. */
75 char *rcv_mpath; /* Recover mail file name. */
76 int rcv_fd; /* Locked mail file descriptor. */
77
78#define F_FIRSTMODIFY 0x001 /* File not yet modified. */
79#define F_MODIFIED 0x002 /* File is currently dirty. */
80#define F_MULTILOCK 0x004 /* Multiple processes running, lock. */
81#define F_NOLOG 0x008 /* Logging turned off. */
82#define F_RCV_ALRM 0x010 /* File needs to be synced. */
83#define F_RCV_NORM 0x020 /* Don't delete recovery files. */
84#define F_RCV_ON 0x040 /* Recovery is possible. */
85#define F_UNDO 0x080 /* No change since last undo. */
86 u_int flags;
87};
88
89/* Flags to file_write(). */
90#define FS_ALL 0x01 /* Write the entire file. */
91#define FS_APPEND 0x02 /* Append to the file. */
92#define FS_FORCE 0x04 /* Force is set. */
93#define FS_POSSIBLE 0x08 /* Force could be set. */
94
95#define GETLINE_ERR(sp, lno) { \
96 msgq((sp), M_ERR, \
97 "Error: %s/%d: unable to retrieve line %u.", \
98 tail(__FILE__), __LINE__, (lno)); \
99}
100
101/* FREF routines. */
102FREF *file_add __P((SCR *, FREF *, CHAR_T *, int));
103FREF *file_first __P((SCR *));
104FREF *file_next __P((SCR *, FREF *));
105FREF *file_prev __P((SCR *, FREF *));
106FREF *file_unedited __P((SCR *));
107
108/* EXF routines. */
109int file_end __P((SCR *, EXF *, int));
110int file_init __P((SCR *, FREF *, char *, int));
111int file_write __P((SCR *, EXF *, MARK *, MARK *, char *, int));
112
113/* Recovery routines. */
114void rcv_hup __P((void));
115int rcv_init __P((SCR *, EXF *));
116int rcv_list __P((SCR *));
117int rcv_read __P((SCR *, char *));
118int rcv_sync __P((SCR *, EXF *));
119void rcv_term __P((void));
120int rcv_tmp __P((SCR *, EXF *, char *));
121
122/* DB interface routines */
123int file_aline __P((SCR *, EXF *, int, recno_t, char *, size_t));
124int file_dline __P((SCR *, EXF *, recno_t));
125char *file_gline __P((SCR *, EXF *, recno_t, size_t *));
126int file_iline __P((SCR *, EXF *, recno_t, char *, size_t));
127int file_lline __P((SCR *, EXF *, recno_t *));
128char *file_rline __P((SCR *, EXF *, recno_t, size_t *));
129int file_sline __P((SCR *, EXF *, recno_t, char *, size_t));