Hello,

I'm a user of mg(1) and I'm not a user of OpenBSD.

According to known resources mg(1) [1] is currently maintained
in OpenBSD's tree.

As maintaining local patches or forking mg(1) for plain compatibility
is doubtful, I'm going to send you a set of patches.

I don't want to make noise with a mail per patch, so I'm attaching all
patches to this mail.
Please review (if needed adapt) and merge.

List of files:
0001-Define-strtonum-3-for-the-NetBSD-target.patch
0002-Add-missing-include-for-struct-timespec-NetBSD.patch
0003-Fix-const-correctness-in-charcost-usage.patch
0004-Fix-const-correctness-of-scroll_fwd.patch
0005-dci-is-set-but-unused.patch
0006-Enhance-type-correctness-cast-parameter-of-isspace-3.patch

My goal is to upgrade pkgsrc's version to the latest mg and reuse
it system-wide, therefore this is the first bunch of patches,
next things are waiting in the queue.

[1] http://en.wikipedia.org/wiki/Mg_%28editor%29
>From d49301b6559e2b1d432fd347fc826a255f9a3fdb Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 17:55:03 +0000
Subject: [PATCH 1/6] Define strtonum(3) for the NetBSD target

---
 strtonum.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sysdef.h   |  4 ++++
 2 files changed, 74 insertions(+)
 create mode 100644 strtonum.h

diff --git a/strtonum.h b/strtonum.h
new file mode 100644
index 0000000..74ed381
--- /dev/null
+++ b/strtonum.h
@@ -0,0 +1,70 @@
+/*	$OpenBSD: strtonum.c,v 1.7 2013/04/17 18:40:58 tedu Exp $	*/
+
+/*
+ * Copyright (c) 2004 Ted Unangst and Todd Miller
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _STRTONUM_COMPAT_
+#define _STRTONUM_COMPAT_
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#define	INVALID		1
+#define	TOOSMALL	2
+#define	TOOLARGE	3
+
+static inline long long
+strtonum(const char *numstr, long long minval, long long maxval,
+    const char **errstrp)
+{
+	long long ll = 0;
+	int error = 0;
+	char *ep;
+	struct errval {
+		const char *errstr;
+		int err;
+	} ev[4] = {
+		{ NULL,		0 },
+		{ "invalid",	EINVAL },
+		{ "too small",	ERANGE },
+		{ "too large",	ERANGE },
+	};
+
+	ev[0].err = errno;
+	errno = 0;
+	if (minval > maxval) {
+		error = INVALID;
+	} else {
+		ll = strtoll(numstr, &ep, 10);
+		if (numstr == ep || *ep != '\0')
+			error = INVALID;
+		else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
+			error = TOOSMALL;
+		else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
+			error = TOOLARGE;
+	}
+	if (errstrp != NULL)
+		*errstrp = ev[error].errstr;
+	errno = ev[error].err;
+	if (error)
+		ll = 0;
+
+	return (ll);
+}
+
+#endif /* _STRTONUM_COMPAT_ */
diff --git a/sysdef.h b/sysdef.h
index 8d3d3a2..3fde496 100644
--- a/sysdef.h
+++ b/sysdef.h
@@ -19,6 +19,10 @@
 #  define LOGIN_NAME_MAX _POSIX_LOGIN_NAME_MAX
 #endif
 
+#if defined(__NetBSD__)
+#  include "strtonum.h" /* OpenBSD specific function */
+#endif
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
-- 
2.1.0

>From 4f4c1beac4422bce6419442320a67e8028ca1876 Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 17:55:36 +0000
Subject: [PATCH 2/6] Add missing include for struct timespec (NetBSD)

---
 sysdef.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sysdef.h b/sysdef.h
index 3fde496..d51fe5b 100644
--- a/sysdef.h
+++ b/sysdef.h
@@ -20,6 +20,7 @@
 #endif
 
 #if defined(__NetBSD__)
+#  include <sys/time.h> /* struct timespec */
 #  include "strtonum.h" /* OpenBSD specific function */
 #endif
 
-- 
2.1.0

>From fb3b8c0f9350e0050de4ca72d60ba1a69d32bcba Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 18:06:05 +0000
Subject: [PATCH 3/6] Fix const correctness in charcost usage

---
 tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tty.c b/tty.c
index f803cc7..7a77ff0 100644
--- a/tty.c
+++ b/tty.c
@@ -35,7 +35,7 @@
 
 #include <term.h>
 
-static int	 charcost(char *);
+static int	 charcost(const char *);
 
 static int	 cci;
 static int	 insdel;	/* Do we have both insert & delete line? */
@@ -438,7 +438,7 @@ fakec(int c)
 
 /* calculate the cost of doing string s */
 static int
