shithub: riscv

Download patch

ref: 0fac86fc85198aa0c4e9478aefb1c93b7ae53257
parent: 921b81d8f8392534a608b43b6f44c5deefd777e2
author: cinap_lenrek <[email protected]>
date: Tue Feb 14 03:42:01 EST 2012

mothra: remove default and badurl pages, set /dev/label, cleanup

--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -24,20 +24,6 @@
 Panel *menu3;	/* button 3 menu */
 Mouse mouse;	/* current mouse data */
 char mothra[] = "mothra!";
-Url defurl={
-	"http://cat-v.org/",
-	"",
-	"http://cat-v.org/",
-	"",
-	"",
-};
-Url badurl={
-	"",
-	"",
-	"No file loaded",
-	"",
-	"",
-};
 Cursor patientcurs={
 	0, 0,
 	0x01, 0x80, 0x03, 0xC0, 0x07, 0xE0, 0x07, 0xe0,
@@ -114,17 +100,13 @@
 
 int wwwtop=0;
 Www *www(int index){
-	static Www a[1+NWWW];
-	return &a[1+(index % NWWW)];
+	static Www a[NWWW];
+	return &a[index % NWWW];
 }
 int nwww(void){
 	return wwwtop<NWWW ? wwwtop : NWWW;
 }
 
-void err(Display *, char *msg){
-	fprint(2, "err: %s (%r)\n", msg);
-	abort();
-}
 int subpanel(Panel *obj, Panel *subj){
 	if(obj==0) return 0;
 	if(obj==subj) return 1;
@@ -296,8 +278,6 @@
 		exits("usage");
 	case 0:
 		url=getenv("url");
-		if(url==0 || url[0]=='\0')
-			url=defurl.fullname;
 		break;
 	case 1: url=argv[0]; break;
 	}
@@ -307,7 +287,7 @@
 		close(errfile);
 	}
 	logfile=mkmfile("mothra.log", 0666|DMAPPEND);
-	if(initdraw(err, 0, "mothra") < 0)
+	if(initdraw(0, 0, mothra) < 0)
 		sysfatal("initdraw: %r");
 	display->locking = 1;
 	chrwidth=stringwidth(font, "0");
@@ -321,23 +301,14 @@
 	if(debug) notify(dienow);
 	getfonts();
 	hrule=allocimage(display, Rect(0, 0, 2048, 5), screen->chan, 0, DWhite);
-	if(hrule==0){
-		fprint(2, "%s: can't allocimage!\n", argv[0]);
-		exits("no mem");
-	}
+	if(hrule==0)
+		sysfatal("can't allocimage!");
 	draw(hrule, Rect(0,1,1280,3), display->black, 0, ZP);
 	linespace=allocimage(display, Rect(0, 0, 2048, 5), screen->chan, 0, DWhite);
-	if(linespace==0){
-		fprint(2, "%s: can't allocimage!\n", argv[0]);
-		exits("no mem");
-	}
+	if(linespace==0)
+		sysfatal("can't allocimage!");
 	bullet=allocimage(display, Rect(0,0,25, 8), screen->chan, 0, DWhite);
 	fillellipse(bullet, Pt(4,4), 3, 3, display->black, ZP);
-	new = www(-1);
-	new->url=&badurl;
-	strcpy(new->title, "See error message above");
-	plrtstr(&new->text, 0, 0, font, "See error message above", 0, 0);
-	new->alldone=1;
 	mkpanels();
 
 	unlockdisplay(display);
@@ -344,7 +315,8 @@
 	eresized(0);
 	lockdisplay(display);
 
-	geturl(url, GET, 0, 1, 0);
+	if(url && url[0])
+		geturl(url, GET, 0, 1, 0);
 
 	if(logfile==-1) message("Can't open log file");
 	mouse.buttons=0;
@@ -486,10 +458,9 @@
 void *emalloc(int n){
 	void *v;
 	v=malloc(n);
-	if(v==0){
-		fprint(2, "out of space\n");
-		exits("no mem");
-	}
+	if(v==0)
+		sysfatal("out of memory");
+	setmalloctag(v, getcallerpc(&n));
 	return v;
 }
 void *emallocz(int n, int z){
@@ -497,6 +468,7 @@
 	v = emalloc(n);
 	if(z)
 		memset(v, 0, n);
+	setmalloctag(v, getcallerpc(&n));
 	return v;
 }
 
@@ -546,6 +518,10 @@
 	if(defdisplay) pldraw(cururl, screen);
 	plinittextview(text, PACKE|EXPAND, Pt(0, 0), current->text, dolink);
 	scrollto(tag);
+	if((i = open("/dev/label", OWRITE)) >= 0){
+		fprint(i, "%s %s", mothra, current->url->fullname);
+		close(i);
+	}
 	donecurs();
 }
 char *arg(char *s){
@@ -927,9 +903,7 @@
 }
 void selurl(char *urlname){
 	static Url url;
-	seturl(&url, urlname, current?
-		current->url->fullname :
-		defurl.fullname);
+	seturl(&url, urlname, current ? current->url->fullname : "");
 	selection=&url;
 	message("selected: %s", urlstr(selection));
 }
@@ -947,8 +921,7 @@
 	return v;
 }
 void freeurl(Url *u){
-	if(u!=&defurl && u!=&badurl)
-		free(u);
+	free(u);
 }
 
 /*
@@ -974,7 +947,6 @@
 	for(;;){
 		if((fd=urlopen(selection, method, body)) < 0){
 			message("%r");
-			setcurrent(-1, 0);
 			break;
 		}
 		message("getting %s", selection->fullname);
@@ -1205,10 +1177,8 @@
 		geturl(name, GET, 0, 1, 0);
 		break;
 	case 6:
-		if(confirm(3)){
-			draw(screen, screen->r, display->white, 0, ZP);
+		if(confirm(3))
 			exits(0);
-		}
 		break;
 	}
 }