razor.c
author Kristian H?gsberg <krh@redhat.com>
Tue Sep 04 23:52:59 2007 -0400 (2007-09-04)
changeset 6 4eeed5fbe6b7
parent 4 c8e9dbcfaf02
child 7 235f7daf817c
permissions -rw-r--r--
Factor out array code.
krh@0
     1
#include <stdlib.h>
krh@0
     2
#include <stdio.h>
krh@0
     3
#include <string.h>
krh@0
     4
#include <sys/types.h>
krh@0
     5
#include <sys/stat.h>
krh@0
     6
#include <sys/mman.h>
krh@0
     7
#include <unistd.h>
krh@0
     8
#include <fcntl.h>
krh@0
     9
krh@0
    10
#include <expat.h>
krh@0
    11
#include "sha1.h"
krh@0
    12
krh@6
    13
struct array {
krh@6
    14
	void *data;
krh@6
    15
	int size, alloc;
krh@6
    16
};
krh@6
    17
krh@6
    18
static void *
krh@6
    19
array_add(struct array *array, int size)
krh@6
    20
{
krh@6
    21
	int alloc;
krh@6
    22
	void *data, *p;
krh@6
    23
krh@6
    24
	if (array->alloc > 0)
krh@6
    25
		alloc = array->alloc;
krh@6
    26
	else
krh@6
    27
		alloc = 1024;
krh@6
    28
krh@6
    29
	while (alloc < array->size + size)
krh@6
    30
		alloc *= 2;
krh@6
    31
krh@6
    32
	if (array->alloc < alloc) {
krh@6
    33
		data = realloc(array->data, alloc);
krh@6
    34
		if (data == NULL)
krh@6
    35
			return 0;
krh@6
    36
		array->data = data;
krh@6
    37
		array->alloc = alloc;
krh@6
    38
	}
krh@6
    39
krh@6
    40
	p = array->data + array->size;
krh@6
    41
	array->size += size;
krh@6
    42
krh@6
    43
	return p;
krh@6
    44
}
krh@6
    45
krh@0
    46
static int
krh@0
    47
write_to_fd(int fd, void *p, size_t size)
krh@0
    48
{
krh@0
    49
	int rest, len;
krh@0
    50
krh@0
    51
	rest = size;
krh@0
    52
	while (rest > 0) {
krh@0
    53
		len = write(fd, p, rest);
krh@0
    54
		if (len < 0)
krh@0
    55
			return -1;
krh@0
    56
		rest -= len;
krh@0
    57
	}
krh@0
    58
krh@0
    59
	return 0;
krh@0
    60
}
krh@0
    61
krh@0
    62
static int
krh@0
    63
write_to_file(const char *filename, void *p, size_t size)
krh@0
    64
{
krh@0
    65
	int fd, err;
krh@0
    66
krh@0
    67
	fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
krh@0
    68
	if (fd < 0)
krh@0
    69
		return -1;
krh@0
    70
	err = write_to_fd(fd, p, size);
krh@0
    71
	close(fd);
krh@0
    72
krh@0
    73
	return err;
krh@0
    74
}
krh@0
    75
krh@0
    76
static void *
krh@0
    77
zalloc(size_t size)
krh@0
    78
{
krh@0
    79
	void *p;
krh@0
    80
krh@0
    81
	p = malloc(size);
krh@0
    82
	memset(p, 0, size);
krh@0
    83
krh@0
    84
	return p;
krh@0
    85
}
krh@0
    86
krh@4
    87
struct razor_set_header {
krh@4
    88
	unsigned int magic;
krh@4
    89
	unsigned int version;
krh@4
    90
	struct { unsigned int type, offset; } sections[0];
krh@4
    91
};
krh@4
    92
krh@4
    93
#define RAZOR_MAGIC 0x7a7a7a7a
krh@4
    94
#define RAZOR_VERSION 1
krh@4
    95
#define RAZOR_BUCKETS 1
krh@4
    96
#define RAZOR_STRINGS 2
krh@4
    97
#define RAZOR_PACKAGES 3
krh@4
    98
krh@4
    99
struct razor_package {
krh@4
   100
	unsigned long name;
krh@4
   101
	unsigned long version;
krh@4
   102
};
krh@4
   103
krh@4
   104
struct razor_set {
krh@6
   105
	struct array buckets;
krh@6
   106
	struct array string_pool;
krh@6
   107
	struct array packages;
krh@4
   108
	struct razor_set_header *header;
krh@4
   109
};
krh@4
   110
