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.
13 static const char sccsid
[] = "$Id: ex_mkexrc.c,v 10.12 2000/07/14 14:29:20 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:20 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
29 #include "../common/common.h"
30 #include "pathnames.h"
33 * ex_mkexrc -- :mkexrc[!] [file]
35 * Create (or overwrite) a .exrc file with the current info.
37 * PUBLIC: int ex_mkexrc __P((SCR *, EXCMD *));
55 INT2CHAR(sp
, cmdp
->argv
[0]->bp
, cmdp
->argv
[0]->len
+ 1,
57 set_alt_name(sp
, fname
);
63 if (!FL_ISSET(cmdp
->iflags
, E_C_FORCE
) && !stat(fname
, &sb
)) {
64 msgq_str(sp
, M_ERR
, fname
,
65 "137|%s exists, not written; use ! to override");
69 /* Create with max permissions of rw-r--r--. */
70 if ((fd
= open(fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
71 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
)) < 0) {
72 msgq_str(sp
, M_SYSERR
, fname
, "%s");
76 if ((fp
= fdopen(fd
, "w")) == NULL
) {
82 if (seq_save(sp
, fp
, "abbreviate ", SEQ_ABBREV
) || ferror(fp
))
84 if (seq_save(sp
, fp
, "map ", SEQ_COMMAND
) || ferror(fp
))
86 if (seq_save(sp
, fp
, "map! ", SEQ_INPUT
) || ferror(fp
))
88 if (opts_save(sp
, fp
) || ferror(fp
))
95 msgq_str(sp
, M_INFO
, fname
, "138|New exrc file: %s");
101 msgq_str(sp
, M_SYSERR
, fname
, "%s");