Commit Diff


commit - 04d32eda6a47cae61c0347e1f514d00b28b9ffc8
commit + d254498948dc2abda7c283e671d747be67d99a18
blob - 7c7f77a1f4e1fbe7110be914331bfaf7aea92664
blob + cd81b211e7caffceca6749147016f0e168eb48ed
--- telescope.c
+++ telescope.c
@@ -3,6 +3,7 @@
 #include <sys/socket.h>
 
 #include <errno.h>
+#include <limits.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -671,21 +672,77 @@ save_session(void)
 
 	imsg_compose(fsibuf, IMSG_SESSION_END, 0, 0, -1, NULL, 0);
 	imsg_flush(fsibuf);
+}
+
+static void
+session_new_tab_cb(const char *url)
+{
+	new_tab(url);
+}
+
+static void
+usage(void)
+{
+	fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
+	fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
 }
 
 int
 main(int argc, char * const *argv)
 {
-	struct imsgbuf	network_ibuf, fs_ibuf;
-	int		net_fds[2], fs_fds[2];
+	struct imsgbuf	 network_ibuf, fs_ibuf;
+	int		 net_fds[2], fs_fds[2];
+	int		 ch, configtest = 0, fail = 0;
+	int		 has_url = 0;
+	char		 path[PATH_MAX];
+	char		*url = NEW_TAB_URL;
 
 	signal(SIGCHLD, SIG_IGN);
 	signal(SIGPIPE, SIG_IGN);
 
+	if (getenv("NO_COLOR") != NULL)
+		enable_colors = 0;
+
+	strlcpy(path, getenv("HOME"), sizeof(path));
+	strlcat(path, "/.telescope/config", sizeof(path));
+
+	while ((ch = getopt(argc, argv, "c:hn")) != -1) {
+		switch (ch) {
+		case 'c':
+			fail = 1;
+			strlcpy(path, optarg, sizeof(path));
+			break;
+		case 'n':
+			configtest = 1;
+			break;
+		case 'h':
+			usage();
+			return 0;
+		default:
+			usage();
+			return 1;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc != 0) {
+		has_url = 1;
+		url = argv[0];
+	}
+
 	/* initialize part of the fs layer.  Before starting the UI
 	 * and dropping the priviledges we need to read some stuff. */
 	fs_init();
 
+	config_init();
+	parseconfig(path, fail);
+	if (configtest){
+		puts("config OK");
+		exit(0);
+	}
+
 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fs_fds) == -1)
 		err(1, "socketpair");
 
@@ -741,7 +798,11 @@ main(int argc, char * const *argv)
 	    handle_dispatch_imsg, fsibuf);
 	event_add(&fsev, NULL);
 
-	if (ui_init(argc, argv)) {
+	if (ui_init()) {
+		load_last_session(session_new_tab_cb);
+		if (has_url || TAILQ_EMPTY(&tabshead))
+			new_tab(url);
+
 		sandbox_ui_process();
 		event_dispatch();
 		ui_end();
blob - c3bf19a86c41d7b406d8c52f127e5b90e1afa5d1
blob + c36446b1e7b9bad76590c8c8433d642f54646ef6
--- telescope.h
+++ telescope.h
@@ -496,7 +496,7 @@ void		 switch_to_tab(struct tab *);
 struct tab	*current_tab(void);
 struct tab	*new_tab(const char *);
 unsigned int	 tab_new_id(void);
-int		 ui_init(int, char * const*);
+int		 ui_init(void);
 void		 ui_on_tab_loaded(struct tab*);
 void		 ui_on_tab_refresh(struct tab*);
 const char	*ui_keyname(int);
blob - ca89afd51e72a82a608b6081242772fec177670b
blob + 0ace57df30c79c5e9397a143af208e15730ce943
--- ui.c
+++ ui.c
@@ -35,7 +35,6 @@
 #include <assert.h>
 #include <curses.h>
 #include <event.h>
-#include <limits.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -76,8 +75,6 @@ static void		 rec_compute_help(struct kmap*, char*, si
 static void		 recompute_help(void);
 static void		 update_loading_anim(int, short, void*);
 static void		 stop_loading_anim(struct tab*);
-static void		 session_new_tab_cb(const char*);
-static void		 usage(void);
 
 static int		 x_offset;
 
@@ -1277,70 +1274,17 @@ new_tab(const char *url)
 
 	load_url_in_tab(tab, url);
 	return tab;
-}
-
-static void
-session_new_tab_cb(const char *url)
-{
-	new_tab(url);
 }
 
-static void
-usage(void)
-{
-	fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
-	fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
-}
-
 int
-ui_init(int argc, char * const *argv)
+ui_init()
 {
-	char path[PATH_MAX];
-	const char *url = NEW_TAB_URL;
-	int ch, configtest = 0, fonf = 0;
-
-	if (getenv("NO_COLOR") != NULL)
-		enable_colors = 0;
-
-	strlcpy(path, getenv("HOME"), sizeof(path));
-	strlcat(path, "/.telescope/config", sizeof(path));
-
-	while ((ch = getopt(argc, argv, "c:hn")) != -1) {
-		switch (ch) {
-		case 'c':
-			fonf = 1;
-			strlcpy(path, optarg, sizeof(path));
-			break;
-		case 'n':
-			configtest = 1;
-			break;
-		case 'h':
-			usage();
-			return 0;
-		default:
-			usage();
-			return 1;
-		}
-	}
-	argc -= optind;
-	argv += optind;
-
 	/* setup keys before reading the config */
 	TAILQ_INIT(&global_map.m);
 	global_map.unhandled_input = global_key_unbound;
 
 	TAILQ_INIT(&minibuffer_map.m);
 
-	config_init();
-	parseconfig(path, fonf);
-	if (configtest){
-		puts("config OK");
-		exit(0);
-	}
-
-	if (argc != 0)
-		url = argv[0];
-
 	setlocale(LC_ALL, "");
 
 	TAILQ_INIT(&eecmd_history.head);
@@ -1407,10 +1351,6 @@ ui_init(int argc, char * const *argv)
 	signal_set(&winchev, SIGWINCH, handle_resize, NULL);
 	signal_add(&winchev, NULL);
 
-	load_last_session(session_new_tab_cb);
-	if (strcmp(url, NEW_TAB_URL) || TAILQ_EMPTY(&tabshead))
-		new_tab(url);
-
 	return 1;
 }