1996-11-01 06:45:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* Copyright (c) 1992, 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for redistribution information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifndef lint
|
2013-08-11 09:44:58 +00:00
|
|
|
static const char sccsid[] = "$Id: ex_file.c,v 10.14 2001/06/25 15:19:16 skimo Exp $";
|
1996-11-01 06:45:43 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/queue.h>
|
2013-08-11 09:44:58 +00:00
|
|
|
#include <sys/time.h>
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
#include <bitstring.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../common/common.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_file -- :f[ile] [name]
|
|
|
|
* Change the file's name and display the status line.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int ex_file(SCR *, EXCMD *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2013-08-11 09:44:58 +00:00
|
|
|
ex_file(SCR *sp, EXCMD *cmdp)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
2013-08-11 09:44:58 +00:00
|
|
|
char *p;
|
1996-11-01 06:45:43 +00:00
|
|
|
FREF *frp;
|
2013-08-11 09:44:58 +00:00
|
|
|
char *np;
|
|
|
|
size_t nlen;
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
NEEDFILE(sp, cmdp);
|
|
|
|
|
|
|
|
switch (cmdp->argc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
frp = sp->frp;
|
|
|
|
|
|
|
|
/* Make sure can allocate enough space. */
|
2013-08-11 09:44:58 +00:00
|
|
|
INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
|
|
|
|
np, nlen);
|
|
|
|
if ((p = v_strdup(sp, np, nlen - 1)) == NULL)
|
1996-11-01 06:45:43 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* If already have a file name, it becomes the alternate. */
|
|
|
|
if (!F_ISSET(frp, FR_TMPFILE))
|
|
|
|
set_alt_name(sp, frp->name);
|
|
|
|
|
|
|
|
/* Free the previous name. */
|
|
|
|
free(frp->name);
|
|
|
|
frp->name = p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The file has a real name, it's no longer a temporary,
|
|
|
|
* clear the temporary file flags.
|
|
|
|
*/
|
|
|
|
F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
|
|
|
|
|
|
|
|
/* Have to force a write if the file exists, next time. */
|
|
|
|
F_SET(frp, FR_NAMECHANGE);
|
|
|
|
|
|
|
|
/* Notify the screen. */
|
|
|
|
(void)sp->gp->scr_rename(sp, sp->frp->name, 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
|
|
|
|
return (0);
|
|
|
|
}
|