void rdbio(char *file, char *user, Acctbio *a) { int i,n; Biobuf *b; char *p; char *field[20]; memset(a, 0, sizeof(Acctbio)); b = Bopen(file, OREAD); if(b != 0){ while(p = Brdline(b, '\n')){ p[Blinelen(b)-1] = 0; n = getfields(p, field, nelem(field), 0, "|"); if(n < 4) continue; if(strcmp(field[0], user) != 0) continue; clrbio(a); a->postid = strdup(field[1]); a->name = strdup(field[2]); a->dept = strdup(field[3]); if(n-4 >= Nemail) n = Nemail-4; for(i = 4; i < n; i++) a->email[i-4] = strdup(field[i]); } Bterm(b); } a->user = strdup(user); }
int ordbio(Biobuf *b, Acctbio *a) { char *p, *cp, *next; int ne; clrbio(a); while(p = Brdline(b, '\n')){ if(*p == '\n') continue; p[Blinelen(b)-1] = 0; /* get user */ for(cp = p; *cp && *cp != ' ' && *cp != '\t'; cp++) ; a->user = malloc(cp - p + 1); strncpy(a->user, p, cp - p); a->user[cp - p] = 0; p = cp; /* get name */ while(*p == ' ' || *p == '\t') p++; for(cp = p; *cp; cp++){ if(isdigit(*cp) || *cp == '<'){ while(cp > p && *(cp-1) != ' ' && *(cp-1) != '\t') cp--; break; } } next = cp; while(cp > p && (*(cp-1) == ' ' || *(cp-1) == '\t')) cp--; a->name = malloc(cp - p + 1); strncpy(a->name, p, cp - p); a->name[cp - p] = 0; p = next; /* get dept */ for(cp = p; *cp; cp++){ if(*cp == '<') break; } next = cp; while(cp > p && (*(cp-1) == ' ' || *(cp-1) == '\t')) cp--; a->dept = malloc(cp - p + 1); strncpy(a->dept, p, cp - p); a->dept[cp - p] = 0; p = next; /* get emails */ ne = 0; for(cp = p; *cp && ne < Nemail;){ if(*cp != '<'){ cp++; continue; } p = ++cp; while(*cp && *cp != '>') cp++; if(cp == p) break; a->email[ne] = malloc(cp - p + 1); strncpy(a->email[ne], p, cp - p); a->email[ne][cp-p] = 0; ne++; } return 0; } return -1; }