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

  1. /***************************************************************************
  2.  *                                                                         *
  3.  * ZOO Processing Functions                                                *
  4.  *                                                                         *
  5.  **************************************************************************/
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <io.h>
  9.  
  10. #include "fff.h"
  11. #include "zoo.h"
  12.  
  13. int Match (char *Str, char *Pat);
  14. void PrtVerbose (char *Path, char *Name, unsigned Time, unsigned Date,
  15.                  long Size);
  16. void ChkPage (void);
  17.  
  18. extern char Pattern[66];
  19.  
  20. static int Printed;
  21.  
  22.  void
  23. DoZOO (char *ZOOFileName) {
  24.     extern int Spaced, PageSwt, Lnno;
  25.  
  26.     FILE *ZOOFile;
  27.     unsigned long ZOOPos;
  28.     ZOO_FIXED_TYPE ZOOEntry;
  29.  
  30.     if ( (ZOOFile = fopen(ZOOFileName, "rb")) == NULL) {
  31.         fprintf(stderr, "%s", ZOOFileName);
  32.         perror("");
  33.         }
  34.     if ( !GetZOOHeader(ZOOFile, &ZOOPos) ) {
  35.         Printed = 0;
  36.         while ( !GetNextZOOEntry(ZOOFile, &ZOOPos, &ZOOEntry) )
  37.             DisplayZOOEntry(ZOOFile, ZOOFileName, &ZOOEntry);
  38.         if (Printed) {
  39.             if (PageSwt) ChkPage();
  40.             printf("\n");
  41.             ++Lnno;
  42.             Spaced = 1;
  43.             }
  44.         }
  45.     }
  46.  
  47.  int
  48. GetZOOHeader (FILE *ZOOFile, unsigned long *ZOOPos) {
  49.     ZOO_HEADER_TYPE ZOOHeader;
  50.  
  51.     if ( !fread(&ZOOHeader, sizeof(ZOOHeader), 1, ZOOFile) )
  52.         return(FORMAT_ERROR);
  53.     else if (ZOOHeader.ZOOTag != VALID_ZOO) return(FORMAT_ERROR);
  54.     else *ZOOPos = ZOOHeader.ZOOStart;
  55.     return(0);
  56.     }
  57.  
  58.  int
  59. GetNextZOOEntry (FILE *ZOOFile, unsigned long *ZOOPos, ZOO_FIXED_TYPE *ZOOEntry) {
  60.  
  61.     fseek(ZOOFile, *ZOOPos, SEEK_SET);
  62.     if ( !fread(ZOOEntry, sizeof(*ZOOEntry), 1, ZOOFile) )
  63.         return(FORMAT_ERROR);
  64.     else if (ZOOEntry->ZOOTag != VALID_ZOO) return(FORMAT_ERROR);
  65.     else if ( (*ZOOPos = ZOOEntry->Next) == 0) return(END_OF_FILE);
  66.     return(0);
  67.     }
  68.  
  69.  void
  70. DisplayZOOEntry (FILE *ZOOFile, char *ZOOFileName, ZOO_FIXED_TYPE *ZOOEntry) {
  71.     extern int TotalMatch, VerboseSwt, Spaced, PageSwt;
  72.     extern ARC_TYPE ArcType;
  73.     extern int Lnno;
  74.     extern int S[6][3];
  75.  
  76.     char FileName[13];
  77.     char DirectName[65];
  78.     char LongName[65];
  79.     int DelFile;
  80.     ZOO_VARYING_TYPE ZOOVarying;
  81.     unsigned char NamLen;
  82.     unsigned char DirLen;
  83.     char *p;
  84.     int SystemID;
  85.  
  86.     strcpy(FileName, ZOOEntry->FName);
  87.     DelFile = (ZOOEntry->Deleted == 1);
  88.     strcpy(LongName, ""); strcpy(DirectName, "");
  89.     if (DelFile) strcpy(LongName, "  (Deleted");
  90.     else if (ZOOEntry->VarDirLen) {
  91.         if (fread(&ZOOVarying, ZOOEntry->VarDirLen, 1, ZOOFile)) {
  92.             NamLen = ZOOVarying[0];
  93.             DirLen = ZOOVarying[1];
  94.             if ( (NamLen + DirLen + 2) < ZOOEntry->VarDirLen)
  95.                 strncpy( (char *) &SystemID, &ZOOVarying[NamLen + DirLen + 2], 2);
  96.             else SystemID = 4095;
  97.             if ( DirLen || NamLen) {
  98.                 if (NamLen) {
  99.                     strncpy(FileName, (char *) &ZOOVarying[2], NamLen);
  100.                     FileName[NamLen] = '\0';
  101.                     }
  102.                 else strcpy(FileName, ZOOEntry->FName);
  103.                 if (DirLen) {
  104.                     strncpy(DirectName, &ZOOVarying[NamLen+2], DirLen);
  105.                     DirectName[DirLen] = '\0';
  106.                     if (SystemID <= 2)
  107.                         if (DirectName[strlen(DirectName)-1] != '/')
  108.                             strcat(DirectName, "/");
  109.                     }
  110.                 }
  111.             }
  112.         ++S[ArcType][1];
  113.         strcpy(LongName, DirectName); strcat(LongName, FileName);
  114.         if (DirectName[0] != '\0') {
  115.             if (DirectName[strlen(DirectName)-1] != '/')
  116.                 strcat(DirectName, "/");
  117.             }
  118.         strupr(LongName);
  119.         if ( (p = strrchr(LongName, '/')) != NULL) ++p;
  120.         else p = LongName;
  121.         if ( Match(p, Pattern) ) {
  122.             ++S[ArcType][2];
  123.             ++TotalMatch;
  124.             if (PageSwt) ChkPage();
  125.             if (VerboseSwt) {
  126.                 if (!Printed) {
  127.                     if (!Spaced) {
  128.                         if (PageSwt) ChkPage();
  129.                         printf("\n");
  130.                         ++Lnno;
  131.                         }
  132.                     if (PageSwt) ChkPage();
  133.                     printf("%s\n", ZOOFileName);
  134.                     ++Lnno;
  135.                     Printed = 1;
  136.                     }
  137.                 fputs("* ", stdout);
  138.                 PrtVerbose(DirectName, FileName, ZOOEntry->Time.u,
  139.                            ZOOEntry->Date.u, ZOOEntry->OrgSize);
  140.                 }
  141.             else {
  142.                 fputs(ZOOFileName, stdout);
  143.                 fputs("--> (", stdout);
  144.                 fputs(LongName, stdout);
  145.                 puts(")");
  146.                 }
  147.             ++Lnno;
  148.             }
  149.         }
  150.     }