gawk

[old] Sed-like interface to the Gopher protocol
Log | Files | Refs | LICENSE

commit 20cfe910ceadf3f1dbddcc08fdcb99294b9acfd2
parent 9e4d93b53b1d29a48cd06653bc87787e626a5c87
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Tue,  5 Jan 2021 22:28:28 -0800

Significantly simplify sgoto()

Instead of performing many manual and confusing tests use a simple
loop to overwrite old address parameters.

Diffstat:
Mcommand.c | 12+++---------
Mgawk.h | 2+-
2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/command.c b/command.c @@ -225,6 +225,7 @@ int sgoto(int argc, char const **argv, int depth, char const **addr) { char const *newaddr[AR_NULL]; + int i; if (warg(1, 4, argc, argv)) return FAIL; @@ -233,15 +234,8 @@ sgoto(int argc, char const **argv, int depth, char const **addr) newaddr[AR_PATH] = "/"; newaddr[AR_PORT] = addr[AR_PORT]; - if (argc > 1) { - newaddr[AR_PATH] = argv[1]; - if (argc > 2) { - newaddr[AR_HOST] = argv[2]; - if (argc > 3) - newaddr[AR_PORT] = argv[3]; - } - } - + for (i = 1; i < argc; ++i) + newaddr[i - 1] = argv[i]; return gawk(newaddr); } diff --git a/gawk.h b/gawk.h @@ -15,7 +15,7 @@ #define MY_PROMPT_MAX 64 #define MY_URL_MAX 72 -/* NOTE: don't change address order, see itemtoaddr() */ +/* NOTE: don't change address order (see itemtoaddr and sgoto) */ enum address { AR_PATH, AR_HOST, AR_PORT, AR_NULL }; enum gphitem { GI_INFO, GI_PATH, GI_HOST, GI_PORT, GI_PLUS, GI_NULL };