freebsd-dev/contrib/nvi/ex/ex_file.c
Peter Wemm f0957ccae4 Update nvi-1.79 to 2.1.1-4334a8297f
This is the gsoc-2011 project to clean up and backport multibyte support
from other nvi forks in a form we can use.

USE_WIDECHAR is on unless building for the rescue crunchgen. This should
allow editing in the native locale encoding.

USE_ICONV depends on make.conf having 'WITH_ICONV=YES' for now.  This
adds the ability to do things like edit a KOI8-R file while having $LANG
set to (say) en_US.UTF-8.  iconv is used to transcode the characters for
display.

Other points:
* It uses gencat and catopen/etc instead of homegrown msg catalog stuff.
* A lot of stuff has been trimmed out, eg: the perl and tcl bindings which
  we could never use in base anyway.
* It uses ncursesw when in widechar mode.  This could be interesting.

GSoC info: http://www.google-melange.com/gsoc/proposal/review/google/gsoc2011/zy/1
Repo at: https://github.com/lichray/nvi2

Obtained from:  Zhihao Yuan <lichray@gmail.com>
2013-08-11 20:03:12 +00:00

83 lines
1.7 KiB
C

/*-
* 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
static const char sccsid[] = "$Id: ex_file.c,v 10.14 2001/06/25 15:19:16 skimo Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/time.h>
#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.
*
* PUBLIC: int ex_file __P((SCR *, EXCMD *));
*/
int
ex_file(SCR *sp, EXCMD *cmdp)
{
char *p;
FREF *frp;
char *np;
size_t nlen;
NEEDFILE(sp, cmdp);
switch (cmdp->argc) {
case 0:
break;
case 1:
frp = sp->frp;
/* Make sure can allocate enough space. */
INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
np, nlen);
if ((p = v_strdup(sp, np, nlen - 1)) == 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;
/*
* 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);
}