home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCLST.C < prev    next >
C/C++ Source or Header  |  1989-12-29  |  5KB  |  193 lines

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