home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / compression / lister12.lha / ListSit.c < prev    next >
Encoding:
Text File  |  1992-04-01  |  1.7 KB  |  65 lines

  1. /* lists an StuffIt file's contents */
  2. BOOL
  3. ListSit(ULONG type,UBYTE *infile)
  4. {
  5.   int ct, counter, max;
  6.   ULONG uncomp, comp, time, tfiles = 0, tcomp = 0, tuncomp = 0;
  7.   UBYTE b[200],time_str[25];
  8.   struct tm *tm;
  9.   FILE *fp;
  10.  
  11.   fp = OpenFile(type,infile);
  12.   ct = fread(b, 22, 1, fp);
  13.  
  14.   /* check SIT signature and fread status */
  15.   if ((strnicmp(SIT_SIG,b,4) != 0) || ct != 1)
  16.    {
  17.     /* skip that part and read next section in case of MacBinary header */
  18.     fread(b, 106, 1, fp);
  19.     ct = fread(b, 22, 1, fp);
  20.     if ((strnicmp(SIT_SIG,b,4) != 0) || ct != 1)
  21.      {
  22.       fclose(fp);
  23.       return (WRONG_ARCHIVE);
  24.      }
  25.     }
  26.  
  27.   /* reader first header */
  28.   max = b[4] * 256 + b[5];
  29.   fread(b, 122, 1, fp);
  30.   counter = 1;
  31.  
  32.   /* start listing */
  33.   InitList(SIT,infile);
  34.  
  35.   /* parse each header block until done */
  36.   while ( counter <= max) {
  37.     comp = b[92] * 16777216 + b[93] * 65536 + b[94] * 256 +
  38.       b[95] + b[96] * 16777216 + b[97] * 65536 + b[98] * 256
  39.       + b[99];
  40.     uncomp = b[84] * 16777216 + b[85] * 65536 + b[86] * 256 +
  41.       b[87] + b[88] * 16777216 + b[89] * 65536 + b[90] * 256
  42.       + b[91];
  43.  
  44.     /* get Un*x stored time and subtract Mac time difference */
  45.     time = b[76] * 16777216 + b[77] * 65536 + b[78] * 256 + b[79];
  46.     time -= 0x7c25b080;
  47.     tm = localtime (&time);
  48.     sprintf (time_str,"%02d-%s-19%d %02d:%02d:%02d",
  49.       tm->tm_mday,months[tm->tm_mon],tm->tm_year,tm->tm_hour,
  50.       tm->tm_min,tm->tm_sec);
  51.  
  52.     /* print and get next record */
  53.     b[b[2] + 3] = '\0';
  54.     PrintList(b+3, uncomp, comp,&tfiles,&tcomp,&tuncomp,time_str);
  55.     fseek(fp, (comp-10), SEEK_CUR);
  56.     ct = fread(b, 122, 1, fp);
  57.     if (ct < 1) break;
  58.     counter ++;
  59.     }
  60.  
  61.   fclose(fp);
  62.   EndStats(tfiles,tcomp,tuncomp);
  63.   return(TRUE);
  64. }
  65.