summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mg/def.h4
-rw-r--r--usr.bin/mg/fileio.c8
-rw-r--r--usr.bin/mg/main.c14
-rw-r--r--usr.bin/mg/mg.110
-rw-r--r--usr.bin/mg/ttykbd.c5
5 files changed, 27 insertions, 14 deletions
diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h
index e0ec494871b..cb1d67356d4 100644
--- a/usr.bin/mg/def.h
+++ b/usr.bin/mg/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.166 2020/02/09 10:13:13 florian Exp $ */
+/* $OpenBSD: def.h,v 1.167 2021/02/23 08:10:51 lum Exp $ */
/* This file is in the public domain. */
@@ -471,7 +471,7 @@ int ffputbuf(FILE *, struct buffer *, int);
int ffgetline(FILE *, char *, int, int *);
int fbackupfile(const char *);
char *adjustname(const char *, int);
-char *startupfile(char *);
+char *startupfile(char *, char *);
int copy(char *, char *);
struct list *make_file_list(char *);
int fisdir(const char *);
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index 615cca3b4b0..567f74c3a54 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.106 2019/06/22 10:21:57 lum Exp $ */
+/* $OpenBSD: fileio.c,v 1.107 2021/02/23 08:10:51 lum Exp $ */
/* This file is in the public domain. */
@@ -330,7 +330,7 @@ adjustname(const char *fn, int slashslash)
* to the startup file name.
*/
char *
-startupfile(char *suffix)
+startupfile(char *suffix, char *conffile)
{
static char file[NFILEN];
char *home;
@@ -339,7 +339,9 @@ startupfile(char *suffix)
if ((home = getenv("HOME")) == NULL || *home == '\0')
goto nohome;
- if (suffix == NULL) {
+ if (conffile != NULL) {
+ (void)strncpy(file, conffile, NFILEN);
+ } else if (suffix == NULL) {
ret = snprintf(file, sizeof(file), _PATH_MG_STARTUP, home);
if (ret < 0 || ret >= sizeof(file))
return (NULL);
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index 634fceb9742..d0d94e365ad 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.87 2019/06/22 15:38:15 lum Exp $ */
+/* $OpenBSD: main.c,v 1.88 2021/02/23 08:10:51 lum Exp $ */
/* This file is in the public domain. */
@@ -48,7 +48,8 @@ extern void closetags(void);
static __dead void
usage()
{
- fprintf(stderr, "usage: %s [-nR] [-f mode] [+number] [file ...]\n",
+ fprintf(stderr, "usage: %s [-nR] [-f mode] [-u file] [+number] "
+ "[file ...]\n",
__progname);
exit(1);
}
@@ -56,7 +57,7 @@ usage()
int
main(int argc, char **argv)
{
- char *cp, *init_fcn_name = NULL;
+ char *cp, *conffile = NULL, *init_fcn_name = NULL;
PF init_fcn = NULL;
int o, i, nfiles;
int nobackups = 0;
@@ -66,7 +67,7 @@ main(int argc, char **argv)
NULL) == -1)
err(1, "pledge");
- while ((o = getopt(argc, argv, "nRf:")) != -1)
+ while ((o = getopt(argc, argv, "nRf:u:")) != -1)
switch (o) {
case 'R':
allbro = 1;
@@ -80,6 +81,9 @@ main(int argc, char **argv)
"initial function");
init_fcn_name = optarg;
break;
+ case 'u':
+ conffile = optarg;
+ break;
default:
usage();
}
@@ -129,7 +133,7 @@ main(int argc, char **argv)
update(CMODE);
/* user startup file. */
- if ((cp = startupfile(NULL)) != NULL)
+ if ((cp = startupfile(NULL, conffile)) != NULL)
(void)load(cp);
/*
diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1
index 0fefc33b919..9e5754b81a8 100644
--- a/usr.bin/mg/mg.1
+++ b/usr.bin/mg/mg.1
@@ -1,7 +1,7 @@
-.\" $OpenBSD: mg.1,v 1.118 2019/11/08 19:54:40 solene Exp $
+.\" $OpenBSD: mg.1,v 1.119 2021/02/23 08:10:51 lum Exp $
.\" This file is in the public domain.
.\"
-.Dd $Mdocdate: November 8 2019 $
+.Dd $Mdocdate: February 23 2021 $
.Dt MG 1
.Os
.Sh NAME
@@ -11,6 +11,7 @@
.Nm mg
.Op Fl nR
.Op Fl f Ar mode
+.Op Fl u Ar file
.Op + Ns Ar number
.Op Ar
.Sh DESCRIPTION
@@ -38,6 +39,11 @@ line of the file, +-2 will be second last, and so on.
Run the mode command for all buffers created from
arguments on the command line, including the
scratch buffer and all files.
+.It Fl u Ar file
+Use
+.Ar file
+as the startup file, instead of the default
+.Pa ~/.mg .
.It Fl n
Turn off backup file generation.
.It Fl R
diff --git a/usr.bin/mg/ttykbd.c b/usr.bin/mg/ttykbd.c
index e18a0d69ee4..defb73690b2 100644
--- a/usr.bin/mg/ttykbd.c
+++ b/usr.bin/mg/ttykbd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttykbd.c,v 1.19 2017/12/17 14:37:57 bcallah Exp $ */
+/* $OpenBSD: ttykbd.c,v 1.20 2021/02/23 08:10:51 lum Exp $ */
/* This file is in the public domain. */
@@ -58,7 +58,8 @@ ttykeymapinit(void)
dobindkey(fundamental_map, "delete-char", key_dc);
if ((cp = getenv("TERM"))) {
- if (((cp = startupfile(cp)) != NULL) && (load(cp) != TRUE))
+ if (((cp = startupfile(cp, NULL)) != NULL) &&
+ (load(cp) != TRUE))
ewprintf("Error reading key initialization file");
}
if (keypad_xmit)