X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Flibauth%2Fattr.c;h=740fb5f2c5305d0942674fd685f7120e31beeee2;hb=a7f5ecaf636e38f407c951d0e86dcc4c4f424bd6;hp=5f35750bad938688ff3e10b84dac4799478b4171;hpb=a9060cc06bee66e12fe16644511f181a4b0cdbd3;p=plan9front.git diff --git a/sys/src/libauth/attr.c b/sys/src/libauth/attr.c index 5f35750ba..740fb5f2c 100644 --- a/sys/src/libauth/attr.c +++ b/sys/src/libauth/attr.c @@ -5,28 +5,26 @@ int _attrfmt(Fmt *fmt) { - char *b, buf[1024], *ebuf; Attr *a; + int first = 1; - ebuf = buf+sizeof buf; - b = buf; - strcpy(buf, " "); - for(a=va_arg(fmt->args, Attr*); a; a=a->next){ + for(a=va_arg(fmt->args, Attr*); a != nil; a=a->next){ if(a->name == nil) continue; switch(a->type){ + default: + continue; case AttrQuery: - b = seprint(b, ebuf, " %q?", a->name); + fmtprint(fmt, first+" %q?", a->name); break; case AttrNameval: - b = seprint(b, ebuf, " %q=%q", a->name, a->val); - break; case AttrDefault: - b = seprint(b, ebuf, " %q:=%q", a->name, a->val); + fmtprint(fmt, first+" %q=%q", a->name, a->val); break; } + first = 0; } - return fmtstrcpy(fmt, buf+1); + return 0; } Attr* @@ -128,7 +126,7 @@ Attr* _parseattr(char *s) { char *p, *t, *tok[256]; - int i, ntok, type; + int i, ntok; Attr *a; s = strdup(s); @@ -139,25 +137,17 @@ _parseattr(char *s) a = nil; for(i=ntok-1; i>=0; i--){ t = tok[i]; - if(p = strchr(t, '=')){ + if((p = strchr(t, '=')) != nil){ *p++ = '\0'; - // if(p-2 >= t && p[-2] == ':'){ - // p[-2] = '\0'; - // type = AttrDefault; - // }else - type = AttrNameval; - a = _mkattr(type, t, p, a); - setmalloctag(a, getcallerpc(&s)); - } - else if(t[strlen(t)-1] == '?'){ - t[strlen(t)-1] = '\0'; + a = _mkattr(AttrNameval, t, p, a); + }else if((p = strchr(t, '\0')-1) >= t && *p == '?'){ + *p = '\0'; a = _mkattr(AttrQuery, t, "", a); - setmalloctag(a, getcallerpc(&s)); }else{ /* really a syntax error, but better to provide some indication */ a = _mkattr(AttrNameval, t, "", a); - setmalloctag(a, getcallerpc(&s)); } + setmalloctag(a, getcallerpc(&s)); } free(s); return cleanattr(a);