krh@4
   111
struct razor_set *
krh@4
   112
razor_set_create(void)
krh@0
   113
{
krh@4
   114
	struct razor_set *set;
krh@6
   115
	char *p;
krh@0
   116
krh@6
   117
	set = zalloc(sizeof(struct razor_set));
krh@6
   118
	p = array_add(&set->string_pool, 1);
krh@6
   119
	*p = '\0';
krh@3
   120
krh@4
   121
	return set;
krh@0
   122
}
krh@0
   123
krh@4
   124
struct razor_set *
krh@4
   125
razor_set_open(const char *filename)
krh@0
   126
{
krh@4
   127
	struct razor_set *set;
krh@0
   128
	struct stat stat;
krh@0
   129
	unsigned int size, offset;
krh@0
   130
	int fd, i;
krh@0
   131
krh@4
   132
	set = zalloc(sizeof *set);
krh@0
   133
	fd = open(filename, O_RDONLY);
krh@0
   134
	if (fstat(fd, &stat) < 0)
krh@0
   135
		return NULL;
krh@4
   136
	set->header = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
krh@4
   137
	if (set->header == MAP_FAILED) {
krh@4
   138
		free(set);
krh@0
   139
		return NULL;
krh@0
   140
	}
krh@0
   141
krh@4
   142
	for (i = 0; i < set->header->sections[i].type; i++) {
krh@4
   143
		offset = set->header->sections[i].offset;
krh@4
   144
		size = set->header->sections[i + 1].offset - offset;
krh@0
   145
krh@4
   146
		switch (set->header->sections[i].type) {
krh@4
   147
		case RAZOR_BUCKETS:
krh@6
   148
			set->buckets.data = (void *) set->header + offset;
krh@6
   149
			set->buckets.size = size;
krh@6
   150
			set->buckets.alloc = size;
krh@0
   151
			break;
krh@4
   152
		case RAZOR_STRINGS:
krh@6
   153
			set->string_pool.data = (void *) set->header + offset;
krh@6
   154
			set->string_pool.size = size;
krh@6
   155
			set->string_pool.alloc = size;
krh@0
   156
			break;
krh@4
   157
		case RAZOR_PACKAGES:
krh@6
   158
			set->packages.data = (void *) set->header + offset;
krh@6
   159
			set->packages.size = size;
krh@6
   160
			set->packages.size = size;
krh@3
   161
			break;
krh@0
   162
		}
krh@0
   163
	}
krh@0
   164
	close(fd);
krh@0
   165
krh@4
   166
	return set;
krh@0
   167
}
krh@0
   168
krh@0
   169
void
krh@4
   170
razor_set_destroy(struct razor_set *set)
krh@0
   171
{
krh@0
   172
	unsigned int size;
krh@0
   173
	int i;
krh@0
   174
krh@4
   175
	if (set->header) {
krh@4
   176
		for (i = 0; set->header->sections[i].type; i++)
krh@0
   177
			;
krh@4
   178
		size = set->header->sections[i].type;
krh@4
   179
		munmap(set->header, size);
krh@0
   180
	} else {
krh@6
   181
		free(set->buckets.data);
krh@6
   182
		free(set->string_pool.data);
krh@6
   183
		free(set->packages.data);
krh@0
   184
	}
krh@0
   185
krh@4
   186
	free(set);
krh@0
   187
}
krh@0
   188
krh@0
   189
static int
krh@4
   190
