home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
MYWIVE.ZIP
/
GFLEDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-06
|
6KB
|
297 lines
#include "vars.h"
#pragma hdrstop
#include <dir.h>
#define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
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],ch,ch2;
int i,i1,done;
r=gfilesec[n];
done=0;
do {
outchr(12);
npr("A. Name : %s\r\n",r.name);
npr("B. Filename : %s\r\n",r.filename);
npr("C. SL : %d\r\n",r.sl);
npr("D. Min. Age : %d\r\n",r.age);
npr("E. Max Files : %d\r\n",r.maxfiles);
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;
}
npr("F. AR : %s\r\n",s);
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);
mkdir(r.filename);
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) && (!hangup));
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;
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;
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();
ansic(5);
npr("Delete %s? ",gfilesec[i].name);
if (yn())
delete_sec(i);
}
break;
}
} while ((!done) && (!hangup));
sprintf(s,"%sGFILE.DAT",syscfg.datadir);
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);
}
int fill_sec(int sn)
{
gfilerec *g,g1;
int f1,nf,ok,i,i1,i2,chd;
char s[81],s1[81];
struct ffblk ff;
g=read_sec(sn,&nf);
sprintf(s1,"%s%s\\*.*",syscfg.gfilesdir,gfilesec[sn].filename);
f1=findfirst(s1,&ff,0);
ok=1;
chd=0;
while ((f1==0) && (!hangup) && (nf<gfilesec[sn].maxfiles) && (ok)) {
strcpy(s,(ff.ff_name));
align(s);
i=1;
for (i1=0; i1<nf; i1++)
if (compare(s,g[i1].filename))
i=0;
if (i) {
ansic(2);
npr("%s : ",s);
inputl(s1,60);
if (s1[0]) {
chd=1;
i=0;
while ((strcmp(s1,g[i].description)>0) && (i<nf))
++i;
for (i1=nf; i1>i; i1--)
g[i1]=g[i1-1];
++nf;
strcpy(g1.filename,s);
strcpy(g1.description,s1);
time(&(g1.daten));
g[i]=g1;
} else
ok=0;
}
f1=findnext(&ff);
}
if (!ok)
pl("Aborted.");
if (nf>=gfilesec[sn].maxfiles)
pl("Section full.");
if (chd) {
sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
i=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
write(i,(void *)g,nf*sizeof(gfilerec));
close(i);
}
farfree(g);
return(!ok);
}