home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d050 / unixarc.lha / UnixArc / arclst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-17  |  5.0 KB  |  169 lines

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