commit 0df0f7aba5b67df304029df2856c967dab902c6f
parent c232c0ea0c5f046e86ea6ee27597fc168ae70f86
Author: glenda <glenda@9front.local>
Date: Sun, 14 Jun 2020 14:30:30 +0000
sanitized (and renamed) extrcturi()
Diffstat:
M | gophra.c | | | 59 | +++++++++++++++++++++++++++++++++++------------------------ |
1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/gophra.c b/gophra.c
@@ -35,7 +35,7 @@ const char *tmpfile = "/tmp/gophra.tmp";
long scroll;
char* getlinep(Text*, ulong);
-int extracturl(char*);
+URI extracturi(char *s);
int runuri(char*);
int save(char*, char*);
void back(void);
@@ -53,6 +53,7 @@ void usage(void);
void
threadmain(int argc, char **argv)
{
+ URI uri;
Mousectl *mc;
Keyboardctl *kc;
char *sv;
@@ -156,8 +157,9 @@ threadmain(int argc, char **argv)
scroll;
s = getlinep(&text, sline);
if (s == nil) break;
- extracturl(s);
- snprint(status, 255, "%s/%c%s", addr, type, path);
+ uri = extracturi(s);
+ snprint(status, 255, "%s:%s/%s", uri.host, uri.port, uri.path);
+ freeuri(&uri);
drawstatus();
flush = 1;
}
@@ -167,8 +169,10 @@ threadmain(int argc, char **argv)
scroll;
s = getlinep(&text, sline);
if (s == nil) break;
- extracturl(s);
- handlelink(addr, type, path);
+ uri = extracturi(s);
+ snprint(addr, 1024, "tcp!%s!%s", uri.host, uri.port);
+ handlelink(addr, uri.path[0], uri.path + 1);
+ freeuri(&uri);
}
if (mv.buttons == 4) {
mpress = 1;
@@ -333,26 +337,33 @@ getlinep(Text *text, ulong ln)
return lp;
}
-int
-extracturl(char *s)
+URI
+extracturi(char *s)
{
- char *sp, *ep, buf[1024], port[256];
- type = s[0];
- sp = strchr(s, '\t') + 1;
- ep = strchr(sp, '\t');
- strncpy(path, sp, ep-sp);
- path[ep-sp] = 0;
- sp = ep + 1;
- ep = strchr(sp, '\t');
- buf[0] = 0;
- strncpy(buf, sp, ep-sp);
- buf[ep-sp] = 0;
- sp = ep + 1;
- ep = strchr(sp, '\r');
- strncpy(port, sp, ep-sp);
- port[ep-sp] = 0;
- snprint(addr, 1024, "tcp!%s!%s", buf, port);
- return 0;
+ URI uri;
+ char *sp, *ep;
+ char *val[3];
+ int i;
+ char *sep = "\t\t\r";
+ uri.scheme = 0;
+ uri.user = 0;
+ uri.host = 0;
+ uri.port = 0;
+ uri.path = 0;
+ uri.query = 0;
+ uri.fragment = 0;
+ ep = strchr(s, sep[0]);
+ for (i = 0; i < 3; i++){
+ sp = ep + 1;
+ ep = strchr(sp, sep[i]);
+ val[i] = mallocz(ep - sp + 1, 1);
+ memcpy(val[i], sp, ep - sp);
+ }
+ uri.path = smprint("%c%s", s[0], val[0]);
+ uri.host = val[1];
+ uri.port = val[2];
+ free(val[0]);
+ return uri;
}
void