1 /* Test for sorting routines */
4 #include "lib/getopt.h"
5 #include "lib/fastbuf.h"
15 #define SORT_KEY struct key
16 #define SORT_PREFIX(x) s_##x
18 #define SORT_INPUT_FILE
19 #define SORT_OUTPUT_FILE
23 s_compare(struct key *a, struct key *b)
25 return strcmp(a->line, b->line);
29 s_fetch_key(struct fastbuf *f, struct key *a)
31 return !!bgets(f, a->line, sizeof(a->line));
35 s_copy_data(struct fastbuf *src UNUSED, struct fastbuf *dest, struct key *k)
37 bputsn(dest, k->line);
41 s_fetch_item(struct fastbuf *src UNUSED, struct key *k, byte *limit UNUSED)
43 byte *end = (byte *) k->line + strlen(k->line) + 1;
44 #if 0 /* Testing splits */
45 uns r = random_max(10000);
56 s_store_item(struct fastbuf *f, struct key *k)
58 s_copy_data(NULL, f, k);
63 s_merge_data(struct fastbuf *src1 UNUSED, struct fastbuf *src2 UNUSED, struct fastbuf *dest, struct key *k1, struct key *k2 UNUSED)
65 s_copy_data(NULL, dest, k1);
68 static inline struct key *
69 s_merge_items(struct key *a, struct key *b UNUSED)
75 #include "lib/sorter.h"
78 main(int argc, char **argv)
81 if (cf_getopt(argc, argv, CF_SHORT_OPTS, CF_NO_LONG_OPTS, NULL) >= 0 ||
84 fputs("This program supports only the following command-line arguments:\n" CF_USAGE, stderr);
88 s_sort(argv[optind], argv[optind+1]);