razor_set_write(struct razor_set *set, const char *filename)
krh@0
   191
{
krh@0
   192
	char data[4096];
krh@4
   193
	struct razor_set_header *header = (struct razor_set_header *) data;
krh@6
   194
	int fd, pool_size, packages_size;
krh@3
   195
krh@3
   196
	/* Align these to pages sizes */
krh@6
   197
	pool_size = (set->string_pool.size + 4095) & ~4095;
krh@6
   198
	packages_size = (set->packages.size + 4095) & ~4095;
krh@0
   199
krh@0
   200
	memset(data, 0, sizeof data);
krh@4
   201
	header->magic = RAZOR_MAGIC;
krh@4
   202
	header->version = RAZOR_VERSION;
krh@0
   203
krh@4
   204
	header->sections[0].type = RAZOR_BUCKETS;
krh@0
   205
	header->sections[0].offset = sizeof data;
krh@0
   206
krh@4
   207
	header->sections[1].type = RAZOR_STRINGS;
krh@6
   208
	header->sections[1].offset =
krh@6
   209
		header->sections[0].offset + set->buckets.alloc;
krh@0
   210
krh@4
   211
	header->sections[2].type = RAZOR_PACKAGES;
krh@6
   212
	header->sections[2].offset =
krh@6
   213
		header->sections[1].offset + pool_size;
krh@3
   214
krh@3
   215
	header->sections[3].type = 0;
krh@6
   216
	header->sections[3].offset =
krh@6
   217
		header->sections[2].offset + packages_size;
krh@0
   218
krh@0
   219
	fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
krh@0
   220
	if (fd < 0)
krh@0
   221
		return -1;
krh@0
   222
krh@0
   223
	write_to_fd(fd, data, sizeof data);
krh@6
   224
	write_to_fd(fd, set->buckets.data, set->buckets.alloc);
krh@6
   225
	write_to_fd(fd, set->string_pool.data, pool_size);
krh@6
   226
	write_to_fd(fd, set->packages.data, packages_size);
krh@0
   227
krh@0
   228
	return 0;
krh@0
   229
}
krh@0
   230
krh@0
   231
static unsigned int
krh@0
   232
hash_string(const char *key)
krh@0
   233
{
krh@0
   234
	const char *p;
krh@0
   235
	unsigned int hash = 0;
krh@0
   236
krh@0
   237
	for (p = key; *p; p++)
krh@0
   238
		hash = (hash << 2) ^ *p;
krh@0
   239
krh@0
   240
	return hash;
krh@0
   241
}
krh@0
   242
krh@0
   243
unsigned long
krh@4
   244
razor_set_lookup(struct razor_set *set, const char *key)
krh@0
   245
{
krh@6
   246
	unsigned int mask, start, i;
krh@6
   247
	unsigned long *b;
krh@6
   248
	char *pool;
krh@0
   249
krh@6
   250
	pool = set->string_pool.data;
krh@6
   251
	mask = set->buckets.alloc - 1;
krh@6
   252
	start = hash_string(key) * sizeof(unsigned long);
krh@0
   253
krh@6
   254
	for (i = 0; i < set->buckets.alloc; i += sizeof *b) {
krh@6
   255
		b = set->buckets.data + ((start + i) & mask);
krh@6
   256
krh@6
   257
		if (*b == 0)
krh@0
   258
			return 0;
krh@0
   259
krh@6
   260
		if (strcmp(key, &pool[*b]) == 0)
krh@6
   261
			return *b;
krh@6
   262
	}
krh@0
   263
krh@0
   264
	return 0;
krh@0
   265
}
krh@0
   266
krh@0
   267
static unsigned long
krh@4
   268
add_to_string_pool(struct razor_set *set, const char *key)
krh@0
   269
{
krh@6
   270
	int len;
krh@6
   271
	char *p;
krh@0
   272
krh@0
   273
	len = strlen(key) + 1;
krh@6
   274
	p = array_add(&set->string_pool, len);
krh@6
   275
	memcpy(p, key, len);
krh@0
   276
krh@6
   277
	return p - (char *) set->string_pool.data;
krh@0
   278
}
krh@0
   279
krh@0
   280
static void
krh@4
   281
do_insert(struct razor_set *set, unsigned long value)
krh@0
   282
{
krh@6
   283
	unsigned int mask, start, i;
krh@6
   284
	unsigned long *b;
krh@0
   285
	const char *key;
krh@0
   286
krh@6
   287
	key = (char *) set->string_pool.data + value;
krh@6
   288
	mask = set->buckets.alloc - 1;
krh@6
   289
	start = hash_string(key) * sizeof(unsigned long);
krh@6
   290
krh@6
   291
	for (i = 0; i < set->buckets.alloc; i += sizeof *b) {
krh@6
   292
		b = set->buckets.data + ((start + i) & mask);
krh@6
   293
		if (*b == 0) {
krh@6
   294
			*b = value;
krh@0
   295
			break;
krh@0
   296
		}
krh@6
   297
	}
krh@0
   298
}
krh@0
   299
krh@0
   300
unsigned long
krh@4
   301
