00001
00017
00018 #include "HuffwordLib.h"
00019
00020
00021 int main()
00022 {
00023
00024 FILE *textfile;
00025 struct stat sbuf;
00026 char *text,*cbody,*cstring,*dstring,*dblock;
00027 int tlen,clen,dlen,dblocklen,cbodylen,dbytes,tmp;
00028 Console console;
00029
00030 textfile = fopen("example.dat","r");
00031 stat("example.dat",&sbuf);
00032 tlen = (int)sbuf.st_size;
00033 text = (char *) mmap(NULL,tlen,PROT_READ,MAP_SHARED,fileno(textfile),0);
00034
00035
00036
00037 Huffw_compress(text,tlen,10,&cstring,&clen,1);
00038
00039
00040
00041 Huffw_decompress(cstring,clen,&dstring,&dlen,0);
00042
00043
00044 printf("Comparing the compressed and decompressed files = %d (0 is OK)\n",
00045 strncmp(dstring,text,dlen));
00046
00047
00048
00049
00050
00051
00052
00053 printf("\n---- Some test ----\n");
00054
00055
00056
00057 HDecompress_getBodyAndConsole(cstring,clen,&dlen,&cbody,&cbodylen,&console);
00058
00059
00060 HDecompress_nextBlock_tokens(cbody,cbodylen,10,&dblock,&dblocklen,
00061 &dbytes,&console);
00062
00063
00064 printf("\n10 words from the beginning:\n\"");
00065 HPrint_string(dblock,dblocklen);
00066 printf("\"\n");
00067
00068
00069 HDecompress_previousBlock_tokens(cbody+dbytes,dbytes,5,&dblock,
00070 &dblocklen,&tmp,&console);
00071
00072
00073 printf("\nLast 5 words of the previous phrase:\n\"");
00074 HPrint_string(dblock,dblocklen);
00075 printf("\"\n");
00076
00077 printf("\nDo you wish to see the dictionary content ? (y/n) ");
00078 if (getchar() == 'y')
00079 HDictionary_print(&(console.dictionary),&(console.hashtable),1);
00080
00081
00082 return 0;
00083 }