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

81 lines
1.6 KiB
C
Raw Normal View History

/*-
* Copyright (c) 1992, 1993, 1994
* 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.
*
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"
#ifndef lint
1996-05-20 07:47:00 +04:00
static const char sccsid[] = "@(#)ex_file.c 10.11 (Berkeley) 5/2/96";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <bitstring.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
1996-05-20 07:47:00 +04:00
#include "../common/common.h"
/*
* ex_file -- :f[ile] [name]
* 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 *));
*/
int
1996-05-20 07:47:00 +04:00
ex_file(sp, cmdp)
SCR *sp;
1996-05-20 07:47:00 +04:00
EXCMD *cmdp;
{
CHAR_T *p;
FREF *frp;
1996-05-20 07:47:00 +04:00
NEEDFILE(sp, cmdp);
switch (cmdp->argc) {
case 0:
break;
case 1:
frp = sp->frp;
/* Make sure can allocate enough space. */
if ((p = v_strdup(sp,
cmdp->argv[0]->bp, cmdp->argv[0]->len)) == NULL)
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;
/*
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.
*/
1996-05-20 07:47:00 +04:00
F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
/* Have to force a write if the file exists, next time. */
F_SET(frp, FR_NAMECHANGE);
1996-05-20 07:47:00 +04:00
/* Notify the screen. */
(void)sp->gp->scr_rename(sp);
break;
default:
abort();
}
1996-05-20 07:47:00 +04:00
msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
return (0);
}