]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/libauth/attr.c
dtracy: missing break in dteverify
[plan9front.git] / sys / src / libauth / attr.c
old mode 100755 (executable)
new mode 100644 (file)
index 5f35750..740fb5f
@@ -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);