home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
LASTCA3S
/
LASTCALL.C
next >
Wrap
Text File
|
1992-03-21
|
7KB
|
253 lines
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include "user.h"
int s_len, userfile, num_users, test = 0, alias = 0;
long length;
time_t tnow;
struct tm *tmnow;
#define MAX_USERS 500
typedef struct _info
{
char name[36];
char from[36];
union stamp_combo ludate;
unsigned int time;
} INFO;
INFO *info[MAX_USERS];
FILE *out;
int back(const void *a, const void *b);
void qsort2(void *base, unsigned nel, unsigned width,
int (*comp)(const void *, const void *));
main(int argc, char *argv[])
{
struct _usr users;
int x, y, z;
if(argc < 4)
{
puts("Usage:");
puts(" LASTCALL userfile output_file system_name [A]");
puts("Example: ");
puts(" LASTCALL USER.BBS C:\\MAX\\MISC\\LASTCALL.BBS \"The Source for Source\" A");
puts(" ");
puts("The A is optional, it is used for Aliases in the Name field.");
exit(255);
}
if(argc == 5) alias = 1;
tzset();
time(&tnow);
tmnow = localtime(&tnow);
printf("\nLASTCALL By Erik VanRiper (1:107/230@fidonet.org)\n\n" \
"This program is free for non-commercial use.\n");
if(alias)
printf("\nUsing Aliases.\n");
if((userfile=open(argv[1],O_RDONLY | O_BINARY))==-1)
{
printf("\nError: Unable to locate %s\n",argv[1]);
exit(255);
}
read(userfile,&users,sizeof(struct _usr));
s_len = users.struct_len ? users.struct_len * 20 : 180;
length = filelength(userfile);
num_users = length / s_len;
printf("\n%d Users . . .\n",num_users);
for(x = 0; x < MAX_USERS; x++)
{
if((info[x] = malloc(sizeof(INFO))) == NULL)
{
printf("\nOut of memory!\n");
exit(255);
}
}
printf("\rReading . . .");
test = read_user(num_users);
close(userfile);
if((out = fopen(argv[2],"w+b")) == NULL)
exit(0);
x = strlen(argv[3]);
x += 27;
y = (80 - x) / 2;
for(z = 0; z < y; z++) fprintf(out," ");
fprintf(out,"ÅLast callers on %s (%-2.2d/%-2.2d/%-2.2d)\nî",
argv[3],
tmnow->tm_mon+1,
tmnow->tm_mday,
tmnow->tm_year);
for(z = 0; z < y; z++) fprintf(out," ");
for(y = 0;y < x;y++) fprintf(out,"─");
fprintf(out,"\n\nâ");
fprintf(out," ┌─────────────────────────┬─────────────────────────────┬─────────┬──────┐\n");
fprintf(out," │¢ User Name â│¢ City / State / Province â│¢ Time On â│¢ Used â│\n");
fprintf(out," ├─────────────────────────┼─────────────────────────────┼─────────┼──────┤\n");
printf("\rSorting . . .");
qsort2(info, test, sizeof(INFO *), back);
printf("\rWriting . . .");
z = 0;
for(x = 0;x < test; x++)
{
if(z == 0)
{
fprintf(out," │Ä %-23s â│Ä %-27s â│Ä %-2.2d:%-2.2d â│Ä %-3d â│\n",
info[x]->name,
info[x]->from,
info[x]->ludate.msg_st.time.hh,
info[x]->ludate.msg_st.time.mm,
info[x]->time);
z = 1;
}
else
fprintf(out," │ç %-23s â│ç %-27s â│ç %-2.2d:%-2.2d â│ç %-3d â│\n",
info[x]->name,
info[x]->from,
info[x]->ludate.msg_st.time.hh,
info[x]->ludate.msg_st.time.mm,
info[x]->time);
}
fprintf(out,"â └─────────────────────────┴─────────────────────────────┴─────────┴──────┘\n\n");
fclose(out);
printf("\rDone! \n");
for(x = 0; x < MAX_USERS; x++)
{
free(info[x]);
}
return(1);
}
read_user(int p)
{
struct _usr users[1];
int x, y = 0;
for (x=1;x < p;x++)
{
lseek(userfile,(long)x*(long)s_len,SEEK_SET);
read(userfile,&users[0],sizeof(struct _usr));
if((users[0].ludate.msg_st.date.mo == tmnow->tm_mon+1) &&
(users[0].ludate.msg_st.date.da == tmnow->tm_mday) &&
(users[0].ludate.msg_st.date.yr+80 == tmnow->tm_year) &&
((users[0].bits & BITS_NOULIST) == 0))
{
info[y]->ludate = users[0].ludate;
info[y]->time = users[0].time;
if(alias)
{
if(users[0].alias[0] != NULL)
{
strcpy(info[y]->name,users[0].alias);
}
else
{
strcpy(info[y]->name,users[0].name);
}
}
else strcpy(info[y]->name,users[0].name);
strcpy(info[y]->from,users[0].city);
y++;
if(y > MAX_USERS)
{
printf("\nError number 72. Please report this to the author!\n");
close(userfile);
for(x = 0; x < MAX_USERS; x++) free(info[x]);
exit(255);
}
}
}
return(y);
}
int back(const void *a, const void *b)
{
INFO *ai = *((INFO **)a);
INFO *bi = *((INFO **)b);
if(ai->ludate.msg_st.date.yr == bi->ludate.msg_st.date.yr)
{
if(ai->ludate.msg_st.date.mo == bi->ludate.msg_st.date.mo)
{
if(ai->ludate.msg_st.date.da == bi->ludate.msg_st.date.da)
{
if(ai->ludate.msg_st.time.hh == bi->ludate.msg_st.time.hh)
{
return((ai->ludate.msg_st.time.mm < bi->ludate.msg_st.time.mm) ? 1 : -1);
}
return((ai->ludate.msg_st.time.hh < bi->ludate.msg_st.time.hh) ? 1 : -1);
}
return((ai->ludate.msg_st.date.da < bi->ludate.msg_st.date.da) ? 1 : -1);
}
return((ai->ludate.msg_st.date.mo < bi->ludate.msg_st.date.mo) ? 1 : -1);
}
return((ai->ludate.msg_st.date.yr < bi->ludate.msg_st.date.yr) ? 1 : -1);
}
/* From: Ray Gardner */
/* qsort2() -- Shell sort Raymond Gardner public domain 11/91
**
** A version of qsort that uses Shell's sort algorithm.
*/
void qsort2(void *base, unsigned nel, unsigned width,
int (*comp)(const void *, const void *))
{
unsigned int wnel, gap, wgap, i, j, k;
char *a, *b, tmp;
wnel = width * nel;
for(gap = 0; ++gap < nel;)
gap *= 3;
while ( gap /= 3 )
{
wgap = width * gap;
for ( i = wgap; i < wnel; i += width )
{
for ( j = i - wgap; ;j -= wgap )
{
a = j + (char *)base;
b = a + wgap;
if((*comp)(a, b) <= 0)
break;
k = width;
do
{
tmp = *a;
*a++ = *b;
*b++ = tmp;
} while ( --k );
if(j < wgap)
break;
}
}
}
}