home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
140_01
/
backup.c
< prev
next >
Wrap
Text File
|
1985-03-11
|
17KB
|
895 lines
/*
BACKUP is by Steve de Plater
66 Priam St.
Chester Hill, NSW, 2162, Australia
Phone: (02) 644 4009
VERSION LIST - Most recent version first.
04/Jul/82 Added "usage" display when a "?" is entered
on command line or in response to drive prompt.
Bill Bolton, Software Tools
You may make as many copies of this programme in either
source or .COM forms as you like for your own use, or for
your friends, relatives, dogs, cats, mothers-in-law etc.
HOWEVER if I ever hear of anyone commercially marketing
this I'll come and find them and insert their heads
into an S-100 slot!!!
All I ask is that because I did the original work that
you leave my name where it is in the programme. After
all, nobody else should get the blame for my shoddy
programming!
The function of BACKUP is to copy files from one disk to
another much as PIP does. The difference is that BACKUP
normally will not make a copy when a filename is found on
the destination disk. Therefore, if this programme is used
then you can be sure that NO files will accidently be
clobbered!
BACKUP also allows the following features:
(i) many filename masks may be included together.
They must be separated only by commas, NO SPACES!
e.g. "*.com,backup.c"
(ii) The NOT wildcard is supported when used as the first
character of a filename mask.
e.g. "!*.com" would match ALL the non .COM files.
(iii) both source and destination disks may be changed
many times during a run, as prompted by BACKUP.
(iv) If required, existing files may be renamed as .BAK
and then the copy will proceed.
(v) If required, then ONLY existing files will be copied
e.g. for installing an updated copy of a compiler etc.
(vi) If required, the copy will be stopped at the first ^Z
detected.
(vii) If required, the VERIFY programme will be called
automatically, and the BACKUP parameters will be
passed to it.
CALLING PROCEDURE:
BACKUP may be called simply by typing BACKUP<cr>;
however, the following parameters may be included on the
CP/M command line:
(i) mask(s) This must be the first parameter and will
control which files are copied.
ALL THE PARAMETERS WHICH FOLLOW MAY OCCUR IN ANY ORDER AT ALL
WITH OR WITHOUT SPACES BETWEEN THEM.
(ii) <d copy FROM drive 'd'
(iii) >d copy TO drive 'd'
(iv) n Don't prompt for disk changes
(v) b If file exists rename to .BAK and then copy
(vi) v Run VERIFY after BACKUP is finished
(vii) z Copy only to the first CP/M EOF (^Z).
(viii) i Inverse mode. Copy ONLY files which exist on
both source and destination disks.
(ix) d Debug mode. Show where everything is in RAM
BACKUP configures itself to make the most of
your system.
(x) r Remember which files have been backed up so
that subsequent runs will not repeat.
(Implies also the Check mode below.)
(xi) c Check (only) for previous backups
(xii) p Print out parameter settings
\*******************************************************/
#include bdscio.h
#define VERSION "1.3"
#define STACKSPACE 0x1000
#define DATE "July 5th, 1982"
#define TIME "14:00"
#define V_DEFAULT FALSE /* these default values */
#define Z_DEFAULT FALSE /* should be changed to */
#define N_DEFAULT FALSE /* configure any special*/
#define B_DEFAULT FALSE /* BACKUP for any */
#define M_DEFAULT FALSE /* particular application*/
#define D_DEFAULT FALSE
#define R_DEFAULT FALSE
#define C_DEFAULT FALSE
#define P_DEFAULT TRUE
char mask [50]; /* Buffer for filename masks */
char pass_mask [50]; /* The masks passed to VERIFY*/
char work_mask [16];
char fcb1 [36];
char fn [14];
int code;
int files;
int copies;
char *dir; /* Where to find DIR */
char *databuf; /* Where to buffer stuff */
unsigned stackspace;
int sectors; /* sectors to buffer */
char id;
char od;
char ld;
char fn1 [16];
char fn2 [16];
char fn3 [16];
char fn4 [16];
char temp [20];
char verify;
char ctr_z;
int found_eof;
int no_wait;
int debug;
int bak;
int mode;
int remember;
int check;
int parm;
int no_bak;
int read_only;
int system;
int bak_flag;
int not_mask;
char mask2 [36];
int masks;
int matched;
int total_matched;
int total_copied;
int no_questions;
main (argc,argv)
char **argv;
{
int x;
int p,z;
char *y;
y = 0x501; *y = 0x20; /* modifies fn
'legfc' in RTP */
stackspace = STACKSPACE; /* configure */
dir = endext (); /* the RAM */
printf ("\nBACKUP, Ver %s, ",VERSION);
printf ("%s, by Steve de Plater\n\n",DATE);
verify = V_DEFAULT;
ctr_z = Z_DEFAULT;
no_wait = N_DEFAULT;
bak = B_DEFAULT;
mode = M_DEFAULT;
debug = D_DEFAULT;
remember = R_DEFAULT;
check = C_DEFAULT;
parm = P_DEFAULT;
getclp (argc,argv,&id,&od,
&verify,&ctr_z,&no_wait,&bak,&mode,&debug,
&remember,&check,&parm);
if (remember)
check = TRUE;
if (parm){
printf ("Parameter flag settings for this run are:\n");
printflg ("(i) Run Verify :",verify);
printflg ("(ii) Stop on ^Z :",ctr_z);
printflg ("(iii) No-Waiting :",no_wait);
printflg ("(iv) Backup file :",bak);
printflg ("(v) Inverse mode :",mode);
printflg ("(vi) Debug mode :",debug);
printflg ("(vii) Remember :",remember);
printflg ("(viii) Check prev. :",check);
putch ('\n');
}
if (argc < 2)
getmask ();
else
strcpy (mask,argv[1]);
strcpy (pass_mask,mask);
ld=bdos(25) + 'A';
matched = copies = total_matched = total_copied = 0;
no_questions = TRUE;
do_it ();
}
getmask ()
{
int x;
printf ("Which files? ");
gets (mask);
for (x=0; *(mask+x); x++)
*(mask+x) = toupper (*(mask+x));
no_questions = FALSE;
}
getdir (fcb)
char *fcb;
{
int x,y,z;
char *s;
y=files<<4;
s=0x80+(code<<5);
if (*(s+12))
return;
files++;
for (x=0; x<16; x++){
dir[y]=*(s+x);
y++;
}
}
match_mask (s)
char *s;
{
int x,y;
y=TRUE;
for (x=1; x<12; x++){
if (((*(s+x)&0x7f) != mask2[x]) &&
(mask2[x] != '?' )){
y=FALSE;
}
}
if (not_mask)
return !y;
else
return y;
}
does_exist (s)
char *s;
{
char fcb [36];
setfcb (fcb,s);
if (bdos (17,fcb) > 3)
return FALSE;
else
return TRUE;
}
copy (s1,s2)
char *s1,*s2;
{
int fd1,fd2;
int x,y,z;
int records;
records=0;
if ((fd1=open (s1,0)) == ERROR){
printf (" OPEN ERROR: Can't open '%s\n",s1);
quit (1);
}
if ((fd2=creat (s2)) == ERROR){
change_disks (s2,fd1,fd2);
return;
}
found_eof = FALSE;
while (TRUE){
x = read (fd1,databuf,sectors);
if (!x)
break;
if (ctr_z)
z = check_eof (databuf,x); /* returns sector */
else /* which contains */
z = x; /* ^Z */
y = write (fd2,databuf,z);
if (y != z){
change_disks (s2,fd1,fd2);
return;
}
records+=z;
if (z < sectors)
break;
if (found_eof)
break;
}
close (fd2);
fabort (fd1);
fabort (fd2);
printf ("%4d records ",records);
if (read_only)
printf ("R/O ");
else
printf (" ");
if (system)
printf ("SYS ");
else
printf (" ");
if (bak_flag)
printf ("BAK");
putch ('\n');
copies++;
}
quit (a)
int a;
{
char t1[5],t2[5];
if (!a){
printf ("%d file",matched);
if (matched != 1)
putch ('s');
printf (" matched, %d copied\n",copies);
}
total_matched += matched;
matched = 0;
total_copied += copies;
copies = 0;
if (!no_wait){
printf ("\nMore ? ");
if (toupper (getchar ()) == 'Y'){
printf ("\n\n");
getmask ();
id = od = FALSE;
do_it ();
}
printf ("\nTotal Matched %d, Total Copied %d",
total_matched,total_copied);
printf ("\nMount system disk on drive '%c'\n",ld);
printf (" press <CR> to continue: ");
bios (3); putch ('\n');
}
temp[0]=ld;
temp[1]=':';
temp[2]=0;
strcat (temp,"verify.com");
if (verify)
if (does_exist (temp)){
t1[0]=id;
t2[0]=od;
t1[1]=0;
t2[1]=0;
strcpy (temp,"<");
strcat (temp,t1);
strcat (temp,">");
strcat (temp,t2);
if (ctr_z)
strcat (temp,"Z");
if (no_wait)