home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
UTILITY
/
ES102.ARJ
/
GFE.C
< prev
next >
Wrap
Text File
|
1990-07-16
|
12KB
|
507 lines
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <dos.h>
#include <stdlib.h>
#include <sys\stat.h>
#include <dir.h>
#include "vardec.h"
#define DO_PW_CHECK
/* delete or comment out above line if sysop password check is not desired */
int usernum, /* user number for the user */
age, /* age of the user */
screenchars, /* chars/line user has specified */
screenlines, /* lines/screen user has specified */
sl, /* sec lev for user (0-255) */
so, /* non-zero if user is sysop (sl=255) */
cs, /* non-zero if user is co-sysop */
okansi, /* non-zero if user can support ANSI */
incom, /* non-zero if user is calling remotely */
comport; /* com port user is on */
char name[81], /* name/alias of user */
realname[81], /* real name of user */
callsign[10], /* amateur radio callsign of user */
sex, /* sex of user, M or F */
laston[81], /* date user was last on */
gfiles[81], /* directory for text files, ends in \ */
data[81], /* directory for non-text files, ends in \ */
sysoplog[81], /* full path & filename for sysop log */
curspeed[81]; /* speed user is on at, "KB" if local */
double gold, /* gold user has */
timeallowed, /* number of seconds before user logged off */
version; /* version of WWIV running under */
configrec syscfg;
int num_sec;
gfiledirrec gfilesec[32];
char cdir[81];
void far interrupt (*inli)(char *, char *, int, int);
void far interrupt (*checka)(int *, int *);
void far interrupt (*pla)(char *, int *);
void far interrupt (*outchr)(char);
void far interrupt (*outstr)(char *);
void far interrupt (*nl)();
void far interrupt (*pl)(char *);
int far interrupt (*empty)();
char far interrupt (*inkey)();
unsigned char far interrupt (*getkey)();
void far interrupt (*input)(char *, int);
void far interrupt (*inputl)(char *, int);
int far interrupt (*yn)();
int far interrupt (*ny)();
void far interrupt (*ansic)(int);
char far interrupt (*onek)(char *);
void far interrupt (*prt)(int, char *);
void far interrupt (*mpl)(int);
void far **funcs;
int read_in_data(char *fn)
{
char buf[1024];
char *ptr[30],*ss,s[81];
int i,f,len,i1;
float fl;
f=open(fn,O_RDONLY | O_BINARY);
if (f<0) {
return(-1);
}
i1=1;
ptr[0]=buf;
len=read(f,(void *)buf,1024);
close(f);
for (i=0; i<len; i++)
if (buf[i]==13) {
buf[i]=0;
ptr[i1++]=&buf[i+2];
}
while (*ptr[6]==32)
++(ptr[6]);
while (*ptr[15]==32)
++(ptr[15]);
usernum=atoi(ptr[0]);
strcpy(name,ptr[1]);
strcpy(realname,ptr[2]);
strcpy(callsign,ptr[3]);
age=atoi(ptr[4]);
sex=*ptr[5];
sscanf(ptr[6],"%f",&fl);
gold=(double)fl;
strcpy(laston,ptr[7]);
screenchars=atoi(ptr[8]);
screenlines=atoi(ptr[9]);
sl=atoi(ptr[10]);
so=atoi(ptr[11]);
cs=atoi(ptr[12]);
okansi=atoi(ptr[13]);
incom=atoi(ptr[14]);
sscanf(ptr[15],"%f",&fl);
timeallowed=(double)fl;
strcpy(gfiles,ptr[16]);
strcpy(data,ptr[17]);
strcpy(sysoplog,gfiles);
strcat(sysoplog,ptr[18]);
strcpy(curspeed,ptr[19]);
comport=atoi(ptr[20]);
version=-1.0;
ss=getenv("BBS");
if (strncmp(ss,"WWIV",4)) {
printf("\nThis program MUST be run under WWIV v4.07 or later.\n");
exit(0);
}
strcpy(s,&(ss[6]));
i=(s[0]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
version=((double)i)/100.0;
if (i<407) {
printf("\nThis program requires WWIV v4.07 or later.\n");
exit(0);
}
funcs=(void far *)getvect(0x6a);
inli=funcs[0];
checka=funcs[1];
pla=funcs[2];
outchr=funcs[3];
outstr=funcs[4];
nl=funcs[5];
pl=funcs[8];
empty=funcs[9];
inkey=funcs[10];
getkey=funcs[11];
input=funcs[12];
inputl=funcs[13];
yn=funcs[14];
ny=funcs[15];
ansic=funcs[16];
onek=funcs[17];
prt=funcs[18];
mpl=funcs[19];
return(0);
}
int checkpw()
{
#ifdef DO_PW_CHECK
char s[81];
nl();
prt(2,"SY: ");
input(s,20);
if (strcmp(s,(syscfg.systempw))==0)
#endif
return(1);
#ifdef DO_PW_CHECK
else
return(0);
#endif
}
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 pausescr()
{
int i;
outstr("[PAUSE]");
getkey();
for (i = 0; i < 7; i++)
outstr("\b \b");
}
void gfiledata(int n, char *s)
{
char x,y,k,i;
gfiledirrec r;
r=gfilesec[n];
if (r.ar==0)
x=32;
else {
for (i=0; i<16; i++)
if ((1 << i) & r.ar)
x='A'+i;
}
sprintf(s,"%2d %1c %-40s %-8s %-3d %-3d %-3d",
n,x,r.name,r.filename,r.sl,r.age,r.maxfiles);
}
void showsec()
{
int abort,i;
char s[180];
outchr(12);
abort=0;
pla("NN AR Name FN SL AGE MAX",
&abort);
pla("-- == ---------------------------------------- ======== --- === ---",
&abort);
for (i=0; (i<num_sec) && (!abort); i++) {
gfiledata(i,s);
pla(s,&abort);
}
}
int exist_dir(char *s)
{
int ok;
cd_to(syscfg.gfilesdir);
if (chdir(s))
ok=0;
else
ok=1;
cd_to(cdir);
return(ok);
}
void modify_sec(int n)
{
gfiledirrec r;
char s[81],s1[81],s2[81],ch,ch2;
int i,i1,done;
r=gfilesec[n];
done=0;
do {
outchr(12);
sprintf(s2, "A. Name : %s",r.name); pl(s2);
sprintf(s2, "B. Filename : %s",r.filename); pl(s2);
itoa(r.sl,s,10);
sprintf(s2, "C. SL : %s",s); pl(s2);
itoa(r.age,s,10);
sprintf(s2, "D. Min. Age : %s",s); pl(s2);
itoa(r.maxfiles,s,10);
sprintf(s2, "E. Max Files : %s",s); pl(s2);
strcpy(s,"None.");
if (r.ar!=0) {
for (i=0; i<16; i++)
if ((1 << i) & r.ar)
s[0]='A'+i;
s[1]=0;
}
sprintf(s2, "F. AR : %s",s); pl(s2);
nl();
prt(2,"Which (A-F,Q) ? ");
ch=onek("QABCDEF");
switch(ch) {
case 'Q':done=1; break;
case 'A':
nl();
prt(2,"New Name? ");
inputl(s,40);
if (s[0])
strcpy(r.name,s);
break;
case 'B':
nl();
if (exist_dir(r.filename)) {
nl();
pl("There is currently a directory for this g-file section.");
pl("If you change the filename, the directory will still be there.");
nl();
}
nl();
prt(2,"New Filename? ");
input(s,8);
if ((s[0]!=0) && (strchr(s,'.')==0)) {
strcpy(r.filename,s);
if (!exist_dir(r.filename)) {
nl();
prt(5,"Create directory for this section? ");
if (yn()) {
cd_to(syscfg.gfilesdir);
i = mkdir(r.filename);
if (i == -1) {
nl();
pl("Could not create directory.");
nl();
}
cd_to(cdir);
} else {
nl();
pl("You will have to create the directory manually, then.");
nl();
}
} else {
nl();
pl("A directory already exists under this filename.");
nl();
}
pausescr();
}
break;
case 'C':
nl();
prt(2,"New SL? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<256) && (s[0]))
r.sl=i;
break;
case 'D':
nl();
prt(2,"New Min Age? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<128) && (s[0]))
r.age=i;
break;
case 'E':
nl();
pl("Max 99 files/section.");
prt(2,"New Max Files? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<99) && (s[0]))
r.maxfiles=i;
break;
case 'F':
nl();
prt(2,"New AR (<SPC>=None) ? ");
ch2=onek("ABCDEFGHIJKLMNOP ");
if (ch2==32)
r.ar=0;
else
r.ar=1 << (ch2-'A');
break;
}
} while (!done);
gfilesec[n]=r;
}
void insert_sec(int n)
{
gfiledirrec r;
int i,i1,nu;
for (i=num_sec-1; i>=n; i--)
gfilesec[i+1]=gfilesec[i];
strcpy(r.name,"** NEW SECTION **");
strcpy(r.filename,"NONAME");
r.sl=10;
r.age=0;
r.maxfiles=99;
r.ar=0;
gfilesec[n]=r;
++num_sec;
modify_sec(n);
}
void delete_sec(int n)
{
int i,i1,nu;
char s[81],s1[81];
int f1;
struct ffblk ff;
prt(5, "Delete data files? ");
if (yn()) {
sprintf(s, "%s%s.GFL", syscfg.datadir, gfilesec[n].filename);
unlink(s);
}
prt(5, "Delete all text files in that section's directory? ");
if (yn()) {
sprintf(s, "%s%s\\*.*", syscfg.gfilesdir, gfilesec[n].filename);
f1=findfirst(s,&ff,0);
while (f1==0) {
sprintf(s, "%s%s\\%s", syscfg.gfilesdir, gfilesec[n].filename,
ff.ff_name);
unlink(s);
sprintf(s1, "Deleting %s...", ff.ff_name);
pl(s1);
f1=findnext(&ff);
}
prt(5, "Delete G-File section directory? ");
if (yn()) {
sprintf(s, "%s%s", syscfg.gfilesdir, gfilesec[n].filename);
f1=rmdir(s);
}
}
for (i=n; i<num_sec; i++)
gfilesec[i]=gfilesec[i+1];
--num_sec;
}
void gfileedit()
{
int i,i1,i2,done,f;
char s[81],s1[81],s2[81],ch;
if (!checkpw())
return;
showsec();
done=0;
do {
nl();
prt(2,"G-files: D:elete, I:nsert, M:odify, Q:uit, ? : ");
ch=onek("QDIM?");
switch(ch) {
case '?':
showsec();
break;
case 'Q':
done=1;
break;
case 'M':
nl();
prt(2,"Section number? ");
input(s,2);
i=atoi(s);
if ((s[0]!=0) && (i>=0) && (i<num_sec))
modify_sec(i);
break;
case 'I':
if (num_sec<32) {
nl();
prt(2,"Insert before which section? ");
input(s,2);
i=atoi(s);
if ((s[0]!=0) && (i>=0) && (i<=num_sec))
insert_sec(i);
}
break;
case 'D':
nl();
prt(2,"Delete which section? ");
input(s,2);
i=atoi(s);
if ((s[0]!=0) && (i>=0) && (i<num_sec)) {
nl();
strcpy(s1,"Delete ");
strcat(s1,gfilesec[i].name);
strcat(s1,"? ");
prt(5,s1);
if (yn())
delete_sec(i);
}
break;
}
} while (!done);
strcpy(s,syscfg.datadir);
strcat(s,"GFILE.DAT");
f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
write(f,(void *)(&gfilesec[0]), num_sec * sizeof(gfiledirrec));
close(f);
}
void main(int argc, char *argv[])
{
char s[81];
int i;
if (argc<2)
strcpy(s,"chain.txt");
else
strcpy(s,argv[1]);
if (read_in_data(s)==-1) {
printf("\nData file not found: %s\n\n", s);
abort();
}
strcpy(s,"CONFIG.DAT");
i=open(s,O_RDWR | O_BINARY);
if (i<0) {
printf("%s NOT FOUND.\n",s);
exit(1);
}
read(i, (void *)(&syscfg), sizeof(configrec));
close(i);
strcpy(cdir,"X:\\");
cdir[0]='A'+getdisk();
getcurdir(0,&(cdir[3]));
sprintf(s, "%sGFILE.DAT", syscfg.datadir);
i=open(s, O_RDWR | O_BINARY);
if (i<0)
num_sec=0;
else
num_sec=read(i,(void *)gfilesec,32*sizeof(gfiledirrec))/sizeof(gfiledirrec);
close(i);
gfileedit();
}