 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <dos.h>
 typedef struct
 {
  char name[13];
  long offset ;
 }  FileEntry;
 int getfromST(char *filename)
 {
    FILE *fp ;
    long status,status1 ;
    char groundname[20];
    char buffer[600];
    if ( (fp =fopen( "\\st.txt","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,600,fp)!=NULL)
  {
   sscanf(buffer, "%lx %lx %s" ,&status1,&status,groundname);
   strcpy (buffer,"mapz");
   strcat(buffer,groundname);
   strcat(buffer,".pak");
   strcpy(groundname,buffer);

 //  strcat(groundname,"A.BMP");
  if (strcmpi(groundname,filename) == 0 ){fclose(fp); return 1;}
  }
  fclose(fp);
  return 0;
 }
 int getfromTALK(char *filename)
  {
      FILE *fp ;

    long status,status1 ;
    int frame,i,j;
    char actname[20];
    char groundname[20];
    char buff11[5];
    char buffer[600];
    if ( (fp =fopen( "\\acttalk.txt","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,600,fp)!=NULL)
  {
   sscanf(buffer, "%d %d" ,&status1,&status);
   for ( i= 0; i< status ;i ++ )
      {
      if ( fgets( buffer,600,fp)== NULL){fclose(fp); return 0;}
     sscanf(buffer,"%s %d" ,groundname,&frame);
     for (j=1;j<=frame ; j++ )
     {
      itoa(j,buff11,10);
      strcpy (actname,groundname);
      strcat(actname,buff11);
      strcat(actname,".bmp");
     if (strcmpi(actname,filename)==0){fclose(fp); return 1;}
     }
      }
  }
  fclose(fp);
  return 0;
 }
 int getfromACT(char * filename)
 {
   FILE   *fp ;

    long status,status1 ;
    int frame,i,j   ;
    char actname[20];
    char groundname[20];
    char buff11[5];
    char buffer[600];
    if ( (fp =fopen( "\\act.txt","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,600,fp)!=NULL)
  {
   sscanf(buffer, "%d %d" ,&status1,&status);
   for ( i= 0; i< status ;i ++ )
      {
      if ( fgets( buffer,600,fp)== NULL){fclose(fp); return 0;}
     sscanf(buffer,"%s %d" ,groundname,&frame);
     for (j=1;j<=frame ; j++ )
     {
      itoa(j,buff11,10);
      strcpy (actname,groundname);
      strcat(actname,buff11);
      strcat(actname,".bmp");
     if (strcmpi(actname,filename)==0){fclose(fp); return 1;}
     }
      }
  }
  fclose(fp);
  return 0;
 }
 int getfromGOOD(char * filename)
 {
  FILE  *fp ;

    long status,status1 ;
    int frame,i;
    char actname[20];
    char groundname[20];
    char buff11[5];
    char buffer[600];
    if ( (fp =fopen( "\\pick.txt","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,600,fp)!=NULL)
  {
   sscanf(buffer, "%d %d" ,&status1,&status);
   for ( i= 0; i< status ;i ++ )
      {
      if ( fgets( buffer,600,fp)== NULL){fclose(fp); return 0;}
       sscanf(buffer,"%s " ,groundname );


      strcpy (actname,groundname);

      strcat(actname,".bmp");
     if (strcmpi(actname,filename)==0){fclose(fp); return 1;}
       strcpy (actname,groundname);
       strcat(actname,"1");
       strcat(actname,".bmp");
       if (strcmpi(actname,filename)==0){fclose(fp); return 1;}
      }
  }
  fclose(fp);
  return 0;
 }
     char buffer[2000];
 int getfromCProg(char * filename)

 {
     FILE   *fp ;

    long status,status1 ;
    int frame;
    char actname[20];
    char groundname[20];
    char buff11[5];
/*
    strcpy(actname,"\"");
    strcat(actname,filename);
    strcat(actname,"\"");
    */
    strupr(filename);
    if ( (fp =fopen( "D:\\hero\\hs6.c","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,1000,fp)!=NULL)
  {
       strupr(buffer);
  if (   strstr(buffer,filename) ){ fclose(fp); return 1;}
  }
  fclose(fp);
  return 0;

 }
 int getfromtalkTXT(char * filename)

 {
     FILE   *fp ;

    long status,status1 ;
    int frame;
    char actname[20];
    char groundname[20];
    char buff11[5];

    strupr(filename);
    if ( (fp =fopen( "talk1.txt","rt")) == NULL) { printf("cann't find ST.txt\n");exit(0); }
  while(  fgets(buffer,100,fp)!=NULL)
  {
       buffer[4]=0;
       strcat(buffer,".bmp");
  if (   strcmpi(buffer,filename) == 0 ){ fclose(fp); return 1;}
  }
  fclose(fp);
  return 0;

 }
 int getfromMain(char * mainman,char *filename)
 {
  FILE * fp;
  int i; FileEntry Entry [40];
  fp = fopen(mainman,"rb");
  if(fp==NULL) { printf("getmain error"); exit(0); }
  fseek(fp,4l,SEEK_SET);
  fread(Entry,sizeof(FileEntry),40,fp);
  for (i =0 ;i<40; i++ )
  if (strcmpi(Entry[i].name,filename)==0) {fclose(fp);return 1;}
  fclose (fp);
  return 0;
 }
 int getfromMainman(char * filename)
 {
  if (getfromMain("bw.man",filename)) return 1;
//  if (getfromMain("fw.man",filename)) return 1;
  //  if (getfromMain("sew.man",filename)) return 1;
 // if (getfromMain("sfw.man",filename)) return 1;

  return 0 ;
 }
 FILE * unusedfp ;
 FILE * usefp;
 int getfile(char * filestruct)
 {
     struct find_t fileinfo;
     unsigned rc ;
     int i = 0 ;
   rc =    _dos_findfirst(filestruct,0xff,&fileinfo);
   while (!rc)
   {
  if (
   getfromST( fileinfo.name )
/*  ||  getfromTALK(fileinfo.name )
 || getfromGOOD(fileinfo.name )|| getfromACT(fileinfo.name )
  ||
 getfromCProg(fileinfo.name )
 || getfromMainman(fileinfo.name)
 || getfromtalkTXT(fileinfo.name)*/
     )
	  fprintf(usefp,"%s\n",fileinfo.name);
    else  fprintf(unusedfp,"%s\n",fileinfo.name);
     rc =_dos_findnext(&fileinfo);
   }
   return i;
 }

void main(void)
{
//  if ( (usefp=fopen("\\usedat.doc","wt") ) == NULL ) { printf("error creat");exit(0);}
// if ( (unusedfp=fopen("\\unusedat.doc","wt") ) == NULL ) { printf("error creat");exit(0);}
    if ( (usefp=fopen("\\usepak.doc","wt") ) == NULL ) { printf("error creat");exit(0);}
 if ( (unusedfp=fopen("\\unusepak.doc","wt") ) == NULL ) { printf("error creat");exit(0);}

//  if ( (usefp=fopen("\\theuse.doc","wt") ) == NULL ) { printf("error creat");exit(0);}
 //   if ( (unusedfp=fopen("\\theunuse.doc","wt") ) == NULL ) { printf("error creat");exit(0);}
//    getfile("*.dat");
  getfile("*.pak");
    fclose (usefp);
    fclose(unusedfp);
}
