NetBSD/usr.bin/vi/ex/ex_preserve.c

111 lines
2.1 KiB
C
Raw Normal View History

2002-04-09 05:47:30 +04:00
/* $NetBSD: ex_preserve.c,v 1.8 2002/04/09 01:47:33 thorpej Exp $ */
1998-01-09 11:03:16 +03:00
/*-
* Copyright (c) 1993, 1994
* The Regents of the University of California. All rights reserved.
1996-05-20 07:47:00 +04:00
* Copyright (c) 1993, 1994, 1995, 1996
* Keith Bostic. All rights reserved.
*
1996-05-20 07:47:00 +04:00
* See the LICENSE file for redistribution information.
*/
1996-05-20 07:47:00 +04:00
#include "config.h"
2002-04-09 05:47:30 +04:00
#include <sys/cdefs.h>
#ifndef lint
2002-04-09 05:47:30 +04:00
#if 0
1996-05-20 07:47:00 +04:00
static const char sccsid[] = "@(#)ex_preserve.c 10.12 (Berkeley) 4/27/96";
2002-04-09 05:47:30 +04:00
#else
__RCSID("$NetBSD");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <bitstring.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
1996-05-20 07:47:00 +04:00
#include "../common/common.h"
/*
* ex_preserve -- :pre[serve]
* Push the file to recovery.
1996-05-20 07:47:00 +04:00
*
* PUBLIC: int ex_preserve __P((SCR *, EXCMD *));
*/
int
1996-05-20 07:47:00 +04:00
ex_preserve(sp, cmdp)
SCR *sp;
1996-05-20 07:47:00 +04:00
EXCMD *cmdp;
{
recno_t lno;
1996-05-20 07:47:00 +04:00
NEEDFILE(sp, cmdp);
if (!F_ISSET(sp->ep, F_RCV_ON)) {
msgq(sp, M_ERR, "142|Preservation of this file not possible");
return (1);
}
/* If recovery not initialized, do so. */
1996-05-20 07:47:00 +04:00
if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
return (1);
/* Force the file to be read in, in case it hasn't yet. */
1996-05-20 07:47:00 +04:00
if (db_last(sp, &lno))
return (1);
/* Sync to disk. */
1996-05-20 07:47:00 +04:00
if (rcv_sync(sp, RCV_SNAPSHOT))
return (1);
1996-05-20 07:47:00 +04:00
msgq(sp, M_INFO, "143|File preserved");
return (0);
}
/*
* ex_recover -- :rec[over][!] file
1996-05-20 07:47:00 +04:00
* Recover the file.
*
1996-05-20 07:47:00 +04:00
* PUBLIC: int ex_recover __P((SCR *, EXCMD *));
*/
int
1996-05-20 07:47:00 +04:00
ex_recover(sp, cmdp)
SCR *sp;
1996-05-20 07:47:00 +04:00
EXCMD *cmdp;
{
ARGS *ap;
FREF *frp;
ap = cmdp->argv[0];
/* Set the alternate file name. */
set_alt_name(sp, ap->bp);
/*
* Check for modifications. Autowrite did not historically
* affect :recover.
*/
1996-05-20 07:47:00 +04:00
if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
return (1);
/* Get a file structure for the file. */
if ((frp = file_add(sp, ap->bp)) == NULL)
return (1);
/* Set the recover bit. */
F_SET(frp, FR_RECOVER);
/* Switch files. */
1996-05-20 07:47:00 +04:00
if (file_init(sp, frp, NULL, FS_SETALT |
(FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
return (1);
1996-05-20 07:47:00 +04:00
F_SET(sp, SC_FSWITCH);
return (0);
}