void main(int argc, char **argv) { Ndb *db; char *dbfile = 0; ARGBEGIN{ case 'f': dbfile = ARGF(); break; default: usage(); break; }ARGEND; if(argc < 3) usage(); db = ndbopen(dbfile); if(db == 0){ fprint(2, "no db files\n"); exits("no db"); } search(db, argv[0], argv[1], argv+2, argc-2); ndbclose(db); exits(0); }
int dbctlr(char* name, Vga* vga) { Ndb *db; Ndbs s; Ndbtuple *tuple; Ndbtuple *pcituple; db = dbopen(name); /* * Search vgadb for a matching BIOS string or PCI id. * If we have both, the BIOS string wins. */ pcituple = nil; for(tuple = ndbsearch(db, &s, "ctlr", ""); tuple; tuple = ndbsnext(&s, "ctlr", "")){ if(!pcituple && dbpci(vga, tuple)) pcituple = tuple; if(dbbios(vga, tuple)){ save(vga, tuple); if(pcituple && pcituple != tuple) ndbfree(pcituple); ndbfree(tuple); ndbclose(db); return 1; } if(tuple != pcituple) ndbfree(tuple); } if(pcituple){ save(vga, pcituple); ndbfree(pcituple); } ndbclose(db); if(pcituple) return 1; return 0; }
void main(int argc, char **argv) { int reps = 1; char *rattr = nil, *dbfile = nil; Ndb *db; ARGBEGIN{ case 'a': all++; break; case 'm': multiple++; break; case 'f': dbfile = EARGF(usage()); break; default: usage(); }ARGEND; switch(argc){ case 4: reps = atoi(argv[3]); /* wtf use is this? */ /* fall through */ case 3: rattr = argv[2]; break; case 2: rattr = nil; break; default: usage(); } if(Binit(&bout, 1, OWRITE) == -1) sysfatal("Binit: %r"); db = ndbopen(dbfile); if(db == nil){ fprint(2, "%s: no db files\n", argv0); exits("no db"); } while(reps--) search(db, argv[0], argv[1], rattr); ndbclose(db); exits(0); }
Mode* dbmode(char* name, char* type, char* size) { Ndb *db; Ndbs s; Ndbtuple *t, *tuple; Mode *mode; char attr[Namelen+1]; ulong videobw; db = dbopen(name); mode = alloc(sizeof(Mode)); strcpy(attr, type); videobw = 0; /* * Look for the attr=size entry. */ if(dbmonitor(db, mode, attr, size)){ strcpy(mode->type, type); strcpy(mode->size, size); ndbclose(db); return mode; } if(mode->videobw && videobw == 0) /* we at least found that; save it away */ videobw = mode->videobw; /* * Not found. Look for an attr="" entry and then * for an alias=attr within. */ buggery: for(tuple = ndbsearch(db, &s, attr, ""); tuple; tuple = ndbsnext(&s, attr, "")){ for(t = tuple->entry; t; t = t->entry){ if(strcmp(t->attr, "alias")) continue; strcpy(attr, t->val); if(dbmonitor(db, mode, attr, size)){ strcpy(mode->type, type); strcpy(mode->size, size); ndbfree(tuple); ndbclose(db); if(videobw) mode->videobw = videobw; return mode; } /* * Found an alias but no match for size, * restart looking for attr="" with the * new attr. */ ndbfree(tuple); goto buggery; } ndbfree(tuple); } free(mode); ndbclose(db); return 0; }