home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
138_01
/
bu.c
< prev
next >
Wrap
Text File
|
1985-08-21
|
32KB
|
1,028 lines
/*
HEADER: CUG
TITLE: BU.C - Archival File Backup Utility for CP/M
VERSION: 1.1
DATE: 01/18/85
DESCRIPTION: "Published under the title "Archiving Files with
CP/M-80 and CP/M-86" in the January 1985 issue of
DR. DOBB'S JOURNAL, BU is an archival file backup
utility for hard disks as well as floppies.
Functions include file copy and verification
using all of free RAM memory and full runtime
validation of CP/M file references entered on
command line."
KEYWORDS: archival, backup, CP/M, CP/M-80, CP/M-86, DDJ
SYSTEM: Any CP/M-80 or CP/M-86 system
FILENAME: BU.C
WARNINGS: "BU cannot detect files that have been updated
through random access disk writes or have had
data appended through sequential disk writes. It
will detect files that have been rewritten in
their entirety or have been renamed. In practise,
this has been found to be a minor inconvenience."
CRC: xxxx
SEE-ALSO: BU.DOC
AUTHORS: Ian Ashdown - byHeart Software
COMPILERS: Any C compiler for CP/M-80 or CP/M-86
REFERENCES: AUTHORS: Ian Ashdown;
TITLE: 'Archiving Files with CP/M-80 and
CP/M-86'
Dr. Dobb's Journal
January, 1985;
ENDREF
*/
/*-------------------------------------------------------------*/
/* BU.C - A File Backup Utility for CP/M-80 & CP/M-86
*
* Copyright: Ian Ashdown
* byHeart Software
* 2 - 2016 West First Avenue
* Vancouver, B.C. V6J 1G8
* Canada
*
* This program may be copied for personal, non-commercial use
* only, provided that the above copyright notice is included in
* all copies of the source code. Copying for any other use
* without previously obtaining the written permission of the
* author is prohibited.
*
* pHILANTHROPICAL nOTES:
*
* Considerable time and effort went into the development of this
* software, which was expressly written for the public domain.
* The author will gladly accept any and all monetary
* contributions for the purpose of continuing such work!
*
* Acknowledgment: DeSmet C code and suggestions for program
* improvement courtesy of Dr. Dobb's Journal
* Contributing Editor Anthony Skjellum. This
* program appeared in the January 1985 issue
* of Dr. Dobb's Journal under the title of
* "Archiving Files with CP/M-80 and CP/M-86".
*
* Version: 1.1 Written for Aztec CII v1.06b (CP/M-80)
* and DeSmet C88 v2.2 (CP/M-86)
*
* Date: December 31st, 1983 (Version 1.0)
* September 7th, 1984 (Version 1.1)
* January 18th, 1985 (Public Domain Release)
*
* Version Modifications:
*
* 24/09/84 - "read()" and "write()" accept maximum of 32767
* bytes, not 32768. Functions "copy_file()" and
* "verify_file()" modified accordingly.
*
* BU utilizes the undocumented "archive" file attribute feature
* of CP/M-80 Versions 2.x and CP/M-86 to automatically detect
* files that have been changed since the disk was last "backed
* up" and copy them (with verification) to a backup disk. This
* program performs the same action as the "A" option of PIP
* under Digital Research's MP/M 2, for which the Archive
* attribute is documented.
*
* Usage: BU x[:afn] y [-AFHQSn]
*
* where x = drive name of disk to be backed up
* y = drive name of backup disk
*
* and the optional arguments are:
*
* -A All files, regardless of status
* -F Fast copy (without verification)
* -H Hard disk (files may be split)
* -Q Query each file before backup
* -S System attribute copied to backup
* -n Backup USER 'n' files only (0-31)
* afn Any legal CP/M ambiguous fileref
* (can only be used with -n option)
*/
#include "stdio.h"
#include "ctype.h" /* Contains macro for "isdigit()" */
/*** DEFINITIONS ***/
#define AZTEC 1 /* Aztec CII v1.06b (CP/M-80) */
#define DESMET 0 /* DeSmet C88 v2.2 (CP/M-86) */
#if DESMET
#define movmem(src,dest,len) _mov(len,src,dest)
#endif
#define ERROR -1
#define DEL -1 /* Deleted fileref flag */
#define ALL -1 /* All user numbers flag */
#define TRUE -1
#define FALSE 0
#define SUCCESS 0
#define O_RDONLY 0
#define USER_ERR 0 /* Specified fileref must only be used
with -number command-line option */
#define BAD_FREF 1 /* Illegal file reference */
#define BAD_ARGS 2 /* Illegal command line */
#define BAD_OPT 3 /* Illegal option */
#define BAD_USER 4 /* Illegal user number */
#define BAD_DRV 5 /* Illegal drive names */
#define SAME_DRV 6 /* Same drive name for output as input */
#define OPN_ERR 8 /* File open error */
#define READ_ERR 9 /* File read error */
#define CLS_ERR 10 /* File close error */
#define BAD_VFY 11 /* File verify error */
#define DIR_IO 6 /* BDOS Direct I/O service */
#define RESET_DRV 13 /* BDOS Reset All Drives service */
#define SEL_DRV 14 /* BDOS Select Drive service */
#define SRCH_F 17 /* BDOS Search Next service */
#define SRCH_N 18 /* BDOS Search Next service */
#define GET_DRV 25 /* BDOS Get Default Drive service */
#define SET_DMA 26 /* BDOS Set DMA Address service */
#define SET_ATT 30 /* BDOS Set File Attributes service */
#define USER_CODE 32 /* BDOS Get/Set User Code service */
#define MAX_USER 32 /* 32 user codes under CP/M (see DR's
documentation for BDOS Service 32) */
/*** GLOBAL VARIABLES ***/
char ent_drv, /* Entry drive code */
ent_user, /* Entry user code */
cur_user; /* Current user code */
/*** MAIN BODY OF CODE ***/
main(argc,argv)
int argc;
char *argv[];
{
char in_dsk, /* Drive name of input disk */
out_dsk, /* Drive name of output (backup) disk */
in_drv, /* Drive code of input disk */
out_drv, /* Drive code of output disk */
seg_no, /* Segment number for split files */
in_file[15], /* Fileref of current input file */
out_file[15], /* Fileref of current output file */
c, /* Scratch variable */
*s, /* Scratch string pointer */
*buffer, /* Pointer to directory entry returned */
/* by "srch_file()" */
*srch_file(),
*malloc();
/* File control blocks of current input and output files */
static char in_fcb[33], /* (Automatically initialized */
out_fcb[33]; /* to zero by compiler) */
/* Structure for linked list of filerefs */
struct file_ref
{
char name[12]; /* File reference */
struct file_ref *next; /* Pointer to next instance */
} root, /* Start of linked list */
*fref_1, /* Scratch pointers to */
*fref_2; /* linked list instances */
/* Initialized file control block for "srch_file()". This FCB
is for a fully ambiguous fileref that causes "srch_file()"
to return all directory entries for the current default
drive. */
static char fcb[] = {'?','?','?','?','?','?','?','?',
'?','?','?','?','?',0,0,0};
int file_cnt = 0, /* Count of file to be backed up */
dup_flag, /* Duplicate fileref flag */
all_files, /* All_files flag (cmd-line option) */
fast_copy, /* Fast copy flag (cmd-line option) */
hard_disk, /* Hard disk flag (cmd-line option) */
query, /* Query flag (cmd-line option) */
system, /* System flag (cmd-line option) */
user_no, /* User number (cmd-line option) */
next_flag = FALSE;/* Flag to indicate to "srch_file()"
that a "search next" is required */
register int i,j; /* Loop indices */
long begin, /* Input file position variables */
end;
/* Display program header */
printf("\nBU Version 1.1");
printf(" Copyright 1983, 1984");
printf(" byHeart Software\n\n");
/* Initialize command-line options */
all_files = FALSE; /* Copy only non-archived files */
fast_copy = FALSE; /* Copy files with verification */
hard_disk = FALSE; /* Files will not be split across backup
disks if remaining capacity of backup
disk is less than current file size */
query = FALSE; /* Backup without query */
system = FALSE; /* Assign directory attribu