home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
GFLEDIT.C
< prev
next >
Wrap
Text File
|
1991-12-26
|
7KB
|
329 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1991 by Wayne Bell
Distribution of the source code for WWIV, in any form, modified or unmodified,
without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
Distribution of compiled versions of WWIV is limited to copies compiled BY
THE AUTHOR. Distribution of any copies of WWIV not compiled by the author
is expressly prohibited.
*****************************************************************************/
#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,"3%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("3NN AR Name FN SL AGE MAX",
&abort);
pla("7════════════════════════════════════════════════════════════════════",
&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("1A.3 Name 1 :7 %s\r\n",r.name);
npr("1B.3 Filename 1 :7 %s\r\n",r.filename);
npr("1C.3 SL 1 :7 %d\r\n",r.sl);
npr("1D.3 Min. Age 1 :7 %d\r\n",r.age);
npr("1E.3 Max Files 1 :7 %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("1F.3 AR 1 :7 %s\r\n",s);
nl();
prt(7,"[1Which7] 5(1A-F,Q5) 3? ");
ch=onek("QABCDEF");
switch(ch) {
case 'Q':done=1; break;
case 'A':
nl();
prt(1,"New name? ");
inputl(s,40);
if (s[0])
strcpy(r.name,s);
break;
case 'B':
nl();
if (exist_dir(r.filename)) {
nl();
pl("3There is currently a directory for this g-file section.");
pl("3If you change the filename, the directory will still be there.");
nl();
}
nl();
prt(1,"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("3You will have to create the directory manually, then.");
nl();
}
} else {
nl();
pl("3A directory already exists under this filename.");
nl();
}
pausescr();
}
break;
case 'C':
nl();
prt(1,"New SL? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<256) && (s[0]))
r.sl=i;
break;
case 'D':
nl();
prt(1,"New Min Age? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<128) && (s[0]))
r.age=i;
break;
case 'E':
nl();
pl("7Max 99 files/section.");
prt(1,"New max files? ");
input(s,3);
i=atoi(s);
if ((i>=0) && (i<99) && (s[0]))
r.maxfiles=i;
break;
case 'F':
nl();
prt(1,"New AR 5(7<1SPC7>1=None5) 1? ");
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;
if (!checkpw())
return;
showsec();
done=0;
do {
nl();
prt(1,"G-files: 7D1:elete, 7I1:nsert, 7M1:odify, 7Q1:uit, ? : ");
ch=onek("QDIM?");
switch(ch) {
case '?':
showsec();
break;
case 'Q':
done=1;
break;
case 'M':
nl();
prt(1,"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(1,"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(1,"Delete which section? ");
input(s,2);
i=atoi(s);
if ((s[0]!=0) && (i>=0) && (i<num_sec)) {
nl();
ansic(5);
npr("3Delete %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("6Aborted.");
if (nf>=gfilesec[sn].maxfiles)
pl("6Section 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);
}