]> git.tdb.fi Git - gldbg.git/blob - source/gldump.c
Initial revision
[gldbg.git] / source / gldump.c
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "glprint.h"
12
13 int main(int argc, char **argv)
14 {
15         FILE *in;
16         GlDecoder *dec;
17         char *buf;
18         unsigned size;
19         unsigned start;
20         unsigned end;
21
22         in = fopen(argv[1], "r");
23
24         dec = glprint_new(NULL, 0);
25
26         size = 16384;
27         buf = (char *)malloc(size);
28         start = 0;
29         end = 0;
30         while(1)
31         {
32                 if(start>size/2)
33                 {
34                         memmove(buf, buf+start, end-start);
35                         end -= start;
36                         start = 0;
37                 }
38                 if(end<size && !feof(in))
39                         end += fread(buf+end, 1, size-end, in);
40                 else if(start==end)
41                         break;
42                 start += gldecoder_decode(dec, buf+start, end-start);
43                 printf("%s\n", glprint_get_buffer(dec));
44         }
45         fclose(in);
46         free(buf);
47         gldecoder_delete(dec);
48
49         return 0;
50 }