plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

sdbquery.c (491B)


      1 #include "std.h"
      2 
      3 static char *file;
      4 
      5 static void
      6 usage(void)
      7 {
      8 	fprint(2, "sdbquery: "
      9 		"[-f file] attr0 value0 [attr1 value1]...\n");
     10 	exits("usage");
     11 }
     12 
     13 void
     14 main(int argc, char *argv[])
     15 {
     16 	Sdbr q;
     17 	Sdb db;
     18 
     19 	ARGBEGIN {
     20 	case 'f':
     21 		file = EARGF(usage());
     22 		break;
     23 	default:
     24 		usage();
     25 	} ARGEND;
     26 	if (argc < 2)
     27 		usage();
     28 	sdbr_init(&q);
     29 	sdbr_arg2r(&q, argv);
     30 	sdb_open(&db, file);
     31 	for (;sdb_query(&db, q);) {
     32 		sdbr_print(db.r[db.n]);
     33 		if (!sdb_next(&db))
     34 			break;
     35 	}
     36 	exits(0);
     37 }