Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

dlltest.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "bzlib.h"

Go to the source code of this file.

Defines

#define BZ_IMPORT

Functions

void usage (void)
int main (int argc, char *argv[])


Define Documentation

#define BZ_IMPORT
 

Definition at line 11 of file dlltest.c.


Function Documentation

int main int    argc,
char *    argv[]
 

Definition at line 61 of file dlltest.c.

00062 {
00063    int decompress = 0;
00064    int level = 9;
00065    char *fn_r = NULL;
00066    char *fn_w = NULL;
00067 
00068 #ifdef _WIN32
00069    if(BZ2DLLLoadLibrary()<0){
00070       puts("can't load dll");
00071       exit(1);
00072    }
00073 #endif
00074    while(++argv,--argc){
00075       if(**argv =='-' || **argv=='/'){
00076          char *p;
00077 
00078          for(p=*argv+1;*p;p++){
00079             if(*p=='d'){
00080                decompress = 1;
00081             }else if('1'<=*p && *p<='9'){
00082                level = *p - '0';
00083             }else{
00084                usage();
00085                exit(1);
00086             }
00087          }
00088       }else{
00089          break;
00090       }
00091    }
00092    if(argc>=1){
00093       fn_r = *argv;
00094       argc--;argv++;
00095    }else{
00096       fn_r = NULL;
00097    }
00098    if(argc>=1){
00099       fn_w = *argv;
00100       argc--;argv++;
00101    }else{
00102       fn_w = NULL;
00103    }
00104    {
00105       int len;
00106       char buff[0x1000];
00107       char mode[10];
00108 
00109       if(decompress){
00110          BZFILE *BZ2fp_r = NULL;
00111          FILE *fp_w = NULL;
00112 
00113          if(fn_w){
00114             if((fp_w = fopen(fn_w,"wb"))==NULL){
00115                printf("can't open [%s]\n",fn_w);
00116                perror("reason:");
00117                exit(1);
00118             }
00119          }else{
00120             fp_w = stdout;
00121          }
00122          if((BZ2fp_r == NULL && (BZ2fp_r = bzdopen(fileno(stdin),"rb"))==NULL)
00123             || (BZ2fp_r != NULL && (BZ2fp_r = bzopen(fn_r,"rb"))==NULL)){
00124             printf("can't bz2openstream\n");
00125             exit(1);
00126          }
00127          while((len=bzread(BZ2fp_r,buff,0x1000))>0){
00128             fwrite(buff,1,len,fp_w);
00129          }
00130          bzclose(BZ2fp_r);
00131          if(fp_w != stdout) fclose(fp_w);
00132       }else{
00133          BZFILE *BZ2fp_w = NULL;
00134          FILE *fp_r = NULL;
00135 
00136          if(fn_r){
00137             if((fp_r = fopen(fn_r,"rb"))==NULL){
00138                printf("can't open [%s]\n",fn_r);
00139                perror("reason:");
00140                exit(1);
00141             }
00142          }else{
00143             fp_r = stdin;
00144          }
00145          mode[0]='w';
00146          mode[1] = '0' + level;
00147          mode[2] = '\0';
00148 
00149          if((fn_w == NULL && (BZ2fp_w = bzdopen(fileno(stdout),mode))==NULL)
00150             || (fn_w !=NULL && (BZ2fp_w = bzopen(fn_w,mode))==NULL)){
00151             printf("can't bz2openstream\n");
00152             exit(1);
00153          }
00154          while((len=fread(buff,1,0x1000,fp_r))>0){
00155             bzwrite(BZ2fp_w,buff,len);
00156          }
00157          bzclose(BZ2fp_w);
00158          if(fp_r!=stdin)fclose(fp_r);
00159       }
00160    }
00161 #ifdef _WIN32
00162    BZ2DLLFreeLibrary();
00163 #endif
00164    return 0;
00165 }

void usage void   
 

Definition at line 56 of file dlltest.c.

Referenced by main().

00057 {
00058    puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
00059 }


Generated on Sat Oct 13 16:08:47 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001