Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / ex / ex_preserve.c
blob88592bbadfc117c5cc99837950ebeecc4dcf3b69
1 /* $NetBSD: ex_preserve.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
2 /*-
3 * Copyright (c) 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #include <sys/cdefs.h>
14 #if 0
15 #ifndef lint
16 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 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: ex_preserve.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
20 #endif
22 #include <sys/types.h>
23 #include <sys/queue.h>
25 #include <bitstring.h>
26 #include <errno.h>
27 #include <limits.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "../common/common.h"
34 * ex_preserve -- :pre[serve]
35 * Push the file to recovery.
37 * PUBLIC: int ex_preserve __P((SCR *, EXCMD *));
39 int
40 ex_preserve(SCR *sp, EXCMD *cmdp)
42 db_recno_t lno;
44 NEEDFILE(sp, cmdp);
46 if (!F_ISSET(sp->ep, F_RCV_ON)) {
47 msgq(sp, M_ERR, "142|Preservation of this file not possible");
48 return (1);
51 /* If recovery not initialized, do so. */
52 if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
53 return (1);
55 /* Force the file to be read in, in case it hasn't yet. */
56 if (db_last(sp, &lno))
57 return (1);
59 /* Sync to disk. */
60 if (rcv_sync(sp, RCV_SNAPSHOT))
61 return (1);
63 msgq(sp, M_INFO, "143|File preserved");
64 return (0);
68 * ex_recover -- :rec[over][!] file
69 * Recover the file.
71 * PUBLIC: int ex_recover __P((SCR *, EXCMD *));
73 int
74 ex_recover(SCR *sp, EXCMD *cmdp)
76 ARGS *ap;
77 FREF *frp;
78 const char *np;
79 size_t nlen;
81 ap = cmdp->argv[0];
83 /* Set the alternate file name. */
84 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
85 set_alt_name(sp, np);
88 * Check for modifications. Autowrite did not historically
89 * affect :recover.
91 if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
92 return (1);
94 /* Get a file structure for the file. */
95 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
96 if ((frp = file_add(sp, np)) == NULL)
97 return (1);
99 /* Set the recover bit. */
100 F_SET(frp, FR_RECOVER);
102 /* Switch files. */
103 if (file_init(sp, frp, NULL, FS_SETALT |
104 (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
105 return (1);
107 F_SET(sp, SC_FSWITCH);
108 return (0);