razor_set_insert(struct razor_set *set, const char *key)
krh@0
   302
{
krh@6
   303
	unsigned long value, *buckets, *b, *end;
krh@6
   304
	int alloc;
krh@0
   305
krh@6
   306
	alloc = set->buckets.alloc;
krh@6
   307
	array_add(&set->buckets, 4 * sizeof *buckets);
krh@6
   308
	if (alloc != set->buckets.alloc) {
krh@6
   309
		end = set->buckets.data + alloc;
krh@6
   310
		memset(end, 0, set->buckets.alloc - alloc);
krh@6
   311
		for (b = set->buckets.data; b < end; b++) {
krh@6
   312
			value = *b;
krh@6
   313
			if (value != 0) {
krh@6
   314
				*b = 0;
krh@4
   315
				do_insert(set, value);
krh@6
   316
			}
krh@0
   317
		}
krh@0
   318
	}
krh@0
   319
krh@4
   320
	value = add_to_string_pool(set, key);
krh@4
   321
	do_insert (set, value);
krh@0
   322
krh@0
   323
	return value;
krh@0
   324
}
krh@0
   325
krh@3
   326
static unsigned long
krh@4
   327
razor_set_add_package(struct razor_set *set,
krh@3
   328
		      unsigned long name, unsigned long version)
krh@3
   329
{
krh@6
   330
	struct razor_package *p;
krh@3
   331
krh@6
   332
	p = array_add(&set->packages, sizeof *p);
krh@3
   333
krh@6
   334
	p->name = name;
krh@6
   335
	p->version = version;
krh@3
   336
krh@6
   337
	return p - (struct razor_package *) set->packages.data;
krh@0
   338
}
krh@0
   339
krh@0
   340
unsigned long
krh@4
   341
razor_set_tokenize(struct razor_set *set, const char *string)
krh@0
   342
{
krh@0
   343
	unsigned long token;
krh@0
   344
krh@4
   345
	token = razor_set_lookup(set, string);
krh@0
   346
	if (token != 0)
krh@0
   347
		return token;
krh@0
   348
krh@4
   349
	return razor_set_insert(set, string);
krh@0
   350
}
krh@0
   351
krh@4
   352
static struct razor_set *qsort_set;
krh@3
   353
krh@3
   354
static int
krh@3
   355
compare_packages(const void *p1, const void *p2)
krh@3
   356
{
krh@4
   357
	const struct razor_package *pkg1 = p1, *pkg2 = p2;
krh@6
   358
	char *pool = qsort_set->string_pool.data;
krh@3
   359
krh@6
   360
	return strcmp(&pool[pkg1->name], &pool[pkg2->name]);
krh@3
   361
}
krh@3
   362
krh@3
   363
static void
krh@4
   364
razor_set_sort(struct razor_set *set)
krh@3
   365
{
krh@4
   366
	qsort_set = set;
krh@6
   367
	qsort(set->packages.data,
krh@6
   368
	      set->packages.size / sizeof(struct razor_package),
krh@6
   369
	      sizeof(struct razor_package), compare_packages);
krh@3
   370
}
krh@3
   371
krh@0
   372
struct parsing_context {
krh@4
   373
	struct razor_set *set;
krh@4
   374
	int pkg_id;
krh@0
   375
};
krh@0
   376
krh@0
   377
static void
krh@3
   378
parse_package(struct parsing_context *ctx, const char **atts)
krh@3
   379
{
krh@3
   380
	unsigned long name, version;
krh@3
   381
	int i;
krh@3
   382
krh@3
   383
	for (i = 0; atts[i]; i += 2) {
krh@3
   384
		if (strcmp(atts[i], "name") == 0)
krh@4
   385
			name = razor_set_tokenize(ctx->set, atts[i + 1]);
krh@3
   386
		else if (strcmp(atts[i], "version") == 0)
krh@4
   387
			version = razor_set_tokenize(ctx->set, atts[i + 1]);
krh@3
   388
	}
krh@3
   389
krh@3
   390
	if (name == 0 || version == 0) {
krh@3
   391
		fprintf(stderr, "invalid package tag, "
krh@3
   392
			"missing name or version attributes\n");
krh@3
   393
		return;
krh@3
   394
	}
krh@3
   395
krh@4
   396
	ctx->pkg_id = razor_set_add_package(ctx->set, name, version);
krh@4
   397
krh@4
   398
	return;
krh@3
   399
}
krh@3
   400
krh@3
   401
static void
krh@0
   402
