Statistics
| Branch: | Revision:

grapes / src / Tests / chunkiser_test.c @ 0c461e28

History | View | Annotate | Download (1.11 KB)

1
/*
2
 *  Copyright (c) 2010 Csaba Kiraly
3
 *  Copyright (c) 2010 Luca Abeni
4
 *
5
 *  This is free software; see gpl-3.0.txt
6
 */
7

    
8
#include <unistd.h>
9
#include <stdio.h>
10
#include <stdint.h>
11
#include <stdlib.h>
12
#include <sys/types.h>
13

    
14
#include "chunk.h"
15
#include "chunkiser.h"
16

    
17
int main(int argc, char *argv[])
18
{
19
  int period, done, id;
20
  struct input_stream *input;
21
  struct output_stream *output;
22

    
23
  if (argc < 3) {
24
    fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
25

    
26
    return -1;
27
  }
28
  input = input_stream_open(argv[1], &period, NULL);
29
  if (input == NULL) {
30
    fprintf(stderr, "Cannot open input %s\n", argv[1]);
31

    
32
    return -1;
33
  }
34
  output = out_stream_init(argv[2]);
35
  if (output == NULL) {
36
    fprintf(stderr, "Cannot open output %s\n", argv[2]);
37

    
38
    return -1;
39
  }
40

    
41
  done = 0; id = 0;
42
  while(!done) {
43
    int res;
44
    struct chunk c;
45

    
46
    c.id = id;
47
    res = chunkise(input, &c);
48
    if (res > 0) {
49
      fprintf(stderr,"chunk %d: %d %llu\n", id++, c.size, c.timestamp);
50
      chunk_write(output, &c);
51
    } else if (res < 0) {
52
      done = 1;
53
    }
54
    free(c.data);
55
  }
56
  input_stream_close(input);
57

    
58
  return 0;
59
}