-charcost(char *s)
+charcost(const char *s)
 {
 	cci = 0;
 
-- 
2.1.0

>From 7830cd4b67d0992861d31d3cf8c38a620de47c27 Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 18:07:20 +0000
Subject: [PATCH 4/6] Fix const correctness of scroll_fwd

---
 tty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tty.c b/tty.c
index 7a77ff0..b62bde9 100644
--- a/tty.c
+++ b/tty.c
@@ -39,7 +39,7 @@ static int	 charcost(const char *);
 
 static int	 cci;
 static int	 insdel;	/* Do we have both insert & delete line? */
-static char	*scroll_fwd;	/* How to scroll forward. */
+static const char	*scroll_fwd;	/* How to scroll forward. */
 
 static void	 winchhandler(int);
 
-- 
2.1.0

>From 1d31010b731eb731a6b5801626e2f46dd4f24fbb Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 18:16:25 +0000
Subject: [PATCH 5/6] dci is set but unused

---
 cmode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmode.c b/cmode.c
index 00a32b9..d330cbc 100644
--- a/cmode.c
+++ b/cmode.c
@@ -158,7 +158,7 @@ int
 cc_indent(int f, int n)
 {
 	int pi, mi;			/* Previous indents */
-	int ci, dci;			/* current indent, don't care */
+	int ci;			/* current indent, don't care */
 	struct line *lp;
 	int ret;
 	
@@ -181,7 +181,7 @@ cc_indent(int f, int n)
 	/* Strip leading space on current line */
 	delleadwhite(FFRAND, 1);
 	/* current indent is computed only to current position */
-	dci = getindent(curwp->w_dotp, &ci);
+	(void)getindent(curwp->w_dotp, &ci);
 	
 	if (pi + ci < 0)
 		ret = indent(FFOTHARG, 0);
-- 
2.1.0

>From 6d7ed3eb966e448b321bd7924f03b4f485ca5d9b Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <[email protected]>
Date: Fri, 14 Nov 2014 18:34:44 +0000
Subject: [PATCH 6/6] Enhance type correctness: cast parameter of isspace(3),
 isblank(3), isalnum(3), toupper(3) to int

---
 cscope.c | 2 +-
 extend.c | 2 +-
 grep.c   | 6 +++---
 tags.c   | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/cscope.c b/cscope.c
index 0deada3..4f73ee8 100644
--- a/cscope.c
+++ b/cscope.c
@@ -557,7 +557,7 @@ prettyprint(struct buffer *bp, struct cstokens *t)
 const char *
 ltrim(const char *s)
 {
-	while (isblank(*s))
+	while (isblank((int)*s))
 		s++;
 	return s;
 }
diff --git a/extend.c b/extend.c
index ef59d5f..e6bd820 100644
--- a/extend.c
+++ b/extend.c
@@ -446,7 +446,7 @@ dobindkey(KEYMAP *map, const char *func, const char *str)
 	for (i = 0; *str && i < MAXKEY; i++) {
 		/* XXX - convert numbers w/ strol()? */
 		if (*str == '^' && *(str + 1) !=  '\0') {
-			key.k_chars[i] = CCHR(toupper(*++str));
+			key.k_chars[i] = CCHR(toupper((int)*++str));
 		} else if (*str == '\\' && *(str + 1) != '\0') {
 			switch (*++str) {
 			case '^':
diff --git a/grep.c b/grep.c
index 6a4c1c4..9e4085d 100644
--- a/grep.c
+++ b/grep.c
@@ -124,7 +124,7 @@ gid(int f, int n)
 	/* Skip backwards over delimiters we are currently on */
 	while (i > 0) {
 		c = lgetc(curwp->w_dotp, i);
-		if (isalnum(c) || c == '_')
+		if (isalnum((int)c) || c == '_')
 			break;
 
 		i--;
@@ -133,14 +133,14 @@ gid(int f, int n)
 	/* Skip the symbol itself */
 	for (; i > 0; i--) {
 		c = lgetc(curwp->w_dotp, i - 1);
-		if (!isalnum(c) && c != '_')
+		if (!isalnum((int)c) && c != '_')
 			break;
 	}
 	/* Fill the symbol in cprompt[] */
 	for (j = 0; j < sizeof(cprompt) - 1 && i < llength(curwp->w_dotp);
 	    j++, i++) {
 		c = lgetc(curwp->w_dotp, i);
-		if (!isalnum(c) && c != '_')
+		if (!isalnum((int)c) && c != '_')
 			break;
 		cprompt[j] = c;
 	}
diff --git a/tags.c b/tags.c
index e847b9e..bcc3610 100644
--- a/tags.c
+++ b/tags.c
@@ -482,7 +482,7 @@ curtoken(int f, int n, char *token)
 
 	/* strip away leading whitespace if any like emacs. */
 	while (ltext(curwp->w_dotp) &&
-	    isspace(curwp->w_dotp->l_text[tdoto]))
+	    isspace((int)curwp->w_dotp->l_text[tdoto]))
 		tdoto++;
 
 	size = curwp->w_doto - tdoto;
-- 
2.1.0

Reply via email to