diff --git a/doc/gmni.scd b/doc/gmni.scd
index 2c1dc54272aaf3a4cbd6b1c13e29323f418f199b..1f20672f1fb0c8ff6a4f3a97a3324a25d2a0a01d 100644
--- a/doc/gmni.scd
+++ b/doc/gmni.scd
@@ -68,3 +68,7 @@ -N
Suppress the input prompt if the server requests an input, and instead
print a diagnostic message and exit with a zero (successful) status
code.
+-o path
diff --git a/include/util.h b/include/util.h
index cf731bfdc75a750df6f18873f48dd859786587c7..6193fdf48c0ac6d313de7f35a1d09ecba62e3283 100644
--- a/include/util.h
+++ b/include/util.h
@@ -8,5 +8,7 @@ };
char *getpath(const struct pathspec *paths, size_t npaths);
int mkdirs(char *path, mode_t mode);
+int download_resp(FILE *out, struct gemini_response resp, const char *path,
char *url);
#endif
diff --git a/src/gmni.c b/src/gmni.c
index 171e1407ba2dfa3341f0693ae8d60bb9cedb6564..000a56550a686928f84e2c301c9017a8c48b3d68 100644
--- a/src/gmni.c
+++ b/src/gmni.c
@@ -14,6 +14,7 @@ #include <termios.h>
#include <unistd.h>
#include "gmni.h"
#include "tofu.h"
+#include "util.h"
static void
usage(const char *argv_0)
@@ -125,6 +126,8 @@ };
enum input_mode input_mode = INPUT_READ;
FILE *input_source = stdin;
bool follow_redirects = false, linefeed = true;
int max_redirect = 5;
@@ -136,7 +139,7 @@ struct tofu_config cfg;
cfg.action = TOFU_ASK;
int c;
switch (c) {
case '4':
hints.ai_family = AF_INET;
@@ -204,6 +207,9 @@ fprintf(stderr, "Error: -R expects numeric argument\n");
return 1;
}
break;
case 'o':
output_file = optarg;
break;
default:
fprintf(stderr, "fatal: unknown flag %c\n", c);
return 1;
@@ -301,6 +307,11 @@ /* fallthrough */
case OMIT_HEADERS:
if (gemini_response_class(resp.status) !=
GEMINI_STATUS_CLASS_SUCCESS) {
break;
}
if (output_file != NULL) {
ret = download_resp(stderr, resp, output_file, url);
break;
}
diff --git a/src/gmnlm.c b/src/gmnlm.c
index 9bc95fad89c0f92bc5a68fdd40d272b021c3cc25..d5cb2dc29f9ceb448622d5c36b7b73f0ca985bcb 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -78,6 +78,7 @@ "H\tView all page history\n"
"m\tSave bookmark\n"
"M\tBrowse bookmarks\n"
"r\tReload the page\n"
"\n"
"Other commands include:\n\n"
"<Enter>\tread more lines\n"
@@ -553,6 +554,24 @@ print_media_parameters(browser->tty, browser->meta
? strchr(browser->meta, ';') : NULL);
result = PROMPT_AGAIN;
goto exit;
if (in[1] != '\0' && !isspace(in[1])) break;
struct gemini_response resp;
char url[1024] = {0};
strncpy(&url[0], browser->plain_url, sizeof(url));
// XXX: may affect history, do we care?
enum gemini_result res = do_requests(browser, &resp);
if (res != GEMINI_OK) {
fprintf(stderr, "Error: %s\n",
gemini_strerr(res, &resp));
result = PROMPT_AGAIN;
goto exit;
}
set_url(browser, url, NULL);
download_resp(browser->tty, resp, trim_ws(&in[1]), url);
gemini_response_finish(&resp);
result = PROMPT_AGAIN;
goto exit;
case '?':
if (in[1]) break;
fprintf(browser->tty, "%s", help_msg);
@@ -849,7 +868,9 @@ }
if (strncmp(resp->meta, "text/", 5) == 0) {
return display_plaintext(browser, resp);
}
resp->meta);
}
static enum tofu_action
diff --git a/src/tofu.c b/src/tofu.c
index af5d9f20d78558b3ff7dc9253bef53f2deef1d25..48a627fe131996070d991bcc54bb7bcb40fddce4 100644
--- a/src/tofu.c
+++ b/src/tofu.c
@@ -10,6 +10,7 @@ #include <openssl/x509v3.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include "gmni.h"
#include "tofu.h"
#include "util.h"
diff --git a/src/util.c b/src/util.c
index 26e7283a26cc8e593bb3e3fd53d4b7a9bc646e3f..360c99ac95de9dcfce860610aeef85e8986e99c2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2,9 +2,12 @@ #include <assert.h>
#include <errno.h>
#include <libgen.h>
#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include "gmni.h"
#include "util.h"
static void
@@ -60,3 +63,46 @@ }
}
return NULL;
}
+int
+download_resp(FILE *out, struct gemini_response resp, const char *path,
char *url)
+{
path = "./";
strncat(strncpy(&buf[0], path, sizeof(buf)), basename(url),
sizeof(buf));
path = &buf[0];
fprintf(stderr, "Could not open %s for writing: %s\n",
path, strerror(errno));
return 1;
n = BIO_read(resp.bio, buf, BUFSIZ);
if (n == -1) {
fprintf(stderr, "Error: read\n");
return 1;
}
ssize_t w = 0;
while (w < (ssize_t)n) {
ssize_t x = fwrite(&buf[w], 1, n - w, f);
if (ferror(f)) {
fprintf(stderr, "Error: write: %s\n",
strerror(errno));
return 1;
}
w += x;
}
+}
text/gemini
This content has been proxied by September (ba2dc).