home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
newc_dev
/
uucicosd.lha
/
xferstat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-04
|
3KB
|
131 lines
/* Original by Andrew Kopp, modified by John Bickers */
/* small mods for logging device, unit, and failed messages by Steve Drew */
#include "includes.h"
Prototype void xferinit(char *);
Prototype void xferstat(char *phonenum, char *comment);
Prototype void xferlog(char *,...);
Prototype XferStat xfer;
XferStat xfer;
void xferinit(host) /*================================================*/
char *host;
{
time_t t;
char proto[sizeof(xfer.proto)];
memcpy(proto,xfer.proto,sizeof(proto));
memset(&xfer,0,sizeof(xfer));
memcpy(xfer.proto,proto,sizeof(xfer.proto));
strncpy(xfer.host,host,sizeof(xfer.host)-1);
t = time(NULL);
xfer.time_start = t;
xfer.time_stop = t;
}
void xferstat(char *phonenum, char *comment) /*=======================*/
{
FILE *fo;
struct tm st,et;
long hh,mm,ss,calc,fcalc,perc;
if (xfer.flags & XFERF_WRITTEN) return;
fo = fopen("uuspool:xferstat","a");
if (!fo) return;
xfer.flags |= XFERF_WRITTEN; /* indicate output done */
/* Indicator for type of link */
fprintf(fo,"%c %-8s ",(xfer.flags & XFERF_OUTGOING)? '<': '>',xfer.host);
st = *localtime(&xfer.time_start);
et = *localtime(&xfer.time_stop);
fprintf(fo,"%02d-%02d-%02d %02d:%02d:%02d > ",st.tm_mday,st.tm_mon+1,st.tm_year,st.tm_hour,st.tm_min,st.tm_sec);
fprintf(fo,"%02d-%02d-%02d %02d:%02d:%02d ",et.tm_mday,et.tm_mon+1,et.tm_year,et.tm_hour,et.tm_min,et.tm_sec);
hh = et.tm_hour - st.tm_hour;
if (hh < 0) hh += 24;
mm = et.tm_min - st.tm_min;
ss = et.tm_sec - st.tm_sec;
if (ss < 0) {
ss += 60;
mm--;
}
if (mm < 0) {
mm += 60;
hh--;
}
if (hh < 0) hh += 24;
fprintf(fo,"(%02d:%02d:%02d)",hh,mm,ss);
ss += (hh * 3600L) + (mm * 60L);
calc = xfer.bytes_recv + xfer.bytes_send;
calc = (ss)? calc/ss: 0L;
fprintf(fo,"%6ld",calc);
fcalc = xfer.fbytes_recv + xfer.fbytes_send;
fcalc = (ss)? fcalc/ss: 0L;
fprintf(fo," %6ld",fcalc);
perc = (calc)? (100 * fcalc)/calc: 0L;
fprintf(fo," %3ld%%\n",perc);
switch(xfer.proto[0]) {
case ('g'):
case ('G'):
{
int psize;
psize = (1 << (xfer.proto[2] + 4));
fprintf(fo,"| %c %1d %4d",xfer.proto[0],xfer.proto[1],psize);
}
break;
default:
fprintf(fo,"| ");
}
fprintf(fo," %8ld %8ld # %8ld %8ld # %4ld %4ld\n",
xfer.bytes_recv,xfer.bytes_send,
xfer.fbytes_recv,xfer.fbytes_send,
xfer.files_recv,xfer.files_send
);
/*
* serial port, and comment passed from uucico mods by Steve Drew
*/
{
extern char *DeviceName;
extern long DeviceUnit;
fprintf(fo,"| VIA device %s unit %d", DeviceName,DeviceUnit);
if (phonenum) {
fprintf(fo," number %s\n",phonenum);
}
else fprintf(fo,"\n");
if (comment != NULL) {
fprintf(fo,"%s\n",comment);
}
}
fclose(fo);
}
/* Perhaps put file handle into xfer? */
void xferlog(char *cp,...) /*=========================================*/
{
FILE *fo;
va_list args;
if (cp && fo = fopen("uuspool:xferstat","a")) {
va_start(args,cp);
vfprintf(fo,cp,args)
va_end(args);
fclose(fo);
}
}