diff options
-rw-r--r-- | netbsd/Makefile | 180 | ||||
-rw-r--r-- | netbsd/netbsd.c | 309 | ||||
-rw-r--r-- | netbsd/util.h | 35 | ||||
-rw-r--r-- | xombrero.h | 8 |
4 files changed, 531 insertions, 1 deletions
diff --git a/netbsd/Makefile b/netbsd/Makefile new file mode 100644 index 0000000..17f583c --- /dev/null +++ b/netbsd/Makefile @@ -0,0 +1,180 @@ +GTK_VERSION?= gtk3 +.if ${GTK_VERSION} == "gtk2" +LIBS= gtk+-2.0 webkit-1.0 +.else +LIBS= gtk+-3.0 webkitgtk-3.0 +.endif +LIBS+= libsoup-2.4 gnutls gthread-2.0 + +LDADD= -lutil -lgcrypt -lX11 +GTK_CFLAGS!= pkg-config --cflags $(LIBS) +GTK_LDFLAGS!= pkg-config --libs $(LIBS) +CFLAGS+= $(GTK_CFLAGS) -O2 -Wall -pthread -I. -I.. +LDFLAGS+= $(GTK_LDFLAGS) -pthread + +PREFIX?= /usr/local +BINDIR?= $(PREFIX)/bin +LIBDIR?= $(PREFIX)/lib +MANDIR?= $(PREFIX)/man +RESDIR?= $(PREFIX)/share/xombrero + +CC= cc + +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 + nroff -c -Tascii -mandoc ../xombrero.1 | \ + perl ../ascii2txt.pl | \ + perl ../txt2tooltip.pl > ../tooltip.h + +xombrero.o: ../xombrero.o + +unix.o: ../unix.o + +marco.o: ../marco.o + +whitelist.o: ../whitelist.o + +settings.o: ../settings.o + +about.o: ../about.o + +inspector.o: ../inspector.o + +cookie.o: ../cookie.o + +inputfocus.o: ../inputfocus.o + +history.o: ../history.o + +completion.o: ../completion.o + +externaleditor.o: ../externaleditor.o + +tldlist.o: ../tldlist.o + +../xombrero.o: ../javascript.h ../tooltip.h + +xombrero: xombrero.o netbsd.o marco.o about.o inspector.o whitelist.o settings.o \ + cookie.o history.o completion.o inputfocus.o tldlist.o externaleditor.o \ + unix.o + $(CC) $(LDFLAGS) -o $@ *.o $+ $(LDADD) + +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 xombrero $(DESTDIR)$(BINDIR) + install -m 644 ../xombrero.1 $(DESTDIR)$(MANDIR)/man1/xombrero.1 + install -m 644 ../xombrero.css $(DESTDIR)$(RESDIR) + 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) + +clean: + rm -f xombrero *.o + rm -f javascript.h + rm -f tooltip.h + +.PHONY: all install clean +PREFIX?=/usr/local +BINDIR=${PREFIX}/bin + +PROG=xombrero +MAN=xombrero.1 + +DEBUG= -g + +SRCS= cookie.c inspector.c marco.c about.c whitelist.c settings.c inputfocus.c +SRCS+= history.c completion.c tldlist.c externaleditor.c unix.c xombrero.c +CFLAGS+= -O2 -Wall -Wno-format-extra-args -Wunused +CFLAGS+= -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare ${DEBUG} +CFLAGS+= -DGTK_DISABLE_SINGLE_INCLUDES -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE +CFLAGS+= -I. -I${.CURDIR} +LDADD= -lutil -lgcrypt +GTK_VERSION ?= gtk3 +.if ${GTK_VERSION} == "gtk2" +LIBS+= gtk+-2.0 +LIBS+= webkit-1.0 +.else +LIBS+= gtk+-3.0 +LIBS+= webkitgtk-3.0 +.endif +LIBS+= libsoup-2.4 +LIBS+= gnutls +LIBS+= gthread-2.0 +GTK_CFLAGS!= pkg-config --cflags $(LIBS) +GTK_LDFLAGS!= pkg-config --libs $(LIBS) +CFLAGS+= $(GTK_CFLAGS) +LDFLAGS+= $(GTK_LDFLAGS) +BUILDVERSION != sh "${.CURDIR}/buildver.sh" +.if !${BUILDVERSION} == "" +CPPFLAGS+= -DXOMBRERO_BUILDSTR=\"$(BUILDVERSION)\" +.endif + +MANDIR= ${PREFIX}/man/man + +CLEANFILES += ${.CURDIR}/javascript.h javascript.h tooltip.h xombrero.cat1 xombrero.core + +JSFILES += hinting.js +JSFILES += input-focus.js +JSFILES += autoscroll.js + +.for _js in ${JSFILES} +JSCURDIR += ${.CURDIR}/${_js} +.endfor + +javascript.h: ${JSFILES} js-merge-helper.pl + perl ${.CURDIR}/js-merge-helper.pl \ + ${JSCURDIR} > javascript.h + +tooltip.h: ${MAN} ascii2txt.pl txt2tooltip.pl + mandoc -Tascii ${.CURDIR}/${MAN} | \ + perl ${.CURDIR}/ascii2txt.pl | \ + perl ${.CURDIR}/txt2tooltip.pl > tooltip.h + +beforeinstall: + install -m 755 -d ${PREFIX}/bin + install -m 755 -d ${PREFIX}/man/man1/ + install -m 755 -d ${PREFIX}/share/xombrero + install -m 644 $(.CURDIR)/xombrero.css ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon16.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon32.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon48.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon64.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/xombreroicon128.png ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/tld-rules ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/style.css ${PREFIX}/share/xombrero + install -m 644 ${.CURDIR}/hsts-preload ${PREFIX}/share/xombrero + +${PROG} ${OBJS} beforedepend: javascript.h tooltip.h + +# clang targets +.if ${.TARGETS:M*analyze*} +CFLAGS+= -Wdeclaration-after-statement -Wshadow +CC=clang +CXX=clang++ +CPP=clang -E +CFLAGS+=--analyze +.elif ${.TARGETS:M*clang*} +CFLAGS+= -Wdeclaration-after-statement -Wshadow +CC=clang +CXX=clang++ +CPP=clang -E +.endif + +analyze: all +clang: all + +.include <bsd.prog.mk> diff --git a/netbsd/netbsd.c b/netbsd/netbsd.c new file mode 100644 index 0000000..93c41e0 --- /dev/null +++ b/netbsd/netbsd.c @@ -0,0 +1,309 @@ +/* $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 "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. + */ + +#include <errno.h> +#include <limits.h> +#include <stdlib.h> + +#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/netbsd/util.h b/netbsd/util.h new file mode 100644 index 0000000..d08783f --- /dev/null +++ b/netbsd/util.h @@ -0,0 +1,35 @@ +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ + (x) = (y)) + + +#ifndef TAILQ_END +#define TAILQ_END(head) NULL +#endif + +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head) && \ + ((tvar) = TAILQ_NEXT(var, field), 1); \ + (var) = (tvar)) +#endif + +#define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */ +int fmt_scaled(long long number, char *result); diff --git a/xombrero.h b/xombrero.h index 9365f73..7e97d88 100644 --- a/xombrero.h +++ b/xombrero.h @@ -53,12 +53,18 @@ u_int32_t arc4random_uniform(u_int32_t); #elif defined(__DragonFly__) #include <sys/param.h> #include <sys/un.h> -#include <sys/param.h> #include <libutil.h> #include "dragonfly/util.h" #include <sys/tree.h> #include <X11/Xlib.h> #define LOGIN_NAME_MAX MAXLOGNAME +#elif defined(__NetBSD__) +#include <sys/param.h> +#include <sys/un.h> +#include "netbsd/util.h" +#include <sys/tree.h> +#include <X11/Xlib.h> +#define LOGIN_NAME_MAX_MAXLOGNAME #elif defined(__OpenBSD__) #include <util.h> #include <sys/tree.h> |