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

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * LZH Processing Functions                                                *
  4.  *                                                                         *
  5.  **************************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. #include "fff.h"
  12. #include "lzh.h"
  13.  
  14. int Match (char *Str, char *Pat);
  15. void PrtVerbose (char *Path, char *Name, unsigned Time, unsigned Date,
  16.                  long Size);
  17. void ChkPage (void);
  18.  
  19. extern char Pattern[66];
  20.  
  21. static char *Name;
  22.  
  23.  void
  24. DoLzh (char *Path) {
  25.     extern int Level;
  26.     extern int TotalMatch, VerboseSwt, Spaced, PageSwt;
  27.     extern ARC_TYPE ArcType;
  28.     extern int Lnno;
  29.     extern int S[6][3];
  30.  
  31.     FILE *LzhFile;
  32.     int Status, Printed;
  33.     LZH_HEADER LzhHead;
  34.     char *p;
  35.  
  36.     Printed = 0;
  37.     if ( (LzhFile = fopen(Path, "rb")) == NULL) perror(Path);
  38.     else {
  39.         while ( (Status = GetEntry(LzhFile, &LzhHead)) > 0 ) {
  40.             if ( (p = strrchr(Name, '\\')) != NULL) ++p;
  41.             else p = Name;
  42.             ++S[ArcType][1];
  43.             if ( Match(p, Pattern) ) {
  44.                 ++S[ArcType][2];
  45.                 ++TotalMatch;
  46.                 if (PageSwt) ChkPage();
  47.                 if (VerboseSwt) {
  48.                     if (!Printed) {
  49.                         if (!Spaced) {
  50.                             if (PageSwt) ChkPage();
  51.                             printf("\n");
  52.                             ++Lnno;
  53.                             }
  54.                         if (PageSwt) ChkPage();
  55.                         printf("%s\n", Path);
  56.                         ++Lnno;
  57.                         Printed = 1;
  58.                         }
  59.                     fputs("* ", stdout);
  60.                     PrtVerbose("", p, LzhHead.Time.u, LzhHead.Date.u,
  61.                                 LzhHead.OriginalSize);
  62.                     }
  63.                 else {
  64.                     fputs(Path, stdout);
  65.                     fputs("--> (", stdout);
  66.                     fputs(p, stdout);
  67.                     puts(")");
  68.                     }
  69.                 ++Lnno;
  70.                 }
  71.             }
  72.         free(Name);
  73.         if (Status < 0) printf("%s\n", Path);
  74.         fclose(LzhFile);
  75.         }
  76.     if (Printed) {
  77.         if (PageSwt) ChkPage();
  78.         printf("\n");
  79.         ++Lnno;
  80.         Spaced = 1;
  81.         }
  82.     }
  83.  
  84.  static int
  85. GetEntry (FILE *LzhFile, LZH_HEADER *LzhDir) {
  86.     size_t Len;
  87.  
  88.     if ( (Len = fread(LzhDir, 1, sizeof(LZH_HEADER), LzhFile)) < 2) {
  89.         if ( (Len != 1) || (LzhDir->HeadSize != 0X00) ) {
  90.             printf("Couldn't read header: ");
  91.             return(-1);
  92.             }
  93.         return(0);
  94.         }
  95.  
  96.     if ( (Name = malloc(LzhDir->FileNameLength + 1)) == NULL) {
  97.         printf("Insufficient memory for file name: ");
  98.         return(-1);
  99.         }
  100.     fread(Name, 1, LzhDir->FileNameLength, LzhFile);
  101.     Name[LzhDir->FileNameLength] = '\0';
  102.  
  103.     fseek(LzhFile, sizeof(unsigned) + LzhDir->CompressedSize, SEEK_CUR);
  104.     return(1);
  105.     }