home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 November / VPR0311.ISO / OLS / TAR32223 / tar32223.lzh / tar32_2 / src / Minitar.c < prev    next >
C/C++ Source or Header  |  2003-01-17  |  3KB  |  119 lines

  1. /*
  2.     minitar
  3.     tar32.dll test program
  4.     by Yoshioka Tsuneo(QWF00133@nifty.ne.jp)
  5.     Copy,Edit,Re-distribute FREE!
  6. */
  7. #include <windows.h>
  8. #include <stdio.h>
  9.  
  10. #define FNAME_MAX32        512
  11. typedef struct {
  12.     DWORD             dwOriginalSize;
  13.     DWORD             dwCompressedSize;
  14.     DWORD            dwCRC;
  15.     UINT            uFlag;
  16.     UINT            uOSType;
  17.     WORD            wRatio;
  18.     WORD            wDate;
  19.     WORD             wTime;
  20.     char            szFileName[FNAME_MAX32 + 1];
  21.     char            dummy1[3];
  22.     char            szAttribute[8];
  23.     char            szMode[8];
  24. }    INDIVIDUALINFO;
  25.  
  26. WORD (WINAPI *TarGetVersion)(VOID);
  27. int (WINAPI *Tar)(HWND hwnd,char *cmd,char *buff,int buflen);
  28. int (WINAPI *TarCheckArchive)(char *fname,int mode);
  29. HANDLE (WINAPI *TarOpenArchive)(HANDLE hwnd,char *fname,int mode);
  30. int    (WINAPI *TarCloseArchive)(HANDLE harc);
  31. int (WINAPI *TarFindFirst)(HANDLE hwnd,char *fname,INDIVIDUALINFO *pinfo);
  32. int (WINAPI *TarFindNext)(HANDLE hwnd,INDIVIDUALINFO *pinfo);
  33. int (WINAPI *TarGetFileCount)(LPCSTR _szArcFile);
  34. BOOL (WINAPI *TarConfigDialog)(const HWND _hwnd, LPSTR _lpszComBuffer,const int _iMode);
  35.  
  36. void SelfTest()
  37. {
  38. #define TESTFILE "testfile"
  39.     FILE *fp;
  40.     int i;
  41.     fp = fopen(TESTFILE,"wb");
  42.     for(i=0;i<100;i++){
  43.         fprintf(fp,"%d line.\n",i);
  44.     }
  45.     fclose(fp);
  46.  
  47. }
  48. int main(int argc,char *argv[])
  49. {
  50.     char cmd[1000] = "";
  51.     int i;
  52.     char buff[1001];
  53.     int ret;
  54.     HANDLE hLib;
  55.     int ver;
  56.  
  57.     hLib = LoadLibrary("tar32.dll");
  58.     TarGetVersion = GetProcAddress(hLib, "TarGetVersion");
  59.     TarCheckArchive = GetProcAddress(hLib,"TarCheckArchive");
  60.     TarConfigDialog = GetProcAddress(hLib,"TarConfigDialog");
  61.     Tar = GetProcAddress(hLib,"Tar");
  62.     
  63.     ver = TarGetVersion();
  64.     printf("tar32.dll version <%d>\n", ver);
  65.  
  66.     for(i=1;i<argc;i++){
  67.         strcat(cmd,argv[i]);
  68.         strcat(cmd," ");
  69.     }
  70.  
  71.     if(argc>=2 && strcmp(argv[1],"selftest") == 0){
  72.         SelfTest();
  73.     }
  74.     if(argc>=2 && strcmp(argv[1],"config") == 0){
  75.         TarConfigDialog(NULL,NULL,0);
  76.     }
  77.     if(argc==3 && (strcmp(argv[1],"check")==0 || strcmp(argv[1],"find")==0)){
  78.         TarCheckArchive = GetProcAddress(hLib,"TarCheckArchive");
  79.         ret = TarCheckArchive(argv[2],0);
  80.     }
  81.     
  82.     if(argc>=3 && strcmp(argv[1],"find")==0){
  83.         HANDLE harc;
  84.         INDIVIDUALINFO info;
  85.         char *wildname="";
  86.  
  87.         TarFindFirst = GetProcAddress(hLib,"TarFindFirst");
  88.         TarFindNext = GetProcAddress(hLib,"TarFindNext");
  89.         TarOpenArchive = GetProcAddress(hLib,"TarOpenArchive");
  90.         TarCloseArchive = GetProcAddress(hLib,"TarCloseArchive");
  91.         
  92.         if((harc = TarOpenArchive(NULL,argv[2],0))==NULL){
  93.             exit(1);
  94.         }
  95.         if(argc>=4){wildname=argv[3];}
  96.         ret = TarFindFirst(harc,wildname,&info);
  97.         while(ret!=-1){
  98.             ret = TarFindNext(harc,&info);
  99.         }
  100.         ret = TarCloseArchive(harc);
  101.     }
  102.     if(0){
  103.         /* system("command.com"); */
  104.         TarGetFileCount = GetProcAddress(hLib,"TarGetFileCount");
  105.         ret = TarGetFileCount("c:\\dostool\\utool\\uxtl305.tgz");
  106.         ret = TarGetFileCount("c:\\dostool\\utool\\uxtl305.tar.bz2");
  107. /*        ret = TarGetFileCount("c:\\dostool\\utool\\uxtl305.tgz");
  108.         ret = TarGetFileCount("c:\\dostool\\utool\\uxtl305.tgz");*/
  109.         //ret = TarGetFileCount("aiu.tgz");
  110.     }
  111.     {
  112.         ret = Tar(NULL,cmd,buff,1000);
  113.     }
  114.     FreeLibrary(hLib);
  115.     puts(buff);
  116.     return 0;
  117. }
  118.  
  119.