about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJohn C. Vernaleo <jcv@conformal.com>2013-01-09 08:54:56 -0500
committerJohn C. Vernaleo <jcv@conformal.com>2013-04-19 17:23:11 -0400
commit820b9ddfa479117a385c3da8fb224a301df755cf (patch)
tree46fd347a2eb5b8f886938985bf410ab52aa7a7a9
parent9c415e6086755ad83cfc8a6404fe803e341ee11a (diff)
downloadxombrero-820b9ddfa479117a385c3da8fb224a301df755cf.tar.gz
Add osx build support (using macports).
Based on initial patch from Tim Meunier <trondd@gmail.com>).

Add temporary files to .gitignore.
-rw-r--r--.gitignore4
-rw-r--r--osx/Makefile96
-rw-r--r--osx/osx.c308
-rw-r--r--xombrero.c4
-rw-r--r--xombrero.h9
5 files changed, 421 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4ca070d..374d281 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,11 @@
 *.orig
 *.rej
 *.rej.orig
+*~
 javascript.h
 xombrero
 xombrero.cat1
 tags
+osx/tooltip.h
+osx/tree.h
+osx/util.h
diff --git a/osx/Makefile b/osx/Makefile
new file mode 100644
index 0000000..eaa9bfe
--- /dev/null
+++ b/osx/Makefile
@@ -0,0 +1,96 @@
+LIBS= glib-2.0
+LIBS+= gtk+-2.0 webkit-1.0
+LIBS+= libsoup-2.4 gthread-2.0 gnutls
+
+CFLAGS+= -O2 -Wall -D_GNU_SOURCE -I. -I.. $(shell pkg-config --cflags $(LIBS)) $(JS_CF)
+LDADD+= $(shell pkg-config --libs $(LIBS)) $(JS_LD) -ldl -lgcrypt -lX11
+
+PREFIX?= /usr/local
+BINDIR?= $(PREFIX)/bin
+LIBDIR?= $(PREFIX)/lib
+APPDIR?= $(PREFIX)/share/applications
+MANDIR?= $(PREFIX)/share/man
+RESDIR?= $(PREFIX)/share/xombrero
+
+SRCS= $(shell ls ../*.c)
+SRCS+= osx.c
+OBJS= $(SRCS:.c=.o)
+DEPS= $(addsuffix .depend, $(OBJS))
+
+CC?= gcc
+
+BUILDVERSION= $(shell sh $(CURDIR)/../buildver.sh)
+ifneq ("${BUILDVERSION}", "")
+CFLAGS+= -DXOMBRERO_BUILDSTR=\"$(BUILDVERSION)\"
+endif
+
+all: javascript.h tooltip.h xombrero
+
+javascript.h: ../js-merge-helper.pl ../hinting.js ../autoscroll.js
+	perl ../js-merge-helper.pl ../hinting.js ../input-focus.js \
+	../autoscroll.js > javascript.h
+
+tooltip.h: ../ascii2txt.pl ../txt2tooltip.pl ../xombrero.1
+	ln -sf ../linux/tree.h
+	ln -sf ../linux/util.h
+	nroff -c -Tascii -mandoc ../xombrero.1 | \
+	perl ../ascii2txt.pl | \
+	perl ../txt2tooltip.pl > tooltip.h
+
+xombrero: $(OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LDADD)
+
+%.o: %.c
+	@echo "Generating $@.depend"
+	@$(CC) -MM $(CPPFLAGS) $(CFLAGS) $< | \
+	sed 's,^.*\.o[ :]*,$@ $@.depend : ,g' > $@.depend
+	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
+
+install: all
+	install -m 755 -d $(DESTDIR)$(BINDIR)
+	install -m 755 -d $(DESTDIR)$(LIBDIR)
+	install -m 755 -d $(DESTDIR)$(MANDIR)/man1
+	install -m 755 -d $(DESTDIR)$(RESDIR)
+	install -m 755 -d $(DESTDIR)$(APPDIR)
+	install -m 755 xombrero $(DESTDIR)$(BINDIR)
+	install -m 644 ../xombrero.1 $(DESTDIR)$(MANDIR)/man1/xombrero.1
+	install -m 644 ../xombrero.css $(DESTDIR)$(RESDIR)
+	install -m 644 ../xombrero.desktop $(DESTDIR)$(APPDIR)
+	install -m 644 ../xombreroicon16.png $(DESTDIR)$(RESDIR)
+	install -m 644 ../xombreroicon32.png $(DESTDIR)$(RESDIR)
+	install -m 644 ../xombreroicon48.png $(DESTDIR)$(RESDIR)
+	install -m 644 ../xombreroicon64.png $(DESTDIR)$(RESDIR)
+	install -m 644 ../xombreroicon128.png $(DESTDIR)$(RESDIR)
+	install -m 644 ../tld-rules $(DESTDIR)$(RESDIR)
+	install -m 644 ../style.css $(DESTDIR)$(RESDIR)
+	install -m 644 ../hsts-preload $(DESTDIR)$(RESDIR)
+	install -m 644 ../torenabled.ico $(DESTDIR)$(RESDIR)
+	install -m 644 ../tordisabled.ico $(DESTDIR)$(RESDIR)
+
+uninstall:
+	rm -f $(DESTDIR)$(BINDIR)/xombrero
+	rm -f $(DESTDIR)$(MANDIR)/man1/xombrero.1
+	rm -f $(DESTDIR)$(PREFIX)/share/applications/xombrero.desktop
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon.png
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon16.png
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon32.png
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon48.png
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon64.png
+	rm -f $(DESTDIR)$(RESDIR)/xombreroicon128.png
+	rm -f $(DESTDIR)$(RESDIR)/xombrero.css
+	rm -f $(DESTDIR)$(RESDIR)/tordisabled.ico
+	rm -f $(DESTDIR)$(RESDIR)/torenabled.ico
+	rm -f $(DESTDIR)$(RESDIR)/tld-rules
+	rm -f $(DESTDIR)$(RESDIR)/style.css
+	rm -f $(DESTDIR)$(RESDIR)/hsts-preload
+	if [ -d $(DESTDIR)$(RESDIR) ]; then rmdir $(DESTDIR)$(RESDIR); fi
+clean:
+	rm -f xombrero $(OBJS) $(DEPS)
+	rm -f javascript.h
+	rm -f tooltip.h
+	rm -f tree.h
+	rm -f util.h
+
+-include $(DEPS)
+
+.PHONY: all install clean
diff --git a/osx/osx.c b/osx/osx.c
new file mode 100644
index 0000000..18dbaea
--- /dev/null
+++ b/osx/osx.c
@@ -0,0 +1,308 @@
+/*	$OpenBSD: fmt_scaled.c,v 1.10 2009/06/20 15:00:04 martynas Exp $	*/
+
+/*
+ * Copyright (c) 2001, 2002, 2003 Ian F. Darwin.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * fmt_scaled: Format numbers scaled for human comprehension
+ * scan_scaled: Scan numbers in this format.
+ *
+ * "Human-readable" output uses 4 digits max, and puts a unit suffix at
+ * the end.  Makes output compact and easy-to-read esp. on huge disks.
+ * Formatting code was originally in OpenBSD "df", converted to library routine.
+ * Scanning code written for OpenBSD libutil.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+#include <unistd.h>
+
+#include "util.h"
+
+typedef enum {
+	NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6
+} unit_type;
+
+/* These three arrays MUST be in sync!  XXX make a struct */
+static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA };
+static char scale_chars[] = "BKMGTPE";
+static long long scale_factors[] = {
+	1LL,
+	1024LL,
+	1024LL*1024,
+	1024LL*1024*1024,
+	1024LL*1024*1024*1024,
+	1024LL*1024*1024*1024*1024,
+	1024LL*1024*1024*1024*1024*1024,
+};
+#define	SCALE_LENGTH (sizeof(units)/sizeof(units[0]))
+
+#define MAX_DIGITS (SCALE_LENGTH * 3)	/* XXX strlen(sprintf("%lld", -1)? */
+
+/* Convert the given input string "scaled" into numeric in "result".
+ * Return 0 on success, -1 and errno set on error.
+ */
+int
+scan_scaled(char *scaled, long long *result)
+{
+	char *p = scaled;
+	int sign = 0;
+	unsigned int i, ndigits = 0, fract_digits = 0;
+	long long scale_fact = 1, whole = 0, fpart = 0;
+
+	/* Skip leading whitespace */
+	while (isascii(*p) && isspace(*p))
+		++p;
+
+	/* Then at most one leading + or - */
+	while (*p == '-' || *p == '+') {
+		if (*p == '-') {
+			if (sign) {
+				errno = EINVAL;
+				return -1;
+			}
+			sign = -1;
+			++p;
+		} else if (*p == '+') {
+			if (sign) {
+				errno = EINVAL;
+				return -1;
+			}
+			sign = +1;
+			++p;
+		}
+	}
+
+	/* Main loop: Scan digits, find decimal point, if present.
+	 * We don't allow exponentials, so no scientific notation
+	 * (but note that E for Exa might look like e to some!).
+	 * Advance 'p' to end, to get scale factor.
+	 */
+	for (; isascii(*p) && (isdigit(*p) || *p=='.'); ++p) {
+		if (*p == '.') {
+			if (fract_digits > 0) {	/* oops, more than one '.' */
+				errno = EINVAL;
+				return -1;
+			}
+			fract_digits = 1;
+			continue;
+		}
+
+		i = (*p) - '0';			/* whew! finally a digit we can use */
+		if (fract_digits > 0) {
+			if (fract_digits >= MAX_DIGITS-1)
+				/* ignore extra fractional digits */
+				continue;
+			fract_digits++;		/* for later scaling */
+			fpart *= 10;
+			fpart += i;
+		} else {				/* normal digit */
+			if (++ndigits >= MAX_DIGITS) {
+				errno = ERANGE;
+				return -1;
+			}
+			whole *= 10;
+			whole += i;
+		}
+	}
+
+	if (sign) {
+		whole *= sign;
+		fpart *= sign;
+	}
+
+	/* If no scale factor given, we're done. fraction is discarded. */
+	if (!*p) {
+		*result = whole;
+		return 0;
+	}
+
+	/* Validate scale factor, and scale whole and fraction by it. */
+	for (i = 0; i < SCALE_LENGTH; i++) {
+
+		/* Are we there yet? */
+		if (*p == scale_chars[i] ||
+			*p == tolower(scale_chars[i])) {
+
+			/* If it ends with alphanumerics after the scale char, bad. */
+			if (isalnum(*(p+1))) {
+				errno = EINVAL;
+				return -1;
+			}
+			scale_fact = scale_factors[i];
+
+			/* scale whole part */
+			whole *= scale_fact;
+
+			/* truncate fpart so it does't overflow.
+			 * then scale fractional part.
+			 */
+			while (fpart >= LLONG_MAX / scale_fact) {
+				fpart /= 10;
+				fract_digits--;
+			}
+			fpart *= scale_fact;
+			if (fract_digits > 0) {
+				for (i = 0; i < fract_digits -1; i++)
+					fpart /= 10;
+			}
+			whole += fpart;
+			*result = whole;
+			return 0;
+		}
+	}
+	errno = ERANGE;
+	return -1;
+}
+
+/* Format the given "number" into human-readable form in "result".
+ * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE.
+ * Return 0 on success, -1 and errno set if error.
+ */
+int
+fmt_scaled(long long number, char *result)
+{
+	long long abval, fract = 0;
+	unsigned int i;
+	unit_type unit = NONE;
+
+	abval = llabs(number);
+
+	/* Not every negative long long has a positive representation.
+	 * Also check for numbers that are just too darned big to format
+	 */
+	if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) {
+		errno = ERANGE;
+		return -1;
+	}
+
+	/* scale whole part; get unscaled fraction */
+	for (i = 0; i < SCALE_LENGTH; i++) {
+		if (abval/1024 < scale_factors[i]) {
+			unit = units[i];
+			fract = (i == 0) ? 0 : abval % scale_factors[i];
+			number /= scale_factors[i];
+			if (i > 0)
+				fract /= scale_factors[i - 1];
+			break;
+		}
+	}
+
+	fract = (10 * fract + 512) / 1024;
+	/* if the result would be >= 10, round main number */
+	if (fract == 10) {
+		if (number >= 0)
+			number++;
+		else
+			number--;
+		fract = 0;
+	}
+
+	if (number == 0)
+		strlcpy(result, "0B", FMT_SCALED_STRSIZE);
+	else if (unit == NONE || number >= 100 || number <= -100) {
+		if (fract >= 5) {
+			if (number >= 0)
+				number++;
+			else
+				number--;
+		}
+		(void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c",
+			number, scale_chars[unit]);
+	} else
+		(void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c",
+			number, fract, scale_chars[unit]);
+
+	return 0;
+}
+
+
+/* --------------------------------------------------------------------------- */
+/*	$OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert 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.
+ */
+
+#define INVALID 	1
+#define TOOSMALL 	2
+#define TOOLARGE 	3
+
+long long
+strtonum(const char *numstr, long long minval, long long maxval,
+    const char **errstrp)
+{
+	long long ll = 0;
+	char *ep;
+	int error = 0;
+	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);
+}
diff --git a/xombrero.c b/xombrero.c
index a88c948..ad5b287 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -8719,7 +8719,11 @@ main(int argc, char **argv)
 		warn("getrlimit");
 	else {
 		/* just use them all */
+#ifdef __APPLE__
+		rlp.rlim_cur = OPEN_MAX;
+#else
 		rlp.rlim_cur = rlp.rlim_max;
+#endif
 		if (setrlimit(RLIMIT_NOFILE, &rlp) == -1)
 			warn("setrlimit");
 		if (getrlimit(RLIMIT_NOFILE, &rlp) == -1)
diff --git a/xombrero.h b/xombrero.h
index e47f383..b5f91cc 100644
--- a/xombrero.h
+++ b/xombrero.h
@@ -42,6 +42,15 @@
 void		arc4random_buf(void *, size_t);
 u_int32_t	arc4random_uniform(u_int32_t);
 # endif
+#elif defined(__APPLE__)
+#include "osx/util.h"
+#include "osx/tree.h"
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <sys/un.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+#define LOGIN_NAME_MAX MAXLOGNAME
 #elif defined(__FreeBSD__)
 #include <libutil.h>
 #include "freebsd/util.h"