typo
[nvi.git] / ex / ex_preserve.c
blob2e6a53004285dd820868087daa30a13e075dbb6c
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_preserve.c,v 10.15 2001/06/25 15:19:18 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:18 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "../common/common.h"
28 * ex_preserve -- :pre[serve]
29 * Push the file to recovery.
31 * PUBLIC: int ex_preserve __P((SCR *, EXCMD *));
33 int
34 ex_preserve(SCR *sp, EXCMD *cmdp)
36 db_recno_t lno;
38 NEEDFILE(sp, cmdp);
40 if (!F_ISSET(sp->ep, F_RCV_ON)) {
41 msgq(sp, M_ERR, "142|Preservation of this file not possible");
42 return (1);
45 /* If recovery not initialized, do so. */
46 if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
47 return (1);
49 /* Force the file to be read in, in case it hasn't yet. */
50 if (db_last(sp, &lno))
51 return (1);
53 /* Sync to disk. */
54 if (rcv_sync(sp, RCV_SNAPSHOT))
55 return (1);
57 msgq(sp, M_INFO, "143|File preserved");
58 return (0);
62 * ex_recover -- :rec[over][!] file
63 * Recover the file.
65 * PUBLIC: int ex_recover __P((SCR *, EXCMD *));
67 int
68 ex_recover(SCR *sp, EXCMD *cmdp)
70 ARGS *ap;
71 FREF *frp;
72 char *np;
73 size_t nlen;
75 ap = cmdp->argv[0];
77 /* Set the alternate file name. */
78 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
79 set_alt_name(sp, np);
82 * Check for modifications. Autowrite did not historically
83 * affect :recover.
85 if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
86 return (1);
88 /* Get a file structure for the file. */
89 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
90 if ((frp = file_add(sp, np)) == NULL)
91 return (1);
93 /* Set the recover bit. */
94 F_SET(frp, FR_RECOVER);
96 /* Switch files. */
97 if (file_init(sp, frp, NULL, FS_SETALT |
98 (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
99 return (1);
101 F_SET(sp, SC_FSWITCH);
102 return (0);