home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / tools / lzxstrip / lzxstrip01.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-18  |  2.1 KB  |  111 lines

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<ctype.h>
  4. #include<string.h>
  5. #include <proto/FileID.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8.  
  9.  
  10.  
  11. main(int argc, char **argv)
  12. {
  13.     char     version[]="$VER: LZXCHECK/STRIP V1.0 ©1996 Joe Cool  Date: 18.01.1996\n";
  14.     struct FI_FileInfo        *MyFileInfo=NULL;
  15.     struct FileIDBase            *FileIDBase=NULL;
  16.     char    buffer[200],
  17.             *filename=NULL;
  18.     BOOL    file_ok=FALSE;
  19.     BPTR    readfh=NULL;
  20.  
  21.     printf ("\nLZXCHECK/STRIP V1.0 ©1996 Joe Cool\n");
  22.  
  23.  
  24.     if(!(FileIDBase    =    (struct FileIDBase *)OpenLibrary("FileID.library",6L)))
  25.     {
  26.         printf ("Couldn`t open FileID.library\n");
  27.         exit (RETURN_FAIL);
  28.     }
  29.     if(!(MyFileInfo = (struct FI_FileInfo *)FIAllocFileInfo()))
  30.     {
  31.         printf ("Can't allocate FI_FileInfo!\n");
  32.         exit (RETURN_FAIL);
  33.     }
  34.     if (argc==1)    
  35.     {
  36.         printf("Usage: LZXStrip <LZX-Archive>\n\n");
  37.         exit (RETURN_FAIL);
  38.     }
  39.  
  40.     if(FIIdentifyFromName((struct FI_FileInfo *)MyFileInfo,argv[1]))
  41.     {
  42.         printf("\"%s\" is does not exist!\n\n",argv[1]);
  43.         exit (RETURN_FAIL);
  44.     }
  45.     
  46.     if (MyFileInfo->FI_ID!=543) 
  47.     {
  48.         printf("Not a LZX-Archive!\n\n");
  49.         exit (RETURN_FAIL);
  50.     }
  51.     filename=strrchr(argv[1],'/');
  52.     if (filename) 
  53.     {
  54.         filename++;
  55.         printf ("Processing file: %s\n",filename);
  56.     }
  57.     else printf ("Processing file: %s\n",argv[1]);
  58.     
  59.     printf("Testing....");
  60.     
  61.     readfh=Open("t:lzx.temp",MODE_NEWFILE);
  62.     sprintf (buffer,"lzx t -mfl \"%s\"",argv[1]);
  63.     Execute (buffer,NULL,readfh);
  64.     Close (readfh);
  65.     readfh=Open("t:lzx.temp",MODE_OLDFILE);
  66.     
  67.     while (FGets(readfh, buffer, 200) && (!file_ok))
  68.     {
  69.         if (strstr(buffer,"Operation successful")) file_ok=TRUE;
  70.     }
  71.     Close (readfh);
  72.     DeleteFile("t:lzx.temp");
  73.     
  74.     if (!file_ok)
  75.     {
  76.         printf("corrupt!\n");
  77.     }
  78.     else 
  79.     {
  80.         printf("ok!\n"); 
  81.         printf("Stripping..not implemented yet\n");
  82.  
  83.         readfh=Open("t:lzx.temp",MODE_NEWFILE);
  84.         sprintf (buffer,"lzx l -mfl \"%s\"",argv[1]);
  85.         Execute (buffer,NULL,readfh);
  86.         Close (readfh);
  87.     
  88.         Execute ("type t:lzx.temp",NULL,NULL);
  89.  
  90.  
  91.  
  92.  
  93.  
  94.     }
  95.  
  96.  
  97.  
  98.     if (file_ok) printf("\nFile is OK!\n"); 
  99.     else
  100.     {
  101.         printf("\nFile is corrupt!\n");
  102.         exit (RETURN_FAIL);
  103.     }
  104.  
  105.     if(MyFileInfo)    FIFreeFileInfo((struct FI_FileInfo *)MyFileInfo);
  106.     if(FileIDBase)    CloseLibrary((struct Library *)FileIDBase);
  107.  
  108.  
  109.  
  110. }
  111.