00001 #include <ctype.h>
00002 #include <stdio.h>
00003 #include <fcntl.h>
00004 #include <errno.h>
00005 #include <stdlib.h>
00006
00007 #ifndef __GNUC__
00008 #include <io.h>
00009 #else
00010 #include <unistd.h>
00011 #endif
00012
00013 #include <swcomprs.h>
00014
00015
00016 main(int argc, char **argv)
00017 {
00018 SWCompress *zobj;
00019 int ifd, ofd, ixfd, oxfd;
00020 long offset, loffset, lzoffset;
00021 short size, lsize, lzsize;
00022 char *tmpbuf;
00023
00024 if (argc != 2) {
00025 fprintf(stderr, "usage: %s <datafilename>\n", argv[0]);
00026 exit(1);
00027 }
00028
00029 zobj = new SWCompress();
00030
00031 #ifndef O_BINARY
00032 #define O_BINARY 0
00033 #endif
00034
00035 tmpbuf = new char [ strlen(argv[1]) + 9 ];
00036 ifd = open(argv[1], O_RDONLY|O_BINARY);
00037 sprintf(tmpbuf, "%s.vss", argv[1]);
00038 ixfd = open(tmpbuf, O_RDONLY|O_BINARY);
00039 sprintf(tmpbuf, "%s.zzz", argv[1]);
00040 ofd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00041 sprintf(tmpbuf, "%s.zzz.vss", argv[1]);
00042 oxfd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
00043
00044 delete [] tmpbuf;
00045
00046 printf("\n");
00047
00048 while (1) {
00049 if (read(ixfd, &offset, 4) != 4)
00050 break;
00051 if (read(ixfd, &size, 2) != 2)
00052 break;
00053
00054 if ((offset == loffset) && (size == lsize)) {
00055 printf("using previous offset,size\n", size);
00056 write(oxfd, &lzoffset, 4);
00057 write(oxfd, &lzsize, 2);
00058 }
00059 else {
00060 printf("%d -> ", size);
00061 lsize = size;
00062 loffset = offset;
00063
00064 if (size) {
00065 tmpbuf = (char *) calloc(size + 1, 1);
00066 lseek(ifd, offset, SEEK_SET);
00067 read(ifd, tmpbuf, size);
00068 zobj->Buf(tmpbuf);
00069 zobj->zBuf(&size);
00070 free(tmpbuf);
00071 }
00072 offset = lseek(ofd, 0, SEEK_END);
00073 write(oxfd, &offset, 4);
00074 if (size)
00075 write(ofd, zobj->zBuf(&size), size);
00076 lzoffset = offset;
00077 write(oxfd, &size, 2);
00078 lzsize = size;
00079 printf("%d \n", size);
00080 }
00081 }
00082 delete zobj;
00083 }