Monday, December 5, 2011

Solaris patch for mg

formerly Micro GNU/emacs, here's a patch to make it build on Solaris (cobbled together from vasprintf/fgetln/err/warn compat code found on the web)


diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/buffer.c mg-20110905-bnjf/buffer.c
--- mg-20110905/buffer.c 2011-06-18 19:18:54.000000000 +1000
+++ mg-20110905-bnjf/buffer.c 2011-12-06 10:21:30.525488000 +1100
@@ -12,6 +12,10 @@
#include "def.h"
#include "kbd.h" /* needed for modes */

+#ifndef HAVE_VASPRINTF
+#include "vasprintf.h"
+#endif
+
static struct buffer *makelist(void);
static struct buffer *bnew(const char *);

Binary files mg-20110905/core and mg-20110905-bnjf/core differ
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/display.c mg-20110905-bnjf/display.c
--- mg-20110905/display.c 2011-01-03 09:57:56.000000000 +1100
+++ mg-20110905-bnjf/display.c 2011-12-06 09:56:51.528194000 +1100
@@ -27,7 +27,7 @@
#define XSHORT int

#ifdef STANDOUT_GLITCH
-#include <term.h>
+#include <ncurses/term.h>
#endif

/*
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/echo.c mg-20110905-bnjf/echo.c
--- mg-20110905/echo.c 2011-01-03 09:57:56.000000000 +1100
+++ mg-20110905-bnjf/echo.c 2011-12-06 09:56:51.584367000 +1100
@@ -18,7 +18,7 @@
#include "funmap.h"

#include <stdarg.h>
-#include <term.h>
+#include <ncurses/term.h>

static char *veread(const char *, char *, size_t, int, va_list);
static int complt(int, int, char *, size_t, int, int *);
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/err.h mg-20110905-bnjf/err.h
--- mg-20110905/err.h 1970-01-01 10:00:00.000000000 +1000
+++ mg-20110905-bnjf/err.h 2011-12-06 10:09:50.806926000 +1100
@@ -0,0 +1,38 @@
+/* Fabian Groffen References: <20110123232847.GF12834@xxxxxxxxxxx> */
+#ifndef HAVE_ERR_H
+#include <stdarg.h>
+static inline void
+errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
+{
+ fprintf(stderr, "%s: ", "mg"/*program_invocation_short_name*/);
+ if (fmt != NULL) {
+ va_list argp;
+ va_start(argp, fmt);
+ vfprintf(stderr, fmt, argp);
+ va_end(argp);
+ if (adderr)
+ fprintf(stderr, ": ");
+ }
+ if (adderr)
+ fprintf(stderr, "%s", strerror(errno));
+ fprintf(stderr, "\n");
+ if (doexit)
+ exit(excode);
+}
+
+#ifndef HAVE_ERR
+# define err(E, FMT...) errmsg(1, E, 1, FMT)
+#endif
+
+#ifndef HAVE_ERRX
+# define errx(E, FMT...) errmsg(1, E, 0, FMT)
+#endif
+
+#ifndef HAVE_WARN
+# define warn(FMT...) errmsg(0, 0, 1, FMT)
+#endif
+
+#ifndef HAVE_WARNX
+# define warnx(FMT...) errmsg(0, 0, 0, FMT)
+#endif
+#endif
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/fgetln.c mg-20110905-bnjf/fgetln.c
--- mg-20110905/fgetln.c 2008-12-30 23:41:23.000000000 +1100
+++ mg-20110905-bnjf/fgetln.c 2011-12-06 10:20:33.277728000 +1100
@@ -27,8 +27,8 @@
#include <stdio.h>
#include <string.h>

-#if defined (__GLIBC__) || defined (__CYGWIN__) /* FreeWRT: only build
- this where needed */
+/* FreeWRT: only build this where needed */
+#if defined (__GLIBC__) || defined (__CYGWIN__)
char *fgetln(FILE *, size_t *);

