Commit Diff


commit - 69bdd906cbdaaab353fb7f2d20fd70c31c19d31d
commit + c92e529c273bbb2b59a02d054c2dcbec3c9b12f0
blob - 04a60733b0575d0037f5b4bb9c1de149bedcf649
blob + c6b5f8f3c899a9b5cfd0c1f09714191a6e925f4d
--- .gitignore
+++ .gitignore
@@ -15,8 +15,10 @@ depcomp
 install-sh
 missing
 stamp-h1
+ylwrap
 *.o
 cmd.gen.h
+parse.c
 telescope
 compile_flags.txt
 telescope-*.tar.gz
blob - 33a7c99f19275abab401786c5b3ff2c3402341b5
blob + 3bf75054ea85c4d6faa82c75cc2d7bde823157b1
--- Makefile.am
+++ Makefile.am
@@ -4,6 +4,7 @@ telescope_SOURCES =	cmd.h		\
 			cmd.gen.h	\
 			compat.h	\
 			compat/*.[ch]	\
+			defaults.c	\
 			fs.c		\
 			gemini.c	\
 			gemtext.c	\
@@ -12,6 +13,7 @@ telescope_SOURCES =	cmd.h		\
 			keymap.c	\
 			mime.c		\
 			pages.c		\
+			parse.y		\
 			parser.c	\
 			sandbox.c	\
 			telescope.c	\
blob - /dev/null
blob + 9a41787c14a903f5aa7e05ad2cefdc6f6d49d29d (mode 644)
--- /dev/null
+++ defaults.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ *
+ * 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 "telescope.h"
+
+#include <curses.h>
+
+struct lineprefix line_prefixes[] = {
+	[LINE_TEXT] =		{ "",		"" },
+	[LINE_LINK] =		{ "=> ",	"   " },
+	[LINE_TITLE_1] =	{ "# ",		"  " },
+	[LINE_TITLE_2] =	{ "## ",	"   " },
+	[LINE_TITLE_3] =	{ "### ",	"    " },
+	[LINE_ITEM] =		{ "* ",		"  " },
+	[LINE_QUOTE] =		{ "> ",		"  " },
+	[LINE_PRE_START] =	{ "```",	"   " },
+	[LINE_PRE_CONTENT] =	{ "",		"" },
+	[LINE_PRE_END] =	{ "```",	"```" },
+};
+
+struct line_face line_faces[] = {
+	[LINE_TEXT] =		{ 0,		0 },
+	[LINE_LINK] =		{ 0,		A_UNDERLINE },
+	[LINE_TITLE_1] =	{ A_BOLD,	A_BOLD },
+	[LINE_TITLE_2] =	{ A_BOLD,	A_BOLD },
+	[LINE_TITLE_3] =	{ A_BOLD,	A_BOLD },
+	[LINE_ITEM] =		{ 0,		0 },
+	[LINE_QUOTE] =		{ 0,		A_DIM },
+	[LINE_PRE_START] =	{ 0,		0 },
+	[LINE_PRE_CONTENT] =	{ 0,		0 },
+	[LINE_PRE_END] =	{ 0,		0 },
+};
+
+struct tab_face tab_face = {
+	.background	= A_REVERSE,
+	.tab		= A_REVERSE,
+	.current_tab	= A_NORMAL,
+};
blob - 44927224747f1f2ee75f6cc1f201cc8ee6005ea2
blob + 4c300fbeeba6e9f7382de84a7e6ec47f896ae74e
--- telescope.1
+++ telescope.1
@@ -20,6 +20,8 @@
 .Sh SYNOPSIS
 .Nm
 .Bk -words
+.Op Fl hn
+.Op Fl c Pa config
 .Op Ar URL
 .Ek
 .Sh DESCRIPTION
@@ -28,6 +30,20 @@ is an interactive browser for the Gemini protocol.
 It is able to process text/gemini and more in general every text/* file.
 .Nm
 also features tabs, bookmarks and out-of-band TOFU verification.
+.Pp
+The arguments are as follows:
+.Bl -tag -width tenletters
+.It Fl h
+Display version and usage.
+.It Fl n
+Configtest mode.
+Only check the configuration file for validity.
+.It Fl c Pa config
+Specify an alternative configuration file.
+By default
+.Pa $HOME/.telescope/config
+is loaded.
+.El
 .Sh TOFU
 .Nm
 aims to use the "Trust, but Verify (where appropriate)" approach.
blob - 7857e4f827d82b502488c5e1ac0ea63708f54271
blob + 79ffd87c9f908fdb8f872f699c8e8c728571ebfc
--- telescope.h
+++ telescope.h
@@ -56,8 +56,25 @@ enum imsg_type {
 	IMSG_SESSION_START,
 	IMSG_SESSION_TAB,
 	IMSG_SESSION_END,
+};
+
+struct lineprefix {
+	const char	*prfx1;
+	const char	*prfx2;
+};
+extern struct lineprefix line_prefixes[];
+
+struct line_face {
+	int prefix_prop;
+	int text_prop;
 };
+extern struct line_face line_faces[];
 
+struct tab_face  {
+	int background, tab, current_tab;
+};
+extern struct tab_face tab_face;
+
 enum line_type {
 	LINE_TEXT,
 	LINE_LINK,
@@ -236,6 +253,9 @@ extern const char	*about_new;
 #define UNKNOWN_TYPE_OR_CSET	3
 extern const char	*err_pages[70];
 
+/* parse.y */
+void		 parseconfig(const char *, int);
+
 /* parser.c */
 int		 parser_append(struct parser*, const char*, size_t);
 int		 parser_set_buf(struct parser*, const char*, size_t);
