use three-argument AC_DEFINE instead of acconfig.h
[nvi.git] / ex / ex_file.c
blob09d61d69780d31bc21ca80bdb3561c2178d32d9c
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_file.c,v 10.14 2001/06/25 15:19:16 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:16 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include "../common/common.h"
29 * ex_file -- :f[ile] [name]
30 * Change the file's name and display the status line.
32 * PUBLIC: int ex_file __P((SCR *, EXCMD *));
34 int
35 ex_file(SCR *sp, EXCMD *cmdp)
37 char *p;
38 FREF *frp;
39 char *np;
40 size_t nlen;
42 NEEDFILE(sp, cmdp);
44 switch (cmdp->argc) {
45 case 0:
46 break;
47 case 1:
48 frp = sp->frp;
50 /* Make sure can allocate enough space. */
51 INT2CHAR(sp, cmdp->argv[0]->bp, cmdp->argv[0]->len + 1,
52 np, nlen);
53 if ((p = v_strdup(sp, np, nlen - 1)) == NULL)
54 return (1);
56 /* If already have a file name, it becomes the alternate. */
57 if (!F_ISSET(frp, FR_TMPFILE))
58 set_alt_name(sp, frp->name);
60 /* Free the previous name. */
61 free(frp->name);
62 frp->name = p;
65 * The file has a real name, it's no longer a temporary,
66 * clear the temporary file flags.
68 F_CLR(frp, FR_TMPEXIT | FR_TMPFILE);
70 /* Have to force a write if the file exists, next time. */
71 F_SET(frp, FR_NAMECHANGE);
73 /* Notify the screen. */
74 (void)sp->gp->scr_rename(sp, sp->frp->name, 1);
75 break;
76 default:
77 abort();
79 msgq_status(sp, sp->lno, MSTAT_SHOWLAST);
80 return (0);