gawk

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

commit 5d1d82df44be5ed2fd399a7a1c2f4c97ebeca954
parent 86a094f1f0386a9db4eca4f2f4ab7b615314bb24
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date:   Wed, 23 Dec 2020 14:43:36 -0800

Allow item commands to modify gawk's done variable

This allows alot more to be done with item commands and fixes
unwinding after cgoto().

Diffstat:
Mmain.c | 28++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/main.c b/main.c @@ -334,8 +334,7 @@ splitrun(filter **filters, int argc, const char **argv, unsigned int index, char argv += n; } - func(argc, argv, index, (const char **)item); - return 0; + return func(argc, argv, index, (const char **)item); } int @@ -343,19 +342,18 @@ run_filters(const char *cache, filter **filters, int argc, const char **argv, it { FILE *fp; char item[MY_LINE_MAX]; + int error; unsigned int i; fp = wfopen(cache, "r"); if (fp == NULL) return 1; - for (i = 0; fgets(item, sizeof(item), fp) != NULL && *item != '.'; ++i) { - if (splitrun(filters, argc, argv, i, item, func) < 0) { - wfclose(fp); - return -1; - } - } - return wfclose(fp); + error = 0; + for (i = 0; !error && fgets(item, sizeof(item), fp) != NULL && *item != '.'; ++i) + error = splitrun(filters, argc, argv, i, item, func); + wfclose(fp); /* not fatal */ + return error; } int @@ -481,7 +479,7 @@ cfetch(int argc, const char **argv, int i, const char **request) const char *output; if (warg(0, 1, argc, argv)) - return 1; + return 0; if (argc > 0) output = argv[0]; @@ -491,9 +489,8 @@ cfetch(int argc, const char **argv, int i, const char **request) } if (gph_write(reqtoaddr(request), output) != 0) - return 1; + return 0; warnx("'%s/%s' written to '%s'", request[GI_HOST], request[GI_PATH], output); - return 0; } @@ -504,7 +501,7 @@ cextern(int argc, const char **argv, int index, const char **item) int i; if (warg(1, -1, argc, argv)) - return 1; + return 0; snprintf(url, sizeof(url), "%s/%s", item[GI_HOST], item[GI_PATH]); for (i = 0; i < argc; ++i) @@ -514,7 +511,7 @@ cextern(int argc, const char **argv, int index, const char **item) switch (fork()) { case -1: warn("unable to fork"); - return 1; + return 0; case 0: execvp(*argv, (char *const *)argv); warn("execvp '%s'", *argv); @@ -621,8 +618,7 @@ execute(int argc, const char **argv, int depth, const char *cache, ++argv; if (cmd != NULL) return cmd(argc, argv, depth, addr); - run_filters(cache, filters, argc, argv, itemc); - return 0; + return run_filters(cache, filters, argc, argv, itemc); } void