home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
OLS
/
Os2
/
LHA2P205
/
LHA2P205.LZH
/
lha2-2.05pre
/
source.lzh
/
src
/
files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-25
|
5KB
|
260 lines
/*
* files.c --- collect filenames
* Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
* Copyright (C) 1991-1995, Satoshi HIRAMATSU (OS/2 HPFS version)
*
* $Log$
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "port2.h"
#include "typedef.h"
#include "lh.h"
#include "errmes.h"
int tcount, fcount;
struct fb *fbuf;
static struct fb *flst;
/* initialize pointers for registing files */
static void
init_regfile(void)
{
fbuf = flst = NULL;
tcount = fcount = 0;
}
/* regist file name */
#ifndef __SUPPORT_EA__
static void
regfile(char *p, char *q, char *f, long utc)
#else
static void
regfile(char *p, char *q, char *f, long utc, FEA2LIST *ea)
#endif
/*
* p: directory name including drive & base directory
* q: partial directory name following base directory
* f: file name
*
* "d:pppp/qqqq/\0 ffff\0"
* ^ ^ ^
* p q f
*/
{
struct fb *fp, *fnxt;
char *r, *t;
if(strcmp(f, lhtmp1) == 0 || strcmp(f, lhtmp2) == 0)
return; /* temporary file ? */
if(flg_i == 0)
{
char *s;
s = p;
while(*s)
{
if(iskanji(*s))
s++;
else
*s = toupper(*s);
if(*s)
s++;
}
}
fnxt = e_malloc(strlen(p) + strlen(f) + sizeof(struct fb));
fnxt -> time = utc;
#ifdef __SUPPORT_EA__
fnxt->ea = ea;
#endif
strcpy(r = fnxt -> fname, p);
strcpy(t = fnxt -> fpos = r + strlen(p), f);
if(flg_x)
t = r + (q - p);
fnxt -> cpos = t;
for(fp = fbuf; fp != NULL; fp = fp -> nxt)
if(strcmp(fp -> cpos, t) == 0)
{
if(strcmp(fp -> fname, r) == 0)
{
free(fnxt);
return;
}
else
{
strcpy(work, t);
error(DUPFNERR, work);
/* same registing names of different files */
}
}
if(flst)
flst -> nxt = fnxt;
else
fbuf = fnxt;
flst = fnxt;
flst -> nxt = NULL;
flst -> used = 0;
tcount ++;
}
/* recursive collection of files */
static int
travel(char *p, char *q, char *f)
/*
* p: directory name including drive & base directory
* q: directory name following base directory
* f: file name
*
* "pppp/qqqq/\0 ffff\0"
* ^ ^ ^
* p q f
*/
{
struct find_t srchbuf;
char *r, *s;
int done, cnt;
cnt = 0;
convdelim(p, pathdelim);
done = _dos_findfirst(p, 0x17, &srchbuf); /* search the first file */
convdelim(p, DELIM);
s = backpath(q);
while(! done)
{
if(!(srchbuf.attrib & 0x06) || flg_a)
{
if(srchbuf.attrib & 0x10) /* if this is a sub-directory */
{
/* for directory archive */
if(flg_d && strcmp(srchbuf.name, ".") &&
strcmp(srchbuf.name, ".."))
{
cnt++;
#ifndef __SUPPORT_EA__
regfile(p, q, strcat(srchbuf.name, DELIMSTR),
dos2unix((struct ftime *)&(srchbuf.wr_time)));
#else
regfile(p, q, strcat(srchbuf.name, DELIMSTR),
dos2unix((struct ftime *)&(srchbuf.wr_time)),
srchbuf.ea);
#endif
}
if(flg_r)
if(strcmp(srchbuf.name, ".") && strcmp(srchbuf.name, ".."))
{
if(flg_d) /* for directory archive */
r = stpcpy(stpcpy(s, srchbuf.name), "*.*");
else
r = stpcpy(stpcpy(s, srchbuf.name), DELIMSTR "*.*");
if(r - p > MAXPATHLEN)
error(TOOLONGERR, p);
cnt += travel(p, q, f);
/* search recursively */
*s = '\0';
}
}
else /* if this is a file */
{
if(flg_r != 1 || *matchfname(f, srchbuf.name) == '\0')
{
cnt++;
#ifndef __SUPPORT_EA__
regfile(p, q, srchbuf.name,
dos2unix((struct ftime *)&(srchbuf.wr_time)));
#else
regfile(p, q, srchbuf.name,
dos2unix((struct ftime *)&(srchbuf.wr_time)),
srchbuf.ea);
#endif
}
}
}
done = _dos_findnext(&srchbuf);
}
return cnt; /* number of registed files */
}
/* make file lists to append */
void
mklist(void)
{
char *p, *q, *r;
int cnt, Nfile;
struct pat *pt;
char fname[MAXPATHLEN];
Nfile = 0;
init_regfile();
for(pt = pbuf -> nxt; pt != NULL; pt = pt -> nxt)
{
p = pt -> pname;
r = work;
if(p[1] == ':') /* if file name includes drive */
{
strcpy(r, p); /* ignore base directory */
r += 2; /* don't regist drive name */
}
else
{
if((uchar)*p != DELIM)
r = (char *)stpcpy(r, pt -> bdir);
else if(*(pt -> bdir) && (pt -> bdir)[1] == ':')
{
strcpy(r, pt -> bdir);
r += 2;
}
strcpy(r, p);
}
#ifndef __SUPPORT_HPFS__
if((q = strchr(work, '+')) != NULL)
strcpy(q, "*.*");
#endif
q = getfilename(work);
if(flg_r == 1) /* /r+ mode */
{
strcpy(fname, q);
strcpy(q, "*.*");
cnt = travel(work, r, fname);
}
else
{
if(flg_r == 2) /* /r2 mode */
if(*q == '.')
strcat(r, DELIMSTR "*.*");
cnt = travel(work, r, NULL);
}
Nfile += pt -> cnt = cnt;
}
}
struct fb *
searchfile(char *path)
{
struct fb *fp;
for(fp = fbuf; fp != NULL; fp = fp -> nxt)
if(strcmp(path, fp -> cpos) == 0)
{
fp -> used = 1;
return fp;
}
return NULL;
}