ref: 1fe76cb758c2be655ff778499e002b66d756e4dc
parent: 291e2955f505e3167a725e8b00371e4ef597ecef
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun May 17 09:14:54 EDT 2020
rewrite relative urls with abslute ones
--- a/main.c
+++ b/main.c
@@ -165,7 +165,7 @@
main(int argc, char **argv)
{
Response *r;
- char *s;
+ char *s, *t, *u;
int len;
if(argc < 2){
@@ -187,7 +187,18 @@
while((s = Brdstr(&r->body, '\n', 1)) != nil){
if((len = Blinelen(&r->body)) > 0)
s[len] = 0;
- print("%s\n", s);
+ if(s[0] == '=' && s[1] == '>'){
+ t = s + 2;
+ while(isspace(*t))
+ t++;
+ u = t;
+ if((t = strpbrk(t, " :/")) == nil || t[0] != ':' || t[1] != '/' || t[2] != '/') /* relative URL */
+ print("=> gemini://%s:%s/%s\n", r->url->server, r->url->port, u);
+ else
+ print("%s\n", s);
+ }else{
+ print("%s\n", s);
+ }
free(s);
}
}