Advertisement
Guest User

DragonflyBSD xombrero port

a guest
Aug 29th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. diff --git a/dragonfly/Makefile b/dragonfly/Makefile
  2. new file mode 100644
  3. index 0000000..949e1b8
  4. --- /dev/null
  5. +++ b/dragonfly/Makefile
  6. @@ -0,0 +1,89 @@
  7. +GTK_VERSION?= gtk3
  8. +.if ${GTK_VERSION} == "gtk2"
  9. +LIBS= gtk+-2.0 webkit-1.0
  10. +.else
  11. +LIBS= gtk+-3.0 webkitgtk-3.0
  12. +.endif
  13. +LIBS+= libsoup-2.4 gnutls gthread-2.0
  14. +
  15. +LDADD= -lutil -lgcrypt -lX11
  16. +GTK_CFLAGS!= pkg-config --cflags $(LIBS)
  17. +GTK_LDFLAGS!= pkg-config --libs $(LIBS)
  18. +CFLAGS+= $(GTK_CFLAGS) -O2 -Wall -pthread -I. -I..
  19. +LDFLAGS+= $(GTK_LDFLAGS) -pthread
  20. +
  21. +PREFIX?= /usr/local
  22. +BINDIR?= $(PREFIX)/bin
  23. +LIBDIR?= $(PREFIX)/lib
  24. +MANDIR?= $(PREFIX)/man
  25. +#SRCS= $(shell ls ../*.c)
  26. +#SRCS+= dragonfly.c
  27. +
  28. +CC= cc
  29. +
  30. +all: ../javascript.h ../tooltip.h xombrero
  31. +
  32. +../javascript.h: ../js-merge-helper.pl ../hinting.js ../autoscroll.js
  33. + perl ../js-merge-helper.pl ../hinting.js ../input-focus.js \
  34. + ../autoscroll.js > ../javascript.h
  35. +
  36. +../tooltip.h: ../ascii2txt.pl ../txt2tooltip.pl ../xombrero.1
  37. + nroff -c -Tascii -mandoc ../xombrero.1 | \
  38. + perl ../ascii2txt.pl | \
  39. + perl ../txt2tooltip.pl > ../tooltip.h
  40. +
  41. +xombrero.o: ../xombrero.o
  42. +
  43. +unix.o: ../unix.o
  44. +
  45. +marco.o: ../marco.o
  46. +
  47. +whitelist.o: ../whitelist.o
  48. +
  49. +settings.o: ../settings.o
  50. +
  51. +about.o: ../about.o
  52. +
  53. +inspector.o: ../inspector.o
  54. +
  55. +cookie.o: ../cookie.o
  56. +
  57. +inputfocus.o: ../inputfocus.o
  58. +
  59. +history.o: ../history.o
  60. +
  61. +completion.o: ../completion.o
  62. +
  63. +externaleditor.o: ../externaleditor.o
  64. +
  65. +tldlist.o: ../tldlist.o
  66. +
  67. +../xombrero.o: ../javascript.h ../tooltip.h
  68. +
  69. +xombrero: xombrero.o dragonfly.o marco.o about.o inspector.o whitelist.o settings.o \
  70. + cookie.o history.o completion.o inputfocus.o tldlist.o externaleditor.o \
  71. + unix.o
  72. + $(CC) $(LDFLAGS) -o $@ *.o $+ $(LDADD)
  73. +
  74. +install: all
  75. + install -m 755 -d $(DESTDIR)$(BINDIR)
  76. + install -m 755 -d $(DESTDIR)$(LIBDIR)
  77. + install -m 755 -d $(DESTDIR)$(MANDIR)/man1
  78. + install -m 755 xombrero $(DESTDIR)$(BINDIR)
  79. + install -m 644 ../xombrero.1 $(DESTDIR)$(MANDIR)/man1/xombrero.1
  80. + install -m 644 ../xombrero.css $(DESTDIR)$(RESDIR)
  81. + install -m 644 ../xombreroicon16.png $(DESTDIR)$(RESDIR)
  82. + install -m 644 ../xombreroicon32.png $(DESTDIR)$(RESDIR)
  83. + install -m 644 ../xombreroicon48.png $(DESTDIR)$(RESDIR)
  84. + install -m 644 ../xombreroicon64.png $(DESTDIR)$(RESDIR)
  85. + install -m 644 ../xombreroicon128.png $(DESTDIR)$(RESDIR)
  86. + install -m 644 ../tld-rules $(DESTDIR)$(RESDIR)
  87. + install -m 644 ../style.css $(DESTDIR)$(RESDIR)
  88. + install -m 644 ../hsts-preload $(DESTDIR)$(RESDIR)
  89. +
  90. +clean:
  91. + rm -f xombrero *.o
  92. + rm -f javascript.h
  93. + rm -f tooltip.h
  94. +
  95. +.PHONY: all install clean
  96. diff --git a/dragonfly/dragonfly.c b/dragonfly/dragonfly.c
  97. new file mode 100644
  98. index 0000000..b86131f
  99. --- /dev/null
  100. +++ b/dragonfly/dragonfly.c
  101. @@ -0,0 +1,244 @@
  102. +/* $OpenBSD: fmt_scaled.c,v 1.10 2009/06/20 15:00:04 martynas Exp $ */
  103. +
  104. +/*
  105. + * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
  106. + *
  107. + * Redistribution and use in source and binary forms, with or without
  108. + * modification, are permitted provided that the following conditions
  109. + * are met:
  110. + * 1. Redistributions of source code must retain the above copyright
  111. + * notice, this list of conditions and the following disclaimer.
  112. + * 2. Redistributions in binary form must reproduce the above copyright
  113. + * notice, this list of conditions and the following disclaimer in the
  114. + * documentation and/or other materials provided with the distribution.
  115. + * 3. The name of the author may not be used to endorse or promote products
  116. + * derived from this software without specific prior written permission.
  117. + *
  118. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  119. + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  120. + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  121. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  122. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  123. + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  124. + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  125. + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  126. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  127. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  128. + */
  129. +
  130. +/*
  131. + * fmt_scaled: Format numbers scaled for human comprehension
  132. + * scan_scaled: Scan numbers in this format.
  133. + *
  134. + * "Human-readable" output uses 4 digits max, and puts a unit suffix at
  135. + * the end. Makes output compact and easy-to-read esp. on huge disks.
  136. + * Formatting code was originally in OpenBSD "df", converted to library routine.
  137. + * Scanning code written for OpenBSD libutil.
  138. + */
  139. +
  140. +#include <stdio.h>
  141. +#include <stdlib.h>
  142. +#include <errno.h>
  143. +#include <string.h>
  144. +#include <ctype.h>
  145. +#include <limits.h>
  146. +
  147. +#include "util.h"
  148. +
  149. +typedef enum {
  150. + NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6
  151. +} unit_type;
  152. +
  153. +/* These three arrays MUST be in sync! XXX make a struct */
  154. +static unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA };
  155. +static char scale_chars[] = "BKMGTPE";
  156. +static long long scale_factors[] = {
  157. + 1LL,
  158. + 1024LL,
  159. + 1024LL*1024,
  160. + 1024LL*1024*1024,
  161. + 1024LL*1024*1024*1024,
  162. + 1024LL*1024*1024*1024*1024,
  163. + 1024LL*1024*1024*1024*1024*1024,
  164. +};
  165. +#define SCALE_LENGTH (sizeof(units)/sizeof(units[0]))
  166. +
  167. +#define MAX_DIGITS (SCALE_LENGTH * 3) /* XXX strlen(sprintf("%lld", -1)? */
  168. +
  169. +/* Convert the given input string "scaled" into numeric in "result".
  170. + * Return 0 on success, -1 and errno set on error.
  171. + */
  172. +int
  173. +scan_scaled(char *scaled, long long *result)
  174. +{
  175. + char *p = scaled;
  176. + int sign = 0;
  177. + unsigned int i, ndigits = 0, fract_digits = 0;
  178. + long long scale_fact = 1, whole = 0, fpart = 0;
  179. +
  180. + /* Skip leading whitespace */
  181. + while (isascii(*p) && isspace(*p))
  182. + ++p;
  183. +
  184. + /* Then at most one leading + or - */
  185. + while (*p == '-' || *p == '+') {
  186. + if (*p == '-') {
  187. + if (sign) {
  188. + errno = EINVAL;
  189. + return -1;
  190. + }
  191. + sign = -1;
  192. + ++p;
  193. + } else if (*p == '+') {
  194. + if (sign) {
  195. + errno = EINVAL;
  196. + return -1;
  197. + }
  198. + sign = +1;
  199. + ++p;
  200. + }
  201. + }
  202. +
  203. + /* Main loop: Scan digits, find decimal point, if present.
  204. + * We don't allow exponentials, so no scientific notation
  205. + * (but note that E for Exa might look like e to some!).
  206. + * Advance 'p' to end, to get scale factor.
  207. + */
  208. + for (; isascii(*p) && (isdigit(*p) || *p=='.'); ++p) {
  209. + if (*p == '.') {
  210. + if (fract_digits > 0) { /* oops, more than one '.' */
  211. + errno = EINVAL;
  212. + return -1;
  213. + }
  214. + fract_digits = 1;
  215. + continue;
  216. + }
  217. +
  218. + i = (*p) - '0'; /* whew! finally a digit we can use */
  219. + if (fract_digits > 0) {
  220. + if (fract_digits >= MAX_DIGITS-1)
  221. + /* ignore extra fractional digits */
  222. + continue;
  223. + fract_digits++; /* for later scaling */
  224. + fpart *= 10;
  225. + fpart += i;
  226. + } else { /* normal digit */
  227. + if (++ndigits >= MAX_DIGITS) {
  228. + errno = ERANGE;
  229. + return -1;
  230. + }
  231. + whole *= 10;
  232. + whole += i;
  233. + }
  234. + }
  235. +
  236. + if (sign) {
  237. + whole *= sign;
  238. + fpart *= sign;
  239. + }
  240. +
  241. + /* If no scale factor given, we're done. fraction is discarded. */
  242. + if (!*p) {
  243. + *result = whole;
  244. + return 0;
  245. + }
  246. +
  247. + /* Validate scale factor, and scale whole and fraction by it. */
  248. + for (i = 0; i < SCALE_LENGTH; i++) {
  249. +
  250. + /* Are we there yet? */
  251. + if (*p == scale_chars[i] ||
  252. + *p == tolower(scale_chars[i])) {
  253. +
  254. + /* If it ends with alphanumerics after the scale char, bad. */
  255. + if (isalnum(*(p+1))) {
  256. + errno = EINVAL;
  257. + return -1;
  258. + }
  259. + scale_fact = scale_factors[i];
  260. +
  261. + /* scale whole part */
  262. + whole *= scale_fact;
  263. +
  264. + /* truncate fpart so it does't overflow.
  265. + * then scale fractional part.
  266. + */
  267. + while (fpart >= LLONG_MAX / scale_fact) {
  268. + fpart /= 10;
  269. + fract_digits--;
  270. + }
  271. + fpart *= scale_fact;
  272. + if (fract_digits > 0) {
  273. + for (i = 0; i < fract_digits -1; i++)
  274. + fpart /= 10;
  275. + }
  276. + whole += fpart;
  277. + *result = whole;
  278. + return 0;
  279. + }
  280. + }
  281. + errno = ERANGE;
  282. + return -1;
  283. +}
  284. +
  285. +/* Format the given "number" into human-readable form in "result".
  286. + * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE.
  287. + * Return 0 on success, -1 and errno set if error.
  288. + */
  289. +int
  290. +fmt_scaled(long long number, char *result)
  291. +{
  292. + long long abval, fract = 0;
  293. + unsigned int i;
  294. + unit_type unit = NONE;
  295. +
  296. + abval = llabs(number);
  297. +
  298. + /* Not every negative long long has a positive representation.
  299. + * Also check for numbers that are just too darned big to format
  300. + */
  301. + if (abval < 0 || abval / 1024 >= scale_factors[SCALE_LENGTH-1]) {
  302. + errno = ERANGE;
  303. + return -1;
  304. + }
  305. +
  306. + /* scale whole part; get unscaled fraction */
  307. + for (i = 0; i < SCALE_LENGTH; i++) {
  308. + if (abval/1024 < scale_factors[i]) {
  309. + unit = units[i];
  310. + fract = (i == 0) ? 0 : abval % scale_factors[i];
  311. + number /= scale_factors[i];
  312. + if (i > 0)
  313. + fract /= scale_factors[i - 1];
  314. + break;
  315. + }
  316. + }
  317. +
  318. + fract = (10 * fract + 512) / 1024;
  319. + /* if the result would be >= 10, round main number */
  320. + if (fract == 10) {
  321. + if (number >= 0)
  322. + number++;
  323. + else
  324. + number--;
  325. + fract = 0;
  326. + }
  327. +
  328. + if (number == 0)
  329. + strlcpy(result, "0B", FMT_SCALED_STRSIZE);
  330. + else if (unit == NONE || number >= 100 || number <= -100) {
  331. + if (fract >= 5) {
  332. + if (number >= 0)
  333. + number++;
  334. + else
  335. + number--;
  336. + }
  337. + (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c",
  338. + number, scale_chars[unit]);
  339. + } else
  340. + (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c",
  341. + number, fract, scale_chars[unit]);
  342. +
  343. + return 0;
  344. +}
  345. +
  346. diff --git a/dragonfly/util.h b/dragonfly/util.h
  347. new file mode 100644
  348. index 0000000..ed115e4
  349. --- /dev/null
  350. +++ b/dragonfly/util.h
  351. @@ -0,0 +1,36 @@
  352. +#define RB_FOREACH(x, name, head) \
  353. + for ((x) = RB_MIN(name, head); \
  354. + (x) != NULL; \
  355. + (x) = name##_RB_NEXT(x))
  356. +
  357. +#define RB_FOREACH_SAFE(x, name, head, y) \
  358. + for ((x) = RB_MIN(name, head); \
  359. + ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \
  360. + (x) = (y))
  361. +
  362. +#define RB_FOREACH_REVERSE(x, name, head) \
  363. + for ((x) = RB_MAX(name, head); \
  364. + (x) != NULL; \
  365. + (x) = name##_RB_PREV(x))
  366. +
  367. +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \
  368. + for ((x) = RB_MAX(name, head); \
  369. + ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \
  370. + (x) = (y))
  371. +
  372. +
  373. +#ifndef TAILQ_END
  374. +#define TAILQ_END(head) NULL
  375. +#endif
  376. +
  377. +#ifndef TAILQ_FOREACH_SAFE
  378. +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
  379. + for ((var) = TAILQ_FIRST(head); \
  380. + (var) != TAILQ_END(head) && \
  381. + ((tvar) = TAILQ_NEXT(var, field), 1); \
  382. + (var) = (tvar))
  383. +#endif
  384. +
  385. +#define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
  386. +int fmt_scaled(long long number, char *result);
  387. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement