git: 9front

Download patch

ref: e17a66f7ebf080535e10042b208d5e73f398d649
parent: 593b8e8cc184014bd0d9146b01c2e80eb731134d
author: cinap_lenrek <cinap_lenrek@rei2.9hal>
date: Sun Nov 6 10:19:02 EST 2011

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

--- a/sys/src/cmd/mothra/forms.c
+++ b/sys/src/cmd/mothra/forms.c
@@ -150,29 +150,12 @@
 		else
 			f->maxlength=atoi(s);
 		s=pl_getattr(g->attr, "type");
-		if(g->tag == Tag_button && (s==0 || cistrcmp(s, "reset") || cistrcmp(s, "button")))
-			s = "submit";
-		if(s==0 || cistrcmp(s, "text")==0 || 
-		   cistrcmp(s, "password")==0 || cistrcmp(s, "int")==0 ||
-		   cistrcmp(s, "email")==0){
-			s=pl_getattr(g->attr, "name");
-			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)
+		if((g->tag == Tag_button) && 
+		   (s==0 || cistrcmp(s, "reset") || cistrcmp(s, "button")))
+			s="submit";
+		else if(s==0)
+			s="text";
+		if(cistrcmp(s, "checkbox")==0)
 			f->type=CHECK;
 		else if(cistrcmp(s, "radio")==0)
 			f->type=RADIO;
@@ -191,8 +174,25 @@
 			f->type=RESET;
 		else if(cistrcmp(s, "hidden")==0)
 			f->type=HIDDEN;
-		else
+		else{
 			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")){
 			free(f->value);
 			f->value=strdup("on");
@@ -341,6 +341,9 @@
 	case TYPEIN:
 		f->p=plentry(0, 0, f->size*chrwidth, f->value, h_submittype);
 		break;
+	case PASSWD:
+		f->p=plentry(0, 1, f->size*chrwidth, f->value, h_submittype);
+		break;
 	case CHECK:
 		f->p=plcheckbutton(0, 0, "", h_checkinput);
 		f->state=f->checked;
@@ -433,9 +436,11 @@
 	Option *o;
 	for(f=((Field *)p->userp)->form->fields;f;f=f->next) switch(f->type){
 	case TYPEIN:
-	case PASSWD:
 		plinitentry(f->p, 0, f->size*chrwidth, f->value, 0);
 		break;
+	case PASSWD:
+		plinitentry(f->p, 1, f->size*chrwidth, f->value, 0);
+		break;
 	case CHECK:
 	case RADIO:
 		f->state=f->checked;
@@ -530,7 +535,9 @@
 	int ntype;
 	Field *f;
 	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);
 }
 void h_submitindex(Panel *p, char *){
--- a/sys/src/cmd/mothra/html.h
+++ b/sys/src/cmd/mothra/html.h
@@ -178,6 +178,8 @@
 	Tag_table,	/* rm 3.8.00 */
 	Tag_td,
 	Tag_tr,
+	Tag_video,
+	Tag_object,
 	Tag_script,
 	Tag_style,
 	Tag_end,	/* also used to indicate unrecognized start tag */
--- a/sys/src/cmd/mothra/html.syntax.c
+++ b/sys/src/cmd/mothra/html.syntax.c
@@ -53,6 +53,8 @@
 [Tag_plaintext]	"plaintext",	NOEND,
 [Tag_pre]	"pre",		END,
 [Tag_samp]	"samp",		END,
+[Tag_video]	"video",	NOEND,
+[Tag_object]	"object",	END,
 [Tag_script]	"script",	END,
 [Tag_style]	"style",	END,
 [Tag_select]	"select",	END,
--- a/sys/src/cmd/mothra/libpanel/entry.c
+++ b/sys/src/cmd/mothra/libpanel/entry.c
@@ -18,12 +18,23 @@
 void pl_drawentry(Panel *p){
 	Rectangle r;
 	Entry *ep;
+	char *s;
+
 	ep=p->data;
 	r=pl_box(p->b, p->r, p->state);
-	if(stringwidth(font, ep->entry)<=r.max.x-r.min.x)
-		pl_drawicon(p->b, r, PLACEW, 0, ep->entry);
+	s=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
-		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 oldstate;
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -241,6 +241,24 @@
 	}
 	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){
 	return c=='#' || 'a'<=c && c<='z' || 'A'<=c && c<='Z' || '0'<=c && c<='9';
 }
@@ -643,8 +661,6 @@
 			break;
 		case Tag_end:	/* unrecognized start tag */
 			break;
-		case Tag_meta:
-			break;
 		case Tag_img:
 			if(str=pl_getattr(g.attr, "src"))
 				strncpy(g.state->image, str, sizeof(g.state->image));
@@ -696,8 +712,25 @@
 				pl_htmloutput(&g, 0, "", 0);
 			}
 			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:
-			pl_htmloutput(&g, 0, "FRAME: ", 0);
 			if(str=pl_getattr(g.attr, "src"))
 				strncpy(g.state->link, str, sizeof(g.state->link));
 			if(str=pl_getattr(g.attr, "name"))
@@ -704,11 +737,13 @@
 				strncpy(g.state->name, str, sizeof(g.state->name));
 			else
 				str = g.state->link;
+			pl_htmloutput(&g, 0, tag[g.tag].name, 0);
+			pl_htmloutput(&g, 0, ": ", 0);
 			pl_htmloutput(&g, 0, str, 0);
 			g.state->link[0]=0;
-			g.state->name[0] =0;
-			g.spacc=0;
+			g.state->name[0]=0;
 			g.linebrk=1;
+			g.spacc=0;
 			break;
 		case Tag_address:
 			g.spacc=0;
@@ -904,6 +939,7 @@
 			rdform(&g);
 			break;
 		case Tag_script:
+		case Tag_object:
 		case Tag_style:
 			/*
 			 * ignore the content of these tags, eat tokens until we
--