home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
WWIV412S.ZIP
/
GFLEDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-25
|
8KB
|
364 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988 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 "vardec.h"
#include "fcns.h"
#include "net.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <dir.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <alloc.h>
#include <dos.h>
extern gfiledirrec *gfilesec;
extern int num_sec,hangup,userfile,echo,useron,userfile,usernum,using_modem;
extern int incom,fwaiting,userfile;
extern configrec syscfg;
extern statusrec status;
extern char ctypes[NUM_CTYPES][18];
extern char cdir[81];
extern userrec thisuser;
extern int numextrn, numchain;
extern chainfilerec *chains;
extern externalrec *externs;
extern smalrec *smallist;
extern int num_call_sys,num_ncn,num_sys_list,global_xx;
extern net_contact_rec *ncn;
extern net_call_out_rec *con;
extern net_interconnect_rec *cnn;
extern messagerec helps[50],menus[30],menus1[30],menus2[30];
extern long last_time_c;
extern unsigned char realsl;
extern net_system_list_rec *csn;
#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);
print("A. Name : ",r.name,"");
print("B. Filename : ",r.filename,"");
itoa(r.sl,s,10);
print("C. SL : ",s,"");
itoa(r.age,s,10);
print("D. Min. Age : ",s,"");
itoa(r.maxfiles,s,10);
print("E. Max Files : ",s,"");
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;
}
print("F. AR : ",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;
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) && (!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) {
strcpy(s1,s);
strcat(s1," : ");
prt(2,s1);
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);
}