Browser git · main
Minimal browser in C (mini and big variant)
C 95.8% Markdown 3.9%git clone https://git.christianimmanuel.de/web-tools/Browser.gitwget https://git.christianimmanuel.de/web-tools/Browser/archive/Browser.tar.gzFix arg handling
Makefile | 2 +- README.md | 5 ++++- browser_core.c | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cf5a755..37c4bbf 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC ?= gcc CFLAGS ?= -O2 -Wall -Wextra PREFIX ?= /usr/local -VERSION := 2.3.3 +VERSION := 2.3.4 SOURCES := browser_core.c browser_core.h browser-mini.c browser-big.c Makefile BUILD_ID := $(shell cat $(SOURCES) 2>/dev/null | md5sum | cut -c1-7) diff --git a/README.md b/README.md index d6b2d3b..dcbff3f 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,16 @@ browser-mini adds nothing to the core. Every hook is optional. ## Version ``` -browser-mini --version # browser-mini 2.3.3 (build 72335fd) +browser-mini --version # browser-mini 2.3.4 (build 848f743) make version ``` The build id is an md5 of the sources, so two builds can be told apart without guessing. +`-h` and `-V` are answered before anything else on the command line is +looked at, so they work even next to a mistyped option. + ## Build Debian and derivatives: diff --git a/browser_core.c b/browser_core.c index eaf6fd5..4e24c5a 100644 --- a/browser_core.c +++ b/browser_core.c @@ -5045,6 +5045,23 @@ browser_main (int argc, char **argv, const BrowserApp *app) g_app = app; theme_defaults (); + /* + * Help and version are answered before anything else is looked at, so + * they cannot be lost behind a mistyped option earlier on the line, a + * config file, or a front-end that exits while parsing its own flags. + */ + for (int i = 1; i < argc; i++) { + if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) { + usage (argv[0], TRUE); + return 0; + } + if (!strcmp (argv[i], "-V") || !strcmp (argv[i], "--version")) { + g_print ("%s %s (build %s)\n", app->default_app_id, + BROWSER_VERSION, BROWSER_BUILD); + return 0; + } + } + /* config first, so anything on the command line still wins */ for (int i = 1; i < argc; i++) { if ((!strcmp (argv[i], "-c") || !strcmp (argv[i], "--config")) && i + 1 < argc) @@ -5167,8 +5184,13 @@ browser_main (int argc, char **argv, const BrowserApp *app) cfg_set_line (a); /* pad=12 */ } else if (a[0] != '-' && !url_arg) { url_arg = a; + } else if (a[0] != '-') { + g_printerr ("%s: a second address: %s\n", argv[0], a); + g_printerr ("%s: already opening: %s\n", argv[0], url_arg); + usage_short (argv[0]); + return 1; } else { - g_printerr ("%s: unknown argument: %s\n", argv[0], a); + g_printerr ("%s: unknown option: %s\n", argv[0], a); usage_short (argv[0]); return 1; }