2002-04-09 05:47:30 +04:00
|
|
|
/* $NetBSD: ex_file.c,v 1.9 2002/04/09 01:47:33 thorpej Exp $ */
|
1998-01-09 11:03:16 +03:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
/*-
|
1994-03-28 08:28:20 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994
|
1994-01-24 08:52:58 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1996-05-20 07:47:00 +04:00
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
1994-01-24 08:52:58 +03:00
|
|
|
*
|
1996-05-20 07:47:00 +04:00
|
|
|
* See the LICENSE file for redistribution information.
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2002-04-09 05:47:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#ifndef lint
|
2002-04-09 05:47:30 +04:00
|
|
|
#if 0
|
2001-03-31 15:37:44 +04:00
|
|
|
static const char sccsid[] = "@(#)ex_file.c 10.12 (Berkeley) 7/12/96";
|
2002-04-09 05:47:30 +04:00
|
|
|
#else
|
|
|
|
__RCSID("$NetBSD");
|
|
|
|
#endif
|
1994-01-24 08:52:58 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <sys/queue.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <bitstring.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <errno.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "../common/common.h"
|
1994-01-24 08:52:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_file -- :f[ile] [name]
|
1994-08-17 20:35:35 +04:00
|
|
|
* Change the file's name and display the status line.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_file __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_file(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
1994-08-17 20:35:35 +04:00
|
|
|
CHAR_T *p;
|
1994-01-24 08:52:58 +03:00
|
|
|
FREF *frp;
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
NEEDFILE(sp, cmdp);
|
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
switch (cmdp->argc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
frp = sp->frp;
|
|
|
|
|
|
|
|
/* Make sure can allocate enough space. */
|
1994-08-17 20:35:35 +04:00
|
|
|
if ((p = v_strdup(sp,
|
|
|
|
cmdp->argv[0]->bp, cmdp->argv[0]->len)) == NULL)
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* If already have a file name, it becomes the alternate. */
|
1994-08-17 20:35:35 +04:00
|
|
|
if (!F_ISSET(frp, FR_TMPFILE))
|
|
|
|
set_alt_name(sp, frp->name);
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-08-17 20:35:35 +04:00
|
|
|
/* Free the previous name. */
|
|
|
|
free(frp->name);
|
|
|
|
frp->name = p;
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-08-17 20:35:35 +04:00
|
|
|
/*
|
1996-05-20 07:47:00 +04:00
|
|
|
* The file has a real name, it's no longer a temporary,
|
|
|
|
* clear the temporary file flags.
|
1994-08-17 20:35:35 +04:00
|
|
|
*/
|
1996-05-20 07:47:00 +04:00
|
|
|
F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
|
1994-01-24 08:52:58 +03:00
|
|
|
|
|
|
|
/* Have to force a write if the file exists, next time. */
|
1994-08-17 20:35:35 +04:00
|
|
|
F_SET(frp, FR_NAMECHANGE);
|
1996-05-20 07:47:00 +04:00
|
|
|
|
|
|
|
/* Notify the screen. */
|
2001-03-31 15:37:44 +04:00
|
|
|
(void)sp->gp->scr_rename(sp, sp->frp->name, 1);
|
1994-01-24 08:52:58 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
1996-05-20 07:47:00 +04:00
|
|
|
msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
|
|
|
|
return (0);
|
1994-01-24 08:52:58 +03:00
|
|
|
}
|