home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
msdos
/
c
/
crcbbs.arc
/
CRCPC1C.C
< prev
next >
Wrap
Text File
|
1985-10-22
|
18KB
|
564 lines
#include "crcpchdr.h"
disp_dir(c,args,opts)
char c, *args, *opts;
{
int quiet,subs,users,boards,current;
quiet = find_option(opts,'q');
current = find_options(opts,'c');
subs = find_option(opts,'s');
users = find_option(opts,'u');
boards = find_option(opts,'b');
/* If none specifically asked for, give all */
if (!(current||subs||users||boards)) subs = users = boards = current = TRUE;
if (!quiet && beginner) disp_msg(10);
if (current && !subs) print_cd(); /* "SUBS SHOWS CURDIR ANYWAYS" */
if (subs) {
cr();
sysdir(cur_dir,cur_root);
printf("Subdirectories on: %s\r\n",
prefix_dir(file_buff,cur_dir,cur_root));
if (dir("*.*",DIR_TYP)) printf("None\r\n");
}
if (users && !quit) {
output = TRUE;
cr();
printf("%s user directories:\r\n",SYSNAME);
sysdir("",user_root);
if (dir("*.*",DIR_TYP)) printf("None\r\n");
}
if (boards && !quit) {
output = TRUE;
cr();
if (!sysdir("",MESSAGES)) {
printf("%s message board directories:\r\n",SYSNAME);
if (dir("*.*",DIR_TYP)) printf("None\r\n");
}
else printf("%s message system not setup.\r\n");
}
cr();
}
type_file(c,args,opts)
char c, *args, *opts;
{
char filename[17];
if (!has_auth("R",cur_dir,cur_root)) return(not_auth('R',cur_dir,cur_root));
if (!*args) {
disp_reply(file_prompt(beginner,"type to terminal"),filename,14);
if (filename[0]=='\0') return(nothing_done());
args = filename;
}
if (check_fn(args,TRUE)) return;
if (check_rsvf(args,TRUE)) return; /* Can't use reserved filename */
typefile(args,opts);
cr();
}
erase_file(c,args,opts)
char c, *args, *opts;
{
char filename[17], *t1, *t2, *t3;
if (!*args && !find_option(opts,'q') && beginner) disp_msg(14);
if (!has_auth("W",cur_dir,cur_root)) return(not_auth('W',cur_dir,cur_root));
threeparse(args,&t1,&t2,&t3);
if (!*t1) {
t1 = disp_reply(file_prompt(beginner,"erase"),filename,14);
if (t1[0]=='\0') return(nothing_done());
}
if (check_fn(t1,TRUE)) return;
if (check_rsvf(t1,TRUE)) return; /* Can't use reserved filename */
if (unlink(t1))
printf("File '%s' not found or illegal name.\r\n",t1);
else printf("File '%s' erased.\r\n",t1);
}
list_file(c,args,opts)
char c, *args, *opts;
{
char fn[DIRSIZE+ROOTSIZE+20];
char *t1;
if (!*args && !find_option(opts,'q') && beginner) disp_msg(51);
if (!*args) args = "*.*";
if (t1=stpchr(args,INVDIRCHR)) return(bad_fn(*t1)); /* Can't use special chars in filename */
prefix_dir(workstr,cur_dir,cur_root);
prefix_dir(fn,args,workstr);
dirc(fn,opts);
}
mk_dir(c,args,opts)
char c, *args, *opts;
{
int quiet;
int rc;
char curdir[DIRSIZE+ROOTSIZE], *type;
quiet = find_option(opts,'q');
if (beginner && !*args && !quiet) disp_msg(30);
if (!has_auth("W",cur_dir,cur_root)) return(not_auth('W',cur_dir,cur_root));
prefix_dir(curdir,cur_dir,cur_root);
if (!quiet) printf("Subdirectory will be attached to: %s\r\n",curdir);
if (*args) {
stptok(args,workstr,9," ");
goto trymd1;
}
getmdagn:
if (*args) return(1000);
disp_reply("Name for new subdirectory? ",workstr,9);
if (!workstr[0]) return(nothing_done()&0);
trymd1:
if (type=stpbrk(workstr,INVDOSFNCHR)) {
bad_dn(*type);
goto getmdagn;
}
uppercase(workstr);
if (!sysdir(workstr,curdir)) {
printf("Already '%s' subdirectory on %s!\r\n",workstr,curdir);
goto getmdagn;
}
printf("Standby:\r\n");
/* Rc==2 when using -XT (??) */
if ((rc=sysmkdir(workstr,curdir))!=0 && rc!=2) {
printf("Oops! Error during subdirectory creation.\r\n");
printf("Not today: sorry.\r\n");
sprintf(file_buff,"SUBDIRECTORY CREATION (%s\\%s) FAILURE FOR %s: RC=%d",
curdir,workstr,user_id,rc);
logevent(file_buff);
}
else {
if (!quiet) printf("Subdirectory '%s' created on %s and ready for use.\r\n",workstr,curdir);
}
return(0);
}
rm_dir(c,args,opts)
char c, *args, *opts;
{
int gnl_flag, quiet;
char curdir[DIRSIZE+ROOTSIZE];
char *type;
quiet = find_option(opts,'q');
if (!*args && !quiet && beginner) disp_msg(31);
if (!has_auth("W",cur_dir,cur_root)) return(not_auth('W',cur_dir,cur_root));
prefix_dir(curdir,cur_dir,cur_root);
if (*args) {
stptok(args,workstr,9," ");
goto tryrm2;
}
g2trmagn:
if (*args) return;
printf("Name of subdirectory to kill? ");
strcpy(workstr,lineinput(9));
if (!workstr[0]) return(nothing_done());
tryrm2:
if (type=stpbrk(workstr,INVDOSFNCHR)) {
bad_dn(*type);
goto g2trmagn;
}
uppercase(workstr);
if (sysdir(workstr,curdir)) {
printf("No such subdirectory '%s' attached to current directory\r\n",workstr);
return;
}
else if (!setup_dir("*.*",FILE_TYP)) {
printf("Subdirectory '%s' has files in it!\r\n",workstr);
if (!quiet) printf("Please erase all files first!\r\n");
return;
}
printf("Please wait; this takes awhile sometimes ...\r\n");
sysdir("",curdir);
if (gnl_flag=sysrmdir(workstr,curdir)) {
if (gnl_flag==5) {
printf("'%s' has files in it!\r\n",workstr);
return;
}
else if (gnl_flag==3) printf("No such subdir: '%s'!\r\n",workstr);
goto g2trmagn;
}
else {
if (!quiet) printf("Ok %s, subdirectory '%s' has been removed.\r\n",usname(),workstr);
}
}
int pchdir(prefixed,homeroot,homedir,curroot,curdir,destroot,destdir,where)
int prefixed;
char *homeroot, *curroot, *destroot;
char *homedir, *curdir, *destdir;
char *where;
{
/*
1. 'marty' -> curroot + curdir + '\marty'
2. '$home' -> homeroot + homedir (i.e. '\users\marty')
3. '\jeff' -> cur_root + '\jeff' (NO Global System Read Access)
4. '\jeff' -> '\jeff' (Global System Read/Write Access Only)
*/
if (!*where) {
strcpy(destdir,curdir);
strcpy(destroot,curroot);
return 0;
}
if (*where == ESCSYM) { /* He wants to specify entire thing */
where++; /* Chop off redund. ESCSYM */
if (prefixed) strcpy(destroot,curroot); /* Tack on current root */
else *destroot = '\0'; /* System access: no root */
strcpy(destdir,where);
return 0;
}
else if (*where == SPCSYM) { /* For special prenamed directories */
++where;
if (!strcmp(SPCHOME,where)) {
strcpy(destdir,homedir);
strcpy(destroot,homeroot);
return 0;
}
return 1; /* Error - no such special directory */
}
else { /* Append (logically) to current dir */
prefix_dir(destdir,where,curdir); /* Logical 'curdir+where' */
strcpy(destroot,curroot);
return 0;
}
}
jump_dir(c,args,opts)
char c, *args, *opts;
{
char *type, *t1, *t2, *t3;
int quiet;
char workbuf[10];
quiet = find_option(opts,'q');
threeparse(args,&t1,&t2,&t3);
if (!*t1) {
if (!strcmp(cur_dir,home_dir) && /* If he's at home ... */
!strcmp(cur_root,user_root)) {
if (!quiet && beginner) disp_msg(19);
}
else printf("Type '*' to go to home directory\r\n");
}
getfdn:
if (!*t1) t1 = disp_reply("Enter message board name: ",workbuf,9);
uppercase(t1);
if (*t1) {
if (!strcmp(t1,"*")) {
t1 = home_dir;
strcpy(cur_root,user_root);
}
else if (type=stpbrk(t1,INVDOSFNCHR)) {
bad_dn(*type);
t1 = "";
goto jumpdone;
}
/* else */
/* we will check the message system for a matching board name */
else if (!sysdir(t1,MESSAGES)) {
if (!quiet && beginner) {
printf("You are currently logged to the %s message board\r\n",t1);
printf("Use 'JUMP *' to return to home directory\r\n");
}
strcpy(cur_dir,t1);
strcpy(cur_root,MESSAGES);
goto jumpdone;
}
/* else we try the user root */
if (sysdir(t1,user_root)) {
printf("Can't find %s\r\n",t1);
t1 = "";
goto jumpdone;
}
/* AND he must at least have Read access to the Main directory, */
else if (!has_auth("R",t1,user_root)) {
printf("Access denied. ");
if (beginner) printf("Contact %s for assistance",SYSOP);
printf("\r\n");
goto jumpdone;
}
else {
strcpy(cur_dir,t1);
strcpy(cur_root,user_root);
}
}
else nothing_done();
jumpdone:
sysdir(cur_dir,cur_root);
if (!quiet) print_cd();
}
go_dir(c,args,opts)
char c, *args, *opts;
{
char *type, *t1, *t2, *t3;
int quiet;
int rc;
char testdir[DIRSIZE];
char test_dir[DIRSIZE];
char test_root[ROOTSIZE];
char workbuf[50];
quiet = find_option(opts,'q');
threeparse(args,&t1,&t2,&t3);
if (!*t1) {
if (!strcmp(cur_dir,home_dir) && /* If he's at home ... */
!strcmp(cur_root,user_root)) {
if (!quiet && beginner) disp_msg(18);
}
else printf("Type '*' to go home\r\n");
}
getddn:
if (!*t1) t1 = disp_reply("Enter directory (path) name: ",workbuf,48);
uppercase(t1);
if (*t1) {
if (!strcmp(t1,"*")) {
strcpy(cur_dir,home_dir);
strcpy(cur_root,user_root);
goto godone;
}
else if (type=stpbrk(t1,INVDOSPNCHR)) {
bad_pn(*type);
t1 = "";
goto godone;
}
/* else */
/* we will prepare a logical pathname from what he/she typed */
else if (rc=pchdir(!sysread,
user_root,home_dir,cur_root,cur_dir,test_root,test_dir,t1)) {
/* No. Probably unrecognized special pathname */
if (rc==1) printf("Unknown special path: %s\r\n",t1);
else printf("pCHdir error\r\n");
}
else {
/* Yes. Preparation was O.K. - check for system understanding of pathname ?! */
/* Make printable version in case of error */
prefix_dir(testdir,test_dir,test_root);
if (!sysdir(test_dir,test_root)) {
/* AND he must at least have Read access to this directory, test_root */
if (!has_auth("R",test_dir,test_root)) {
printf("Access denied: %s\r\n",testdir);
goto godone;
}
strcpy(cur_dir,test_dir);
strcpy(cur_root,test_root);
goto godone;
}
else {
t1 = "";
printf("Can't access %s\r\n",testdir);
goto godone;
}
}
}
else nothing_done();
godone:
sysdir(cur_dir,cur_root);
if (!quiet) print_cd();
}
/* Strip_Arg: Subroutine to DIREXPAND (forward) */
int strip_arg(outptr,inptr,brksym)
char **outptr;
char **inptr;
char brksym;
{
char *testptr;
*inptr=stpblk(*inptr);
if (testptr=stpchr(*inptr,brksym)) {
*outptr = *inptr;
*testptr = '\0'; /* Zap out ESC CHR */
*inptr = testptr+1;
return(0);
}
else {
*outptr = *inptr;
*inptr = NULL;
return(1); /* Error signalling end of list - no more tokens */
}
}
#define MAXNODES 32 /* 32 for safety ? */
int direxpand(outpath,inpath,cur_dir,maxlen)
char *outpath, *inpath,*cur_dir;
int maxlen;
{
char *nodes[MAXNODES];
char *outnodes[MAXNODES];
int i,j,k;
int absolute;
char ourpath[DIRSIZE+ROOTSIZE]; /* Holding buffer for work string array */
inpath=stpblk(inpath);
if (*inpath==ESCSYM) { inpath++; absolute = TRUE; }
else absolute = FALSE;
if (!absolute) {
strcpy(ourpath,cur_dir);
if (*ourpath)
if (ourpath[strlen(ourpath)-1]!=ESCSYM) strcat(ourpath,ESCSTR);
}
else strcpy(ourpath,ESCSTR);
strcat(ourpath,inpath);
inpath=ourpath; /* Use our own copy from now on */
i=0;
while(strip_arg(&nodes[i++],&inpath,ESCSYM)==0) if (i==MAXNODES) break;
j=i;
for (k=i=0;i<j;i++) {
if (!strcmp(nodes[i],CURDIR)) ; /* "." */
else if (!strcmp(nodes[i],UPLEVEL)) { /* ".." */
if (k>0) k--;
else return(1); /* Error 1 = tried to back up too far */
}
else outnodes[k++]=nodes[i];
if (i==MAXNODES) return(2); /* Error 2 = too many nodes specified */
}
*outpath='\0';
for (i=0;i<k;) {
if ((strlen(outpath)+strlen(outnodes[i])+1)<maxlen) strcat(outpath,outnodes[i]);
else return(3); /* Error 3 = Output string too long */
i++;
if (i<k) strcat(outpath,ESCSTR);
}
return(0);
}
dup_file(c,args,opts)
char c, *args, *opts;
{
char filename[DIRSIZE+1], destfile[DIRSIZE+1], *t1, *t2, *t3, *format;
char filetest[DIRSIZE+1], desttest[DIRSIZE+1];
char filedir[DIRSIZE+1], destdir[DIRSIZE+1];
char origname[DIRSIZE+1], destname[DIRSIZE+1];
int append, text;
int rc;
threeparse(args,&t1,&t2,&t3);
uppercase(t1); uppercase(t2);
append = find_option(opts,'a');
text = find_option(opts,'t'); /* Select CONTROL-Z as file EOF */
/* (default is BINARY file copy) */
threeparse(args,&t1,&t2,&t3);
uppercase(t1); uppercase(t2);
if (!*t1) { /* No first argument */
if (!find_option(opts,'q') && beginner) disp_msg(11);
disp_reply("Input [path\\]filename: ",filename,sizeof(filename)-1);
}
else stccpy(filename,t1,sizeof(filename));
if (!*filename) return(nothing_done());
if (rc=direxpand(origname,filename,cur_dir,sizeof(origname)))
return(invpath(rc,filename)); /* Expand filename into ORIGNAME */
stccpy(filename,origname,sizeof(filename)); /* Make them equal */
sep_dir_fn(filename,filedir,filetest);
if (!*filetest) return(nothing_done());
if (!*filedir) stccpy(filedir,cur_dir,sizeof(filedir));
if (check_fn(filetest,TRUE)) return;
if (check_rsvf(filetest,TRUE)) return; /* Can't use reserved filename */
if (*filedir==ESCSYM) strcpy(filedir,filedir+1);
if (!has_auth("R",filedir,cur_root)) return(not_auth('R',filedir,cur_root));
/* We prompt for second argument only iff no first */
if (!*t1) disp_reply("Output [path\\]filename: ",destfile,sizeof(destfile)-1);
/* If second argument, it is file 2 */
else if (*t2) stccpy(destfile,t2,sizeof(destfile));
/* else use filename of file1, and current directory */
else strcpy(destfile,CURDIR); /* Write in "." */
if (!*destfile) return(nothing_done());
if (!strcmp(destfile,CURDIR)||!strcmp(destfile,UPLEVEL)) strcat(destfile,ESCSTR);
if (rc=direxpand(destname,destfile,cur_dir,sizeof(destname)))
return(invpath(rc,destfile)); /* Expand destfile into destname */
stccpy(destfile,destname,sizeof(destfile));
sep_dir_fn(destfile,destdir,desttest);
if (!*desttest) stccpy(desttest,filetest,sizeof(desttest));
if (!*destdir) stccpy(destdir,cur_dir,sizeof(destdir));
if (check_fn(desttest,TRUE)) return;
if (check_rsvf(desttest,TRUE)) return; /* Can't use reserved filename */
if (*destdir==ESCSYM) strcpy(destdir,destdir+1);
uppercase(filetest);uppercase(desttest);uppercase(filedir);uppercase(destdir);
if (!strcmp(filetest,desttest) && !strcmp(filedir,destdir)) return(cusfn());
if (!has_auth("W",destdir,cur_root)) return(not_auth('W',destdir,cur_root));
prefix_dir(destname,destdir,cur_root);
prefix_dir(origname,filedir,cur_root);
if (sysfcopy(destname,desttest,origname,filetest,text,!append))
printf("File not copied.\r\n");
else {
if (text) printf("Text translation used; ^Z is file EOF\r\n");
if (append) format = "File %s appended to %s\r\n";
else format = "File %s copied to %s\r\n";
printf(format,filename,destfile);
}
}
rename_file(c,args,opts)
char c, *args, *opts;
{
char filename[DIRSIZE+1], destfile[DIRSIZE+1], *t1, *t2, *t3;
char filetest[DIRSIZE+1], desttest[DIRSIZE+1];
char filedir[DIRSIZE+1], destdir[DIRSIZE+1];
char origname[DIRSIZE+1], destname[DIRSIZE+1];
int rc;
threeparse(args,&t1,&t2,&t3);
uppercase(t1); uppercase(t2);
if (!*t1) { /* No first argument */
if (!find_option(opts,'q') && beginner) disp_msg(12);
printf("Enter [path\\]name of file to rename: ");
disp_reply("",filename,sizeof(filename)-1);
}
else stccpy(filename,t1,sizeof(filename));
if (!*filename) return(nothing_done());
if (!strcmp(filename,CURDIR)||!strcmp(filename,UPLEVEL)) strcat(filename,ESCSTR);
if (rc=direxpand(origname,filename,cur_dir,sizeof(origname)))
return(invpath(rc,filename)); /* Expand filename into ORIGNAME */
stccpy(filename,origname,sizeof(filename));
sep_dir_fn(filename,filedir,filetest);
if (!*filetest) return(nothing_done());
if (!*filedir) stccpy(filedir,cur_dir,sizeof(filedir));
if (check_fn(filetest,TRUE)) return;
if (check_rsvf(filetest,TRUE)) return; /* Can't use reserved filename */
if (*filedir==ESCSYM) strcpy(filedir,filedir+1);
if (!has_auth("W",filedir,cur_root)) return(not_auth('W',filedir,cur_root));
if (!*t2) {
printf("Enter new [path\\]filename for '%s': ",filename);
disp_reply("",destfile,sizeof(destfile)-1);
}
else stccpy(destfile,t2,sizeof(destfile));
if (!*destfile) return(nothing_done());
/* else use filename of file1, and current directory */
if (!strcmp(destfile,CURDIR)||!strcmp(destfile,UPLEVEL)) strcat(destfile,ESCSTR);
if (rc=direxpand(destname,destfile,cur_dir,sizeof(destname)))
return(invpath(rc,destfile)); /* Expand destfile into destname */
stccpy(destfile,destname,sizeof(destfile));
sep_dir_fn(destfile,destdir,desttest);
if (!*desttest) stccpy(desttest,filetest,sizeof(desttest));
if (!*destdir) stccpy(destdir,filedir,sizeof(destdir));
if (check_fn(desttest,TRUE)) return;
if (check_rsvf(desttest,TRUE)) return; /* Can't use reserved filename */
if (*destdir==ESCSYM) strcpy(destdir,destdir+1);
uppercase(filetest);uppercase(desttest);uppercase(filedir);uppercase(destdir);
if (!strcmp(filetest,desttest) && !strcmp(filedir,destdir)) return(cusfn());
if (!has_auth("W",destdir,cur_root)) return(not_auth('W',destdir,cur_root));
else {
prefix_dir(destfile,destdir,cur_root);
prefix_dir(destdir,desttest,destfile);
stccpy(destfile,destdir,sizeof(destfile));
prefix_dir(filename,filedir,cur_root);
prefix_dir(filedir,filetest,filename);
stccpy(filename,filedir,sizeof(filename));
if (rc=rename(filename,destfile)) printf("RENAME error %d: %s -> %s\r\n",rc,filename,destfile);
else printf("%s -> %s ok.\r\n",origname,destname);
}
}