home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 157.lha / Arc_Src / arclst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-27  |  4.8 KB  |  162 lines

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