home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
f
/
fido_top.zip
/
FIDO-TOP.C
next >
Wrap
C/C++ Source or Header
|
1991-05-13
|
18KB
|
604 lines
/*
FIDO-TOP
Version 1.01
Copyright (c) Bob Swift, 1991. All Rights Reserved.
Compiled with the Turbo C++ 1.0 compiler from Borland.
This program is used to read the Fido 12 CALLER.SYS files and generate a
file listing the top users (upload, download, calls) for the BBS. The
CALLER.SYS file must be in the current directory.
The program will display a VERY brief set of instructions if it is called
without any arguments or if it encounters an error. The following is a
list of the error codes returned by the program:
0 - No errors. Normal termination.
1 - Missing/Bad/Extra command line argument.
2 - Unable to open the CALLER.SYS file.
3 - Unable to open the output file.
4 - Unable to write the output file.
5 - Unable to close the CALLER.SYS file.
6 - Unable to close the output file.
7 - Output file not in current directory. (disabled)
8 - Unable to create output backup file.
9 - No user records to process.
When an error is encountered, the program will exit immediately and will
attempt to properly close all files.
Although I have chosen to retain all rights to this program, you are free
to use it under the following conditions:
- You realize that there is NO Warrantee of any sort.
It was tested pretty thoroughly here before release
but who knows what bugs may be lurking within.
- You will not modify the code and release a new version
of the program. I welcome suggestions for improvement
(especially when accompanied by code) but I make no
guarantee of future releases.
- If you find the program useful, I ask that you do
something to brighten somebody else's day. Just
exactly what, I will leave up to you.
You may freely distribute this program provided that you distribute only
the complete archive which includes the FIDO-TOP.EXE, FIDO-TOP.C and
FIDO-TOP.DOC. In addition, You MUST NOT charge for the program nor may
you charge a copy fee over $4.00 (including the price of the diskette).
Bob Swift (1:140/24)
Revision History
----------------
1.00 91/05/11 First release version.
1.01 91/05/13 Modified first line of output for Bulletin title.
*/
#define TITLE "FIDO-TOP" /* Program Name */
#define DATES "1991" /* Copyright Date */
#define VERSION "1.01" /* Version Number */
#define NUM_TO_LIST 10 /* List Top n Users */
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "fido.h"
void helpscrn(int ernum);
void add_period(char filename[]);
void build_bak_name(char filename[]);
int is_in_dir(char *filename);
int del_backup(char *filename);
int make_backup(char *srcfile, char *destfile);
char *pad_string(char *str_to_pad, int str_len);
char *add_commas(unsigned ul);
/*******************************************************************/
void main(int argc, char *argv[])
{
struct tm *tm_now;
time_t secs_now;
FILE *infile1,*outfile;
char flnames[2][40];
char outline[128];
static struct _clr fido_data;
char version[] = {VERSION}; /* Current Version Number */
char title[] = {TITLE};
char dates[] = {DATES};
int i,
j,
k,
l,
numtolist,
u_flag,
d_flag,
c_flag;
char u_name[NUM_TO_LIST][20],
d_name[NUM_TO_LIST][20],
c_name[NUM_TO_LIST][20];
char u_call[NUM_TO_LIST][20],
d_call[NUM_TO_LIST][20],
c_call[NUM_TO_LIST][20];
unsigned int c_calls[NUM_TO_LIST]; /* number of calls */
unsigned int dl_bytes[NUM_TO_LIST], /* total bytes downloaded */
ul_bytes[NUM_TO_LIST]; /* total bytes uploaded */
int u_index[NUM_TO_LIST],
d_index[NUM_TO_LIST],
c_index[NUM_TO_LIST];
numtolist = NUM_TO_LIST;
printf("\n\n%s Version %s\n",title,version);
printf("Copyright (c) Bob Swift, %s. All Rights Reserved.",dates);
if (argc < 2 || argc > 3) helpscrn(1);
strcpy(flnames[0],strupr(argv[1])); /* Output File */
strcpy(flnames[1],strupr(argv[1])); /* Backup File */
/* if (is_in_dir(flnames[2]) == 1) */
/* helpscrn(7); */
if ((infile1=fopen("CALLER.SYS","rb")) == NULL)
helpscrn(2);
add_period(flnames[1]);
build_bak_name(flnames[1]);
/* Exit if output file has an extension of BAK */
if (strcmp(flnames[0],flnames[1])==0)
helpscrn(8);
if (del_backup(flnames[1]) == 1)
helpscrn(8);
if (make_backup(flnames[0],flnames[1]) == 1)
helpscrn(8);
if ((outfile=fopen(flnames[0],"w")) == NULL)
helpscrn(3);
printf("\n\nInitializing.");
u_flag = 0;
d_flag = 0;
c_flag = 0;
if (argc > 2)
{
if (strchr(argv[2],'U')!=NULL || strchr(argv[2],'u')!=NULL)
u_flag = 1;
if (strchr(argv[2],'D')!=NULL || strchr(argv[2],'d')!=NULL)
d_flag = 1;
if (strchr(argv[2],'C')!=NULL || strchr(argv[2],'c')!=NULL)
c_flag = 1;
}
else
{
u_flag = 1;
d_flag = 1;
c_flag = 1;
}
if (u_flag == 0 && c_flag == 0 && d_flag == 0)
helpscrn(1);
i = 0;
while (i < numtolist)
{
u_index[i] = i;
d_index[i] = i;
c_index[i] = i;
u_name[i][0] = '\0';
d_name[i][0] = '\0';
c_name[i][0] = '\0';
u_call[i][0] = '\0';
d_call[i][0] = '\0';
c_call[i][0] = '\0';
c_calls[i] = 0;
ul_bytes[i] = 0;
dl_bytes[i] = 0;
i++;
}
printf("\n");
i = 0;
while (fread(&fido_data,sizeof(struct _clr),1,infile1) == 1)
{
i++;
printf("\rProcessing User %d",i);
if (c_flag == 1)
{
j = 0;
while (j < numtolist)
{
if (fido_data.times > c_calls[c_index[j]])
{
strcpy(c_name[c_index[numtolist-1]],fido_data.name);
strcpy(c_call[c_index[numtolist-1]],fido_data.date);
c_calls[c_index[numtolist-1]] = fido_data.times;
l = c_index[numtolist-1];
k = numtolist - 1;
while (k > j)
{
c_index[k] = c_index[k-1];
k--;
}
c_index[j] = l;
j = numtolist;
}
j++;
}
}
if (d_flag == 1)
{
j = 0;
while (j < numtolist)
{
if (fido_data.dnld > dl_bytes[d_index[j]])
{
strcpy(d_name[d_index[numtolist-1]],fido_data.name);
strcpy(d_call[d_index[numtolist-1]],fido_data.date);
dl_bytes[d_index[numtolist-1]] = fido_data.dnld;
l = d_index[numtolist-1];
k = numtolist - 1;
while (k > j)
{
d_index[k] = d_index[k-1];
k--;
}
d_index[j] = l;
j = numtolist;
}
j++;
}
}
if (u_flag == 1)
{
j = 0;
while (j < numtolist)
{
if (fido_data.upld > ul_bytes[u_index[j]])
{
strcpy(u_name[u_index[numtolist-1]],fido_data.name);
strcpy(u_call[u_index[numtolist-1]],fido_data.date);
ul_bytes[u_index[numtolist-1]] = fido_data.upld;
l = u_index[numtolist-1];
k = numtolist - 1;
while (k > j)
{
u_index[k] = u_index[k-1];
k--;
}
u_index[j] = l;
j = numtolist;
}
j++;
}
}
}
if (i == 0)
helpscrn(9);
if (fclose(infile1) != 0)
helpscrn(5);
printf("\nWriting output file");
time(&secs_now);
if ((c_flag == 1 && d_flag == 1) || (c_flag == 1 && u_flag == 1) || (d_flag == 1 && u_flag == 1))
strcpy(outline,"Users");
else
{
if (c_flag == 1) strcpy(outline,"Callers");
if (u_flag == 1) strcpy(outline,"Uploaders");
if (d_flag == 1) strcpy(outline,"Downloaders");
}
/* Print header to output file */
if (fprintf(outfile,"\nTop %d %s as of ",numtolist,outline) == EOF) helpscrn(4);
if (fputs(ctime(&secs_now),outfile) == EOF) helpscrn(4);
if (c_flag == 1)
{
if (fputs("\nCallers:\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
if (fputs("## Name Last Called # Calls\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
i = 0;
while (i < numtolist)
{
if (fprintf(outfile,"%2d ",i+1) == EOF) helpscrn(4);
strcpy(outline,c_name[c_index[i]]);
strcat(outline," ");
outline[25] = '\0';
strcat(outline,c_call[c_index[i]]);
strcat(outline," ");
outline[50] = '\0';
if (fputs(outline,outfile) == EOF) helpscrn(4);
/* if (fprintf(outfile,"%s\n",pad_string(add_commas(c_calls[c_index[i]]),10)) == EOF) helpscrn(4); */
strcpy(outline,pad_string(add_commas(c_calls[c_index[i]]),10));
if (fprintf(outfile,"%s\n",outline) == EOF) helpscrn(4);
i++;
}
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
}
if (d_flag == 1)
{
if (fputs("\nDownloads:\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
if (fputs("## Name Last Called D/L (k)\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
i = 0;
while (i < numtolist)
{
if (fprintf(outfile,"%2d ",i+1) == EOF) helpscrn(4);
strcpy(outline,d_name[d_index[i]]);
strcat(outline," ");
outline[25] = '\0';
strcat(outline,d_call[d_index[i]]);
strcat(outline," ");
outline[50] = '\0';
if (fputs(outline,outfile) == EOF) helpscrn(4);
/* if (fprintf(outfile,"%s\n",pad_string(add_commas(dl_bytes[d_index[i]]),10)) == EOF) helpscrn(4); */
strcpy(outline,pad_string(add_commas(dl_bytes[d_index[i]]),10));
if (fprintf(outfile,"%s\n",outline) == EOF) helpscrn(4);
i++;
}
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
}
if (u_flag == 1)
{
if (fputs("\nUploads:\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
if (fputs("## Name Last Called U/L (k)\n",outfile) == EOF) helpscrn(4);
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
i = 0;
while (i < numtolist)
{
if (fprintf(outfile,"%2d ",i+1) == EOF) helpscrn(4);
strcpy(outline,u_name[u_index[i]]);
strcat(outline," ");
outline[25] = '\0';
strcat(outline,u_call[u_index[i]]);
strcat(outline," ");
outline[50] = '\0';
if (fputs(outline,outfile) == EOF) helpscrn(4);
/* if (fprintf(outfile,"%s\n",pad_string(add_commas(ul_bytes[u_index[i]]),10)) == EOF) helpscrn(4); */
strcpy(outline,pad_string(add_commas(ul_bytes[u_index[i]]),10));
if (fprintf(outfile,"%s\n",outline) == EOF) helpscrn(4);
i++;
}
if (fputs("------------------------------",outfile) == EOF) helpscrn(4);
if (fputs("-----------------------------------\n",outfile) == EOF) helpscrn(4);
}
/* Print footer to output file */
if (fputs("\nProduced by ",outfile) == EOF) helpscrn(4);
if (fputs(title,outfile) == EOF) helpscrn(4);
if (fputs(" v",outfile) == EOF) helpscrn(4);
if (fputs(version,outfile) == EOF) helpscrn(4);
if (fputs("\nCopyright (c) Bob Swift, ",outfile) == EOF) helpscrn(4);
if (fputs(dates,outfile) == EOF) helpscrn(4);
if (fputs(". All Rights Reserved.\n\n",outfile) == EOF) helpscrn(4);
/* Close the destination file */
if (fclose(outfile) != 0)
helpscrn(6);
/* Thank the user and exit gracefully */
printf("\n\nOperation complete. Thank-you for using %s.\n\n",title);
exit(0);
}
/*******************************************************************/
int is_in_dir(char *filename)
/* Check if input file in current directory */
{
if (strchr(filename,'\\')!=NULL || strchr(filename,':')!=NULL)
return(1);
else
return(0);
}
/*******************************************************************/
void add_period(char filename[])
/* If input file has no extension finish it with a period */
{
if (strchr(filename,'.')==NULL)
strcat(filename,".");
}
/*******************************************************************/
void build_bak_name(char filename[])
/* Build file name for backup file */
{
int flag;
for (flag=0;filename[flag]!='.';flag++)
{
/* NULL Line */
}
filename[flag] = '\0';
strcat(filename,".BAK");
}
/*******************************************************************/
int del_backup(char *filename)
/* Check for existing backup file and delete */
{
FILE *tempfile;
tempfile=fopen(filename,"r");
fclose(tempfile);
if (tempfile != NULL)
{
if (unlink(filename) != 0)
return(1);
}
return(0);
}
/*******************************************************************/
int make_backup(char *srcfile, char *destfile)
/* Rename source file to destination file */
{
FILE *tempfile;
tempfile=fopen(srcfile,"r");
fclose(tempfile);
if (tempfile != NULL)
{
if (rename(srcfile,destfile) != 0)
return(1);
}
return(0);
}
/*******************************************************************/
int linetest(char *linetst1, char *inline)
/* This is the routine that actually checks for a match */
{
int j;
for ( j=0; linetst1[j] == inline[j]; j++ )
if (linetst1[j+1] == '\0') return(1);
return(0);
}
/*******************************************************************/
char *add_commas(unsigned int ul)
/* This routine returns a string of an unsigned integer with commas */
{
int i;
int j;
char temp[35];
char work[35];
itoa(ul,work,10);
strrev(work);
i=1;
j=1;
temp[0] = work[0];
while(work[i] != '\0')
{
if (i%3 == 0)
{
temp[j] = ',';
j++;
}
temp[j] = work[i];
i++;
j++;
}
temp[j] = '\0';
strrev(temp);
return(temp);
}
/*******************************************************************/
char *pad_string(char *str_to_pad, int str_len)
/* This routine adds leading spaces to a string to a specified length */
{
char temp[35];
int i;
strcpy(temp,str_to_pad);
strrev(temp);
i = strlen(temp);
while (i < str_len)
{
temp[i] = ' ';
i++;
}
temp[i] = '\0';
strrev(temp);
return(temp);
}
/*******************************************************************/
void helpscrn(int ernum)
/* Here are the error messages and VERY brief instructions */
{
printf("\n\n");
switch (ernum) {
case 1 : printf("Missing/Bad/Extra command line argument\n\n");
break;
case 2 : printf("Unable to open the USERSx.SOC file\n\n");
break;
case 3 : printf("Unable to open the output file\n\n");
break;
case 4 : printf("Unable to write the output file\n\n");
break;
case 5 : printf("Unable to close the USERSx.SOC file\n\n");
break;
case 6 : printf("Unable to close the output file\n\n");
break;
case 7 : printf("Output file not in current directory\n\n");
break;
case 8 : printf("Unable to create output backup file\n\n");
break;
case 9 : printf("No user records to process\n\n");
break;
}
printf(" This program is used to read the Fido 12 CALLER.SYS files and ");
printf("generate a\n file listing the top users (upload, download, call");
printf("s) for the BBS. The\n CALLER.SYS file must be in the current d");
printf("irectory.\n\nThe format for using this program is as follows:\n");
printf("\n FIDO-TOP <destfile> [options]\n\nWhere <destfile> is the nam");
printf("e of the output file created\n [options] type of analysis t");
printf("o perform (U = Uploads, D = Downloads,\n ");
printf(" C = Number of Calls)\n\nExamples: FIDO-");
printf("TOP topusers.txt udc (udc is default)\n FIDO-TOP up");
printf("loads.top u\n\n");
exit(ernum);
}
/*******************************************************************/