]> mj.ucw.cz Git - libucw.git/blob - lib/sort-test.c
First version of the sorter. No presorting phase yet.
[libucw.git] / lib / sort-test.c
1 /* Test for sorting routines */
2
3 #include "lib/lib.h"
4 #include "lib/conf.h"
5 #include "lib/fastbuf.h"
6
7 #include <stdio.h>
8 #include <string.h>
9
10 struct key {
11   char line[1024];
12 };
13
14 #define SORT_KEY struct key
15 #define SORT_PREFIX(x) s_##x
16 #define SORT_INPUT_FILE
17 #define SORT_OUTPUT_FILE
18
19 static inline int
20 s_compare(struct key *a, struct key *b)
21 {
22   return strcmp(a->line, b->line);
23 }
24
25 static inline int
26 s_fetch_key(struct fastbuf *f, struct key *a)
27 {
28   return !!bgets(f, a->line, sizeof(a->line));
29 }
30
31 static inline void
32 s_copy_data(struct fastbuf *src UNUSED, struct fastbuf *dest, struct key *k)
33 {
34   bputsn(dest, k->line);
35 }
36
37 #include "lib/sorter.h"
38
39 int
40 main(int argc, char **argv)
41 {
42   log_init(NULL);
43   cf_read(DEFAULT_CONFIG);
44   if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 ||
45       optind != argc - 2)
46     die("Usage: sort-test <input> <output>");
47
48   s_sort(argv[optind], argv[optind+1]);
49   return 0;
50 }