home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
c
/
crcbbs.arc
/
CRCPC0B.C
< prev
next >
Wrap
Text File
|
1985-10-22
|
15KB
|
580 lines
#include "crcpchdr.h"
/* SEP_DIR_FN: Separate filename/pathname into DIRECTORY part, and file part */
/* SIZE OF OUTPUT BUFFERS "DIR" AND "FILE" ARE USERS RESPONSIBILTY */
sep_dir_fn(curspec,dir,file)
char *curspec, dir[], file[];
{
int i;
dir[0] = file[0] = '\0';
i = strlen(curspec);
if (i) {
while(curspec[--i]!=ESCSYM && curspec[i]!=DRVSYM && i!=0);
/* COPY ENTIRE PATH, INCL ESCSYM */
if (i || curspec[i]==ESCSYM) stccpy(dir,curspec,++i+1);
strcpy(file,curspec+i); /* File name */
zaphesc(dir); /* Now delete ESCSYM if possible */
}
}
char *threeparse(inp,one,two,three)
char *inp;
char **one, **two, **three;
{
static char uno[LINESIZE], dos[LINESIZE], tres[LINESIZE];
char *ptr;
ptr = stptok(stpblk(inp),uno,LINESIZE," \r");
ptr = stptok(stpblk(ptr),dos,LINESIZE," \r");
ptr = stptok(stpblk(ptr),tres,LINESIZE," \r");
*one = uno;
*two = dos;
*three = tres;
return(ptr);
}
int sysmkdir(dirname,rootname)
char dirname[], rootname[];
{ return(dos_dir_int(dirname,DOS_MKDIR,rootname)); }
int sysrmdir(dirname,rootname)
char dirname[], rootname[];
{
return(dos_dir_int(dirname,DOS_RMDIR,rootname));
}
/*
F_U_MSG(BOARDNAME): Return pointer to board history record for boardname.
*/
struct lmsg *f_u_msg(board)
char board[];
{
struct lmsg *lmsg_ptr;
for (lmsg_ptr=lmsg_start;lmsg_ptr!=NULL;lmsg_ptr=lmsg_ptr->next_lmsg)
if (!strcmp(lmsg_ptr->boardname,board)) return(lmsg_ptr);
return(NULL);
}
int l_u_msg(board) /* RETURN LAST MSG READ BY USR LAST TIME */
char board[];
{
struct lmsg *lup;
if ((lup=f_u_msg(board))==NULL) return(0); /* Havent been on this BRD before */
else return(lup->lmr); /* Return last message read */
}
int l_b_msg(board) /* RETURN LAST MSG ON BOARD LAST TIME */
char board[];
{
struct lmsg *lup;
if ((lup=f_u_msg(board))==NULL) return(0); /* Havent been on this BRD before */
else return(lup->lmb); /* Return last message on BD */
}
/* A_U_MSG(BOARDNAME): Add (define or change) 'last msg read' counter for
boardname. Returns NULL if GETMEM error. */
struct lmsg *a_u_msg(board,lmb,lmr,mo,dy,yr)
char board[];
int lmb,lmr;
int mo,dy,yr;
{
struct lmsg *lmsg_ptr;
/* Do we already have it in our list ? */
if ((lmsg_ptr=f_u_msg(board))!=NULL) goto foundit;
/* No, so we must allocate memory & build it */
if ((lmsg_ptr=(struct lmsg *)getmem(sizeof(*lmsg_ptr)))==NULL) warn_omem();
else {
lmsg_ptr->next_lmsg = lmsg_start; /* We point to old start */
lmsg_start = lmsg_ptr; /* We become the first */
strcpy(lmsg_ptr->boardname,board);
foundit:lmsg_ptr->lmb = lmb;
lmsg_ptr->lmr = lmr;
lmsg_ptr->mo = mo;
lmsg_ptr->dy = dy;
lmsg_ptr->yr = yr>99?yr-BASEYEAR:yr;
}
return(lmsg_ptr);
}
int dir(fn,type)
char *fn ;
unsigned type;
{
int i, rc, orc;
char dirout[LINESIZE];
orc = setup_dir(fn,type) ;
rc = orc ;
while (rc==0) {
if (type==DIR_TYP) {
if (ftab_ptr->filedata.attribute==DIR_TYP) {
if (!strcmp(ftab_ptr->filedata.filename_ext,".") ||
!strcmp(ftab_ptr->filedata.filename_ext,"..") ) ;
else {
sprintf(dirout,"%-9s %s\r\n",
ftab_ptr->filedata.filename_ext,
filedate(ftab_ptr->filedata.file_date));
mputs(dirout);
}
}
rc = mdos(NEXT_FILE);
}
else {
for (i=0;(i<2)&&(!rc);++i) {
sprintf(dirout,"%14.13s %7.2fK",
ftab_ptr->filedata.filename_ext,
(float) (ftab_ptr->filedata.file_size/1024.0)+0.005);
mputs(dirout);
mputs(" ");
rc = mdos(NEXT_FILE);
}
cr();
}
} /* End While rc==0 */
return(orc);
}
/* End DIR */
int setup_dir(fn,type)
char *fn;
unsigned type;
{
int i, rc;
if (*fn == '\0') strcpy(fn,"*.*"); /* NOTE: LEN(fn[]) >= 4 chars! */
bdos(SET_DTA,disk_buffer); /* Set up our own DTA */
/* And get it from system */
ftab_ptr = (struct fn_struc *) getdta();
rc = mdos(FIND_FILE,NA,NA,type,fn);
switch(rc) { /* Look for ALL files, add them to list */
case 2: printf("File not found.\r\n");
break;
case 18: printf("Nothing found\r\n");
break;
} /* endswitch */
return(rc);
}
char *filetime(codetime)
unsigned codetime;
{
static char ftime[6];
sprintf(ftime,"%2d:%02d",(codetime&0xF800)>>11,
(codetime&0x07E0)>>5);
return(ftime);
}
char *filedate(codedate)
unsigned codedate;
{
static char fdate[11];
sprintf(fdate,"%02d/%02d/%02d",
(codedate&0x01E0)>>5,
(codedate&0x001F),
((codedate&0xFE00)>>9)+80);
return(fdate);
}
int baddir(dirname)
char dirname[];
{
printf("INVALID OR NON EXISTING DIRECTORY: '%s'.\r\n",dirname);
return(3);
}
char *on_off(bool)
int bool;
{
if (bool) return("on");
else return("off");
}
not_open() { printf("Could not open file\r\n"); }
int dsr() { return(rdsr() || sys_test); }
del_crlf(s)
char *s;
{
while(*s && !stpchr("\r\n",*s) && *s!=CTLZ) s++;
*s = '\0';
}
writeln2(iop,s1,s2)
FILE *iop;
char *s1, *s2;
{
fputs(s1,iop);
fputs(s2,iop);
fputs("\r\n",iop);
}
not_auth(c,dir,root)
char c, dir[], root[];
{
char outs[ROOTSIZE+DIRSIZE];
printf("Access denied [%c;%s]\r\n",c,prefix_dir(outs,dir,root));
}
invpath(rc,offensive_path)
int rc;
char *offensive_path;
{
if (beginner) printf("Invalid pathname: %s\r\n",offensive_path);
else printf("Bad pathname\r\n");
}
/* HAS_AUTH: Changes directory to test directory and diagnoses 'ACCESS.USR'
if necessary to obtain answer.
06/06/84: Patch to make any PUBLIC directory OK for READ access.
1) All users have R/W access to all their own directories except PUBLIC
(who has R/W to TOP level, and R/O to other levels)
2) All users have R/O access to any directory on the MESSAGES root
3) Priveledged users given global access according to: SYSREAD/SYSWRITE
4) All other requests given to routine: 'CHECK_ACC' for final dispostn.
07/22/84: I've decided that this is a kludgey routine:
IT SHOULD BE RE-WRITTEN.
*/
has_auth(s,tdir,troot)
char *s, tdir[], troot[];
{
char *ept;
char dir[DIRSIZE]; /* All these buffers are required because of */
char root[ROOTSIZE]; /* previous design 'problems'. */
int onsys, home, msgsys, subdir;
int ans;
char test[DIRSIZE+ROOTSIZE];
static char ctest[DIRSIZE+ROOTSIZE];
static char creq[10];
static int lastans;
uppercase(s);
if (!strcmp(prefix_dir(test,tdir,troot),ctest) && !strcmp(creq,s))
return(lastans);
stccpy(creq,s,sizeof(creq));
strcpy(ctest,test);
stccpy(dir,tdir,sizeof(dir));
stccpy(root,troot,sizeof(root));
uppercase(dir);
uppercase(root);
onsys = strcmp(root,user_root);
msgsys = !strcmp(root,MESSAGES);
if (*dir==ESCSYM) strcpy(dir,dir+1);
if ((ept=stpchr(dir,ESCSYM))!=NULL) {
*ept = '\0';
subdir = TRUE;
}
else subdir = FALSE;
home = !strcmp(dir,home_dir) && !onsys; /* Home iff first level dir=HOME_DIR */
if (home && strcmp(home_dir,DEFLT_DIR)) ans = TRUE; /* Access to own dirs except PUBLIC */
else switch(*s) {
case 'R':
if (msgsys) ans = TRUE; /* Can ALWAYS read MESSAGES */
else if (onsys) ans = sysread; /* Other system dirs: req. SYSREAD priv. */
else if (userread) ans = TRUE; /* Not SYS, if global user read, OK too */
else if (!strcmp(dir,DEFLT_DIR)) ans = TRUE; /* Always READ public */
else ans=check_acc(s,tdir,root);/* Otherwise go fetch ACCESS.USR */
break;
case 'W':
if (onsys) ans = syswrite;
else if (userwrite) ans = TRUE;
else if (home && !subdir) ans =TRUE; /* PUBLIC can write to TOP LEVEL DIR */
else ans=check_acc(s,tdir,root);
break;
}
return(lastans=ans); /* ?? */
}
/* Patch 02/02/84; Accepts username of '*' for global user specification */
static int check_acc(s,dir,root)
char *s, dir[], root[];
{
char save_dir[DIRSIZE],
save_root[ROOTSIZE],
*parseptr,
token1[9],
token2[5];
int answer;
FILE *fp;
strcpy(save_dir,cur_dir); /* Save global current directory */
strcpy(save_root,cur_root); /* And root */
sysdir(dir,root); /* Go to requested spot */
answer = FALSE;
if ((fp=fopen(ACCESS_USR,"r"))!=NULL) {
while(fgets(file_buff,STR_SIZE,fp)!=NULL) {
del_crlf(file_buff);
if (file_buff[0]) {
uppercase(file_buff);
parseptr = stpblk(stptok(stpblk(file_buff),token1,9," \r"));
parseptr = stptok(parseptr,token2,5," \r");
if (token1[0]==CTLZ) ; /* Skip possible last rec from editor */
else if (!strcmp(token1,user_id) || !strcmp(token1,"*")) {
answer = (answer||(stpchr(token2,*s)!=NULL));
}
}
}
fclose(fp);
}
sysdir(save_dir,save_root); /* Restore our old file system */
return(answer);
}
expertstatus()
{
printf("Expert mode is: %s\r\n",on_off(!beginner));
}
int mxti(sstr,index)
char *sstr;
int index;
{
char *array[3];
threeparse(sstr,&array[0],&array[1],&array[2]);
return(stoi(array[--index]));
}
cusfn() { mputs("Cannot use same filename\r\n"); }
prompt()
{
output = TRUE;
if (beginner) {
mputs("----------\r\n");
mputs("Main Level\r\n");
mputs("----------\r\n");
cr();
}
printf("%s> ",prompt_str(beginner));
}
int scanstr(source,search,invl)
char *source, search[];
int invl;
{
int i, j, lsorc, lserc;
lsorc = strlen(source);
lserc = strlen(search);
if (lserc==invl) for (i=0;i<lsorc-lserc+1;i+=lserc) {
for (j=0;j<lserc;j++) if (source[i+j]!=search[j]) break;
if (j==lserc) return i+1; /* Match! - return index + 1 */
}
return 0;
}
static rsvf(fn)
char *fn;
{
printf("Reserved filename: `%s'\r\n",fn);
}
int check_rf(fn,msg,bd,l)
char *fn, *bd;
int msg, l;
{
char *badchr;
char filename[17];
stccpy(filename,ltrim(fn),sizeof(filename));
uppercase(filename);
if (badchr=stpbrk(filename,INVDOSFNCHR)) *badchr='\0'; /* Zap at first badchar */
if (scanstr(bd,filename,l)) {
if (msg) rsvf(filename);
return TRUE;
}
else return FALSE;
}
int check_rsvf(fn,msg)
char *fn;
int msg;
{
if (check_rf(fn,FALSE,"CONAUXPRNNUL",3) ||
check_rf(fn,FALSE,"COM1COM2LPT1LPT2",4)) {
if (msg) rsvf(fn);
return TRUE;
}
else return FALSE;
}
int check_fn(fn,msg)
char *fn;
int msg;
{
char *badchr;
if (badchr=stpbrk(fn,INVDOSFNCHR)) {
if (msg) bad_fn(*badchr);
return TRUE;
}
else return FALSE;
}
bad_dpn(c,s)
char c, *s;
{
if (beginner) printf("You can't use '%c' in a %sname\r\n",c,s);
else printf("'%c' ?!\r\n",c);
}
bad_dn(c) char c; { bad_dpn(c,"directory "); }
bad_pn(c) char c; { bad_dpn(c,"path"); }
bad_fn(c) char c; { bad_dpn(c,"file"); }
/* FILECOPY: Copy a file, possibly between directories, always on USER_ROOT
TEXT = TRUE if file is text file.
CREATE = TRUE if no append to be done.
*/
int filecopy(destdir,destfile,sourcedir,sourcefile,text,create)
char destdir[], destfile[],sourcedir[], sourcefile[];
int text, create;
{
char newdstd[DIRSIZE+ROOTSIZE+2], newsrcd[DIRSIZE+ROOTSIZE+2];
prefix_dir(newdstd,destdir,user_root);
prefix_dir(newsrcd,sourcedir,user_root);
return(sysfcopy(newdstd,destfile,newsrcd,sourcefile,text,create));
}
int sysfcopy(destdir,destfile,sourcedir,sourcefile,text,create)
char sourcedir[], sourcefile[], destdir[], destfile[];
int text, create;
{
int rc;
char source[DIRSIZE+ROOTSIZE];
char dest[DIRSIZE+ROOTSIZE];
rc = 100; /* Guilty until innocent */
if (check_rf(sourcefile,TRUE,"AUXCONNULPRN",3)) return(rc);
if (check_rf(sourcefile,TRUE,"LPT1LPT2COM1COM2",4)) return(rc);
if (check_rf(destfile,TRUE,"AUXCONPRN",3)) return(rc);
if (check_rf(destfile,TRUE,"LPT1LPT2COM1COM2",4)) return(rc);
prefix_dir(source,sourcefile,sourcedir);
prefix_dir(dest,destfile,destdir);
if (rc=doscopy(source,dest,!create,text)) {
if (rc==-1) printf("Disk full!\r\n");
else if (rc==2) printf("Could not read: %s\r\n",source);
else if (rc==3) printf("Could not open: %s\r\n",dest);
else printf("copy error: %d\r\n",rc);
#if DEBUG==TRUE
if (debug) printf("DOS rc=%d, %s -> %s\r\n",rc,source,dest);
#endif
}
return(rc); /* Return with status */
}
#define READ 0x8000
#define CREATE 0x8301
#define APPEND 0x8109
#define BLKSIZE 0x0200
int doscopy(from,to,append,text)
char *from, *to;
int append, text;
{
int rc, f1, f2, bytes, wmode, rmode;
char buffer[BLKSIZE];
wmode = append?APPEND:CREATE;
rmode = READ;
if (text) { wmode &= 0x7FFF; rmode &= 0x7FFF; }
rc = 0;
if ((f1=open(from,rmode))==0) rc = 2; /* Input file not found ? */
else if ((f2=open(to,wmode))==0) rc = 3; /* path not found ? */
else {
do {
if ((bytes=read(f1,buffer,BLKSIZE))<0) rc = 2 ; /* read error */
else if (write(f2,buffer,bytes)!=bytes) rc = -1; /* DISK FULL */
} while (bytes==BLKSIZE && rc==0);
}
if (f1) close(f1);
if (f2) {
close(f2);
if (rc && !append) unlink(to);
}
return rc;
}
char *usname()
{
char *bp;
static char usern[LINESIZE]; /* I WISH IT DIDNT HAVE TO BE THIS LONG! */
/* --- or STATIC ! */
if (!strcmp(home_dir,DEFLT_DIR)) return("");
else if (*username=='\0') return(user_id);
else {
strcpy(usern,username);
if ((bp=stpchr(usern,' '))!=NULL) *bp = '\0';
return(usern);
}
}
inv_arg()
{
printf("Invalid argument(s)\r\n");
}
/* Create a human-readable (decimal) list of numbers, delimited by comma */
char *dec_list(charlist,binlist,maxlen)
char *charlist, *binlist;
int maxlen;
{
int i, j;
char number[15];
for (charlist[0]='\0',i=0,j=0;i<maxlen && binlist[j]!='\0';++j) {
sprintf(number,"%d",binlist[j]);
strcat(charlist,number);
i += strlen(number)+1;
if (i<maxlen && binlist[j+1]!='\0') strcat(charlist,",");
}
return(charlist);
}
/* Create a computer-readable (binary) list of numbers, delimited by comma */
/* from human readable decimal number sequence in CHARLIST */
/* Returns NULL on error, or 'binlist', if no error */
char *bin_list(binlist,charlist,maxlen)
char *charlist, *binlist;
int maxlen;
{
int i, j;
char number[15];
char *strptr;
i = 0;
if (maxlen<2) return(NULL);
if (!charlist[0]) binlist[0] = '\0';
else {
strcat(charlist,",");
strptr = stptok(charlist,number,15," ,");
do {
if ((j=stoi(number))<1 || j>255) {
if (beginner) printf("'%s' is not a valid ASCII code.\r\n",number);
else printf("'%s' ?!\r\n",number);
return(NULL);
}
else {
binlist[i++] = j;
binlist[i] = '\0';
}
number[0] = '\0';
if (stpchr(" ,",*strptr)!=NULL) strptr=stptok(stpblk(strptr+1),number,15," ,");
} while(*number && i<maxlen);
}
return(binlist);
}