]> git.tdb.fi Git - gldbg.git/blobdiff - source/gldump.c
Initial revision
[gldbg.git] / source / gldump.c
diff --git a/source/gldump.c b/source/gldump.c
new file mode 100644 (file)
index 0000000..3a6707b
--- /dev/null
@@ -0,0 +1,50 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "glprint.h"
+
+int main(int argc, char **argv)
+{
+       FILE *in;
+       GlDecoder *dec;
+       char *buf;
+       unsigned size;
+       unsigned start;
+       unsigned end;
+
+       in = fopen(argv[1], "r");
+
+       dec = glprint_new(NULL, 0);
+
+       size = 16384;
+       buf = (char *)malloc(size);
+       start = 0;
+       end = 0;
+       while(1)
+       {
+               if(start>size/2)
+               {
+                       memmove(buf, buf+start, end-start);
+                       end -= start;
+                       start = 0;
+               }
+               if(end<size && !feof(in))
+                       end += fread(buf+end, 1, size-end, in);
+               else if(start==end)
+                       break;
+               start += gldecoder_decode(dec, buf+start, end-start);
+               printf("%s\n", glprint_get_buffer(dec));
+       }
+       fclose(in);
+       free(buf);
+       gldecoder_delete(dec);
+
+       return 0;
+}