mothra: support <video>, <object>, <input type=password> and <meta http-equiv=refresh>

This commit is contained in:
cinap_lenrek 2011-11-06 15:19:02 +01:00
parent 409ed0d966
commit 183a08bc95
5 changed files with 92 additions and 34 deletions

View file

@ -150,29 +150,12 @@ void rdform(Hglob *g){
else else
f->maxlength=atoi(s); f->maxlength=atoi(s);
s=pl_getattr(g->attr, "type"); s=pl_getattr(g->attr, "type");
if(g->tag == Tag_button && (s==0 || cistrcmp(s, "reset") || cistrcmp(s, "button"))) if((g->tag == Tag_button) &&
s = "submit"; (s==0 || cistrcmp(s, "reset") || cistrcmp(s, "button")))
if(s==0 || cistrcmp(s, "text")==0 || s="submit";
cistrcmp(s, "password")==0 || cistrcmp(s, "int")==0 || else if(s==0)
cistrcmp(s, "email")==0){ s="text";
s=pl_getattr(g->attr, "name"); if(cistrcmp(s, "checkbox")==0)
if(s!=0 && strcmp(s, "isindex")==0)
f->type=INDEX;
else
f->type=TYPEIN;
/*
* If there's exactly one attribute, use its value as the name,
* regardless of the attribute name. This makes
* http://linus.att.com/ias/puborder.html work.
*/
if(s==0){
if(g->attr[0].name && g->attr[1].name==0)
f->name=strdup(g->attr[0].value);
else
f->name=strdup("no-name");
}
}
else if(cistrcmp(s, "checkbox")==0)
f->type=CHECK; f->type=CHECK;
else if(cistrcmp(s, "radio")==0) else if(cistrcmp(s, "radio")==0)
f->type=RADIO; f->type=RADIO;
@ -191,8 +174,25 @@ void rdform(Hglob *g){
f->type=RESET; f->type=RESET;
else if(cistrcmp(s, "hidden")==0) else if(cistrcmp(s, "hidden")==0)
f->type=HIDDEN; f->type=HIDDEN;
else else{
f->type=TYPEIN; f->type=TYPEIN;
if(cistrcmp(s, "password")==0)
f->type=PASSWD;
/*
* If there's exactly one attribute, use its value as the name,
* regardless of the attribute name. This makes
* http://linus.att.com/ias/puborder.html work.
*/
s=f->name;
if(s && cistrcmp(s, "isindex")==0)
f->type=INDEX;
if(s==0){
if(g->attr[0].name && g->attr[1].name==0)
f->name=strdup(g->attr[0].value);
else
f->name=strdup("no-name");
}
}
if((f->type==CHECK || f->type==RADIO) && !pl_hasattr(g->attr, "value")){ if((f->type==CHECK || f->type==RADIO) && !pl_hasattr(g->attr, "value")){
free(f->value); free(f->value);
f->value=strdup("on"); f->value=strdup("on");
@ -341,6 +341,9 @@ void mkfieldpanel(Rtext *t){
case TYPEIN: case TYPEIN:
f->p=plentry(0, 0, f->size*chrwidth, f->value, h_submittype); f->p=plentry(0, 0, f->size*chrwidth, f->value, h_submittype);
break; break;
case PASSWD:
f->p=plentry(0, 1, f->size*chrwidth, f->value, h_submittype);
break;
case CHECK: case CHECK:
f->p=plcheckbutton(0, 0, "", h_checkinput); f->p=plcheckbutton(0, 0, "", h_checkinput);
f->state=f->checked; f->state=f->checked;
@ -433,9 +436,11 @@ void h_resetinput(Panel *p, int){
Option *o; Option *o;
for(f=((Field *)p->userp)->form->fields;f;f=f->next) switch(f->type){ for(f=((Field *)p->userp)->form->fields;f;f=f->next) switch(f->type){
case TYPEIN: case TYPEIN:
case PASSWD:
plinitentry(f->p, 0, f->size*chrwidth, f->value, 0); plinitentry(f->p, 0, f->size*chrwidth, f->value, 0);
break; break;
case PASSWD:
plinitentry(f->p, 1, f->size*chrwidth, f->value, 0);
break;
case CHECK: case CHECK:
case RADIO: case RADIO:
f->state=f->checked; f->state=f->checked;
@ -530,7 +535,9 @@ void h_submittype(Panel *p, char *){
int ntype; int ntype;
Field *f; Field *f;
ntype=0; ntype=0;
for(f=((Field *)p->userp)->form->fields;f;f=f->next) if(f->type==TYPEIN) ntype++; for(f=((Field *)p->userp)->form->fields;f;f=f->next)
if(f->type==TYPEIN || f->type==PASSWD)
ntype++;
if(ntype==1) h_submitinput(p, 0); if(ntype==1) h_submitinput(p, 0);
} }
void h_submitindex(Panel *p, char *){ void h_submitindex(Panel *p, char *){

View file

@ -178,6 +178,8 @@ enum{
Tag_table, /* rm 3.8.00 */ Tag_table, /* rm 3.8.00 */
Tag_td, Tag_td,
Tag_tr, Tag_tr,
Tag_video,
Tag_object,
Tag_script, Tag_script,
Tag_style, Tag_style,
Tag_end, /* also used to indicate unrecognized start tag */ Tag_end, /* also used to indicate unrecognized start tag */

View file

@ -53,6 +53,8 @@ Tag tag[]={
[Tag_plaintext] "plaintext", NOEND, [Tag_plaintext] "plaintext", NOEND,
[Tag_pre] "pre", END, [Tag_pre] "pre", END,
[Tag_samp] "samp", END, [Tag_samp] "samp", END,
[Tag_video] "video", NOEND,
[Tag_object] "object", END,
[Tag_script] "script", END, [Tag_script] "script", END,
[Tag_style] "style", END, [Tag_style] "style", END,
[Tag_select] "select", END, [Tag_select] "select", END,

View file

@ -18,12 +18,23 @@ struct Entry{
void pl_drawentry(Panel *p){ void pl_drawentry(Panel *p){
Rectangle r; Rectangle r;
Entry *ep; Entry *ep;
char *s;
ep=p->data; ep=p->data;
r=pl_box(p->b, p->r, p->state); r=pl_box(p->b, p->r, p->state);
if(stringwidth(font, ep->entry)<=r.max.x-r.min.x) s=ep->entry;
pl_drawicon(p->b, r, PLACEW, 0, ep->entry); if(p->flags & 1){
char *p;
s=strdup(s);
for(p=s; *p; p++)
*p='*';
}
if(stringwidth(font, s)<=r.max.x-r.min.x)
pl_drawicon(p->b, r, PLACEW, 0, s);
else else
pl_drawicon(p->b, r, PLACEE, 0, ep->entry); pl_drawicon(p->b, r, PLACEE, 0, s);
if(s != ep->entry)
free(s);
} }
int pl_hitentry(Panel *p, Mouse *m){ int pl_hitentry(Panel *p, Mouse *m){
int oldstate; int oldstate;

View file

@ -241,6 +241,24 @@ int pl_nextc(Hglob *g){
} }
return c; return c;
} }
char *unquot(char *dst, char *src, int len){
char *e;
e=0;
while(strchr("\n\r\t ", *src))
src++;
if(*src=='\'' || *src=='"'){
e=strrchr(src+1, *src);
src++;
}
if(e==0) e=strchr(src, 0);
len--;
if((e - src) < len)
len=e-src;
if(len>0) memmove(dst, src, len);
dst[len]=0;
return dst;
}
int entchar(int c){ int entchar(int c){
return c=='#' || 'a'<=c && c<='z' || 'A'<=c && c<='Z' || '0'<=c && c<='9'; return c=='#' || 'a'<=c && c<='z' || 'A'<=c && c<='Z' || '0'<=c && c<='9';
} }
@ -643,8 +661,6 @@ void plrdhtml(char *name, int fd, Www *dst){
break; break;
case Tag_end: /* unrecognized start tag */ case Tag_end: /* unrecognized start tag */
break; break;
case Tag_meta:
break;
case Tag_img: 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)); strncpy(g.state->image, str, sizeof(g.state->image));
@ -696,19 +712,38 @@ void plrdhtml(char *name, int fd, Www *dst){
pl_htmloutput(&g, 0, "", 0); pl_htmloutput(&g, 0, "", 0);
} }
break; break;
case Tag_meta:
if((str=pl_getattr(g.attr, "http-equiv"))==0)
break;
if(cistrcmp(str, "refresh"))
break;
if((str=pl_getattr(g.attr, "content"))==0)
break;
if((str=strchr(str, '='))==0)
break;
str++;
str=unquot(g.state->link, str, sizeof(g.state->link));
pl_htmloutput(&g, 0, "refresh: ", 0);
pl_htmloutput(&g, 0, str, 0);
g.state->link[0]=0;
g.linebrk=1;
g.spacc=0;
break;
case Tag_video:
case Tag_frame: case Tag_frame:
pl_htmloutput(&g, 0, "FRAME: ", 0);
if(str=pl_getattr(g.attr, "src")) if(str=pl_getattr(g.attr, "src"))
strncpy(g.state->link, str, sizeof(g.state->link)); strncpy(g.state->link, str, sizeof(g.state->link));
if(str=pl_getattr(g.attr, "name")) if(str=pl_getattr(g.attr, "name"))
strncpy(g.state->name, str, sizeof(g.state->name)); strncpy(g.state->name, str, sizeof(g.state->name));
else else
str = g.state->link; str = g.state->link;
pl_htmloutput(&g, 0, tag[g.tag].name, 0);
pl_htmloutput(&g, 0, ": ", 0);
pl_htmloutput(&g, 0, str, 0); pl_htmloutput(&g, 0, str, 0);
g.state->link[0]=0; g.state->link[0]=0;
g.state->name[0] =0; g.state->name[0]=0;
g.spacc=0;
g.linebrk=1; g.linebrk=1;
g.spacc=0;
break; break;
case Tag_address: case Tag_address:
g.spacc=0; g.spacc=0;
@ -904,6 +939,7 @@ void plrdhtml(char *name, int fd, Www *dst){
rdform(&g); rdform(&g);
break; break;
case Tag_script: case Tag_script:
case Tag_object:
case Tag_style: case Tag_style:
/* /*
* ignore the content of these tags, eat tokens until we * ignore the content of these tags, eat tokens until we