home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / COMPRESS / ARC520S.ZIP / ARCLST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-23  |  5.3 KB  |  177 lines

  1. /*  ARC - Archive utility - ARCLST
  2.  
  3.     Version 2.38, created on 07/25/86 at 17:52:20
  4.  
  5. (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  6.  
  7.     By:  Thom Henderson
  8.  
  9.     Description:
  10.          This file contains the routines used to list the contents
  11.          of an archive.
  12.  
  13.     Language:
  14.          Computer Innovations Optimizing C86
  15. */
  16. #include <stdio.h>
  17. #include "arc.h"
  18.  
  19. lstarc(num,arg)                        /* list files in archive */
  20. int num;                               /* number of arguments */
  21. char *arg[];                           /* pointers to arguments */
  22. {
  23.     struct heads hdr;                  /* header data */
  24.     int list;                          /* true to list a file */
  25.     int did[25];                  /* true when argument was used */
  26.     long tnum, tlen, tsize;            /* totals */
  27.     int n;                             /* index */
  28.  
  29.     tnum = tlen = tsize = 0;           /* reset totals */
  30.  
  31.     for(n=0; n<num; n++)               /* for each argument */
  32.          did[n] = 0;                   /* reset usage flag */
  33.     rempath(num,arg);                  /* strip off paths */
  34.  
  35.     if(!kludge)
  36.     {    printf("Name          Length  ");
  37.          if(bose)
  38.               printf("  Stowage    SF   Size now");
  39.          printf("  Date     ");
  40.          if(bose)
  41.               printf("  Time    CRC");
  42.          printf("\n");
  43.  
  44.          printf("============  ========");
  45.          if(bose)
  46.               printf("  ========  ====  ========");
  47.          printf("  =========");
  48.          if(bose)
  49.               printf("  ======  ====");
  50.          printf("\n");
  51.     }
  52.  
  53.     openarc(0);                        /* open archive for reading */
  54.  
  55.     if(num)                            /* if files were named */
  56.     {    while(readhdr(&hdr,arc))      /* process all archive files */
  57.          {    list = 0;                /* reset list flag */
  58.               for(n=0; n<num; n++)     /* for each template given */
  59.               {    if(match(hdr.name,arg[n]))
  60.                    {    list = 1;      /* turn on list flag */
  61.                         did[n] = 1;    /* turn on usage flag */
  62.                         break;         /* stop looking */
  63.                    }
  64.               }
  65.  
  66.               if(list)                 /* if this file is wanted */
  67.               {    if(!kludge)
  68.                         lstfile(&hdr); /* then tell about it */
  69.                    tnum++;             /* update totals */
  70.                    tlen += hdr.length;
  71.                    tsize += hdr.size;
  72.               }
  73.  
  74.               fseek(arc,hdr.size,1);   /* move to next header */
  75.          }
  76.     }
  77.  
  78.     else while(readhdr(&hdr,arc))      /* else report on all files */
  79.     {    if(!kludge)
  80.               lstfile(&hdr);
  81.          tnum++;                       /* update totals */
  82.          tlen += hdr.length;
  83.          tsize += hdr.size;
  84.          fseek(arc,hdr.size,1);        /* skip to next header */
  85.     }
  86.  
  87.     closearc(0);                       /* close archive after reading */
  88.  
  89.     if(!kludge)
  90.     {    printf("        ====  ========");
  91.          if(bose)
  92.               printf("            ====  ========");
  93.          printf("\n");
  94.     }
  95.  
  96.     printf("Total %6ld  %8ld",tnum,tlen);
  97.     if(bose)
  98.     {    if(tlen)
  99.               printf("            %3ld%%",100L - (100L*tsize)/tlen);
  100.          else printf("            ---");
  101.          printf("  %8ld",tsize);
  102.     }
  103.     printf("\n");
  104.  
  105.     if(note)
  106.     {    for(n=0; n<num; n++)          /* report unused args */
  107.          {    if(!did[n])
  108.               {    printf("File not found: %s\n",arg[n]);
  109.                    nerrs++;
  110.               }
  111.          }
  112.     }
  113. }
  114.  
  115. static lstfile(hdr)                    /* tell about a file */
  116. struct heads *hdr;                     /* pointer to header data */
  117. {
  118.     int yr, mo, dy;                    /* parts of a date */
  119.     int hh, mm, ss;                    /* parts of a time */
  120.  
  121.     static char *mon[] =               /* month abbreviations */
  122.     {    "Jan",    "Feb",    "Mar",    "Apr",
  123.          "May",    "Jun",    "Jul",    "Aug",
  124.          "Sep",    "Oct",    "Nov",    "Dec"
  125.     };
  126.  
  127.     yr = (hdr->date >> 9) & 0x7f;      /* dissect the date */
  128.     mo = (hdr->date >> 5) & 0x0f;
  129.     dy = hdr->date & 0x1f;
  130.  
  131.     hh = (hdr->time >> 11) & 0x1f;     /* dissect the time */
  132.     mm = (hdr->time >> 5) & 0x3f;
  133.     ss = (hdr->time & 0x1f) * 2;
  134.  
  135.     printf("%-12s  %8ld  ",hdr->name,hdr->length);
  136.  
  137.     if(bose)
  138.     {    switch(hdrver)
  139.          {
  140.          case 1:
  141.          case 2:
  142.               printf("   --   ");
  143.               break;
  144.          case 3:
  145.               printf(" Packed ");
  146.               break;
  147.          case 4:
  148.               printf("Squeezed");
  149.               break;
  150.          case 5:
  151.          case 6:
  152.          case 7:
  153.               printf("crunched");
  154.               break;
  155.          case 8:
  156.               printf("Crunched");
  157.               break;
  158.          default:
  159.               printf("Unknown!");
  160.          }
  161.  
  162.          if(hdr->length)
  163.               printf("  %3d%%",100L - (100L*hdr->size)/hdr->length);
  164.          else printf("  ---");
  165.          printf("  %8ld  ",hdr->size);
  166.     }
  167.  
  168.     printf("%2d %3s %02d", dy, mon[mo-1], (yr+80)%100);
  169.  
  170.     if(bose)
  171.          printf("  %2d:%02d%c  %04x",
  172.               (hh>12?hh-12:hh), mm, (hh>11?'p':'a'),
  173.               hdr->crc);
  174.  
  175.     printf("\n");
  176. }
  177.