when end a "temporary file" edit session, turn on the FR_IGNORE bit
[nvi.git] / ex / ex_file.c
blobb7dbb18762827a2454b7afb2be7b75d697aa8b00
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_file.c,v 8.7 1993/12/02 10:47:41 bostic Exp $ (Berkeley) $Date: 1993/12/02 10:47:41 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <errno.h>
15 #include <stdlib.h>
16 #include <string.h>
18 #include "vi.h"
19 #include "excmd.h"
22 * ex_file -- :f[ile] [name]
23 * Status line and change the file's name.
25 int
26 ex_file(sp, ep, cmdp)
27 SCR *sp;
28 EXF *ep;
29 EXCMDARG *cmdp;
31 FREF *frp;
32 char *p, *t;
34 switch (cmdp->argc) {
35 case 0:
36 break;
37 case 1:
38 frp = sp->frp;
40 /* Make sure can allocate enough space. */
41 if ((p = strdup(cmdp->argv[0]->bp)) == NULL) {
42 msgq(sp, M_SYSERR, NULL);
43 return (1);
46 /* If already have a file name, it becomes the alternate. */
47 if ((t = FILENAME(frp)) != NULL)
48 set_alt_name(sp, t);
50 /* Free any previously changed name. */
51 if (frp->cname != NULL)
52 free(frp->cname);
53 frp->cname = p;
55 /* The read-only bit follows the file name; clear it. */
56 F_CLR(frp, FR_RDONLY);
58 /* Have to force a write if the file exists, next time. */
59 F_CLR(frp, FR_CHANGEWRITE);
60 break;
61 default:
62 abort();
64 status(sp, ep, sp->lno, 1);
65 return (0);