]> mj.ucw.cz Git - libucw.git/blob - lib/lizard-test.c
a9a82a28a15029f4bbb872b242dd1e7fe826c213
[libucw.git] / lib / lizard-test.c
1 #include "lib/lib.h"
2 #include "lib/fastbuf.h"
3 #include "lib/lizzard.h"
4 #include <stdio.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7
8 int
9 main(int argc, char **argv)
10 {
11   if (argc < 4)
12     die("Syntax: lizzard-test -cd input-file output-file");
13   uns compress = !strcmp(argv[1], "-c");
14   struct fastbuf *fi, *fo;
15   void *mi, *mo;
16   uns li, lo;
17
18   struct stat st;
19   stat(argv[2], &st);
20   li = st.st_size;
21   fi = bopen(argv[2], O_RDONLY, 1<<16);
22   if (compress)
23   {
24     lo = li * LIZZARD_MAX_MULTIPLY + LIZZARD_MAX_ADD;
25     li += LIZZARD_NEEDS_CHARS;
26   }
27   else
28   {
29     lo = bgetl(fi);
30     li -= 4;
31   }
32   mi = xmalloc(li);
33   mo = xmalloc(lo);
34   li = bread(fi, mi, li);
35   bclose(fi);
36
37   printf("%d ", li);
38   if (!compress)
39     printf("->expected %d ", lo);
40   fflush(stdout);
41   if (compress)
42     lo = lizzard_compress(mi, li, mo);
43   else
44     lo = lizzard_decompress(mi, mo);
45   printf("-> %d\n", lo);
46   fflush(stdout);
47
48   fo = bopen(argv[3], O_CREAT | O_TRUNC | O_WRONLY, 1<<16);
49   if (compress)
50     bputl(fo, li);
51   bwrite(fo, mo, lo);
52   bclose(fo);
53 }