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