home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
CEREBRUM
/
WWFFL114.ZIP
/
FFL.CPP
next >
Wrap
C/C++ Source or Header
|
2000-01-02
|
27KB
|
1,151 lines
/* v1.4 */
/* - Y2K-compliant date patches and display issues. Compatibility with all */
/* changes in WWIV v4.3 code. */
/* */
/* v1.3 */
/* - Added check for existence on files residing on hard disk (to account */
/* for all the missing files after my crash!) */
/* */
/* v1.2 */
/* - Treats description to strip trailing CR/LF pairs */
/* - Honors FILEnet flag to identify directory type (UFRD or successor). */
/* */
/* v1.1 changes */
/* - Changed fprintf(...) to fputs() in several places to avoid unlinked */
/* floating point errors which occurred with a "%f" was in description. */
/* - Replaced atime() routine with strftime() (TC function) as suggested */
/* by Dawg. */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys\stat.h>
#include <fcntl.h>
#include <string.h>
#include <dos.h>
#include <io.h>
#include <alloc.h>
#include <time.h>
#include <dir.h>
#include <errno.h>
#include <process.h>
#include <ctype.h>
#include <conio.h>
#include <mem.h>
#include <share.h>
#include <math.h>
#include <direct.h>
#include "vardec.h"
#include "net.h"
#define VERSION "1.4"
#define WAIT_TIME 10
#define TRIES 100
#define MT_DESQVIEW 0x01
#define MT_WINDOWS 0x02
#define MT_OS2 0x04
#define DELIMS_WHITE " \t\r\n"
#define SETREC(f,i) sh_lseek(f,((long) (i)) * \
((long)sizeof(uploadsrec)), SEEK_SET);
#define LAST(s) s[strlen(s)-1]
typedef struct {
char nam[13], desc[59], uplddate[9];
unsigned long bytes;
int num;
} toprec;
typedef struct {
char filename[9];
int type;
} whichdir;
whichdir *DIR;
directoryrec huge *directories;
configrec syscfg;
configoverrec syscfgovr;
toprec *top;
net_networks_rec netcfg;
static unsigned char whichtype[3] = {254, 240, 237};
char dlfn[81], text1[161], text2[161], maindir[161], buffer[201];
int instance, net_num, net_num_max, num_dirs;
int numdirs, multitasker, file_date;
unsigned int totaldirs;
unsigned long totalfiles, numf;
char wwiv_net_no[20], net_name[16], net_data[121];
unsigned short net_sysnum;
void dv_pause(void)
{
_AX = 0x101a;
geninterrupt(0x15);
_AX = 0x1000;
geninterrupt(0x15);
_AX = 0x1025;
geninterrupt(0x15);
}
void win_pause(void)
{
__emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
}
void giveup_timeslice(void)
{
if (multitasker) {
switch (multitasker) {
case 1:
dv_pause();
break;
case 2:
win_pause();
break;
case 3:
dv_pause();
break;
case 4:
_AX = 0x1680;
geninterrupt(0x2f);
break;
case 5:
case 6:
case 7:
win_pause();
break;
default:
break;
}
}
}
int get_dos_version(void)
{
_AX = 0x3000;
geninterrupt(0x21);
if (_AX % 256 >= 10) {
multitasker |= MT_OS2;
}
return (_AX);
}
int get_dv_version(void)
{
int v;
_AX = 0x2b01;
_CX = 0x4445;
_DX = 0x5351;
geninterrupt(0x21);
if (_AL == 0xff) {
return 0;
} else {
v = _BX;
multitasker |= MT_DESQVIEW;
return v;
}
}
int get_win_version(void)
{
int v = 0;
__emit__(0x55, 0x06, 0x53);
_AX = 0x352f;
geninterrupt(0x21);
_AX = _ES;
if (_AX | _BX) {
_AX = 0x1600;
geninterrupt(0x2f);
v = _AX;
if (v % 256 <= 1)
v = 0;
}
__emit__(0x5b, 0x07, 0x5d);
if (v != 0)
multitasker |= MT_WINDOWS;
return (v);
}
void detect_multitask(void)
{
get_dos_version();
get_win_version();
get_dv_version();
}
int sh_open(char *path, int file_access, unsigned mode)
{
int handle, count, share;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
if ((file_access & O_RDWR) || (file_access & O_WRONLY) ||
(mode & S_IWRITE)) {
share = SH_DENYRW;
} else {
share = SH_DENYWR;
}
handle = open(path, file_access | share, mode);
if (handle < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
handle = open(path, file_access | share, mode);
while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
if (count % 2)
delay(WAIT_TIME);
else
giveup_timeslice();
count++;
handle = open(path, file_access | share, mode);
}
}
}
return (handle);
}
int sh_open1(char *path, int access)
{
unsigned mode;
mode = 0;
if ((access & O_RDWR) || (access & O_WRONLY))
mode |= S_IWRITE;
if ((access & O_RDWR) || (access & O_RDONLY))
mode |= S_IREAD;
return (sh_open(path, access, mode));
}
long sh_lseek(int handle, long offset, int fromwhere)
{
if (handle == -1) {
return (-1L);
}
return (lseek(handle, offset, fromwhere));
}
FILE *fsh_open(char *path, char *mode)
{
FILE *f;
int count, share, md, fd;
char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
share = SH_DENYWR;
md = 0;
if (_fstrchr(mode, 'w') != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT | O_TRUNC;
} else
if (_fstrchr(mode, 'a') != NULL) {
share = SH_DENYRD;
md = O_RDWR | O_CREAT;
} else {
md = O_RDONLY;
}
if (_fstrchr(mode, 'b') != NULL) {
md |= O_BINARY;
}
if (_fstrchr(mode, '+') != NULL) {
md &= ~O_RDONLY;
md |= O_RDWR;
share = SH_DENYRD;
}
fd = open(path, md | share, S_IREAD | S_IWRITE);
if (fd < 0) {
count = 1;
fnsplit(path, drive, dir, file, ext);
if (access(path, 0) != -1) {
delay(WAIT_TIME);
fd = open(path, md | share, S_IREAD | S_IWRITE);
while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
delay(WAIT_TIME);
count++;
fd = open(path, md | share, S_IREAD | S_IWRITE);
}
}
}
if (fd > 0) {
if (_fstrchr(mode, 'a'))
sh_lseek(fd, 0L, SEEK_END);
f = fdopen(fd, mode);
if (!f) {
close(fd);
}
} else
f = 0;
return (f);
}
int sh_close(int f)
{
if (f != -1)
close(f);
return (-1);
}
void fsh_close(FILE * f)
{
fclose(f);
}
int sh_read(int handle, void *buf, unsigned len)
{
if (handle == -1) {
return (-1);
}
return (read(handle, buf, len));
}
int sh_write(int handle, void *buf, unsigned len)
{
if (handle == -1) {
return (-1);
}
return (write(handle, buf, len));
}
static unsigned char *trimstr1(unsigned char *s)
{
int i;
static char *whitespace = " \r\n\t";
i = strlen(s);
while ((i > 0) && (_fstrchr(whitespace, s[i - 1])))
--i;
while ((i > 0) && (_fstrchr(whitespace, *s))) {
memmove(s, s + 1, --i);
}
s[i] = 0;
return (s);
}
void far *malloca(unsigned long nbytes)
{
void *buf;
buf = (void *) farmalloc(nbytes + 1);
if (buf == NULL) {
cprintf("Unable to allocate %ld bytes memory!", nbytes + 1);
}
return (buf);
}
void far *mallocx(unsigned long l, char *where)
{
void *x;
char huge *xx;
if (!l)
l = 1;
x = (long *) malloca(l);
if (!x) {
fprintf(stderr, "Insufficient memory (%ld bytes) for %s.\n", l, where);
exit(EXIT_FAILURE);
}
xx = (char huge *) x;
while (l > 0L) {
if (l > 32768L) {
memset((void *) xx, 0, (int) 32768L);
l -= 32768L;
xx += 32768L;
} else {
memset((void *) xx, 0, (int) l);
break;
}
}
return (x);
}
#define MAX_XFER 61440L
long huge_xfer(int fd, void huge * buf, unsigned sz, unsigned nel, int wr)
{
long nxfr = 0, len = ((long) sz) * ((long) nel);
char huge *xbuf = (char huge *) buf;
unsigned cur, cur1;
while (len > 0) {
if (len > MAX_XFER)
cur = (unsigned int) MAX_XFER;
else
cur = (unsigned int) len;
if (wr)
cur1 = sh_write(fd, (char *) xbuf, cur);
else
cur1 = sh_read(fd, (char *) xbuf, cur);
if (cur1 != 65535L) {
len -= cur1;
nxfr += cur1;
xbuf = ((char huge *) buf) + nxfr;
}
if (cur1 != cur)
break;
}
return (nxfr);
}
void cd_to(char *s)
{
char s1[81];
int i, db;
strcpy(s1, s);
i = strlen(s1) - 1;
db = (s1[i] == '\\');
if (i == 0)
db = 0;
if ((i == 2) && (s1[1] == ':'))
db = 0;
if (db)
s1[i] = 0;
chdir(s1);
if (s[1] == ':')
setdisk(s[0] - 'A');
}
void get_dir(char *s, int be)
{
strcpy(s, "X:\\");
s[0] = 'A' + getdisk();
getcurdir(0, s + 3);
if (be) {
if (s[strlen(s) - 1] != '\\')
strcat(s, "\\");
}
}
int exist(char *s)
{
int i;
struct ffblk ff;
i = findfirst(s, &ff, FA_HIDDEN);
if (i)
return (0);
else
return (1);
}
char *center_text(char *s)
{
static char s1[160];
int i, x, col, lenx;
div_t len;
i = 0;
x = 0;
lenx = strlen(s);
while (s[x]) {
if (s[x] == 3) {
lenx--;
lenx--;
}
x++;
}
col = 80 - lenx;
len = div(col, 2);
i = len.quot;
strcpy(s1, "");
while (i > 0) {
strcat(s1, " ");
i--;
}
strcat(s1, s);
return (s1);
}
char *filedate(char *fpath)
{
struct ftime d;
static char s[21];
int i;
if (!exist(fpath))
return ("");
i = sh_open1(fpath, O_RDONLY);
if (i == -1)
sprintf(s, "");
else {
if (getftime(i, &d) == 0)
sprintf(s, "%02d/%02d/%02d", d.ft_month, d.ft_day,
d.ft_year < 20 ? (d.ft_year + 80) : (d.ft_year - 20));
else
return ("");
}
i = sh_close(i);
return (s);
}
void strip_colors(char *text)
{
int pos = 0;
int len = strlen(text);
while (pos < len && text[pos] != 26) {
if (text[pos] == 3) {
memmove(text + pos, text + pos + 2, len - pos);
--len;
--len;
} else {
if ((text[pos] == 13) || (text[pos] == 26) || (text[pos] == 37)) {
memmove(text + pos, text + pos + 1, len - pos);
--len;
} else
++pos;
}
}
}
void sortlist(void)
{
int i8, i9;
toprec temp;
if (memcpy(&temp, &top[9], sizeof(toprec)) == NULL) {
fprintf(stderr, "Could not allocate %u bytes for top downloads!",
(sizeof(toprec) * 10));
return;
}
i8 = 9;
temp.num = top[9].num;
strcpy(temp.nam, top[9].nam);
strcpy(temp.desc, top[9].desc);
strcpy(temp.uplddate, top[9].uplddate);
temp.bytes = top[9].bytes;
while ((top[9].num >= top[i8].num) && (i8 >= 0)) {
i8--;
}
for (i9 = 8; i9 > i8; i9--) {
top[i9 + 1].num = top[i9].num;
strcpy(top[i9 + 1].nam, top[i9].nam);
strcpy(top[i9 + 1].desc, top[i9].desc);
strcpy(top[i9 + 1].uplddate, top[i9].uplddate);
top[i9 + 1].bytes = top[i9].bytes;
}
top[i8 + 1].num = temp.num;
strcpy(top[i8 + 1].nam, temp.nam);
strcpy(top[i8 + 1].desc, temp.desc);
strcpy(top[i8 + 1].uplddate, temp.uplddate);
top[i8 + 1].bytes = temp.bytes;
return;
}
void toplist(void)
{
int ok, f, i, i1, i2, count, bad1, bad2, bad3;
char s[81], s1[81];
uploadsrec u1;
directoryrec tdir;
for (count = 0; count < 10; count++) {
strcpy(top[count].nam, "01234567.ZIP");
strcpy(top[count].desc, "The quick brown fox jumps over the lazy dog.");
strcpy(top[count].uplddate, "00-00-00");
top[count].bytes = 0;
top[count].num = 0;
}
for (i2 = 0; (i2 < num_dirs); i2++) {
if (kbhit()) {
if (getch() == 27) {
cd_to(maindir);
fprintf(stderr, "\nAborted!\n\n");
exit(EXIT_FAILURE);
}
}
ok = 0;
tdir = directories[i2];
for (i = 0; i < numdirs; i++) {
if (strcmpi(DIR[i].filename, tdir.filename) == 0) {
ok = 1;
break;
}
}
if (ok) {
sprintf(dlfn, "%s%s.DIR", syscfg.datadir, tdir.filename);
f = sh_open1(dlfn, O_RDONLY | O_BINARY);
if (f > -1) {
sh_read(f, (void *) &u1, sizeof(uploadsrec));
numf = u1.numbytes;
sprintf(text2, "%s", tdir.name);
fprintf(stderr, "\rSearching for top downloads in %-30.30s", text2);
for (i1 = 1; i1 <= numf; i1++) {
if (multitasker)
giveup_timeslice();
SETREC(f, i1);
sh_read(f, (void *) &u1, sizeof(uploadsrec));
if (u1.numdloads > top[9].num) {
strcpy(top[9].nam, u1.filename);
strip_colors(u1.description);
strcpy(top[9].desc, u1.description);
if ((file_date) && (!(tdir.mask & mask_cdrom))) {
sprintf(s, "%s%s", tdir.path, u1.filename);
strcpy(s1, filedate(s));
if (s1[0] != 0)
strcpy(top[9].uplddate, s1);
else {
if ((u1.date[0] == 0) || (isalpha(u1.date[0])))
strcpy(top[9].uplddate, "UNKNOWN ");
else {
strcpy(top[9].uplddate, u1.date);
sscanf(top[9].uplddate, "%02d/%02d/%02d", &bad1,
&bad2, &bad3);
if (((bad1 <= 0) || (bad1 > 12)) || ((bad2 <= 0) ||
(bad2 > 31)) || (bad3 <= 0))
strcpy(top[9].uplddate, "UNKNOWN ");
else
sprintf(top[9].uplddate, "%02d-%02d-%02d", bad1,
bad2, bad3);
}
}
} else {
if ((u1.date[0] == 0) || (isalpha(u1.date[0])))
strcpy(top[9].uplddate, "UNKNOWN ");
else {
strcpy(top[9].uplddate, u1.date);
sscanf(top[9].uplddate, "%02d/%02d/%02d", &bad1, &bad2, &bad3);
if (((bad1 <= 0) || (bad1 > 12)) || ((bad2 <= 0) ||
(bad2 > 31)) || (bad3 <= 0))
strcpy(top[9].uplddate, "UNKNOWN ");
else
sprintf(top[9].uplddate, "%02d-%02d-%02d", bad1, bad2, bad3);
}
}
top[9].bytes = u1.numbytes;
top[9].num = u1.numdloads;
sortlist();
}
}
f = sh_close(f);
}
}
}
}
char *stripfn(char *fn)
{
static char ofn[15];
int i,i1;
char s[81];
i1=-1;
for (i=0; i<strlen(fn); i++)
if ((fn[i]=='\\') || (fn[i]==':') || (fn[i]=='/'))
i1=i;
if (i1!=-1)
strcpy(s,&(fn[i1+1]));
else
strcpy(s,fn);
for (i=0; i<strlen(s); i++)
if ((s[i]>='A') && (s[i]<='Z'))
s[i]=s[i]-'A'+'a';
i=0;
while (s[i]!=0) {
if (s[i]==32)
strcpy(&s[i],&s[i+1]);
else
++i;
}
strcpy(ofn,s);
return(ofn);
}
void align(char *s)
{
char f[40], e[40], s1[20], *s2;
int i, i1, i2;
i1 = 0;
if (s[0] == '.')
i1 = 1;
for (i = 0; i < strlen(s); i++)
if ((s[i] == '\\') || (s[i] == '/') || (s[i] == ':') || (s[i] == '<') ||
(s[i] == '>') || (s[i] == '|'))
i1 = 1;
if (i1) {
strcpy(s, "!");
return;
}
s2 = strchr(s, '.');
if (s2 == NULL) {
e[0] = 0;
} else {
strcpy(e, &(s2[1]));
e[3] = 0;
s2[0] = 0;
}
strcpy(f, s);
for (i = strlen(f); i < 8; i++)
f[i] = 32;
f[8] = 0;
i1 = 0;
i2 = 0;
for (i = 0; i < 8; i++) {
if (f[i] == '*')
i1 = 1;
if (f[i] == ' ')
i2 = 1;
if (i2)
f[i] = ' ';
if (i1)
f[i] = '?';
}
for (i = strlen(e); i < 3; i++)
e[i] = 32;
e[3] = 0;
i1 = 0;
for (i = 0; i < 3; i++) {
if (e[i] == '*')
i1 = 1;
if (i1)
e[i] = '?';
}
for (i = 0; i < 12; i++)
s1[i] = 32;
strcpy(s1, f);
s1[8] = '.';
strcpy(&(s1[9]), e);
strcpy(s, s1);
strupr(s);
}
char *unalign(char *filename)
{
char *temp, *exttemp;
temp = strstr(filename, " ");
if (temp) {
temp[0] = 0;
++temp;
exttemp = strstr(temp, ".");
if (exttemp)
strcat(filename, exttemp);
}
return (filename);
}
unsigned long file_lister(char *listname, char *which, char type)
{
int i1, i2, f;
int ok, na, dir, newflag, bad1, bad2, bad3;
long l, nscandate;
static char s[101], s1[81], s2[81], s3[81], s4[81];
struct date d;
struct time t;
uploadsrec u;
directoryrec one_dir;
FILE *fp;
gettime(&t);
getdate(&d);
if (d.da_mon > 1) {
d.da_mon = d.da_mon - 1;
} else {
d.da_mon = 12;
d.da_year = d.da_year - 1;
}
t.ti_min = 0;
t.ti_hour = 0;
t.ti_hund = 0;
t.ti_sec = 0;
nscandate = dostounix(&d, &t);
fp = fsh_open(listname, "a+t");
for (dir = 0; dir < num_dirs; dir++) {
one_dir = directories[dir];
ok = 0;
if (strcmp(one_dir.filename, which) == 0)
ok = 1;
if (ok) {
++totaldirs;
sprintf(text1, "%s", one_dir.name);
fprintf(stderr, "\rAdding files in %-45.45s", text1);
sprintf(dlfn, "%s%s.DIR", syscfg.datadir, one_dir.filename);
f = sh_open1(dlfn, O_RDONLY | O_BINARY);
numf = 0;
if (f > -1) {
sh_read(f, (void *) &u, sizeof(uploadsrec));
numf = u.numbytes;
sprintf(buffer, "\n%c %s (%ld files) %c\n", type, one_dir.name,
numf, type);
fputs(buffer, fp);
for (i1 = 1; (i1 <= numf); i1++) {
if (kbhit()) {
if (getch() == 27) {
cd_to(maindir);
fprintf(stderr, "\nFile listing aborted!\n\n");
exit(EXIT_FAILURE);
}
}
SETREC(f, i1);
sh_read(f, (void *) &u, sizeof(uploadsrec));
newflag = 0;
if (u.daten == 0L) {
time(&l);
u.daten = l;
}
if (u.daten >= nscandate)
newflag = 1;
if ((u.date[0] == 0) || (isalpha(u.date[0])))
strcpy(s3, "UNKNOWN ");
else {
strcpy(s3, u.date);
sscanf(s3, "%02d/%02d/%02d", &bad1, &bad2, &bad3);
if (((bad1 <= 0) || (bad1 > 12)) || ((bad2 <= 0) ||
(bad2 > 31)) || (bad3 <= 0))
strcpy(s3, "UNKNOWN ");
else
sprintf(s3, "%02d-%02d-%02d", bad1, bad2, bad3);
}
if (!(one_dir.mask & mask_cdrom)) {
strcpy(s1, one_dir.path);
strcat(s1, stripfn(u.filename));
na = (exist(s1));
align(u.filename);
}
if ((na) || (one_dir.mask && mask_cdrom)) {
s1[0] = 0;
sprintf(s, "%s", ltoa((((u.numbytes) + 1023) / 1024), s1, 10));
sprintf(s1, "%sK", s);
} else
sprintf(s1, "N/A");
strcpy(s2, u.filename);
unalign(s2);
strcpy(s4, u.description);
strip_colors(s4);
trimstr1(s4);
s4[48] = NULL;
sprintf(buffer, "%-12s %6s%s %s %s\n", s2, s1,
(newflag ? "*" : " "), s3, s4);
fputs(buffer, fp);
}
}
f = sh_close(f);
if (!numf) {
sprintf(buffer, " No Files in Directory\n");
fputs(buffer, fp);
}
}
}
fsh_close(fp);
return numf;
}
void set_net_num(int n)
{
char s[121];
int f;
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
f = sh_open1(s, O_RDONLY | O_BINARY);
if (f < 0)
return;
lseek(f, ((long) (n)) * sizeof(net_networks_rec), SEEK_SET);
sh_read(f, &netcfg, sizeof(net_networks_rec));
close(f);
net_num = n;
net_sysnum = netcfg.sysnum;
strcpy(net_name, netcfg.name);
strcpy(net_data, netcfg.dir);
if (LAST(net_data) != '\\')
strcat(net_data, "\\");
sprintf(wwiv_net_no, "WWIV_NET=%d", net_num);
}
int count_lines(char *s)
{
FILE *fp;
char fn[121];
unsigned int nl = 0;
const int NEWLINE = '\n';
int c;
strcpy(fn, s);
fp = fsh_open(fn, "rt");
if (fp == NULL) {
printf("\n ■ Cannot open %s", fn);
return 0;
}
while ((c = getc(fp)) != EOF) {
if (c == NEWLINE)
++nl;
}
fclose(fp);
return nl;
}
#pragma warn -par
void main(int argc, char *argv[])
{
int i, i1, ok, dirtype;
char s[101], s1[21], fsize[11], fname[21], fdesc[81], flist[MAXPATH], *ss;
FILE *fp;
time_t now;
struct tm *ptr;
time(&now);
ptr = localtime(&now);
#ifdef DEBUG
cprintf("\r\nSize of directoryrec = %d", sizeof(directoryrec));
cprintf("\r\nSize of toprec = %d", sizeof(toprec));
cprintf("\r\nSize of configrec = %d", sizeof(configrec));
cprintf("\r\nSize of configoverrec = %d", sizeof(configoverrec));
getch();
#endif
fprintf(stderr, "\nFILEnet File Lister v%s\n", VERSION);
get_dir(maindir, 1);
detect_multitask();
ss = getenv("WWIV_INSTANCE");
if (ss) {
instance = atoi(ss);
if ((instance <= 0) || (instance > 999)) {
fprintf(stderr, "WWIV_INSTANCE can only be 1..999!");
instance = 1;
}
} else {
instance = 1;
}
i = -1;
s[0] = 0;
strcpy(s, "CONFIG.DAT");
i = sh_open1(s, O_RDONLY | O_BINARY);
if (i < 0) {
fprintf(stderr, "\n%s%s not found. Run in BBS main directory!\n\n",
maindir, s);
cd_to(maindir);
exit(EXIT_FAILURE);
}
read(i, (void *) (&syscfg), sizeof(configrec));
i = sh_close(i);
strcpy(s, "CONFIG.OVR");
i = sh_open1(s, O_RDONLY | O_BINARY);
if (i < 0) {
fprintf(stderr, "\n%s%s not found.\n\n", maindir, s);
cd_to(maindir);
exit(EXIT_FAILURE);
}
sh_lseek(i, (instance - 1) * sizeof(configoverrec), SEEK_SET);
read(i, &syscfgovr, sizeof(configoverrec));
i = sh_close(i);
directories = (directoryrec *) mallocx(((long) syscfg.max_dirs) *
((long) sizeof(directoryrec)), "directories");
sprintf(s, "%sDIRS.DAT", syscfg.datadir);
i = sh_open1(s, O_RDWR | O_BINARY);
if (i < 0) {
fprintf(stderr, "\n%s not found!\n\n", s);
cd_to(maindir);
exit(EXIT_FAILURE);
} else {
num_dirs = (int) huge_xfer(i, directories, sizeof(directoryrec),
syscfg.max_dirs, 0) / sizeof(directoryrec);
}
i = sh_close(i);
top = (toprec *) malloca((long) 10 * sizeof(toprec) + 1);
if (top == NULL) {
fprintf(stderr, "\nCould not allocate %u bytes for top downloads!\n\n",
sizeof(toprec) * 10);
exit(EXIT_FAILURE);
}
sprintf(s, "%sNETWORKS.DAT", syscfg.datadir);
i = sh_open1(s, O_RDONLY | O_BINARY);
net_num_max = 0;
if (i > 0) {
net_num_max = (int) (filelength(i) / sizeof(net_networks_rec));
i = sh_close(i);
}
ok = 1;
for (i = 0; i < net_num_max && ok; i++) {
set_net_num(i);
if (strnicmp(net_name, "filenet", 7) == 0) {
ok = 0;
net_num = i;
}
}
if (ok) {
fprintf(stderr, "\nFILEnet not defined in INIT... aborting.\n\n");
cd_to(maindir);
exit(EXIT_FAILURE);
}
#ifdef DEBUG
else
fprintf(stderr, "\nFILEnet found in INIT!\n\n");
#endif
sprintf(s, "%sDIRLIST.FTS", net_data);
if (!exist(s)) {
fprintf(stderr, "\n%s not found!\n\n", s);
cd_to(maindir);
exit(EXIT_FAILURE);
}
numdirs = count_lines(s);
DIR = (whichdir *) malloc((numdirs + 2) * sizeof(whichdir));
if (!DIR) {
fprintf(stderr, "\nInsufficient memory for %s.\n\n", s);
cd_to(maindir);
exit(EXIT_FAILURE);
} else {
fprintf(stderr,
"\nCreating file list of %d directories... [Esc] aborts!\n", numdirs);
}
fp = fsh_open(s, "rt");
i = dirtype = 0;
while (fgets(s, 9, fp) != NULL) {
if ((s[0]) && ((s[0] != 10) && (s[0] != 13))) {
ss = strtok(s, " \r\n");
trimstr1(ss);
if (ss[0] == '!') {
strcpy(s1, &ss[1]);
if (strnicmp(s1, "REGULAR", 7) == 0)
dirtype = 0;
else
if (strnicmp(s1, "SYSOP", 5) == 0)
dirtype = 1;
else
if (strnicmp(s1, "WWIVREG", 7) == 0)
dirtype = 2;
} else {
strcpy(DIR[i].filename, ss);
DIR[i].type = dirtype;
}
i++;
}
}
#ifdef DEBUG
fprintf(stderr, "\nNow looking at %d dirs.\n", numdirs);
for (i = 0; i < numdirs; i++)
fprintf(stderr, "\n%s", DIR[i].filename);
getch();
#endif
toplist();
sprintf(flist, "%sL%hu.FTS", net_data, net_sysnum);
fp = fsh_open(flist, "wt+");
if (!fp) {
fprintf(stderr, "\nUnable to open %s for write operation.", flist);
cd_to(maindir);
exit(EXIT_FAILURE);
}
fprintf(fp, "╒");
for (i = 0; i < 77; i++)
fprintf(fp, "═");
fprintf(fp, "╕\n│");
for (i = 0; i < 77; i++)
fprintf(fp, " ");
fprintf(fp, "│\n│");
sprintf(text1, "File Listing from %s (%hu.FILEnet)", syscfg.systemname,
net_sysnum);
sprintf(s, "%s", center_text(text1));
fputs(s, fp);
for (i = 77; i > strlen(s); i--)
fprintf(fp, " ");
fprintf(fp, "│\n│");
strftime(text1, 80, "as of %A, %B %d, %Y", ptr);
sprintf(s, "%s", center_text(text1));
fputs(s, fp);
for (i = 77; i > strlen(s); i--)
fprintf(fp, " ");
fprintf(fp, "│\n│");
for (i = 0; i < 77; i++)
fprintf(fp, " ");
fprintf(fp, "│\n");
fprintf(fp, "╘");
for (i = 0; i < 77; i++)
fprintf(fp, "═");
fprintf(fp, "╛\n\n");
sprintf(text1, "Files marked with \'*\' are less than 30 days old.\n");
sprintf(buffer, "%s", center_text(text1));
fputs(buffer, fp);
fprintf(fp, "\n");
fprintf(fp, "■ Top Ten Downloaded Files ■");
for (i = 0; i < 10; i++) {
ltoa((((top[i].bytes) + 1023) / 1024), fsize, 10);
strcat(fsize, "K");
strncpy(fname, top[i].nam, 8);
i1 = 8;
while (i1--)
if (fname[i1] != ' ')
break;
fname[i1 + 1] = '\0';
strncat(fname, &((top[i].nam)[8]), 4);
trimstr1(top[i].desc);
strcpy(fdesc, top[i].desc);
if (strlen(fdesc) > 42)
fdesc[42] = '\0';
sprintf(buffer, "\n%-12s %6s %s [%03.03d] %s",
fname, fsize, top[i].uplddate, top[i].num, fdesc);
fputs(buffer, fp);
}
fprintf(fp, "\n");
fclose(fp);
totaldirs = 0;
totalfiles = 0L;
for (i = 0; i < numdirs; i++)
totalfiles += file_lister(flist, DIR[i].filename, whichtype[DIR[i].type]);
fp = fsh_open(flist, "a+t");
if (fp) {
sprintf(buffer, "\n%ld total files in %d directories.", totalfiles,
totaldirs);
fputs(buffer, fp);
}
fsh_close(fp);
exit(EXIT_SUCCESS);
}