ewilts%Ins.MRC.AdhocNet.CA%Stasis.MRC.AdhocNet.CA%UNCAEDU.@CORNELLC.CCS.CORNELL.EDU.BITNET (Ed Wilts) (06/24/88)
$Part06:
$ File_is="ARCLST.C"
$ Check_Sum_is=2032959550
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
Xstatic char *RCSid = "$Header: arclst.c,v 1.2 86/07/15 07:53:15 turner Exp $";
X
X/*
X * $Log:`009arclst.c,v $
X * Hack-attack 1.3 86/12/20 01:23:45 wilhite@usceast.uucp
X * `009Bludgeoned into submission for VAX 11/780 BSD4.2
X *`009(ugly code, but fewer core dumps)
X *
X * Revision 1.2 86/07/15 07:53:15 turner
X *
X *
X * Revision 1.1 86/06/26 15:00:23 turner
X * initial version
X *
X *
X */
X
X/* ARC - Archive utility - ARCLST
X
X$define(tag,$$segment(@1,$$index(@1,=)+1))#
X$define(version,Version $tag(
XTED_VERSION DB =2.34), created on $tag(
XTED_DATE DB =02/03/86) at $tag(
XTED_TIME DB =22:56:57))#
X$undefine(tag)#
X $version
X
X(C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
X
X By: Thom Henderson
X
X Description:
X This file contains the routines used to list the contents
X of an archive.
X
X Language:
X Computer Innovations Optimizing C86
X*/
X#include <stdio.h>
X#include "arc.h"
X
XINT lstarc(num,arg) /* list files in archive */
XINT num; /* number of arguments */
Xchar *arg[]; /* pointers to arguments */
X{
X struct heads hdr; /* header data */
X INT list; /* true to list a file */
X INT did[MAXARG]; /* true when argument was used */
X long tnum, tlen, tsize; /* totals */
X INT n; /* index */
X INT lstfile();
X
X tnum = tlen = tsize = 0; /* reset totals */
X
X for(n=0; n<num; n++) /* for each argument */
X did[n] = 0; /* reset usage flag */
X rempath(num,arg); /* strip off paths */
X
X if(!kludge)
X { printf("Name Length ");
X if(bose)
X printf(" Stowage SF Size now");
X printf(" Date ");
X if(bose)
X printf(" Time CRC");
X printf("\n");
X
X printf("============ ========");
X if(bose)
X printf(" ======== ==== ========");
X printf(" =========");
X if(bose)
X printf(" ====== ====");
X printf("\n");
X }
X
X openarc(0); /* open archive for reading */
X
X if(num) /* if files were named */
X { while(readhdr(&hdr,arc)) /* process all archive files */
X { list = 0; /* reset list flag */
X for(n=0; n<num; n++) /* for each template given */
X { if(match(hdr.name,arg[n]))
X { list = 1; /* turn on list flag */
X did[n] = 1; /* turn on usage flag */
X break; /* stop looking */
X }
X }
X
X if(list) /* if this file is wanted */
X { if(!kludge)
X lstfile(&hdr); /* then tell about it */
X tnum++; /* update totals */
X tlen += hdr.length;
X tsize += hdr.size;
X }
X
X fseek(arc,hdr.size,1); /* move to next header */
X }
X }
X
X else while(readhdr(&hdr,arc)) /* else report on all files */
X { if(!kludge)
X lstfile(&hdr);
X tnum++; /* update totals */
X tlen += hdr.length;
X tsize += hdr.size;
X fseek(arc,hdr.size,1); /* skip to next header */
X }
X
X closearc(0); /* close archive after reading */
X
X if(!kludge)
X { printf(" ==== ========");
X if(bose)
X printf(" ==== ========");
X printf("\n");
X }
X
X printf("Total %6ld %8ld ",tnum,tlen);
X if(bose)
X/*
X * To get around divide by zero error's, check for a zero length tsize.
X * pop a one in place of zero...
X */
X`009if (tlen)
X printf(" %3ld%% %8ld ",100L - (100L*tsize)/tlen,tsize);
X`009else
X printf(" %3ld%% %8ld ",0,tsize);
X
X printf("\n");
X
X if(note)
X { for(n=0; n<num; n++) /* report unused args */
X { if(!did[n])
X { printf("File not found: %s\n",arg[n]);
X nerrs++;
X }
X }
X }
X}
X
Xstatic INT lstfile(hdr) /* tell about a file */
Xstruct heads *hdr; /* pointer to header data */
X{
X INT yr, mo, dy; /* parts of a date */
X INT hh, mm, ss; /* parts of a time */
X
X static char *mon[] = /* month abbreviations */
X { "Jan", "Feb", "Mar", "Apr",
X "May", "Jun", "Jul", "Aug",
X "Sep", "Oct", "Nov", "Dec"
X };
X
X yr = (hdr->date >> 9) & 0x7f; /* dissect the date */
X mo = (hdr->date >> 5) & 0x0f;
X dy = hdr->date & 0x1f;
X
X hh = (hdr->time >> 11) & 0x1f; /* dissect the time */
X mm = (hdr->time >> 5) & 0x3f;
X ss = (hdr->time & 0x1f) * 2;
X
X printf("%-12s %8ld ",hdr->name,hdr->length);
X
X if(bose)
X { switch(hdrver)
X {
X case 1:
X case 2:
X printf(" -- ");
X break;
X case 3:
X printf(" Packed ");
X break;
X case 4:
X printf("Squeezed");
X break;
X case 5:
X case 6:
X case 7:
X printf("crunched");
X break;
X case 8:
X printf("Crunched");
X break;
X`009 case 9:
X`009 printf("Squashed");
X`009 break;
X default:
X printf("Unknown!");
X }
X
X printf(" %3d%%",100L - (100L*hdr->size)/hdr->length);
X printf(" %8ld ",hdr->size);
X }
X
X printf("%2d %3s %02d", dy, mon[mo-1], (yr+80)%100);
X
X if(bose)
X printf(" %2d:%02d%c %04x",
X (hh>12?hh-12:hh), mm, (hh>12?'p':'a'),
X (unsigned INT)hdr->crc);
X
X printf("\n");
X}
X
$ GoSub Convert_File
$ Goto Part08