home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 65 / arclst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  5.6 KB  |  196 lines

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