start_element(void *data, const char *name, const char **atts)
krh@0
   403
{
krh@0
   404
	struct parsing_context *ctx = data;
krh@0
   405
	int i;
krh@0
   406
krh@3
   407
	if (strcmp(name, "package") == 0)
krh@3
   408
		parse_package(ctx, atts);
krh@3
   409
krh@0
   410
	for (i = 0; atts[i]; i += 2)
krh@4
   411
		razor_set_tokenize(ctx->set, atts[i + 1]);
krh@0
   412
}
krh@0
   413
krh@0
   414
static void
krh@0
   415
end_element (void *data, const char *name)
krh@0
   416
{
krh@4
   417
	struct parsing_context *ctx = data;
krh@4
   418
krh@4
   419
	if (strcmp(name, "package") == 0)
krh@4
   420
		ctx->pkg_id = 0;
krh@0
   421
}
krh@0
   422
krh@0
   423
static char *
krh@0
   424
sha1_to_hex(const unsigned char *sha1)
krh@0
   425
{
krh@0
   426
	static int bufno;
krh@0
   427
	static char hexbuffer[4][50];
krh@0
   428
	static const char hex[] = "0123456789abcdef";
krh@0
   429
	char *buffer = hexbuffer[3 & ++bufno], *buf = buffer;
krh@0
   430
	int i;
krh@0
   431
krh@0
   432
	for (i = 0; i < 20; i++) {
krh@0
   433
		unsigned int val = *sha1++;
krh@0
   434
		*buf++ = hex[val >> 4];
krh@0
   435
		*buf++ = hex[val & 0xf];
krh@0
   436
	}
krh@0
   437
	*buf = '\0';
krh@0
   438
krh@0
   439
	return buffer;
krh@0
   440
}
krh@0
   441
krh@0
   442
static int
krh@4
   443
razor_set_import(struct razor_set *set, const char *filename)
krh@0
   444
{
krh@0
   445
	SHA_CTX sha1;
krh@0
   446
	XML_Parser parser;
krh@4
   447
	struct parsing_context ctx;
krh@0
   448
	int fd;
krh@0
   449
	void *p;
krh@0
   450
	struct stat stat;
krh@0
   451
	char buf[128];
krh@0
   452
	unsigned char hash[20];
krh@0
   453
krh@0
   454
	fd = open(filename, O_RDONLY);
krh@0
   455
	if (fstat(fd, &stat) < 0)
krh@0
   456
		return -1;
krh@0
   457
	p = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
krh@0
   458
	if (p == MAP_FAILED)
krh@0
   459
		return -1;
krh@0
   460
krh@0
   461
	parser = XML_ParserCreate(NULL);
krh@4
   462
	ctx.set = set;
krh@4
   463
	XML_SetUserData(parser, &ctx);
krh@0
   464
	XML_SetElementHandler(parser, start_element, end_element);
krh@0
   465
	if (XML_Parse(parser, p, stat.st_size, 1) == XML_STATUS_ERROR) {
krh@0
   466
		fprintf(stderr,
krh@0
   467
			"%s at line %d, %s\n",
krh@0
   468
			XML_ErrorString(XML_GetErrorCode(parser)),
krh@0
   469
			XML_GetCurrentLineNumber(parser),
krh@0
   470
			filename);
krh@0
   471
		return 1;
krh@0
   472
	}
krh@0
   473
krh@0
   474
	XML_ParserFree(parser);
krh@0
   475
krh@0
   476
	SHA1_Init(&sha1);
krh@0
   477
	SHA1_Update(&sha1, p, stat.st_size);
krh@0
   478
	SHA1_Final(hash, &sha1);
krh@0
   479
krh@0
   480
	close(fd);
krh@0
   481
krh@0
   482
	snprintf(buf, sizeof buf, "set/%s", sha1_to_hex(hash));
krh@0
   483
	if (write_to_file(buf, p, stat.st_size) < 0)
krh@0
   484
		return -1;
krh@0
   485
	munmap(p, stat.st_size);
krh@0
   486
krh@0
   487
	return 0;
krh@0
   488
}
krh@0
   489
krh@0
   490
void
krh@4
   491
razor_set_list(struct razor_set *set)
krh@3
   492
{
krh@6
   493
	struct razor_package *p, *end;
krh@6
   494
	char *pool;
krh@3
   495
krh@6
   496
	pool = set->string_pool.data;
krh@6
   497
	end = set->packages.data + set->packages.size;
krh@6
   498
	for (p = set->packages.data; p < end && p->name; p++)
krh@6
   499
		printf("%s %s\n", &pool[p->name], &pool[p->version]);
krh@3
   500
}
krh@3
   501
