home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
APPS
/
dm14.lzh
/
multicopy.c
< prev
next >
Wrap
Text File
|
1996-07-24
|
6KB
|
205 lines
/* multicopy.c function for DISKMASTER.C */
/* copyright (c) 1995 by Bob Devries */
/* email: bdevries@gil.ipswichcity.qld.gov.au */
/* copies all tagged files to a destination directory */
#include "diskmaster.h"
#include <stdio.h>
#include <modes.h>
#include <strings.h>
#include <module.h>
#include <errno.h>
int
multicopy(numfiles)
int numfiles;
{
extern char **nameptr;
extern short *attrptr;
int x, confirm, overwrite, ask, s_error;
char *copycmd, *todir, *malloc();
mod_exec *modloadp(), *modp;
if ((modp = modloadp("copy",0,NULL)) == NULL) {
error("Can't load command","COPY",errno);
return(FAIL);
}
copycmd = malloc(numfiles*32+256);
todir = malloc(80);
gotoxy(1,24);
cleol();
printf(" %cCopy tagged files to: ",7);
lineinput(todir,80);
if(*todir == '\0') {
free(copycmd);
free(todir);
commands();
munlink(modp);
return(FAIL);
}
if(access(todir,S_IFDIR+S_IWRITE+S_IREAD) != 0) {
gotoxy(1,24);
cleol();
printf(" %c%s is not a directory!",7,todir);
sleep(1);
free(copycmd);
free(todir);
commands();
munlink(modp);
return(FAIL);
}
gotoxy(1,24);
cleol();
#ifdef MM1
CurOn(1);
#endif
printf(" %cConfirm each copy y/N ",7);
do {
confirm = toupper(getchar());
flush_kbd();
} while ((confirm != 'Y') && (confirm != 'N') && (confirm != '\n'));
if(confirm == '\n') {
confirm = 'N';
}
gotoxy(1,24);
cleol();
printf(" %cForce overwrite y/N ",7);
do {
overwrite = toupper(getchar());
flush_kbd();
} while ((overwrite != 'Y') && (overwrite != 'N') && (overwrite != '\n'));
if(overwrite == '\n') {
overwrite = 'N';
}
if((confirm == 'N') && (overwrite == 'Y')) {
strcpy(copycmd,"copy -rw=");
strcat(copycmd,todir);
strcat(copycmd," ");
for(x=1;x<=numfiles;x++) {
if((attrptr[x]&TAG) == TAG) {
attrptr[x]&=0xFF;
strcat(copycmd,nameptr[x]);
strcat(copycmd,">>>/nil");
gotoxy(1,24);
cleol();
printf(" Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
system(copycmd);
*(rindex(copycmd,' ') + 1) = '\0';
}
}
free(copycmd);
free(todir);
commands();
munlink(modp);
#ifdef MM1
CurOff(1);
#endif
return(PASS);
}
if((confirm == 'Y') && (overwrite == 'Y')) {
strcpy(copycmd,"copy -rw=");
strcat(copycmd,todir);
for(x=1;x<=numfiles;x++) {
if((attrptr[x]&TAG) == TAG) {
attrptr[x]&=0xFF;
strcat(copycmd," ");
strcat(copycmd,nameptr[x]);
strcat(copycmd,">>>/nil");
gotoxy(1,24);
cleol();
printf(" %cCopy %s TO %s? (y/N)",7,nameptr[x],todir);
ask = toupper(getchar());
flush_kbd();
if(ask == 'Y') {
gotoxy(1,24);
cleol();
printf(" Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
system(copycmd);
}
*(rindex(copycmd,' ')) = '\0';
}
}
free(copycmd);
free(todir);
commands();
munlink(modp);
#ifdef MM1
CurOff(1);
#endif
return(PASS);
}
if((confirm == 'N') && (overwrite == 'N')) {
strcpy(copycmd,"copy -w=");
strcat(copycmd,todir);
strcat(copycmd," ");
for(x=1;x<=numfiles;x++) {
if((attrptr[x]&TAG) == TAG) {
attrptr[x]&=0xFF;
strcat(copycmd,nameptr[x]);
strcat(copycmd,">>>/nil");
gotoxy(1,24);
cleol();
printf(" Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
s_error = system(copycmd);
if(s_error == 218) {
gotoxy(1,24);
cleol();
printf(" %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
sleep(1);
}
*(rindex(copycmd,' ') + 1) = '\0';
}
}
free(copycmd);
free(todir);
commands();
munlink(modp);
#ifdef MM1
CurOff(1);
#endif
return(PASS);
}
if((confirm == 'Y') && (overwrite == 'N')) {
strcpy(copycmd,"copy -w=");
strcat(copycmd,todir);
for(x=1;x<=numfiles;x++) {
if((attrptr[x]&TAG) == TAG) {
attrptr[x]&=0xFF;
strcat(copycmd," ");
strcat(copycmd,nameptr[x]);
strcat(copycmd,">>>/nil");
gotoxy(1,24);
cleol();
printf(" %cCopy %s TO %s? y/N ",7,nameptr[x],todir);
ask = toupper(getchar());
flush_kbd();
if(ask == 'Y') {
gotoxy(1,24);
cleol();
printf(" Copying %s to %s/%s",nameptr[x],todir,nameptr[x]);
s_error = system(copycmd);
if(s_error == 218) {
gotoxy(1,24);
cleol();
printf(" %c%s not copied to %s -- File exists!",7,nameptr[x],todir);
}
}
*(rindex(copycmd,' ')) = '\0';
}
}
free(copycmd);
free(todir);
commands();
munlink(modp);
#ifdef MM1
CurOff(1);
#endif
return(PASS);
}
}
/* EOF multicopy.c */