home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
TAM121.ZIP
/
UTS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-10
|
5KB
|
193 lines
/***************************************************************************/
/* This program, UTS (Update Transfer Stats) takes three commandline */
/* parameters: the user number to update, the number of files to add (or */
/* delete) from that caller's upload stats, and the number of k to add (or */
/* delete) from that caller's upload stats. This program does nothing to */
/* the screen but will return an errorlevel of 1 on exit if the update was */
/* unsuccessful, or 0 if it was successful. */
/* */
/* Jon R. Rickher */
/* February 3, 1992 */
/* Tolkien 1 @3456 */
/* */
/***************************************************************************/
#include <sys\stat.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <dir.h>
#include "vardec.h"
int configfile;
int userfile;
int whichuser;
int numfiles;
int numk;
char s[81];
userrec u;
configrec cfg;
void fix_user_rec(userrec *u)
{
u->name[30]=0;
u->realname[20]=0;
u->callsign[6]=0;
u->phone[12]=0;
u->pw[8]=0;
u->laston[8]=0;
u->note[40]=0;
u->macros[0][80]=0;
u->macros[1][80]=0;
u->macros[2][80]=0;
}
void close_user()
{
if (userfile!=-1) {
close(userfile);
userfile=-1;
}
}
void open_user()
{
char s[81];
if (userfile==-1) {
sprintf(s,"%sUSER.LST",cfg.datadir);
userfile=open(s,O_RDWR | O_BINARY);
if (userfile<0) {
userfile=-1;
}
}
}
int number_userrecs()
{
open_user();
return((int) (filelength(userfile)/cfg.userreclen)-1);
}
int read_user(unsigned int un, userrec *u)
{
long pos;
char s[80];
int i;
open_user();
if ((userfile<0) || (un>number_userrecs())) {
u->inact=inact_deleted;
fix_user_rec(u);
return(0);
}
pos=((long) cfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=read(userfile, (void *)u, cfg.userreclen);
if (i==-1) {
open_user();
if ((userfile<0) || (un>number_userrecs())) {
u->inact=inact_deleted;
fix_user_rec(u);
return(0);
}
pos=((long) cfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=read(userfile, (void *)u, cfg.userreclen);
if (i==-1) {
close_user();
return(0);
}
close_user();
}
fix_user_rec(u);
return(1);
}
int write_user(unsigned int un, userrec *u)
{
long pos;
char s[80];
unsigned char oldsl;
int i;
if (userfile==-1) {
sprintf(s,"%sUSER.LST",cfg.datadir);
userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
}
pos=((long) cfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=write(userfile, (void *)u, cfg.userreclen);
if (i==-1) {
sprintf(s,"%sUSER.LST",cfg.datadir);
userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
pos=((long) cfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=write(userfile, (void *)u, cfg.userreclen);
if (i==-1) {
close_user();
return(0);
}
close_user();
}
return(1);
}
void main(int argc, char *argv[])
{
int i;
int okay;
userfile=-1;
okay=1;
if (argc != 4)
exit(1);
for (i=1; i<argc; i++) {
strcpy(s,argv[i]);
switch(i) {
case 1: if (atoi(s))
whichuser=atoi(s);
else
okay=0;
break;
case 2: if (okay)
if (atoi(s))
numfiles=atoi(s);
else
okay=0;
break;
case 3: if (okay)
if (atoi(s))
numk=atoi(s);
else
okay=0;
break;
}
}
if (!okay)
exit(1);
configfile=open("CONFIG.DAT",O_RDWR | O_BINARY);
if (configfile<0) {
exit(1);
}
read(configfile,(&cfg), sizeof(configrec));
close(configfile);
if (read_user(whichuser,&u)>0) {
u.uploaded += numfiles;
u.uk += numk;
write_user(whichuser,&u);
close_user();
exit(0);
}
exit(1);
}