home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / directry / fff320 / procarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-07  |  2.3 KB  |  96 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * ARC Processing Functions                                                *
  4.  *                                                                         *
  5.  **************************************************************************/
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "fff.h"
  10. #include "arc.h"
  11.  
  12. int Match (char *Str, char *Pat);
  13. void PrtVerbose (char *Path, char *Name, unsigned Time, unsigned Date,
  14.                  long Size);
  15. void ChkPage (void);
  16.  
  17. extern char Pattern[66];
  18.  
  19.  void
  20. DoArc (char *Path) {
  21.     extern int Level;
  22.     extern int TotalMatch, VerboseSwt, Spaced, PageSwt;
  23.     extern ARC_TYPE ArcType;
  24.     extern int Lnno;
  25.     extern S[6][3];
  26.  
  27.     FILE *ArcFile;
  28.     int Status, Printed;
  29.     ARCHIVE_HEADER ArchiveHead;
  30.  
  31.     Printed = 0;
  32.     if ( (ArcFile = fopen(Path, "rb")) == NULL) perror(Path);
  33.     else {
  34.         while ( (Status = GetEntry(ArcFile, &ArchiveHead)) != 0 ) {
  35.             if (Status < 0) {
  36.                 printf("%s\n", Path);
  37.                 break;
  38.                 }
  39.             else {
  40.                 ++S[ArcType][1];
  41.                 if ( Match(ArchiveHead.Name, Pattern) ) {
  42.                     ++S[ArcType][2];
  43.                     ++TotalMatch;
  44.                     if (PageSwt) ChkPage();
  45.                     if (VerboseSwt) {
  46.                         if (!Printed) {
  47.                             if (!Spaced) {
  48.                                 if (PageSwt) ChkPage();
  49.                                 printf("\n");
  50.                                 ++Lnno;
  51.                                 }
  52.                             if (PageSwt) ChkPage();
  53.                             printf("%s\n", Path);
  54.                             ++Lnno;
  55.                             Printed = 1;
  56.                             }
  57.                         fputs("* ", stdout);
  58.                         PrtVerbose("", ArchiveHead.Name, ArchiveHead.Time.u,
  59.                                    ArchiveHead.Date.u, ArchiveHead.Length);
  60.                         }
  61.                     else {
  62.                         fputs(Path, stdout);
  63.                         fputs("--> (", stdout);
  64.                         fputs(ArchiveHead.Name, stdout);
  65.                         puts(")");
  66.                         }
  67.                     ++Lnno;
  68.                     }
  69.                 }
  70.             }
  71.         fclose(ArcFile);
  72.         }
  73.     if (Printed) {
  74.         if (PageSwt) ChkPage();
  75.         printf("\n");
  76.         ++Lnno;
  77.         Spaced = 1;
  78.         }
  79.     }
  80.  
  81.  static int
  82. GetEntry (FILE *ArcFile, ARCHIVE_HEADER *ArchiveDir) {
  83.  
  84.     if (fread(ArchiveDir, sizeof(char), sizeof(ARCHIVE_HEADER), ArcFile) < 2) {
  85.         printf("couldn't read header: ");
  86.         return(-1);
  87.         }
  88.     if (ArchiveDir->ArcMark != 0x1A) {
  89.         printf("invalid ArcMark: ");
  90.         return(-1);
  91.         }
  92.     if (ArchiveDir->HeaderVersion == 0) return(0);
  93.  
  94.     fseek(ArcFile, ArchiveDir->Size, SEEK_CUR);
  95.     return(1);
  96.     }