From 388e7781c24cbdb2299607d47472f7741cc5f80f Mon Sep 17 00:00:00 2001 From: stanley lieber Date: Tue, 27 Sep 2011 12:54:39 -0500 Subject: [PATCH] mothra: add menu option to save url --- sys/man/1/mothra | 4 ++++ sys/src/cmd/mothra/mothra.c | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sys/man/1/mothra b/sys/man/1/mothra index 4786b965d..75dcf9686 100644 --- a/sys/man/1/mothra +++ b/sys/man/1/mothra @@ -91,6 +91,10 @@ Copy the current URL to the snarf buffer. .B paste Paste the current snarf buffer at the current cursor position. .TP +.B save url +Save the currently selected URL as a file. Directory indexes are saved in a file named +.I index. +.TP .B save hit Save the current URL to the hit list. .TP diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c index d562234d0..60e8ba544 100644 --- a/sys/src/cmd/mothra/mothra.c +++ b/sys/src/cmd/mothra/mothra.c @@ -92,6 +92,7 @@ char *buttons[]={ "alt display", "snarf url", "paste", + "save url", "save hit", "hit list", "exit", @@ -1048,6 +1049,7 @@ void paste(Panel *p){ } void hit3(int button, int item){ char name[NNAME]; + char file[128]; Panel *swap; int fd; USED(button); @@ -1073,6 +1075,16 @@ void hit3(int button, int item){ paste(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); + break; + case 4: snprint(name, sizeof(name), "%s/hit.html", home); fd=open(name, OWRITE); if(fd==-1){ @@ -1089,11 +1101,11 @@ void hit3(int button, int item){ selection->fullname, selection->fullname); close(fd); break; - case 4: + case 5: snprint(name, sizeof(name), "file:%s/hit.html", home); geturl(name, GET, 0, 1, 0); break; - case 5: + case 6: if(confirm(3)){ draw(screen, screen->r, display->white, 0, ZP); exits(0);