home *** CD-ROM | disk | FTP | other *** search
/ ftp.rarlab.com / 2014.05.ftp.rarlab.com.tar / ftp.rarlab.com / rar / sunrar.zip / somefn.c < prev    next >
C/C++ Source or Header  |  1998-07-01  |  5KB  |  189 lines

  1. void GetArcNames(void)
  2. {
  3.   ArcNamesSize=ArcCount=0;
  4.   SplitPath(ArcName,FindPath,FindName,0);
  5.   FindArchives();
  6.   TotalArcCount=ArcCount;
  7.   ArcNamesSize=0;
  8. }
  9.  
  10.  
  11. void FindArchives(void)
  12. {
  13.   DIR *dir;
  14.   struct dirent *ent;
  15.   struct FileStat FS;
  16.   int NameLen;
  17.   char *ChPtr,*PtrToDrive;
  18.   static char ArchiveName[NM];
  19.  
  20.   if ((dir=DirOpen(FindPath))!=NULL)
  21.     while ((ent=readdir(dir))!=NULL)
  22.     {
  23.       strcpy(ArchiveName,FindPath);
  24.       strcat(ArchiveName,ent->d_name);
  25.       if (!GetFileStat(ArchiveName,&FS))
  26.         continue;
  27.  
  28.       if (FS.IsDir)
  29.       {
  30.         if (Opt.Recurse && strcmp(ent->d_name,".")!=0 &&
  31.             strcmp(ent->d_name,"..")!=0)
  32.         {
  33.           strcat(FindPath,ent->d_name);
  34.           strcat(FindPath,PATHDIVIDER);
  35.           FindArchives();
  36.         }
  37.       }
  38.       else
  39.         if (CmpName(FindName,ent->d_name,0) )
  40.         {
  41.           NameLen=strlen(ArchiveName)+1;
  42.           if ((ArcNamePtr=realloc(ArcNamePtr,ArcNamesSize+NameLen))==NULL)
  43.             ErrExit(EMEMORY,MEMORY_ERROR);
  44.           strcpy(ArcNamePtr+ArcNamesSize,ArchiveName);
  45.           ArcNamesSize+=NameLen;
  46.           ArcCount++;
  47.         }
  48.     }
  49.  
  50.   if (dir!=NULL)
  51.     closedir(dir);
  52.  
  53.   PtrToDrive=FindPath;
  54.  
  55. #ifdef _WIN_32
  56.   if ((ChPtr=strchr(FindPath,':'))!=NULL)
  57.     PtrToDrive=ChPtr+1;
  58. #endif
  59.  
  60.   if ((ChPtr=strrchr(FindPath,CPATHDIVIDER))!=NULL)
  61.   {
  62.     *ChPtr=0;
  63.     if ((ChPtr=strrchr(FindPath,CPATHDIVIDER))!=NULL)
  64.       *(ChPtr+1)=0;
  65.     else
  66.       *PtrToDrive=0;
  67.   }
  68.   else
  69.     *PtrToDrive=0;
  70. }
  71.  
  72.  
  73. int ReadArcName(void)
  74. {
  75.   if (ArcCount==0)
  76.     return(0);
  77.   strcpy(ArcName,ArcNamePtr+ArcNamesSize);
  78.   ArcNamesSize+=strlen(ArcName)+1;
  79.   ArcCount--;
  80.   return(1);
  81. }
  82.  
  83.  
  84. int IsArchive(void)
  85. {
  86.   long CurPos;
  87.   int ReadSize;
  88.   unsigned char *ChPtr;
  89.   SFXLen=ArcType=SolidType=LockedType=AVType=0;
  90.   ArcFormat=MainComment=BrokenMhd=0;
  91.  
  92.   if (tread(ArcPtr,MarkHead.Mark,SIZEOF_MARKHEAD)!=SIZEOF_MARKHEAD)
  93.     return(0);
  94.   if (MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x45 &&
  95.       MarkHead.Mark[2]==0x7e && MarkHead.Mark[3]==0x5e)
  96.   {
  97.     ArcFormat=OLD;
  98.     tseek(ArcPtr,0,SEEK_SET);
  99.     ReadHeader(MAIN_HEAD);
  100.     ArcType=(OldMhd.Flags & MHD_MULT_VOL) ? VOL : ARC;
  101.   }
  102.   else
  103.     if (MarkHead.Mark[0]==0x52 && MarkHead.Mark[1]==0x61 &&
  104.         MarkHead.Mark[2]==0x72 && MarkHead.Mark[3]==0x21 &&
  105.         MarkHead.Mark[4]==0x1a && MarkHead.Mark[5]==0x07 &&
  106.         MarkHead.Mark[6]==0x00)
  107.     {
  108.       ArcFormat=NEW;
  109.       if (ReadHeader(MAIN_HEAD)!=SIZEOF_NEWMHD)
  110.         return(0);
  111.       if (NewMhd.Flags & MHD_MULT_VOL)
  112.         ArcType=VOL;
  113.       else
  114.         ArcType=ARC;
  115.     }
  116.     else
  117.     {
  118.       if ((TempMemory=malloc(0x20000))==NULL)
  119.         ErrExit(EMEMORY,MEMORY_ERROR);
  120.       CurPos=ftell(ArcPtr);
  121.       ReadSize=tread(ArcPtr,TempMemory,0x1FFF0);
  122.       ChPtr=TempMemory;
  123.       while  (ArcType==0 && ChPtr!=NULL && ChPtr<TempMemory+ReadSize)
  124.       {
  125.         if ((ChPtr=memchr((void *)ChPtr,0x52,ReadSize-(int)(ChPtr-TempMemory)))!=NULL)
  126.         {
  127.           ChPtr++;
  128.           if (ChPtr[0]==0x45 && ChPtr[1]==0x7e && ChPtr[2]==0x5e &&
  129.               TempMemory[28-CurPos]==0x52 && TempMemory[29-CurPos]==0x53 &&
  130.               TempMemory[30-CurPos]==0x46 && TempMemory[31-CurPos]==0x58)
  131.           {
  132.             ArcFormat=OLD;
  133.             SFXLen=(int)(CurPos+ChPtr-TempMemory-1);
  134.             tseek(ArcPtr,SFXLen,SEEK_SET);
  135.             ReadHeader(MAIN_HEAD);
  136.             if (OldMhd.Flags & MHD_MULT_VOL)
  137.               ArcType=VOL;
  138.             else
  139.               ArcType=SFX;
  140.           }
  141.           if (ChPtr[0]==0x61 && ChPtr[1]==0x72 && ChPtr[2]==0x21 &&
  142.               ChPtr[3]==0x1a && ChPtr[4]==0x07 && ChPtr[5]==0x00 &&
  143.               ChPtr[8]==MAIN_HEAD)
  144.           {
  145.             ArcFormat=NEW;
  146.             SFXLen=(int)(CurPos+ChPtr-TempMemory-1);
  147.             tseek(ArcPtr,SFXLen,SEEK_SET);
  148.             tread(ArcPtr,MarkHead.Mark,SIZEOF_MARKHEAD);
  149.             ReadHeader(MAIN_HEAD);
  150.             if (NewMhd.Flags & MHD_MULT_VOL)
  151.               ArcType=VOL;
  152.             else
  153.               ArcType=SFX;
  154.           }
  155.         }
  156.       }
  157.       free(TempMemory);
  158.       TempMemory=NULL;
  159.       if (!ArcType)
  160.         return(0);
  161.     }
  162.   if (ArcFormat==OLD)
  163.   {
  164.     MainHeadSize=SIZEOF_OLDMHD;
  165.     NewMhd.Flags=OldMhd.Flags & 0x3f;
  166.     NewMhd.HeadSize=OldMhd.HeadSize;
  167.   }
  168.   else
  169.   {
  170.     MainHeadSize=SIZEOF_NEWMHD;
  171.     if ((UWORD)~HeaderCRC!=NewMhd.HeadCRC)
  172.     {
  173.       mprintf(MBrokArcHead);
  174.       BrokenMhd=1;
  175.     }
  176.   }
  177.   if (NewMhd.Flags & MHD_SOLID)
  178.     SolidType=1;
  179.   if (NewMhd.Flags & MHD_COMMENT)
  180.     MainComment=1;
  181.   if (NewMhd.Flags & MHD_LOCK)
  182.     LockedType=1;
  183.   if (NewMhd.Flags & MHD_AV)
  184.     AVType=1;
  185.   return(ArcType);
  186. }
  187.  
  188.  
  189.