home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
useful
/
dist
/
util
/
arc
/
zoo
/
zoolist.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-03
|
17KB
|
591 lines
#ifndef LINT
/* derived from: zoolist.c 2.27 88/08/15 11:03:16 */
static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/zoolist.c,v $\n\
$Id: zoolist.c,v 1.4 91/07/09 01:54:16 dhesi Exp $";
#endif /* LINT */
/*
If TRACE_LIST is defined, any list command may be followed
by 'D' to show verbose information about each directory
entry in the archive. Do not define both TRACE_LIST and
TRACE_IO else a symbol conflict will occur and in any case
duplicate information will be dumped.
*/
/* #define TRACE_LIST */
/*
Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
(C) Copyright 1988 Rahul Dhesi -- All rights reserved
*/
#include "options.h"
#include "portable.h"
#include "zoomem.h" /* to get ZOOCOUNT */
/* Lists files in archive */
#include "zoo.h"
#include "errors.i"
#include "zooio.h"
#include "various.h"
#include "zoofns.h"
#include <stdio.h>
#ifdef TRACE_LIST
void show_dir PARMS ((struct direntry *direntry));
static int trace_list = 0;
#endif /* TRACE_LIST */
static char tot_fmt[] = "%8lu %3u%% %8lu %4d file";
static char tot_line[] =
/* "------------ -------- --- -------- --------- --------\n"; */
"-------- --- -------- --------- --------\n";
static char dbl_percent[] = "Archive %s: %s";
extern int quiet; /* assumed initialized to zero */
void show_comment PARMS((struct direntry *, ZOOFILE, int, char *));
int ver_too_high PARMS((struct zoo_header *));
int needed PARMS((char *, struct direntry *, struct zoo_header *));
void printtz PARMS((int));
void zoolist (argv, option, argc)
char **argv, *option;
int argc;
{
char whichname[PATHSIZE]; /* which name to use */
char *this_zoo; /* currently matched archive name */
register ZOOFILE zoo_file;
char *flist[ZOOCOUNT]; /* list of ptrs to input archive names */
int fptr; /* will point to within list of archive names */
struct direntry direntry;
struct zoo_header zoo_header;
int size_factor;
unsigned long tot_org_siz = 0L, tot_siz_now = 0L;
int tot_sf;
int file_count = 0;
int del_count = 0; /* number of deleted entries */
int bad_pack; /* 1 if packing method is unknown */
static char *month_list="000JanFebMarAprMayJunJulAugSepOctNovDec";
static char dashes[] = "------------\n";
int year, month, day, hours, min, sec;
int list_deleted = 0; /* list deleted files too */
int fast = 0; /* fast list */
long fiz_ofs = 0; /* offset where to start */
long dat_ofs = 0; /* ... data offset of file data */
int verb_list = 0; /* if verbose listing needed */
int show_name = 0; /* if archive name to be included in listing */
int show_crc = 0; /* if crc should be listed */
int zoocount = 1; /* number of archives to list */
int biglist = 0; /* multiarchive listing */
int one_col = 0; /* one column listing requested */
int showdir = 0; /* show directory name in fast listing */
int longest; /* length of longest archive name */
int talking; /* opposite of quiet */
int column = 0; /* for column printing */
int first_ever = 1; /* first time ever -- very special case */
int neednl = 0; /* whether to print a newline */
int need_acmt = 0; /* show archive comment */
int show_gen = 0; /* show generation count */
int genson = 1; /* enable/disable generations */
#ifdef FATTR
int show_mode = 0; /* show file protection */
#endif
int first_dir = 1; /* if first direntry -- to adjust dat_ofs */
while (*option) {
switch (*option) {
case 'a': show_name++; break;
#ifdef TRACE_LIST
case 'D': trace_list++; break;
#endif /* TRACE_LIST */
case 'd': list_deleted++; break;
case 'f': fast++; break;
case 'g': show_gen++; break;
case '/': showdir++; break;
case 'A':
case 'v': need_acmt++; break;
case 'V': need_acmt++; /* fall through */
case 'c': verb_list++; break;
case 'C': show_crc++; break;
case 'l': break;
case 'L': biglist++; zoocount = argc; break;
#ifdef FATTR
case 'm': show_mode++; break;
#endif
case '1': one_col++; break;
case '+': genson = 1; break;
case '-': genson = 0; break;
/* following code same as in zooext.c */
case '@': /* if @m,n specified, fiz_ofs = m, dat_ofs = n */
{
char *comma_pos;
++option;
comma_pos = strchr(option, ',');
if (comma_pos != NULL) {
dat_ofs = calc_ofs (comma_pos + 1);
*comma_pos = '\0';
}
fiz_ofs = calc_ofs(option);
goto no_more;
}
case 'q': quiet++; break;
default:
prterror ('w', option_ignored, *option);
}
option++;
}
no_more: /* come from exit from while loop above */
if (fast && show_name) { /* don't allow 'a' with 'f' */
show_name = 0;
prterror ('w', option_ignored, 'a');
}
talking = !quiet; /* for convenience */
#ifdef WILDCARD
/* For each archive name supplied, if it is not a char range and
does not contain a dot, append "*.zoo". */
{
int i;
for (i = 0; i < argc; i++) {
if (strchr (nameptr (argv[i]), EXT_CH) == NULL &&
!match_half (nameptr (argv[0]), "?-?"))
argv[i] = newcat (argv[i], "*.zoo");
}
}
#endif
makelist (zoocount, argv, flist, ZOOCOUNT-2, (char *) NULL,".","..", &longest);
/* ^argc ^argv ^list_pointer ^max_no_files ^exclude */
for (fptr = 0; (this_zoo = flist[fptr]) != NULL; fptr++) {
int ercount; /* count of errors */
int entrycount; /* count of directory entries */
int expl_deleted; /* explain what D means */
int expl_comment; /* explain what comment means */
int expl_ver; /* Explain what V means */
int expl_star; /* Explain what * means */
int first_time; /* first time through loop for an archive */
ercount = entrycount = del_count =
expl_deleted = expl_comment = expl_ver = expl_star = 0;
if (talking)
column = 0; /* if quiet, names will run together */
first_time = 1;
#ifndef WILDCARD
/* Add default extension if none supplied */
if (strchr (nameptr (this_zoo), EXT_CH) == NULL)
this_zoo = newcat (this_zoo, EXT_DFLT);
#endif
zoo_file = zooopen (this_zoo, Z_READ);
if (zoo_file == NOFILE) {
prterror ('e', could_not_open, this_zoo);
continue;
} else if (!show_name && talking)
printf ("\nArchive %s:\n", this_zoo);
if (fiz_ofs != 0L) { /* if offset specified, start there */
prterror ('m', start_ofs, fiz_ofs, dat_ofs);
zooseek (zoo_file, fiz_ofs, 0);
} else {
if (frd_zooh (&zoo_header, zoo_file) == -1 ||
zoo_header.zoo_tag != ZOO_TAG) {
prterror ('e', dbl_percent, this_zoo, invalid_header);
goto loop_end;
}
#if 0
if (talking && (!show_name || verb_list || need_acmt))
#else
if (need_acmt && talking)
#endif
{
void show_acmt PARMS ((struct zoo_header *, ZOOFILE, int));
show_acmt (&zoo_header, zoo_file, 0); /* show archive comment */
}
/* Seek to the beginning of the first directory entry */
if (zooseek (zoo_file, zoo_header.zoo_start, 0) != 0) {
ercount++;
prterror ('e', dbl_percent, this_zoo, bad_directory);
goto loop_end;
}
if (!show_name && ver_too_high (&zoo_header)) {
ercount++;
if (ercount < 2)
prterror ('M', wrong_version,
zoo_header.major_ver, zoo_header.minor_ver);
}
} /* end if (fiz_ofs !- 0L) */
/* Now we print information about each file in the archive */
if (!show_name) { /* initialize for each file only if not disk catalog */
tot_org_siz = 0L;
tot_siz_now = 0L;
file_count = 0;
del_count = 0;
}
while (1) {
if (readdir (&direntry, zoo_file, 0) == -1) {
prterror ('F', dbl_percent, this_zoo, bad_directory);
goto givesummary;
}
if (direntry.zoo_tag != ZOO_TAG) {
long currpos, zoolength;
prterror ('F', dbl_percent, this_zoo, invalid_header);
if ((currpos = zootell (zoo_file)) != -1L)
if (zooseek (zoo_file, 0L, 2) == 0)
if ((zoolength = zootell (zoo_file)) != -1L)
printf (cant_process, zoolength - currpos);
goto givesummary;
}
if (direntry.next == 0L) /* EXIT on end of chain */
break;
else
entrycount++; /* Number of directory entries */
/* first direntry read, change dat_ofs from abs. pos. to rel. offset */
if (first_dir && dat_ofs != 0) {
dat_ofs -= direntry.offset;
first_dir = 0;
}
direntry.next += dat_ofs; /* allow for user-specified offset */
if (direntry.comme