X-Git-Url: http://git.tdb.fi/?p=gldbg.git;a=blobdiff_plain;f=source%2Fgldump.c;h=79896c2fa4bad9c902726e949d03015b899160ae;hp=3a6707b962abd6e7cf8b058809067b28a781602a;hb=0cdc7b50b0e7758a1660c94be664a810504a88f4;hpb=9d1825d591a7261b1cff620ba535d333352984bf diff --git a/source/gldump.c b/source/gldump.c index 3a6707b..79896c2 100644 --- a/source/gldump.c +++ b/source/gldump.c @@ -7,43 +7,54 @@ Distributed under the GPL #include #include -#include +#include +#include +#include +#include #include "glprint.h" int main(int argc, char **argv) { - FILE *in; + int fd; + struct stat st; GlDecoder *dec; - char *buf; - unsigned size; - unsigned start; - unsigned end; + char *addr; + char *end; + char *ptr; - in = fopen(argv[1], "r"); + if(argc<2) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + + fd = open(argv[1], O_RDONLY); + if(fd==-1) + { + perror("open"); + return 1; + } + fstat(fd, &st); + addr = (char *)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + end = addr+st.st_size; + ptr = addr; dec = glprint_new(NULL, 0); - size = 16384; - buf = (char *)malloc(size); - start = 0; - end = 0; - while(1) + while(ptrsize/2) + int ret; + ret = gldecoder_decode(dec, ptr, end-ptr); + if(ret<0) { - memmove(buf, buf+start, end-start); - end -= start; - start = 0; - } - if(end