home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / arc68k.arc / ARCLST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-27  |  5.5 KB  |  193 lines

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