home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
c
/
crcbbs.arc
/
CRCPC1B.C
< prev
next >
Wrap
Text File
|
1985-10-22
|
21KB
|
759 lines
#include "crcpchdr.h"
int fork_board(c,args,opts)
char c, *args, *opts;
{
char *type;
int rc;
if (!fork_allowed) {
printf("Sorry, this command has been disabled.\r\n");
return(99);
}
if (!*args && beginner && !find_option(opts,'q')) disp_msg(16);
if (no_account) {
printf("You must first obtain an account before\r\n");
printf("using this command. See <A> command at main menu.\r\n");
return(99);
}
if (*args) {
stptok(args,workstr,9," ");
goto tryth1;
}
getdnagn:
if (*args) return(1000);
disp_reply("Enter name for new message board: ",workstr,9);
if (!workstr[0]) return(nothing_done()&0);
tryth1:
if (type=stpbrk(workstr,INVDOSFNCHR)) {
bad_dn(*type);
goto getdnagn;
}
uppercase(workstr);
if (!sysdir(workstr,user_root)) {
printf("There exists a user '%s' on the system. Use another name.r\n",workstr);
goto getdnagn;
}
else if (!sysdir(workstr,MESSAGES)) {
printf("There already exists a '%s' board!\r\n",workstr);
goto getdnagn;
}
printf("Standby:\r\n");
/* Rc==2 when using -XT (??) */
if ((rc=sysmkdir(workstr,MESSAGES)) && rc!=2) {
printf("Oops! Error during directory creation.\r\n");
printf("Not today: sorry.\r\n");
sprintf(file_buff,"MESSAGE BOARD '%s' CREATION BY %s FAILED: RC=%d",
workstr,user_id,rc);
logevent(file_buff);
}
else {
printf("Ok %s, message directory '%s' created and ready for use.\r\n",
usname(),workstr);
sprintf(file_buff,"MESSAGE BOARD '%s' CREATED BY %s",workstr,user_id);
logevent(file_buff);
}
return(0);
}
kill_board(c,args,opts)
char c, *args, *opts;
{
int gnl_flag;
char *type;
if (!fork_allowed) {
printf("Sorry, this command has been disabled.\r\n");
return;
}
if (!*args && !find_option(opts,'q') && beginner) disp_msg(17);
if (no_account) {
printf("You must first obtain an account before\r\n");
printf("using this command. See <A> command at main menu.\r\n");
return;
}
if (*args) {
stptok(args,workstr,9," ");
goto tryth2;
}
g2tdnagn:
if (*args) return;
printf("Enter name of message board to kill: ");
strcpy(workstr,lineinput(9));
if (!workstr[0]) return(nothing_done());
tryth2:
if (type=stpbrk(workstr,INVDOSFNCHR)) {
bad_dn(*type);
goto g2tdnagn;
}
uppercase(workstr);
if (sysdir(workstr,MESSAGES)) {
printf("No such board.\r\n");
return;
}
else if (!setup_dir("*.*",FILE_TYP)) {
printf("Directory '%s' has files in it!\r\n",workstr);
return;
}
printf("Please wait; this takes awhile sometimes...\r\n");
sysdir("",MESSAGES);
if (gnl_flag=sysrmdir(workstr,MESSAGES)) {
if (gnl_flag==5) {
printf("'%s' has files in it!\r\n",workstr);
return;
}
else if (gnl_flag==3) printf("No such board: '%s'!\r\n",workstr);
goto g2tdnagn;
}
else {
printf("Ok %s, message board '%s' has been removed.\r\n",usname(),workstr);
sprintf(file_buff,"MESSAGE BOARD %s REMOVED BY %s",workstr,user_id);
logevent(file_buff);
}
}
msg_sys(c,args,opts)
char c, *args, *opts;
{
char messtyp[15];
int quiet, ags;
ags = (*args);
quiet = find_option(opts,'q');
do {
if (sysdir("",MESSAGES)) {
printf("Cannot access message tree: %s.\r\n",MESSAGES);
return;
}
else {
if (beginner && !quiet && !*args) {
mputs("Enter the name of a system message board.\r\n");
mputs("For a list of current message boards, type <*>, or <ENTER> to quit\r\n");
cr();
}
brdlist:
if (!*args) disp_reply("Message board? ",boardname,9);
else args = stpblk(stptok(args,boardname,9," "));
while(boardname[0]=='*') {
dir("*.*",DIR_TYP);
disp_reply("Message board? ",boardname,9);
}
if (boardname[0]) {
if (sysdir(boardname,MESSAGES))
printf("Message board '%s' not found.\r\n",boardname);
else {
if (wildcards) {
if (!*args) {
if (beginner && !quiet) {
mputs("You may use UNIX, and CP/M style 'wildcards' which are\r\n");
mputs("used in selecting the messages you access. The filename\r\n");
mputs("is the name of the sender, the extension is msg #.\r\n");
}
disp_reply("Enter wildcard or press <ENTER>: ",messtyp,9);
}
else args = stpblk(stptok(args,messtyp,9," "));
if (messtyp[0]=='\0') strcpy(messtyp,"*.*");
else if (stpchr(messtyp,'.')==NULL) strcat(messtyp,".*");
}
else strcpy(messtyp,"*.*");
msgdir(boardname,messtyp,args,opts);
}
}
}
} while(boardname[0] && !ags);
}
/* MOVETOBOARD: We are logged onto the BOARD directory we want a users file
to go to. First, we determine the message number, then copy it.
*/
static movetoboard(bname,fname,udir)
char bname[];
char fname[];
char udir[];
{
int rc;
int lm;
char sourcen[15];
char extn[5];
char newdir1[40];
char newdir2[33];
if (rc=setup_dir("*.*",FILE_TYP)) lm = 1; /* Setup for msg scan */
else {
create_list(); /* Create memory array from names */
sort_list(list,list_idx); /* Sort the names */
lm = list[list_idx-1]->value+1;
drop_list();
}
strcpy(sourcen,user_id); /* Get senders name as filename */
sprintf(extn,".%d",lm); /* Next avail. msg # */
strcat(sourcen,extn); /* Create filename */
prefix_dir(newdir1,bname,MESSAGES);
prefix_dir(newdir2,udir,user_root);
/* text,create */
if (!sysfcopy(newdir1,sourcen,newdir2,fname,TRUE,TRUE)) {
printf("Msg %d saved into %s message board.\r\n",lm,bname);
sprintf(newdir1,"%s POSTED MSG#%d TO %s",user_id,lm,bname);
logevent(newdir1);
}
}
/*****************************************************************************
* MSGDIR: Perform disk directory into string array. Sort array, then *
* goto user with sorted list, allowing access to files in list. *
*****************************************************************************/
static int msgdir(board,fn,args,opts)
char board[];
char *fn ;
char *args, *opts;
{
int rc;
int lastmsg;
int mo,dy,yr;
sysdate(&mo,&dy,&yr);
uppercase(board);
if (sysdir(board,MESSAGES)) return(baddir(board));
if (rc=setup_dir(fn,FILE_TYP)) ;
else {
create_list(); /* Create memory array from names */
sort_list(list,list_idx); /* Sort the names */
lastmsg = l_u_msg(board); /* Find out where he was */
if (!strcmp(fn,"*.*") && /* If on entire board */
!no_account) /* And user has account */
if (list[list_idx-1]->value==l_b_msg(board) && !find_option(opts,'q'))
printf("No new messages.\r\n");
lastmsg = goto_user(lastmsg,board,fn,args,opts);
if (!strcmp(fn,"*.*") && /* If on entire board */
!no_account) /* And user has account */
a_u_msg(board,list[list_idx-1]->value,lastmsg,mo,dy,yr);
drop_list(); /* Drop the names from memory */
}
return(rc);
}
static char *smsg_fnc(c)
char c;
{
switch(c) {
case 'W': return("WSCAN");
case 'R': return("READ");
case 'S': return("SCAN");
case 'D': return("DELETE");
}
return("");
}
/* NOTE: LIST_IDX is defined as being positive during thes routines ! */
static int next_midx(msgnum)
int msgnum;
{
int i;
for (i=0;i<list_idx;++i) if (list[i]->value>msgnum) break;
return(i<list_idx?i:-1);
}
/* NEXT_IDX: We search forward or backward until finding non deleted filename */
/* Return "-1" if not found */
static int next_idx(sidx,dir)
int sidx;
int dir;
{
for (sidx+=dir;sidx>=0 && sidx<list_idx;sidx+=dir)
if (list[sidx]->filedata.filename_char[0]!='*'&&list[sidx]->value) break;
return((sidx>=0 && sidx<list_idx)?sidx:-1);
}
/*****************************************************************************
* FIRST_IDX: Find index to first file number in array. *
* Returns "-1" if no data in array. *
*****************************************************************************/
static int first_idx()
{
return(next_midx(0));
}
/*****************************************************************************
* FIND_IDX: Find index to corresponding file number in the array. *
* Return index to indicated file number, else -1 for not found. *
*****************************************************************************/
static int find_idx(msgnum)
int msgnum;
{
int i;
if ((i=first_idx())!=-1)
while(i<list_idx)
if (list[i]->value==msgnum) return(i);
else i++;
return (-1);
}
/* Returns '0' if no message files in array, else first message number */
static int first_msg()
{
int ans;
ans = list_idx ? list[first_idx()]->value : 0;
return(ans);
}
/* Returns '0' if no message files in array, else last message number */
static int last_msg()
{
int ans;
ans = list_idx ? list[list_idx-1]->value : 0;
return(ans);
}
/* Returns '0' if no message files in array, else number of messages in array */
/* NOTE: The result of this routine is incorrect if any 'deleted' files exist */
/* in the array */
static int tot_msg()
{
int ans;
ans = list_idx ? list_idx-first_idx() : 0;
return(ans);
}
/*****************************************************************************
* GOTO_USER: We have a sorted list of file entries in the string array. *
* We present an acceptable method of accessing these files here. *
*****************************************************************************/
static int goto_user(lstusrmsg,board,filter,args,opts)
int lstusrmsg;
char board[];
char filter[];
char *args, *opts;
{
char c;
int mode;
int index;
int alt_index;
int alt_msg;
int quiet;
int firstmsgnum, lastmsgnum, totmsgs;
char fromwho[9];
char token[LINESIZE+2];
char *parseptr;
char string[LINESIZE+2];
quiet = find_option(opts,'q');
quit = FALSE;
firstmsgnum = first_msg();
lastmsgnum = last_msg();
if (!list_idx || !lastmsgnum) {
printf("No messages (%s) on %s board.\r\n",filter,board);
return(0);
}
/* Get index to next msg */
if ((index=next_midx(lstusrmsg)==-1)) index=list_idx-1; /* In case not found */
totmsgs = tot_msg();
if (totmsgs>1) strcpy(string,"s");
else string[0] = '\0';
printf("%d message%s (%s) on %s: %d-%d\r\n",totmsgs,string,filter,board,firstmsgnum,lastmsgnum);
do {
output = TRUE;
if (!*args) {
if (!quiet && beginner) {
mputs("--------------\r\n");
mputs("Message Access\r\n");
mputs("--------------\r\n");
cr();
mputs("Press <ENTER> to return to main level.\r\n");
}
printf("(%s: W,R,S,D,?): ",board);
c = *ltrim(lineinput(2));
}
else {
c = *args ;
args = skptok(args);
}
if (c=toupper(c)) {
if (stpchr("WRSD?",c)==NULL) printf("? %c: type ? for help.\r\n",c);
else if (c=='?') help(SYSACC,opts);
else {
if (c!='D' && beginner && !quiet) msgaccinst(c,index);
do {
get_name(fromwho,list[index]->filedata.filename_ext);
quit = FALSE;
if (beginner && !quiet) {
sprintf(token,"Current message: %d\r\n",list[index]->value);
mputs(token);
}
if (!*args) {
if (beginner && !quiet) printf("Press <ENTER> to return.\r\n");
sprintf(token,"(%s [%d-%d]: Y=%d, ?=help): ",
smsg_fnc(c),firstmsgnum,lastmsgnum,list[index]->value);
mputs(token);
strcpy(string,lineinput(LINESIZE));
}
else strcpy(string,args);
output = TRUE;
if (string[0]) index=perform_line(c,string,index,opts);
} while (string[0] && index>=0 && !*args);
} /* End Else */
} /* End IF */
if (index<0) printf("All messages deleted.\r\n");
} while(c && index>=0 && !*args);
/* Point to last msg read */
index = index==list_idx-1?index:index-1;
index = chk_idx(index);
return(index<0?0:list[index]->value);
}
/* End GOTO USER */
static int perform_line(c,string,index,opts)
char c;
char string[];
int index;
char *opts;
{
int alt_index;
int alt_msg;
char token[LINESIZE+2];
char *parseptr;
parseptr = stpblk(string);
*parseptr = toupper(*parseptr);
/* Make 'FORWARD', 'REVERSE' and 'BACKWARD' work too */
if (*parseptr=='F') *parseptr = '+';
else if (*parseptr=='B' || *parseptr=='R') *parseptr = '-';
if (*parseptr=='Y') index=access(c,index,'+',1,opts);
else if (*parseptr=='?') help(SYSMSG,opts);
else if (*parseptr=='-'||*parseptr=='+') index=access(c,index,*parseptr,999,opts);
else {
while(*parseptr && !quit && index>=0) {
parseptr = stptok(parseptr,token,sizeof(token)," ,#;:-+\n");
alt_msg = stoi(token);
if (!alt_msg) printf("Bad msg #%s\r\n",token);
else if (*stpblk(parseptr)=='+'||*stpblk(parseptr)=='-') {
parseptr = stpblk(parseptr);
if ((alt_index=next_midx(alt_msg-1))<0) msgnf(alt_msg);
else index=access(c,alt_index,*parseptr,999,opts);
}
else {
if ((alt_index=find_idx(alt_msg))<0) msgnf(alt_msg);
else index=access(c,alt_index,'+',1,opts);
}
if (*parseptr) parseptr = stpblk(++parseptr);
} /* End While */
} /* End Else */
/* Return index to NEXT msg to read, or "-1" */
return(index);
}
static msgnf(mn)
int mn;
{
printf("#%d not found.\r\n",mn);
}
static int user_is_sure()
{
char c;
mputs("Enter <Y> if you are sure. ");
c = *ltrim(lineinput(2));
return((toupper(c)=='Y'));
}
static int access(function,index,direction,max,opts)
char function;
int index;
char direction;
int max;
char *opts;
{
int inc;
char filename[14];
char workstr[LINESIZE];
char fname[9];
char c;
int i;
int gnl_flg;
int ctr;
int alt_index ;
for (ctr=0,inc=(direction=='-')?-1:1;ctr<max &&
list_idx &&
index>=first_idx() &&
index<list_idx &&
!quit;index+=inc,ctr++) {
if (bdos(KBHIT)) {
c = bdos(CONSINP);
c = toupper(c);
if (c==CTL_K || c=='K') {
quit = TRUE;
cr();
break;
}
else if (!c) local_function(bdos(CONSINP));
}
get_name(fname,list[index]->filedata.filename_ext);
if (fname[0]!='*') { /* Not been deleted */
if (function=='D') del_msg(uppercase(fname),index);
else if (function=='W') { /* Wscan */
sprintf(workstr,"%d by %s on %s is %ld chars\r\n",
list[index]->value,
get_name(filename,list[index]->filedata.filename_ext),
filedate(list[index]->filedata.file_date),
(long)list[index]->filedata.file_size);
mputs(workstr);
}
else r_or_sc(index,function,fname,opts); /* Read, or Scan */
} /* End If (file not already deleted) */
} /* End FOR */
index = chk_idx(index); /* make sure dont go out of bounds on 'list' */
if (index>=0) {
if (list[index]->filedata.filename_ext[0]=='*') {
if ((alt_index=next_idx(index,inc))<0)
alt_index=next_idx(index,0-inc);
index = alt_index ;
}
}
/* Return INDEX TO NEXT msg to read in curdir, or "-1" */
return(index);
}
/* End ACCESS */
static int chk_idx(idx)
int idx;
{
if (!list_idx) return(-1);
if (idx<first_idx()) idx = first_idx();
else if (idx>=list_idx) idx = list_idx-1;
return(idx);
}
static r_or_sc(index,function,fname,opts)
int index;
char function;
char fname[];
char *opts;
{
FILE *path;
int gnl_flag, i;
char workstr[LINESIZE];
if ((path=fopen((*list[index]).filedata.filename_ext,"r"))==NULL) {
printf("Msg '%s' was deleted.\r\n",
list[index]->filedata.filename_ext);
}
else {
switch(function) {
case 'R':
printf("Message #%d was ",list[index]->value);
printf("written by %s on %s at %s\r\n",
fname,
filedate(list[index]->filedata.file_date),
filetime(list[index]->filedata.file_time));
printf("(%ld characters)\r\n",(long)list[index]->filedata.file_size);
fileterm(path,opts);
cr();
break;
case 'S':
sprintf(workstr,"%d by %s on %s is %ld characters:\r\n",
list[index]->value,fname,
filedate(list[index]->filedata.file_date),
(long)list[index]->filedata.file_size);
mputs(workstr);
gnl_flag = TRUE;
for (i=0;i<MSGHDRSIZ && gnl_flag;++i)
if (gnl_flag=(fgets(workstr,LINESIZE,path)!=NULL))
mputs(workstr);
cr();
break;
} /* End Switch */
if (path!=NULL) fclose(path);
} /* End Else (no error opening file) */
}
/* End Read or Scan */
static del_msg(fname,index)
char fname[];
int index;
{
if (strcmp(home_dir,uppercase(fname)) && /* Not creator of MSG, AND */
!syswrite) { /* no system write priveledges */
printf("Only the creator of the message, user %s, or\r\n",fname);
printf("the system operator may delete msg %d.\r\n",list[index]->value);
return;
}
else if (0 & (int)printf("Delete msg %d ? ",
list[index]->value) ||
!user_is_sure()) ;
else if (unlink(list[index]->filedata.filename_ext)) {
printf("Error during delete of msg %d.\r\n",list[index]->value);
}
else {
printf("Message %d deleted.\r\n",list[index]->value);
list[index]->filedata.filename_ext[0]='*'; /* Zap */
}
}
/* SMFILE: Send MAIL file */
smfile(c,args,opts)
char c, *args, *opts;
{
char boardname[11], filename[17], alt_user[11], mailfile[17];
char b, *ftype, *type, *delete, *t1, *t2, *t3, *t4;
char comments[LINESIZE+2];
int gnl_flag, quiet, dlf, ndlf, posflg;
FILE *fp;
if (!has_auth("R",cur_dir,cur_root)) {
not_auth('R',cur_dir,cur_root);
return;
}
t4 = stpblk(threeparse(args,&t1,&t2,&t3));
quiet = find_option(opts,'q');
if (ndlf=find_option(opts,'k')) dlf = FALSE; /* Only one: Keep, or Delete */
else dlf=find_option(opts,'d');
posflg = (find_option(opts,'!') && *t3);
if (!*args && !quiet && beginner) disp_msg(20);
if (!*t1) {
disp_reply(file_prompt(beginner,"send"),filename,14);
if (filename[0]=='\0') return(nothing_done());
}
else stptok(t1,filename,sizeof(filename),"");
if (check_fn(filename,TRUE)) return;
if (check_rsvf(filename,TRUE)) return; /* Can't use reserved filename */
if ((fp=fopen(filename,"r"))==NULL) return(not_open());
else { /* 1 */
fclose(fp);
gnl_flag = FALSE;
uppercase(filename);
send_file:
if (!*t2) {
printf("Send message file: %s\r\n",filename);
if (beginner && !quiet) {
printf("If you want to use the public message board, type '%s'.\r\n",DEFLT_MSB);
printf("Enter username or message board name: ");
}
else printf("Boardname or user id: ");
disp_reply("",boardname,9);
}
else stptok(t2,boardname,sizeof(boardname),"");
uppercase(boardname);
strcpy(alt_user,boardname);
if (boardname[0]) {
if (!sysdir(boardname,MESSAGES))
movetoboard(boardname,filename,cur_dir);
else if (sysdir(boardname,user_root))
printf("No user directory '%s' found.\r\n",boardname);
else if (sysdir("",MAILBOX)) {
printf("Sorry, mail system inoperable.\r\n");
printf("System mail directory not found.\r\n");
}
/*3*/ else {
stccpy(mailfile,alt_user,sizeof(mailfile));
strcat(mailfile,MAIL_EXT);
if ((fp=fopen(mailfile,"a"))==NULL)
printf("Error opening user SYSMAIL file.\r\n");
/*4*/ else {
if (!*t3) {
printf("Enter 'M' for MAIL, or 'S' for file transfer: ");
b = *ltrim(lineinput(2));
}
else b = *t3;
if (toupper(b)=='S') {
ftype = "File";
type = "SEND";
if (!*t4) disp_reply("Enter optional comment line:\r\n",comments,LINESIZE);
else stptok(t4,comments,sizeof(comments),"");
}
else {
comments[0] = '\0';
type = "MAIL";
ftype = "Mail";
}
if (!(dlf||ndlf)) {
printf("File to be deleted when read (Y/N)? ");
b = *ltrim(lineinput(2));
}
else b = dlf?'Y':'N'; /* 'Y' if delete flag */
b = toupper(b);
if (b=='Y') delete = "DELETE";
else delete = "KEEP";
if (posflg) {
printf("%s file: %s to %s%s; CORRECT ? ",type,filename,
alt_user,b=='Y'?" and DELETE when read":"");
b = *ltrim(lineinput(4));
}
else b = 'Y';
if (toupper(b)!='Y') {
fclose(fp);
goto send_file;
}
sprintf(file_buff,"%s,%s,%s,%s,%s,%s,%s,%s\r\n",home_dir,filename,cur_dir,cur_root,delete,type,timedate(),comments);
fputs(file_buff,fp);
fclose(fp);
printf("%s (%s) posted for '%s'.\r\n",ftype,filename,alt_user);
if (!strcmp(delete,"DELETE")) printf("File will be deleted when read.\r\n");
gnl_flag = TRUE;
if (!*t2) goto send_file;
} /* END ELSE 4 */
} /* END ELSE 3 */
} /* END IF 2 */
if (gnl_flag) {
if (beginner && !quiet) {
printf("File sent. You will be informed when it has been read.\r\n");
printf("Remember: the file you just queued, called '%s'\r\n",filename);
mputs("must remain in your directory until read by whoever you sent it\r\n");
mputs("to. If you specified DELETE, it will be removed after being read.\r\n");
mputs("automatically by the system.\r\n");
}
}
} /* END ELSE 1 */
}
static msgaccinst(c,index)
char c;
int index;
{
char token[LINESIZE+2];
ctlsctlk();
cr();
if (c=='R' || c=='r') mputs("Control-O will skip rest of message\r\n");
sprintf(token,"%s mode: current msg# = %d\r\n",smsg_fnc(c),list[index]->value);
mputs(token);
mputs("CONTINUOUS: Enter 'F' for forward or 'B' for backward\r\n");
mputs("INDIVIDUAL: Enter 'Y' for current msg, or enter msg#, or msg#'s\r\n");
mputs(" (append '+' or '-' for continous)\r\n");
}