char *
@@ -40,4 +40,54 @@
*len = getline(&lb, &lbsz, stream);
return ((*len == (size_t)-1) ? NULL : lb);
}
+#elif defined(__sun)
+/* no getline(), this code is from NetBSD */
+#include <stdlib.h>
+#include <errno.h>
+/*
+ * XXX: This implementation doesn't quite conform to the specification
+ * in the man page, in that it only manages one buffer at all, not one
+ * per stdio stream. Since the previous implementation did the same,
+ * this won't break anything new.
+ */
+char *
+fgetln(fp, len)
+ FILE *fp;
+ size_t *len;
+{
+ static char *buf = NULL;
+ static size_t bufsiz = 0;
+ static size_t buflen = 0;
+ int c;
+
+ if (buf == NULL) {
+ bufsiz = BUFSIZ;
+ if ((buf = malloc(bufsiz)) == NULL)
+ return NULL;
+ }
+
+ buflen = 0;
+ while ((c = fgetc(fp)) != EOF) {
+ if (buflen >= bufsiz) {
+ size_t nbufsiz = bufsiz + BUFSIZ;
+ char *nbuf = realloc(buf, nbufsiz);
+
+ if (nbuf == NULL) {
+ int oerrno = errno;
+ free(buf);
+ errno = oerrno;
+ buf = NULL;
+ return NULL;
+ }
+
+ buf = nbuf;
+ bufsiz = nbufsiz;
+ }
+ buf[buflen++] = c;
+ if (c == '\n')
+ break;
+ }
+ *len = buflen;
+ return buflen == 0 ? NULL : buf;
+}
#endif
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/fileio.c mg-20110905-bnjf/fileio.c
--- mg-20110905/fileio.c 2011-09-06 04:26:37.000000000 +1000
+++ mg-20110905-bnjf/fileio.c 2011-12-06 10:22:23.772502000 +1100
@@ -27,6 +27,10 @@

#include "kbd.h"

+#ifndef HAVE_VASPRINTF
+#include "vasprintf.h"
+#endif
+
static FILE *ffp;

/*
@@ -570,7 +574,7 @@
#if defined (__CYGWIN__) /* Cygwin lacks reclen/namlen. */
if (strlen(dent->d_name) < len
|| memcmp(cp, dent->d_name, len) != 0)
-#elif defined (__GLIBC__) /* Linux uses reclen instead. */
+#elif defined (__GLIBC__) || (__sun) /* Linux uses reclen instead. */
if (dent->d_reclen < len || memcmp(cp, dent->d_name, len) != 0)
#else
if (dent->d_namlen < len || memcmp(cp, dent->d_name, len) != 0)
@@ -579,7 +583,7 @@

isdir = 0;

