home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / unix / arcunx11 / arc.sh2 / arclst.c next >
Encoding:
C/C++ Source or Header  |  1987-04-01  |  5.2 KB  |  190 lines

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