mothra: <base> tag, nstrcpy
This commit is contained in:
parent
dd04c51470
commit
2aa121fd6c
4 changed files with 25 additions and 18 deletions
|
@ -76,7 +76,7 @@ void getimage(Rtext *t, Www *w){
|
|||
}
|
||||
close(fd);
|
||||
p = emallocz(sizeof(Pix), 1);
|
||||
strncpy(p->name, ap->image, sizeof(p->name));
|
||||
nstrcpy(p->name, ap->image, sizeof(p->name));
|
||||
p->b=b;
|
||||
p->width=ap->width;
|
||||
p->height=ap->height;
|
||||
|
|
|
@ -473,6 +473,10 @@ void *emallocz(int n, int z){
|
|||
setmalloctag(v, getcallerpc(&n));
|
||||
return v;
|
||||
}
|
||||
void nstrcpy(char *to, char *from, int len){
|
||||
strncpy(to, from, len);
|
||||
to[len-1] = 0;
|
||||
}
|
||||
|
||||
char *genwww(Panel *, int index){
|
||||
static char buf[1024];
|
||||
|
@ -798,7 +802,7 @@ int fileurlopen(Url *url){
|
|||
url->tag[0] = 0;
|
||||
if(x = strrchr(url->fullname, '#')){
|
||||
*x++ = 0;
|
||||
strncpy(url->tag, x, sizeof(url->tag));
|
||||
nstrcpy(url->tag, x, sizeof(url->tag));
|
||||
}
|
||||
fd = open(cleanname(url->fullname), OREAD);
|
||||
if(fd < 0)
|
||||
|
@ -905,9 +909,7 @@ char*
|
|||
urlstr(Url *url){
|
||||
if(url->fullname[0])
|
||||
return url->fullname;
|
||||
if(url->reltext[0])
|
||||
return url->reltext;
|
||||
return nil;
|
||||
}
|
||||
void selurl(char *urlname){
|
||||
static Url url;
|
||||
|
@ -916,8 +918,8 @@ void selurl(char *urlname){
|
|||
message("selected: %s", urlstr(selection));
|
||||
}
|
||||
void seturl(Url *url, char *urlname, char *base){
|
||||
strncpy(url->reltext, urlname, sizeof(url->reltext));
|
||||
strncpy(url->basename, base, sizeof(url->basename));
|
||||
nstrcpy(url->reltext, urlname, sizeof(url->reltext));
|
||||
nstrcpy(url->basename, base, sizeof(url->basename));
|
||||
url->fullname[0] = 0;
|
||||
url->tag[0] = 0;
|
||||
url->map = 0;
|
||||
|
@ -1120,7 +1122,7 @@ void paste(Panel *p){
|
|||
int n, len, fd;
|
||||
if((fd=open("/dev/snarf", OREAD))<0)
|
||||
return;
|
||||
strncpy(buf, plentryval(p), sizeof(buf));
|
||||
nstrcpy(buf, plentryval(p), sizeof(buf));
|
||||
len=strlen(buf);
|
||||
n=read(fd, buf+len, sizeof(buf)-len-1);
|
||||
if(n>0){
|
||||
|
|
|
@ -93,6 +93,7 @@ int urlopen(Url *, int, char *);
|
|||
void getfonts(void);
|
||||
void *emalloc(int);
|
||||
void *emallocz(int, int);
|
||||
void nstrcpy(char *to, char *from, int len);
|
||||
void freeform(void *p);
|
||||
void message(char *, ...);
|
||||
int snooptype(int fd);
|
||||
|
|
|
@ -613,7 +613,7 @@ void plrdplain(char *name, int fd, Www *dst){
|
|||
g.etext=g.text+NTITLE-1;
|
||||
g.spacc=0;
|
||||
g.form=0;
|
||||
strncpy(g.text, name, NTITLE);
|
||||
nstrcpy(g.text, name, NTITLE);
|
||||
plaintext(&g);
|
||||
finish(dst);
|
||||
}
|
||||
|
@ -675,10 +675,10 @@ void plrdhtml(char *name, int fd, Www *dst){
|
|||
if(str=pl_getattr(g.attr, "id")){
|
||||
char swap[NNAME];
|
||||
|
||||
strncpy(swap, g.state->name, sizeof(swap));
|
||||
strncpy(g.state->name, str, sizeof(g.state->name));
|
||||
nstrcpy(swap, g.state->name, sizeof(swap));
|
||||
nstrcpy(g.state->name, str, sizeof(g.state->name));
|
||||
pl_htmloutput(&g, 0, "", 0);
|
||||
strncpy(g.state->name, swap, sizeof(g.state->name));
|
||||
nstrcpy(g.state->name, swap, sizeof(g.state->name));
|
||||
}
|
||||
switch(g.tag){
|
||||
default:
|
||||
|
@ -689,7 +689,7 @@ void plrdhtml(char *name, int fd, Www *dst){
|
|||
break;
|
||||
case Tag_img:
|
||||
if(str=pl_getattr(g.attr, "src"))
|
||||
strncpy(g.state->image, str, sizeof(g.state->image));
|
||||
nstrcpy(g.state->image, str, sizeof(g.state->image));
|
||||
g.state->ismap=pl_hasattr(g.attr, "ismap");
|
||||
if(str=pl_getattr(g.attr, "width"))
|
||||
g.state->width = strtolength(&g, HORIZ, str);
|
||||
|
@ -725,11 +725,15 @@ void plrdhtml(char *name, int fd, Www *dst){
|
|||
case Tag_td:
|
||||
g.spacc++;
|
||||
break;
|
||||
case Tag_base:
|
||||
if(str=pl_getattr(g.attr, "href"))
|
||||
nstrcpy(g.dst->url->fullname, str, sizeof(g.dst->url->fullname));
|
||||
break;
|
||||
case Tag_a:
|
||||
if(str=pl_getattr(g.attr, "href"))
|
||||
strncpy(g.state->link, str, sizeof(g.state->link));
|
||||
nstrcpy(g.state->link, str, sizeof(g.state->link));
|
||||
if(str=pl_getattr(g.attr, "name")){
|
||||
strncpy(g.state->name, str, sizeof(g.state->name));
|
||||
nstrcpy(g.state->name, str, sizeof(g.state->name));
|
||||
pl_htmloutput(&g, 0, "", 0);
|
||||
}
|
||||
break;
|
||||
|
@ -757,9 +761,9 @@ void plrdhtml(char *name, int fd, Www *dst){
|
|||
case Tag_frame:
|
||||
case Tag_iframe:
|
||||
if(str=pl_getattr(g.attr, "src"))
|
||||
strncpy(g.state->link, str, sizeof(g.state->link));
|
||||
nstrcpy(g.state->link, str, sizeof(g.state->link));
|
||||
if(str=pl_getattr(g.attr, "name"))
|
||||
strncpy(g.state->name, str, sizeof(g.state->name));
|
||||
nstrcpy(g.state->name, str, sizeof(g.state->name));
|
||||
else
|
||||
str = g.state->link;
|
||||
pl_htmloutput(&g, 0, tag[g.tag].name, 0);
|
||||
|
@ -1060,7 +1064,7 @@ void plrdhtml(char *name, int fd, Www *dst){
|
|||
break;
|
||||
case TEXT:
|
||||
if(g.state->link[0]==0 && (str = linkify(g.token))){
|
||||
strncpy(g.state->link, str, sizeof(g.state->link));
|
||||
nstrcpy(g.state->link, str, sizeof(g.state->link));
|
||||
pl_htmloutput(&g, g.nsp, g.token, 0);
|
||||
g.state->link[0] = 0;
|
||||
free(str);
|
||||
|
|
Loading…
Reference in a new issue