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

This commit is contained in:
cinap_lenrek 2012-02-14 08:42:01 +01:00
parent 921b81d8f8
commit 0fac86fc85

View file

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