home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hall of Fame
/
HallofFameCDROM.cdr
/
proglc
/
zoo141_c.lzh
/
ZOOADD2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-02-07
|
6KB
|
185 lines
/* zooadd2.c */
/*
Copyright (C) 1986 Rahul Dhesi -- All rights reserved
*/
#include "options.h"
#include "zoo.h"
#include <stdio.h>
#include "various.h"
#include "zoofns.h"
#include "errors.i"
#include "assert.h"
#include "debug.h"
#include "parse.h"
/*
Miscellaneous routines to support zooadd().
*/
/****************
This function is called with zoo_file positioned to the first
directory entry in an archive. It skips past all existing files,
counts the number of deleted files, saves the latest data and time
encountered, and adds all filenames encountered to a global list. The
long filename is added if available, else the MSDOS filename is
added.
*/
void skip_files (zoo_file, latest_date, latest_time, delcount,
latest_name, latest_pos)
FILE *zoo_file;
unsigned int *latest_date, *latest_time;
int *delcount;
char latest_name[];
long *latest_pos;
{
char *whichname; /* will point to name to use */
long save_offset, next_ptr;
struct direntry direntry;
struct direntry *drp = &direntry;
*latest_pos = 0L;
do {
/* read a directory entry */
save_offset = ftell (zoo_file); /* save pos'n of this dir entry */
readdir (&direntry, zoo_file, 1); /* read directory entry */
if (drp->next == 0L) { /* END OF CHAIN */
fseek (zoo_file, save_offset, 0); /* back up */
break; /* EXIT on end of chain */
} else
*latest_pos = save_offset;
/* remember most recent date and time, for files not marked deleted */
if (!drp->deleted)
if (drp->date > *latest_date ||
(drp->date == *latest_date && drp->time > *latest_time)) {
*latest_date = drp->date;
*latest_time = drp->time;
}
next_ptr = drp->next; /* ptr to next dir entry */
if (drp->deleted)
++(*delcount); /* count deleted entries */
/* add name of file and position of direntry into global list */
/* but only if the entry is not deleted */
if (!drp->deleted) {
#ifdef FOLD
strlwr(drp->fname);
#endif
/* if long filename available, use it, else use short filename */
whichname = (drp->namlen > 0) ? drp->lfname : drp->fname;
addfname (whichname, save_offset, drp->date, drp->time);
strcpy (latest_name, whichname); /* save as latest name */
}
fseek (zoo_file, next_ptr, 0); /* ..seek to next dir entry */
} while (next_ptr != 0L); /* loop terminates on null ptr */
}
/*******************/
/* kill_files() deletes all files in the supplied list of pointers to
filenames */
int kill_files (flist, pathlength)
char *flist[]; /* list of ptrs to input fnames */
int pathlength; /* length of longest pathname */
{
int status = 0;
int fptr;
prterror ('M', "-----\nErasing added files...\n");
for (fptr = 0; flist[fptr] != NULL; fptr++) {
prterror ('m', "%-*s -- ", pathlength, flist[fptr]);
if (unlink (flist[fptr]) == 0) {
prterror ('M', "erased\n");
} else {
prterror ('w', "Could not erase %s.\n", flist[fptr]);
status = 1;
}
}
return (status);
}
#ifndef PORTABLE
/*******************/
void copyfields (drp, thp)
struct direntry *drp;
struct tiny_header *thp;
{
drp->org_size = thp->org_size;
drp->file_crc = thp->file_crc;
drp->size_now = thp->size_now;
drp->major_ver = thp->major_ver;
drp->minor_ver = thp->minor_ver;
}
#endif
/*******************/
/* processes option switches for zooadd() */
void opts_add (option, zootime, quiet, suppress, move, new, pack,
update, add_comment, z_fmt, need_dir)
char *option;
int *zootime, *quiet, *suppress, *move, *new, *pack,
*update, *add_comment, *z_fmt, *need_dir;
{
if (*option == 'T') {
(*zootime)++;
option++;
while (*option) {
switch (*option) {
case 'q': (*quiet)++; break;
default:
prterror ('f', inv_option, *option);
}
option++;
}
}
while (*option) {
switch (*option) {
case 'a': break;
case 'f': (*suppress)++; break; /* suppress compression */
case 'M': (*move)++; break; /* delete files after adding them */
case 'n': (*new)++; break; /* add only files not in archive */
case 'P': (*pack)++; break; /* pack after adding */
case 'u': (*update)++; break; /* add only files already in archive */
case 'q': (*quiet)++; break; /* be quiet */
case 'c': (*add_comment)++; break; /* add comment */
case ':': *need_dir = 0; break; /* don't store directories */
#ifndef PORTABLE
case 'z': (*z_fmt)++; break; /* look for Z format files */
#endif
default:
prterror ('f', inv_option, *option);
}
option++;
} /* end while */
}
/*
Stores long filename into direntry.lfname iff it is different from MSDOS
filename. Also stores directory name if need_dir is true. Moved out of
zooadd() so zooadd() doesn't get too big for optimization.
*/
void storefname (direntry, this_path, need_dir)
struct direntry *direntry;
char *this_path;
int need_dir;
{
struct path_st path_st;
parse (&path_st, this_path);
direntry->lfname[0] = '\0';
direntry->namlen = 0;
if (strcmp(path_st.lfname,direntry->fname) != 0) {
strcpy (direntry->lfname, path_st.lfname); /* full filename */
direntry->namlen = strlen(direntry->lfname) + 1;
}
if (need_dir) {
strcpy (direntry->dirname, path_st.dir); /* directory name */
direntry->dirlen = strlen(direntry->dirname) + 1;
if (direntry->dirlen == 1) /* don't store trailing null alone */
direntry->dirlen = 0;
} else {
direntry->dirname[0] = '\0';
direntry->dirlen = 0;
}
}