blob - 15298f99589c45d434a0ddbb1ff264198ac66d4f
blob + f61b3530d23f6d35b384fcff8ec6eac81cfa9812
--- ui.c
+++ ui.c
@@ -38,6 +38,7 @@
 #include <assert.h>
 #include <curses.h>
 #include <event.h>
+#include <limits.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -161,44 +162,6 @@ static struct {
 	struct hist	*hist_cur;
 	size_t		 hist_off;
 } ministate;
-
-struct lineprefix {
-	const char	*prfx1;
-	const char	*prfx2;
-} line_prefixes[] = {
-	[LINE_TEXT] =		{ "",		"" },
-	[LINE_LINK] =		{ "=> ",	"   " },
-	[LINE_TITLE_1] =	{ "# ",		"  " },
-	[LINE_TITLE_2] =	{ "## ",	"   " },
-	[LINE_TITLE_3] =	{ "### ",	"    " },
-	[LINE_ITEM] =		{ "* ",		"  " },
-	[LINE_QUOTE] =		{ "> ",		"  " },
-	[LINE_PRE_START] =	{ "```",	"   " },
-	[LINE_PRE_CONTENT] =	{ "",		"" },
-	[LINE_PRE_END] =	{ "```",	"```" },
-};
-
-static struct line_face {
-	int prefix_prop;
-	int text_prop;
-} line_faces[] = {
-	[LINE_TEXT] =		{ 0,		0 },
-	[LINE_LINK] =		{ 0,		A_UNDERLINE },
-	[LINE_TITLE_1] =	{ A_BOLD,	A_BOLD },
-	[LINE_TITLE_2] =	{ A_BOLD,	A_BOLD },
-	[LINE_TITLE_3] =	{ A_BOLD,	A_BOLD },
-	[LINE_ITEM] =		{ 0,		0 },
-	[LINE_QUOTE] =		{ 0,		A_DIM },
-	[LINE_PRE_START] =	{ 0,		0 },
-	[LINE_PRE_CONTENT] =	{ 0,		0 },
-	[LINE_PRE_END] =	{ 0,		0 },
-};
-
-static struct tab_face {
-	int background, tab, current_tab;
-} tab_face = {
-	A_REVERSE, A_REVERSE, A_NORMAL
-};
 
 static inline void
 global_set_key(const char *key, void (*fn)(struct buffer*))
@@ -1933,25 +1896,46 @@ session_new_tab_cb(const char *url)
 static void
 usage(void)
 {
-	fprintf(stderr, "USAGE: %s [url]\n", getprogname());
+	fprintf(stderr, "USAGE: %s [-hn] [-c config] [url]\n", getprogname());
+	fprintf(stderr, "version: " PACKAGE " " VERSION "\n");
 }
 
 int
 ui_init(int argc, char * const *argv)
 {
+	char path[PATH_MAX];
 	const char *url = NEW_TAB_URL;
-	int ch;
-
-	while ((ch = getopt(argc, argv, "")) != -1) {
+	int ch, configtest = 0, fonf = 0;
+
+	strlcpy(path, getenv("HOME"), sizeof(path));
+	strlcat(path, "/.telescope/config", sizeof(path));
+
+	while ((ch = getopt(argc, argv, "c:hn")) != -1) {
 		switch (ch) {
-		default:
+		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;
 
+	parseconfig(path, fonf);
+	if (configtest){
+		puts("config OK");
+		exit(0);
+	}
+
 	if (argc != 0)
 		url = argv[0];