krh@3
   502
void
krh@4
   503
razor_set_info(struct razor_set *set)
krh@3
   504
{
krh@3
   505
	unsigned int offset, size;
krh@3
   506
	int i;
krh@3
   507
krh@4
   508
	for (i = 0; i < set->header->sections[i].type; i++) {
krh@4
   509
		offset = set->header->sections[i].offset;
krh@4
   510
		size = set->header->sections[i + 1].offset - offset;
krh@3
   511
krh@4
   512
		switch (set->header->sections[i].type) {
krh@4
   513
		case RAZOR_BUCKETS:
krh@3
   514
			printf("bucket section:\t\t%dkb\n", size / 1024);
krh@3
   515
			break;
krh@4
   516
		case RAZOR_STRINGS:
krh@3
   517
			printf("string pool:\t\t%dkb\n", size / 1024);
krh@3
   518
			break;
krh@4
   519
		case RAZOR_PACKAGES:
krh@3
   520
			printf("package section:\t%dkb\n", size / 1024);
krh@3
   521
			break;
krh@3
   522
		}
krh@3
   523
	}
krh@0
   524
}
krh@0
   525
krh@0
   526
static int
krh@0
   527
usage(void)
krh@0
   528
{
krh@3
   529
	printf("usage: razor [ import FILES | lookup <key> | list | info ]\n");
krh@0
   530
	exit(1);
krh@0
   531
}
krh@0
   532
krh@0
   533
static const char repo_filename[] = "system.repo";
krh@0
   534
krh@0
   535
int
krh@0
   536
main(int argc, char *argv[])
krh@0
   537
{
krh@0
   538
	int i;
krh@4
   539
	struct razor_set *set;
krh@0
   540
	struct stat statbuf;
krh@0
   541
krh@3
   542
	if (argc < 2) {
krh@0
   543
		usage();
krh@0
   544
	} else if (strcmp(argv[1], "import") == 0) {
krh@0
   545
		if (stat("set", &statbuf) && mkdir("set", 0777)) {
krh@0
   546
			fprintf(stderr, "could not create directory 'set'\n");
krh@0
   547
			exit(-1);
krh@0
   548
		}
krh@0
   549
			
krh@4
   550
		set = razor_set_create();
krh@0
   551
krh@0
   552
		for (i = 2; i < argc; i++) {
krh@4
   553
			if (razor_set_import(set, argv[i]) < 0) {
krh@0
   554
				fprintf(stderr, "failed to import %s\n",
krh@0
   555
					argv[i]);
krh@0
   556
				exit(-1);
krh@0
   557
			}
krh@0
   558
		}
krh@0
   559
krh@4
   560
		razor_set_sort(set);
krh@3
   561
krh@6
   562
		/* FIXME: We add a sentinel package here, but we
krh@6
   563
		 * should probably just have a size field in the
krh@6
   564
		 * header section. */
krh@6
   565
		razor_set_add_package(set, 0, 0);
krh@6
   566
krh@6
   567
		printf("bucket allocation: %d\n", set->buckets.alloc);
krh@6
   568
		printf("pool size: %d\n", set->string_pool.size);
krh@6
   569
		printf("pool allocation: %d\n", set->string_pool.alloc);
krh@0
   570
krh@4
   571
		razor_set_write(set, repo_filename);
krh@0
   572
krh@4
   573
		razor_set_destroy(set);
krh@0
   574
	} else if (strcmp(argv[1], "lookup") == 0) {
krh@4
   575
		set = razor_set_open(repo_filename);
krh@0
   576
		printf("%s is %lu\n", argv[2],
krh@4
   577
		       razor_set_lookup(set, argv[2]));
krh@4
   578
		razor_set_destroy(set);
krh@3
   579
	} else if (strcmp(argv[1], "list") == 0) {
krh@4
   580
		set = razor_set_open(repo_filename);
krh@4
   581
		razor_set_list(set);
krh@4
   582
		razor_set_destroy(set);
krh@3
   583
	} else if (strcmp(argv[1], "info") == 0) {
krh@4
   584
		set = razor_set_open(repo_filename);
krh@4
   585
		razor_set_info(set);
krh@4
   586
		razor_set_destroy(set);
krh@0
   587
	} else {
krh@0
   588
		usage();
krh@0
   589
	}
krh@0
   590
krh@0
   591
	return 0;
krh@0
   592
}