+ die("usage: %s [-bBdDfFgGiIkKmMnNpPsStTvx] [-a cookiepolicies ] "
+ "[-c cookiefile] [-C stylefile] [-e xid] [-r scriptfile] "
+ "[-u useragent] [-z zoomlevel] [uri]\n", basename(argv0));
+}
+
+void
+die(const char *errstr, ...)
+{
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(1);
+}
+
+void
+setup(void)
+{
+ GdkDisplay *gdpy;
+ int i, j;
+
+ /* clean up any zombies immediately */
+ sigchld(0);
+ if (signal(SIGHUP, sighup) == SIG_ERR)
+ die("Can't install SIGHUP handler");
+
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("Can't open default display");
+
+ /* atoms */
+ atoms[AtomFind] = XInternAtom(dpy, "_SURF_FIND", False);
+ atoms[AtomGo] = XInternAtom(dpy, "_SURF_GO", False);
+ atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False);
+
+ gtk_init(NULL, NULL);
+
+ gdpy = gdk_display_get_default();
+
+ curconfig = defconfig;
+
+ /* dirs and files */
+ cookiefile = buildfile(cookiefile);
+ scriptfile = buildfile(scriptfile);
+ cachedir = buildpath(cachedir);
+ certdir = buildpath(certdir);
+
+ gdkkb = gdk_seat_get_keyboard(gdk_display_get_default_seat(gdpy));
+
+ for (i = 0; i < LENGTH(certs); ++i) {
+ if (!regcomp(&(certs[i].re), certs[i].regex, REG_EXTENDED)) {
+ certs[i].file = g_strconcat(certdir, "/", certs[i].file,
+ NULL);
+ } else {
+ fprintf(stderr, "Could not compile regex: %s\n",
+ certs[i].regex);
+ certs[i].regex = NULL;
+ }
+ }
+
+ if (!stylefile) {
+ styledir = buildpath(styledir);
+ for (i = 0; i < LENGTH(styles); ++i) {
+ if (!regcomp(&(styles[i].re), styles[i].regex,
+ REG_EXTENDED)) {
+ styles[i].file = g_strconcat(styledir, "/",
+ styles[i].file, NULL);
+ } else {
+ fprintf(stderr, "Could not compile regex: %s\n",
+ styles[i].regex);
+ styles[i].regex = NULL;
+ }
+ }
+ g_free(styledir);
+ } else {
+ stylefile = buildfile(stylefile);
+ }