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.11 1996/03/06 19:52:26 bostic Exp $ (Berkeley) $Date: 1996/03/06 19:52:26 $";
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 *));
54 fname
= cmdp
->argv
[0]->bp
;
55 set_alt_name(sp
, fname
);
61 if (!FL_ISSET(cmdp
->iflags
, E_C_FORCE
) && !stat(fname
, &sb
)) {
62 msgq_str(sp
, M_ERR
, fname
,
63 "137|%s exists, not written; use ! to override");
67 /* Create with max permissions of rw-r--r--. */
68 if ((fd
= open(fname
, O_CREAT
| O_TRUNC
| O_WRONLY
,
69 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
)) < 0) {
70 msgq_str(sp
, M_SYSERR
, fname
, "%s");
74 if ((fp
= fdopen(fd
, "w")) == NULL
) {
80 if (seq_save(sp
, fp
, "abbreviate ", SEQ_ABBREV
) || ferror(fp
))
82 if (seq_save(sp
, fp
, "map ", SEQ_COMMAND
) || ferror(fp
))
84 if (seq_save(sp
, fp
, "map! ", SEQ_INPUT
) || ferror(fp
))
86 if (opts_save(sp
, fp
) || ferror(fp
))
93 msgq_str(sp
, M_INFO
, fname
, "138|New exrc file: %s");
99 msgq_str(sp
, M_SYSERR
, fname
, "%s");