ref: 0946587d6c95b365174c88abe47b6f4fcb465741
parent: 0f5e8eb6cd16ae6e1a54bf769826bd7df5cd321d
author: Julien Blanchard <[email protected]>
date: Sat Nov 28 04:53:12 EST 2020
History
--- a/castor.c
+++ b/castor.c
@@ -80,6 +80,16 @@
current_url = url;
}
+void
+show(Gmenu *m)
+{
+ plinittextview(textp, PACKE|EXPAND, ZP, m->text, texthit);
+ pldraw(textp, screen);
+ plinitlabel(urlp, PACKN|FILLX, m->url->url);
+ pldraw(urlp, screen);
+ message("Castor9");
+}
+
Url *
parseurl(char *url)
{
@@ -118,14 +128,6 @@
return u;
}
-int
-starts_with(char *pre, char *str)
-{
- int lenpre = strlen(pre),
- lenstr = strlen(str);
- return lenstr < lenpre ? 1 : memcmp(pre, str, lenpre);
-}
-
char *
protocol(char *link)
{
@@ -156,10 +158,14 @@
if(m==nil)
sysfatal("malloc: %r");
m->text = nil;
- plrtstr(&m->text, 1000000, 0, 0, font, strdup(" "), 0, 0);
- set_current_url(url);
+ Hist *h;
+ h = malloc(sizeof *h);
+ if(h == nil)
+ sysfatal("malloc: %r");
+ plrtstr(&m->text, 1000000, 0, 0, font, strdup(" "), 0, 0);
+
message("loading %s...", url->url);
char *naddr = netmkaddr(url->server, "tcp", url->port);
fd = dial(naddr, 0, 0, 0);
@@ -183,6 +189,13 @@
fprint(fd, "%s\r\n", url->url);
Binit(&body, fd, OREAD);
+ m->url = url;
+
+ char c;
+ do {
+ c = Bgetc(&body);
+ } while (c != '\n');
+
while((line = Brdstr(&body, '\n', 0)) != nil)
{
if (strstr(line, "=>") == nil) {
@@ -195,32 +208,32 @@
width = 80;
while(*base)
- {
- if(length <= width)
- {
+ {
+ if(length <= width)
+ {
plrtstr(&m->text, 1000000, 8, 0, font, strdup(cleanup(base)), 0, 0);
break;
}
- right_margin = base+width;
- while(!isspace(*right_margin))
- {
- right_margin--;
- if(right_margin == base)
- {
- right_margin += width;
- while(!isspace(*right_margin))
- {
- if(*right_margin == '\0')
- break;
- right_margin++;
- }
- }
- }
- *right_margin = '\0';
+ right_margin = base+width;
+ while(!isspace(*right_margin))
+ {
+ right_margin--;
+ if(right_margin == base)
+ {
+ right_margin += width;
+ while(!isspace(*right_margin))
+ {
+ if(*right_margin == '\0')
+ break;
+ right_margin++;
+ }
+ }
+ }
+ *right_margin = '\0';
plrtstr(&m->text, 1000000, 8, 0, font, strdup(cleanup(base)), 0, 0);
- length -= right_margin - base + 1; /* +1 for the space */
- base = right_margin + 1;
- }
+ length -= right_margin - base + 1; /* +1 for the space */
+ base = right_margin + 1;
+ }
} else {
/* a link */
char *copy = strdup(cleanup(line));
@@ -227,10 +240,18 @@
strtok(copy, " ");
char *link = strtok(NULL, " ");
char *rest = strtok(NULL, "\0");
- while(isspace(*rest))
- rest++;
+ char *label;
- char *label = smprint("→ %s%s", rest, protocol(link));
+ if(rest != NULL)
+ {
+ while(isspace(*rest))
+ {
+ rest++;
+ }
+ label = smprint("→ %s%s", rest, protocol(link));
+ }else{
+ label = smprint("→ %s%s", link, protocol(link));
+ }
plrtstr(&m->text, 1000000, 8, 0, font, strdup(label), PL_HOT, strdup(link));
}
@@ -237,17 +258,47 @@
free(line);
}
+ h->p = hist;
+ h->n = nil;
+ h->m = m;
+ hist = h;
+
Bflush(&body);
close(fd);
- plinittextview(textp, PACKE|EXPAND, ZP, m->text, texthit);
- pldraw(textp, screen);
- plinitlabel(urlp, PACKN|FILLX, strdup(url->url));
- pldraw(urlp, screen);
- message("Castor!");
+
+
+ show(m);
}
void
+backhit(Panel *p, int b)
+{
+ USED(p);
+ if(b!=1)
+ return;
+ if(hist==nil || hist->p==nil)
+ return;
+ hist->p->n = hist;
+ hist = hist->p;
+ //set_current_url(hist->m->url);
+ show(hist->m);
+}
+
+void
+nexthit(Panel *p, int b)
+{
+ USED(p);
+ if(b!=1)
+ return;
+ if(hist==nil || hist->n==nil)
+ return;
+ hist = hist->n;
+ //set_current_url(hist->m->url);
+ show(hist->m);
+}
+
+void
menuhit(int button, int item)
{
USED(button);
@@ -254,10 +305,10 @@
switch(item){
case Mback:
- //backhit(backp, 1);
+ backhit(backp, 1);
break;
case Mforward:
- //nexthit(fwdp, 1);
+ nexthit(fwdp, 1);
break;
case Msearch:
//search();