-#ifndef __CYGWIN__ /* No support for d_type in Cygwin, do all
+#if !defined(__CYGWIN__) && !defined(__sun) /* No support for d_type in Cygwin, do all
type cheking with stat. */
if (dent->d_type == DT_DIR) {
isdir = 1;
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/grep.c mg-20110905-bnjf/grep.c
--- mg-20110905/grep.c 2011-01-03 09:57:56.000000000 +1100
+++ mg-20110905-bnjf/grep.c 2011-12-06 10:25:58.503723000 +1100
@@ -13,6 +13,8 @@

#include <time.h>

+#include "strsep.h"
+
int globalwd = FALSE;
static int compile_goto_error(int, int);
int next_error(int, int);
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/main.c mg-20110905-bnjf/main.c
--- mg-20110905/main.c 2011-01-03 09:57:56.000000000 +1100
+++ mg-20110905-bnjf/main.c 2011-12-06 10:26:45.143439000 +1100
@@ -14,7 +14,11 @@
#include "macro.h"
#endif /* NO_MACRO */

+#ifndef HAVE_ERR_H
+#include "err.h"
+#else
#include <err.h>
+#endif

int thisflag; /* flags, this command */
int lastflag; /* flags, last command */
@@ -34,8 +38,7 @@
static void
usage()
{
- fprintf(stderr, "usage: %s [-n] [-f mode] [+number] [file ...]\n",
- __progname);
+ fprintf(stderr, "usage: mg [-n] [-f mode] [+number] [file ...]\n");
exit(1);
}

diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/spawn.c mg-20110905-bnjf/spawn.c
--- mg-20110905/spawn.c 2006-08-02 09:33:03.000000000 +1000
+++ mg-20110905-bnjf/spawn.c 2011-12-06 09:56:52.332736000 +1100
@@ -10,7 +10,7 @@
#include "def.h"

#include <termios.h>
-#include <term.h>
+#include <ncurses/term.h>

/*
* This causes mg to send itself a stop signal. It assumes the parent
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/strsep.c mg-20110905-bnjf/strsep.c
--- mg-20110905/strsep.c 1970-01-01 10:00:00.000000000 +1000
+++ mg-20110905-bnjf/strsep.c 2011-12-06 10:26:16.806106000 +1100
@@ -0,0 +1,30 @@
+#ifndef HAVE_STRSEP
+
+/* http://does-not-exist.org/mail-archives/mutt-dev/msg10335.html */
+
+#include <stdlib.h>
+#include <strings.h>
+
+char* strsep(char** str, const char* delims)
+{
+ char* token;
+
+ if (*str==NULL) {
+ /* No more tokens */
+ return NULL;
+ }
+
+ token=*str;
+ while (**str!='\0') {
+ if (strchr(delims,**str)!=NULL) {
+ **str='\0';
+ (*str)++;
+ return token;
+ }
+ (*str)++;
+ }
+ /* There is no other token */
+ *str=NULL;
+ return token;
+}
+#endif
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/strsep.h mg-20110905-bnjf/strsep.h
--- mg-20110905/strsep.h 1970-01-01 10:00:00.000000000 +1000
+++ mg-20110905-bnjf/strsep.h 2011-12-06 10:26:20.646658000 +1100
@@ -0,0 +1,4 @@
+
+#ifndef HAVE_STRSEP
+char* strsep(char**, const char*);
+#endif
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/sysdef.h mg-20110905-bnjf/sysdef.h
--- mg-20110905/sysdef.h 2011-01-03 10:03:41.000000000 +1100
+++ mg-20110905-bnjf/sysdef.h 2011-12-06 10:14:29.912262000 +1100
@@ -71,3 +71,14 @@
#ifndef LOGIN_NAME_MAX
#define LOGIN_NAME_MAX MAXLOGNAME
#endif
+
+#if (defined (__SVR4) && defined (__sun))
+#include <iso/limits_iso.h> /* INT_MIN, INT_MAX */
+#include <strings.h> /* bcopy(), bzero() */
+#include <sys/filio.h> /* ttyio.c wants FIONREAD */
+#endif
+
+#ifndef MAX
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#endif
+
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/tty.c mg-20110905-bnjf/tty.c
--- mg-20110905/tty.c 2008-12-11 20:32:56.000000000 +1100
+++ mg-20110905-bnjf/tty.c 2011-12-06 09:56:52.438691000 +1100
@@ -33,7 +33,7 @@
#include <sys/time.h>
#include <sys/ioctl.h>

-#include <term.h>
+#include <ncurses/term.h>

static int charcost(char *);

diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/ttyio.c mg-20110905-bnjf/ttyio.c
--- mg-20110905/ttyio.c 2008-12-11 19:59:08.000000000 +1100
+++ mg-20110905-bnjf/ttyio.c 2011-12-06 09:56:52.467209000 +1100
@@ -16,7 +16,7 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include <termios.h>
-#include <term.h>
+#include <ncurses/term.h>

#define NOBUF 512 /* Output buffer size. */

diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/ttykbd.c mg-20110905-bnjf/ttykbd.c
--- mg-20110905/ttykbd.c 2006-04-27 12:28:14.000000000 +1000
+++ mg-20110905-bnjf/ttykbd.c 2011-12-06 09:56:52.487168000 +1100
@@ -12,7 +12,7 @@
#include "kbd.h"

#ifdef XKEYS
-#include <term.h>
+#include <ncurses/term.h>

#ifdef FKEYS
/*
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/vasprintf.c mg-20110905-bnjf/vasprintf.c
--- mg-20110905/vasprintf.c 1970-01-01 10:00:00.000000000 +1000
+++ mg-20110905-bnjf/vasprintf.c 2011-12-06 10:15:28.696799000 +1100
@@ -0,0 +1,43 @@
+
+/* http://blogs.everycity.co.uk/alasdair/2011/07/vasprintf-and-asprintf-on-solaris-10/ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "vasprintf.h"
+
+int vasprintf(char **ret, const char *format, va_list args)
+{
+ va_list copy;
+ va_copy(copy, args);
+
+ /* Make sure it is determinate, despite manuals indicating otherwise */
+ *ret = 0;
+
+ int count = vsnprintf(NULL, 0, format, args);
+ if (count >= 0) {
+ char* buffer = malloc(count + 1);
+ if (buffer != NULL) {
+ count = vsnprintf(buffer, count + 1, format, copy);
+ if (count < 0)
+ free(buffer);
+ else
+ *ret = buffer;
+ }
+ }
+ va_end(args); /* Each va_start() or va_copy() needs a va_end() */
+
+ return count;
+}
+
+int asprintf(char **strp, const char *fmt, ...)
+{
+ int size;
+ va_list args;
+ va_start(args, fmt);
+ size = vasprintf(strp, fmt, args);
+ va_end(args);
+ return size;
+}
+
diff -uN -x Makefile -x config.h -x config.log -x configure mg-20110905/vasprintf.h mg-20110905-bnjf/vasprintf.h
--- mg-20110905/vasprintf.h 1970-01-01 10:00:00.000000000 +1000
+++ mg-20110905-bnjf/vasprintf.h 2011-12-06 10:08:48.358724000 +1100
@@ -0,0 +1,6 @@
+
+#include <varargs.h>
+
+int vasprintf(char **, const char *, va_list);
+int asprintf(char **, const char *, ...);
+

No comments: