home *** CD-ROM | disk | FTP | other *** search
- #include<stdio.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<string.h>
- #include <proto/FileID.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
-
-
-
- main(int argc, char **argv)
- {
- char version[]="$VER: LZXCHECK/STRIP V1.0 ©1996 Joe Cool Date: 18.01.1996\n";
- struct FI_FileInfo *MyFileInfo=NULL;
- struct FileIDBase *FileIDBase=NULL;
- char buffer[300],
- buffer2[300],
- *filename=NULL,
- **main_strip=NULL,
- **main_lzxtemp=NULL;
- BOOL file_ok=FALSE,
- strip=FALSE;
- BPTR readfh=NULL,
- lock=NULL;
- long pos=0,
- pos1=0,
- len=0,
- stripped=0,
- merk=0;
-
- printf ("\nLZXCHECK/STRIP V1.0 ©1996 Joe Cool\n");
-
-
- if(!(FileIDBase = (struct FileIDBase *)OpenLibrary("FileID.library",6L)))
- {
- printf ("Couldn`t open FileID.library\n");
- exit (RETURN_FAIL);
- }
- if(!(MyFileInfo = (struct FI_FileInfo *)FIAllocFileInfo()))
- {
- printf ("Can't allocate FI_FileInfo!\n");
- exit (RETURN_FAIL);
- }
- if (argc==1)
- {
- printf("Usage: LZXStrip <LZX-Archive>\n\n");
- exit (RETURN_FAIL);
- }
-
- if(FIIdentifyFromName((struct FI_FileInfo *)MyFileInfo,argv[1]))
- {
- printf("\"%s\" is does not exist!\n\n",argv[1]);
- exit (RETURN_FAIL);
- }
-
- if (MyFileInfo->FI_ID!=543)
- {
- printf("Not a LZX-Archive!\n\n");
- exit (RETURN_FAIL);
- }
- filename=strrchr(argv[1],'/');
- if (filename)
- {
- filename++;
- printf ("Processing file: %s\n",filename);
- }
- else printf ("Processing file: %s\n",argv[1]);
-
- printf("Testing....\n");
-
- readfh=Open("t:lzx.temp",MODE_NEWFILE);
- sprintf (buffer,"lzx t -mfl \"%s\"",argv[1]);
- Execute (buffer,NULL,readfh);
- Close (readfh);
- readfh=Open("t:lzx.temp",MODE_OLDFILE);
-
- while (FGets(readfh, buffer, 200) && (!file_ok))
- {
- if (strstr(buffer,"Operation successful")) file_ok=TRUE;
- }
- Close (readfh);
- DeleteFile("t:lzx.temp");
-
- if (!file_ok)
- {
- printf("ACcorrupt!\n");
- }
- else
- {
- printf("ACDone!\n");
- printf("Stripping..\n");
-
- readfh=Open("t:lzx.temp",MODE_NEWFILE);
- sprintf (buffer,"lzx -mfl l \"%s\"",argv[1]);
- Execute (buffer,NULL,readfh);
- Close (readfh);
- lock = GetProgramDir();
- NameFromLock(lock, buffer, 200);
- sprintf(buffer2,"%s/lzxstrip.list",buffer);
- readfh=Open(buffer2,MODE_OLDFILE);
-
-
- for (pos=0;FGets(readfh,buffer,200);pos++)
- {
- main_strip=(char **) realloc(main_strip,(pos+1)*sizeof(char *));
- main_strip[pos]=NULL;
- len=strlen(buffer);
- main_strip[pos]=(char *) malloc ((len+1)*sizeof(char));
- if (main_strip[pos]!=NULL)
- strcpy(main_strip[pos],buffer);
- }
- Close(readfh);
- main_strip=(char **) realloc(main_strip,(pos+1)*sizeof(char *));
- main_strip[pos]=NULL;
-
-
- readfh=Open("t:lzx.temp",MODE_OLDFILE);
-
-
-
- for (pos=0;FGets(readfh,buffer,300);pos++)
- {
- main_lzxtemp=(char **) realloc(main_lzxtemp,(pos+1)*sizeof(char *));
- main_lzxtemp[pos]=NULL;
- len=strlen(buffer);
- main_lzxtemp[pos]=(char *) malloc ((len+1)*sizeof(char));
- if (main_lzxtemp[pos]!=NULL)
- strcpy(main_lzxtemp[pos],buffer);
- }
- Close(readfh);
- DeleteFile("t:lzx.temp");
- main_lzxtemp=(char **) realloc(main_lzxtemp,(pos+1)*sizeof(char *));
- main_lzxtemp[pos]=NULL;
-
-
-
- for (pos=0;main_lzxtemp[pos]!=NULL;pos++ )
- {
- strip=FALSE;
- for (pos1=0;main_strip[pos1]!=NULL;pos1++)
- {
- if (strstr(main_lzxtemp[pos],main_strip[pos1]))
- {
- strip=TRUE;
- merk=pos1;
- }
- }
- if (strip)
- {
- strcpy(buffer2,main_strip[merk]);
- buffer2[strlen(buffer2)-1]='\0';
- sprintf (buffer,"lzx d \"%s\" \"%s\"",argv[1],buffer2);
- readfh=Open("NIL:",MODE_OLDFILE);
- Execute (buffer,NULL,readfh);
- Close(readfh);
- stripped++;
- strip=FALSE;
- }
-
- }
- printf ("AC%d stripped!\n",stripped);
-
-
-
-
-
-
-
- }
-
-
-
-
- if (file_ok) printf("\nFile is OK!\n");
- else
- {
- printf("\nFile is corrupt!\n");
- exit (0);
- }
-
- if(MyFileInfo) FIFreeFileInfo((struct FI_FileInfo *)MyFileInfo);
- if(FileIDBase) CloseLibrary((struct Library *)FileIDBase);
-
-
-
- }
-