rework SEQ's to sort on more than the first character of the input
[nvi.git] / ex / ex_file.c
blob21c58956470b69770a2cd648ad3f152e98e2f6e9
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.6 1993/11/26 16:22:42 bostic Exp $ (Berkeley) $Date: 1993/11/26 16:22:42 $";
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((char *)cmdp->argv[0])) == NULL) {
42 msgq(sp, M_SYSERR, NULL);
43 return (1);
46 /* If already have a file name, it becomes the alternate. */
47 t = FILENAME(frp);
48 if (t != NULL)
49 set_alt_name(sp, t);
51 /* Free any previously changed name. */
52 if (frp->cname != NULL)
53 FREE(frp->cname, frp->clen);
54 frp->cname = p;
55 frp->clen = strlen(p);
57 /* The read-only bit follows the file name; clear it. */
58 F_CLR(frp, FR_RDONLY);
60 /* Have to force a write if the file exists, next time. */
61 F_CLR(frp, FR_CHANGEWRITE);
62 break;
63 default:
64 abort();
66 status(sp, ep, sp->lno, 1);
67 return (0);