home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / nx_arc / arclst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  4.4 KB  |  197 lines

  1. /*
  2.  * $Log:    arclst.c,v $
  3.  * Revision 1.2  88/04/11  18:03:10  hyc
  4.  * added support for squashing, re-synch with MTS
  5.  * 
  6.  * Revision 1.1  88/04/11  18:01:46  hyc
  7.  * Initial revision
  8.  * 
  9.  * Revision 1.4  87/08/13  17:03:30  hyc
  10.  * Run thru the indent program...
  11.  *  Revision 1.3  87/07/21  11:41:35  hyc *** empty
  12.  * log message ***
  13.  * 
  14.  * Revision 1.2  87/07/21  08:23:17  hyc *** empty log message ***
  15.  * 
  16.  */
  17.  
  18. /*
  19.  * ARC - Archive utility - ARCLST
  20.  * 
  21.  * Version 2.38, created on 07/25/86 at 17:52:20
  22.  * 
  23.  * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  24.  * 
  25.  * By:  Thom Henderson
  26.  * 
  27.  * Description: This file contains the routines used to list the contents of an
  28.  * archive.
  29.  * 
  30.  * Language: Computer Innovations Optimizing C86
  31.  */
  32. #include <stdio.h>
  33. #include "arc.h"
  34.  
  35. INT
  36. lstarc(num, arg)        /* list files in archive */
  37.     INT             num;    /* number of arguments */
  38.     char           *arg[];    /* pointers to arguments */
  39. {
  40.     struct heads    hdr;    /* header data */
  41.     INT             list;    /* true to list a file */
  42.     INT             did[25];/* true when argument was used */
  43.     LONG            tnum, tlen, tsize;    /* totals */
  44.     INT             n;    /* index */
  45.     INT             lstfile();
  46.  
  47.     tnum = tlen = tsize = 0;/* reset totals */
  48.  
  49.     for (n = 0; n < num; n++)    /* for each argument */
  50.         did[n] = 0;    /* reset usage flag */
  51.     rempath(num, arg);    /* strip off paths */
  52.  
  53.     if (!kludge) {
  54.         printf("Name          Length  ");
  55.         if (bose)
  56.             printf("  Stowage    SF   Size now");
  57.         printf("  Date     ");
  58.         if (bose)
  59.             printf("  Time    CRC");
  60.         printf("\n");
  61.  
  62.         printf("============  ========");
  63.         if (bose)
  64.             printf("  ========  ====  ========");
  65.         printf("  =========");
  66.         if (bose)
  67.             printf("  ======  ====");
  68.         printf("\n");
  69.     }
  70.     openarc(0);        /* open archive for reading */
  71.  
  72.     if (num) {        /* if files were named */
  73.         while (readhdr(&hdr, arc)) {    /* process all archive files */
  74.             list = 0;    /* reset list flag */
  75.             for (n = 0; n < num; n++) {    /* for each template
  76.                              * given */
  77.                 if (match(hdr.name, arg[n])) {
  78.                     list = 1;    /* turn on list flag */
  79.                     did[n] = 1;    /* turn on usage flag */
  80.                     break;    /* stop looking */
  81.                 }
  82.             }
  83.  
  84.             if (list) {    /* if this file is wanted */
  85.                 if (!kludge)
  86.                     lstfile(&hdr);    /* then tell about it */
  87.                 tnum++;    /* update totals */
  88.                 tlen += hdr.length;
  89.                 tsize += hdr.size;
  90.             }
  91.             fseek(arc, hdr.size, 1);    /* move to next header */
  92.         }
  93.     } else
  94.         while (readhdr(&hdr, arc)) {    /* else report on all files */
  95.             if (!kludge)
  96.                 lstfile(&hdr);
  97.             tnum++;    /* update totals */
  98.             tlen += hdr.length;
  99.             tsize += hdr.size;
  100.             fseek(arc, hdr.size, 1);    /* skip to next header */
  101.         }
  102.  
  103.     closearc(0);        /* close archive after reading */
  104.  
  105.     if (!kludge) {
  106.         printf("        ====  ========");
  107.         if (bose)
  108.             printf("            ====  ========");
  109.         printf("\n");
  110.     }
  111.     printf("Total %6ld  %8ld", tnum, tlen);
  112.     if (bose) {
  113.         if (tlen)
  114.             printf("            %3ld%%", 100L - (100L * tsize) / tlen);
  115.         else
  116.             printf("            ---");
  117.         printf("  %8ld", tsize);
  118.     }
  119.     printf("\n");
  120.  
  121.     if (note) {
  122.         for (n = 0; n < num; n++) {    /* report unused args */
  123.             if (!did[n]) {
  124.                 printf("File not found: %s\n", arg[n]);
  125.                 nerrs++;
  126.             }
  127.         }
  128.     }
  129. }
  130.  
  131. INT
  132. lstfile(hdr)            /* tell about a file */
  133.     struct heads   *hdr;    /* pointer to header data */
  134. {
  135.     INT             yr, mo, dy;    /* parts of a date */
  136.     INT             hh, mm, ss;    /* parts of a time */
  137.  
  138.     static char    *mon[] =    /* month abbreviations */
  139.     {
  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.         case 1:
  158.         case 2:
  159.             printf("   --   ");
  160.             break;
  161.         case 3:
  162.             printf(" Packed ");
  163.             break;
  164.         case 4:
  165.             printf("Squeezed");
  166.             break;
  167.         case 5:
  168.         case 6:
  169.         case 7:
  170.             printf("crunched");
  171.             break;
  172.         case 8:
  173.             printf("Crunched");
  174.             break;
  175.         case 9:
  176.             printf("Squashed");
  177.             break;
  178.         default:
  179.             printf("Unknown!");
  180.         }
  181.  
  182.         if (hdr->length)
  183.             printf("  %3d%%", 100L - (100L * hdr->size) / hdr->length);
  184.         else
  185.             printf("  ---");
  186.         printf("  %8ld  ", hdr->size);
  187.     }
  188.     printf("%2d %3s %02d", dy, mon[mo - 1], (yr + 80) % 100);
  189.  
  190.     if (bose)
  191.         printf("  %2d:%02d%c  %04x",
  192.                (hh > 12 ? hh - 12 : hh), mm, (hh > 11 ? 'p' : 'a'),
  193.                hdr->crc & 0xffff);
  194.  
  195.     printf("\n");
  196. }
  197.