summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorstanley lieber <stanley.lieber@gmail.com>2011-10-01 21:30:12 -0500
committerstanley lieber <stanley.lieber@gmail.com>2011-10-01 21:30:12 -0500
commit2036c493940eea8cd9d67fe792713d38b81547af (patch)
treee0543f6be7a813523c1c42beba647341096f41c3 /sys/src
parent931dd8bbe81f10047a85ef73298f0548490753fd (diff)
mothra: add moth mode; display images that are not also links as a link to themselves
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/cmd/mothra/getpix.c6
-rw-r--r--sys/src/cmd/mothra/mothra.c78
-rw-r--r--sys/src/cmd/mothra/rdhtml.c5
3 files changed, 64 insertions, 25 deletions
diff --git a/sys/src/cmd/mothra/getpix.c b/sys/src/cmd/mothra/getpix.c
index 10e7b7467..a7b82a7c3 100644
--- a/sys/src/cmd/mothra/getpix.c
+++ b/sys/src/cmd/mothra/getpix.c
@@ -43,8 +43,6 @@ void getimage(Rtext *t, Www *w){
for(p=w->pix;p!=nil; p=p->next)
if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){
storebitmap(t, p->b);
- free(ap->image);
- ap->image=0;
w->changed=1;
return;
}
@@ -54,8 +52,6 @@ void getimage(Rtext *t, Www *w){
snprint(err, sizeof(err), "[%s: %r]", url.fullname);
free(t->text);
t->text=strdup(err);
- free(ap->image);
- ap->image=0;
w->changed=1;
close(fd);
return;
@@ -99,8 +95,6 @@ void getimage(Rtext *t, Www *w){
p->next=w->pix;
w->pix=p;
storebitmap(t, b);
- free(ap->image);
- ap->image=0;
w->changed=1;
}
diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c
index 60e8ba544..e930a40ff 100644
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -76,10 +76,22 @@ Cursor readingcurs={
0x0E, 0x60, 0x1C, 0x00, 0x38, 0x00, 0x71, 0xB6,
0x61, 0xB6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
+Cursor mothcurs={
+ {-7, -7},
+ {0x00, 0x00, 0x60, 0x06, 0xf8, 0x1f, 0xfc, 0x3f,
+ 0xfe, 0x7f, 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfe,
+ 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xfc, 0x1f, 0xf8,
+ 0x1f, 0xf8, 0x0e, 0x70, 0x0c, 0x30, 0x00, 0x00, },
+ {0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x58, 0x1a,
+ 0x5c, 0x3a, 0x64, 0x26, 0x27, 0xe4, 0x37, 0xec,
+ 0x37, 0xec, 0x17, 0xe8, 0x1b, 0xd8, 0x0e, 0x70,
+ 0x0c, 0x30, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, }
+};
char *mtpt="/mnt/web";
Www *current=0;
Url *selection=0;
int logfile;
+int mothmode;
void docmd(Panel *, char *);
void doprev(Panel *, int, int);
void selurl(char *);
@@ -90,9 +102,9 @@ void dolink(Panel *, int, Rtext *);
void hit3(int, int);
char *buttons[]={
"alt display",
+ "moth mode",
"snarf url",
"paste",
- "save url",
"save hit",
"hit list",
"exit",
@@ -231,6 +243,7 @@ void main(int argc, char *argv[]){
enum { Eplumb = 128 };
Plumbmsg *pm;
Www *new;
+ Action *a;
char *url;
int errfile;
int i;
@@ -314,7 +327,8 @@ void main(int argc, char *argv[]){
current->changed=0;
current->alldone=1;
message(mothra);
- esetcursor(0);
+ if(mothmode==0)
+ esetcursor(0);
}
else if(current->changed){
updtext(current);
@@ -355,6 +369,11 @@ void main(int argc, char *argv[]){
break;
case Emouse:
mouse=e.mouse;
+ if(mouse.buttons > 1){
+ mothmode = 0;
+ esetcursor(current && current->alldone?0:&readingcurs);
+ message(mothra);
+ }
plmouse(root, e.mouse);
break;
case Eplumb:
@@ -439,8 +458,12 @@ char *genwww(Panel *, int index){
}
void donecurs(void){
- esetcursor(current && current->alldone?0:&readingcurs);
+ if(mothmode)
+ esetcursor(current && current->alldone?0:&mothcurs);
+ else
+ esetcursor(current && current->alldone?0:&readingcurs);
}
+
/*
* selected text should be a url.
* get the document, scroll to the given tag
@@ -635,23 +658,47 @@ void doprev(Panel *p, int buttons, int index){
}
/*
+ * convert a url into a local file name.
+ */
+char *urltofile(char *url){
+ static char file[128];
+ if(strrchr(url, '/')){
+ snprint(file, sizeof(file), "%s", strrchr(url, '/')+1);
+ if(file[0]==0)
+ strcpy(file, "index");
+ }else
+ snprint(file, sizeof(file), "%s", url);
+ return file;
+}
+/*
* Follow an html link
*/
void dolink(Panel *p, int buttons, Rtext *word){
- char mapurl[NNAME];
+ char file[128], mapurl[NNAME];
Action *a;
+ Url u;
Point coord;
- int yoffs;
+ int fd, yoffs;
USED(p);
a=word->user;
- if(a && a->link){
+ if(mothmode && a){
+ if(a->image){
+ seturl(&u, a->image, current->url->fullname);
+ snprint(file, sizeof(file), "%s", urltofile(a->image));
+ }else{
+ seturl(&u, a->link, current->url->fullname);
+ snprint(file, sizeof(file), "%s", urltofile(a->link));
+ }
+ save(&u, file);
+ message("saved %s", file);
+ esetcursor(&mothcurs);
+ }else if(a && a->link){
if(a->ismap){
yoffs=plgetpostextview(p);
coord=subpt(subpt(mouse.xy, word->r.min), p->r.min);
snprint(mapurl, sizeof(mapurl), "%s?%d,%d", a->link, coord.x, coord.y+yoffs);
hiturl(buttons, mapurl, 1);
- }
- else
+ }else
hiturl(buttons, a->link, 0);
}
}
@@ -1069,20 +1116,15 @@ void hit3(int button, int item){
pldraw(root, screen);
break;
case 1:
- snarf(cmd);
+ mothmode = 1;
+ message("moth mode");
+ esetcursor(&mothcurs);
break;
case 2:
- paste(cmd);
+ snarf(cmd);
break;
case 3:
- if(strrchr(selection->reltext, '/')){
- snprint(file, sizeof(file), "%s", strrchr(selection->reltext, '/')+1);
- if(file[0]==0)
- strcpy(file, "index");
- } else
- snprint(file, sizeof(file), "%s", selection->reltext);
- save(selection, file);
- message("saved %s", file);
+ paste(cmd);
break;
case 4:
snprint(name, sizeof(name), "%s/hit.html", home);
diff --git a/sys/src/cmd/mothra/rdhtml.c b/sys/src/cmd/mothra/rdhtml.c
index 44ba88c82..33ac45b7c 100644
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -639,8 +639,11 @@ void plrdhtml(char *name, int fd, Www *dst){
case Tag_meta:
break;
case Tag_img:
- if(str=pl_getattr(g.attr, "src"))
+ if(str=pl_getattr(g.attr, "src")){
strncpy(g.state->image, str, sizeof(g.state->image));
+ if(g.state->link[0]==0)
+ strncpy(g.state->link, str, sizeof(g.state->link));
+ }
g.state->ismap=pl_hasattr(g.attr, "ismap");
if(str=pl_getattr(g.attr, "width"))
g.state->width = strtolength(&g, HORIZ, str);