home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2ARC_S.ZIP / ARCLST.C < prev    next >
C/C++ Source or Header  |  1987-10-16  |  5KB  |  177 lines

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