COMCPY.C
资源名称:drdossrc.zip [点击查看]
上传用户:xiaogehua
上传日期:2007-01-08
资源大小:1183k
文件大小:43k
源码类别:
操作系统开发
开发平台:
Asm
- /*
- ; File : $Workfile: COMCPY.C$
- ;
- ; Description :
- ;
- ; Original Author : DIGITAL RESEARCH
- ;
- ; Last Edited By : $CALDERA$
- ;
- ;-----------------------------------------------------------------------;
- ; Copyright Work of Caldera, Inc. All Rights Reserved.
- ;
- ; THIS WORK IS A COPYRIGHT WORK AND CONTAINS CONFIDENTIAL,
- ; PROPRIETARY AND TRADE SECRET INFORMATION OF CALDERA, INC.
- ; ACCESS TO THIS WORK IS RESTRICTED TO (I) CALDERA, INC. EMPLOYEES
- ; WHO HAVE A NEED TO KNOW TO PERFORM TASKS WITHIN THE SCOPE OF
- ; THEIR ASSIGNMENTS AND (II) ENTITIES OTHER THAN CALDERA, INC. WHO
- ; HAVE ACCEPTED THE CALDERA OPENDOS SOURCE LICENSE OR OTHER CALDERA LICENSE
- ; AGREEMENTS. EXCEPT UNDER THE EXPRESS TERMS OF THE CALDERA LICENSE
- ; AGREEMENT NO PART OF THIS WORK MAY BE USED, PRACTICED, PERFORMED,
- ; COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED, ABRIDGED,
- ; CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, RECAST,
- ; TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF
- ; CALDERA, INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT
- ; AUTHORIZATION COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND
- ; CIVIL LIABILITY.
- ;-----------------------------------------------------------------------;
- ;
- ; *** Current Edit History ***
- ; *** End of Current Edit History ***
- ;
- ; $Log$
- ; ENDLOG
- */
- /*
- File COMCPY.C
- Title Copy module for command.com
- Revision History:-
- ==================
- Date Description
- -----------------------------------------------------------------------------
- 20/05/86 Command.com copy routine
- Based on earlier comcpy.c but heavily modified
- 6/06/86 Destination file given the same attributes as source file
- (only applicable to non concatinate cases etc as per
- timestamping)
- Verify calls added
- 24/06/86 Special case of file+,, ('touch') supported
- 27/06/86 Destination now only opened at last possible moment
- (in copy1 routine), to speed up floppy to floppy copying
- 03/07/86 ow supports copy bill+fred bill without destroying the
- original contents of bill. Also supports copy ref.lst+*.lst
- 4 Aug 86 ANSI C compatibilty MSC /W1
- 3 Oct 86 Fix bug in REPWILD temp[12] to temp[13]
- 21 Nov 86 Fixed bug in DOSIF MS_DATETIME
- ------------- DOS Plus 2.1 and 2.1b internal release
- 8 Dec 86 Rewritten to handle single drive copying better
- added preread and readsrc
- 11 Dec 86 Number of files copied message moved into message.c
- 11 Dec 86 Gastly fix for single floppy drive copy of large file
- as DOS Plus wont allow us to keep the destination file open
- when swapping floppies
- (ABswap and ABloop1 flags added)
- 12 Dec 86 Finished and thoroughly tested for DOS Plus 2.1d release
- The few minor bugs remaining are documented in dosplus.doc
- Although the code is now very messy it seems to work well!
- 31 Dec 86 If copying from aux device, set buffer size to 1
- 16 Feb 87 Changed check for single physical floppy disk drive
- to make more generic
- 8 Sep 87 Incorporation of these DOS Plus sources into the Concurrent
- DOS COMMAND.EXE and COPY.EXE files. The memory management
- has been modified to use an internal static buffer for
- copying. An unused routines have been deleted.
- 10 Sep 87 Force BufSize to be a multiple of 512 bytes otherwise
- files greater than the buffer size are not copied.
- 10 Sep 87 Add an extra check to isfile to check for the case "d:"
- 13 Oct 87 Add the /Z option which will force the data to be masked
- with 0x7F to zero the top bit.
- 16 Oct 87 /S option copies hidden files as well as system files
- 16 Oct 87 Copys files with passwords (if source password specified)
- (nb destination does not receive a password unless one is
- explicitly set)
- 19 Oct 87 Added /C confirm option
- 30 Oct 87 isfile() checks for trailing '' as a special case
- 05 Nov 87 Moved isdev(fn1) test till after removing flags from fn1
- 10 Nov 87 If destination is a device, assume ascii when reading source
- and dont send a final ^Z (unless overridden by user flags)
- 5 Apr 88 If Sharing mode open fails on the source file try using
- a compatibilty mode open. For FrameWork SETUP.EXE.
- 20 May 88 Update the ISFILE routine to use the FPTR routine. Fixs the
- Novell COPY bug.
- 25 May 88 Close any open batch files for WS2000 install which copies
- over its installation batch file.
- 27 May 88 Added string undefs.
- 28 Sep 88 Read data from the source device till the buffer is full or
- a ^Z has been reached. Donot append a ^Z to a file when copying
- from a device unless /A used.
- 21 Dec 88 Use IOCTL to determine if a handle is attached to a device
- or not.
- 1 Mar 89 Ignore '[',']','"'
- 14 Apr 89 If dest is a device and /b specified (either src or dst) set
- device to binary
- 6 Jun 89 Do not explicitly set the hidden attribute on password
- protected files let OS do it for us.
- 12 Jun 89 Use all of allocated buffer even for Device Reads
- 14 Jul 89 Move findeof to assembler for speed
- 4 Aug 89 Used to ignore /b on concat src if dest was device
- 6-Mar-90 Watcom C v 7.0
- 22-Mar-90 Copy with control chars cmd string (get_pno terminate bug)
- 8-May-90 "File not found" error goes to STDOUT, not STDERR.
- 24-May-90 samefs uses ms_x_expand to check full physical path
- 5-Jun-90 BODGE copy to dev to be 1 char at a time so we can retry
- correctly (BDOS bug workaround)
- 11-Jun-90 "COPY file1 file2 ; " hanging cured. I hate get_pno.
- 27-Nov-90 samefs() no longer uses ms_x_expand(), for PCNFS
- compatibility.
- 15-Jan-91 "COPY a+b+c d" no longer stops if b does not exist.
- DRDOS BUXTON
- ------------
- 1-Mar-91 COPY /B FILE DEVICE is now supported.
- Copying to a dev is no longer 1 char at a time, in anticipation
- of a fix in the BDOS.
- 2-Apr-91 COPY no longer forces time/date/attributes of source onto
- destination.
- 7-May-91 time/date is now preserved again, attributes are not.
- DRDOS PANTHER
- -------------
- 22-Jun-92 Support for Novell Remote copy added.
- See call to novell_copy().
- ----------------------------------------------------------------------------
- */
- #include "defines.h"
- #include <string.h>
- #if defined(MWC) && defined(strlen)
- #undef strcmp /* These are defined as macros in string.h */
- #undef strcpy /* which are expaneded in line under */
- #undef strlen /* Metaware C. These undefs avoid this. */
- #endif
- #include <portab.h>
- #include <mserror.h>
- #include "command.h" /* COMMAND Definitions */
- #include "dos.h" /* MSDOS Functions */
- #include "dosif.h" /* DOS interface definitions */
- #include "toupper.h"
- #include "support.h" /* Support routines */
- #include "global.h"
- EXTERN VOID batch_close(VOID); /* BATCH.C */
- MLOCAL BYTE * skip_switch(BYTE *);
- MLOCAL BYTE * get_p1(BYTE *, BYTE *, BYTE *);
- MLOCAL BYTE * get_pno(BYTE *, BYTE *);
- MLOCAL BOOLEAN isfile(BYTE *);
- MLOCAL VOID addwild(BYTE *);
- MLOCAL BOOLEAN dopen(BYTE *);
- MLOCAL VOID dclose(BYTE *, WORD, WORD);
- MLOCAL BOOLEAN preread(BYTE *);
- MLOCAL WORD readsrc(VOID);
- MLOCAL WORD copy1(BYTE *, BYTE *);
- MLOCAL BOOLEAN lseek(BYTE *);
- MLOCAL BOOLEAN samefs(BYTE *, BYTE *, WORD);
- MLOCAL WORD ABcheck(BYTE *, BYTE *);
- MLOCAL VOID prtsrc(BYTE *);
- MLOCAL WORD conf_src(BYTE *);
- MLOCAL VOID e_check2(WORD);
- MLOCAL BOOLEAN touch(BYTE *);
- MLOCAL BYTE * get_pswd(BYTE *);
- /* define external variables used */
- #define COPY_VERIFY (global_flg & 1) /* Set Verify Flag */
- #define COPY_SYS (global_flg & 2) /* Include SYSTEM Files */
- #define COPY_ZERO (global_flg & 4) /* Zero the eighth Bit */
- #define COPY_CONFIRM (global_flg & 8) /* Confirm each file */
- #define COPYSRC_ASC (sflag & 1) /* Source is ASCII */
- #define COPYSRC_BIN (sflag & 2) /* Source is Binary */
- #define COPYDST_ASC (dflag & 1) /* Destination is ASCII */
- #define COPYDST_BIN (dflag & 2) /* Destination is BINARY*/
- #define MIN_COPYBUF (10 * (1024/16)) /* Minimum Copy Buffer Size */
- #define MAX_COPYBUF (50 * (1024/16)) /* Maximum Copy Buffer Size */
- /* define static variables for this module */
- MLOCAL BYTE *lp;
- MLOCAL UWORD global_flg; /* Global Flags Verify, System & Zero */
- MLOCAL UWORD dflag;
- MLOCAL BOOLEAN sascii; /* treat current source file as ascii */
- MLOCAL BOOLEAN sbin;
- MLOCAL BOOLEAN concat;
- MLOCAL WORD nfiles; /* number of files copied */
- MLOCAL WORD dfh; /* destination file handle */
- MLOCAL BOOLEAN dstopen; /* destination open */
- MLOCAL WORD sfh;
- MLOCAL ULONG src_len;
- MLOCAL BOOLEAN srcopen; /* flag whether src is still open */
- MLOCAL BOOLEAN srcdev;
- MLOCAL BOOLEAN dstdev;
- MLOCAL BOOLEAN fullbuf; /* buffer contains data */
- MLOCAL BOOLEAN dfailed;
- MLOCAL BOOLEAN ABswap; /* single floppy disk drive copy with disk swap */
- MLOCAL BOOLEAN tstamp; /* set destination timestamp to same as source */
- MLOCAL UWORD date,time; /* source date and time */
- MLOCAL UWORD attrib; /* source file attributes */
- MLOCAL UWORD amount; /* amount of real data in buffer */
- /* ---- start of code ---------------------------------------------*/
- GLOBAL VOID CDECL cmd_copy(cmd)
- BYTE *cmd;
- {
- WORD rmode = 0x0000; /* read mode - normal files only */
- BYTE delim;
- BYTE npara;
- BYTE src[MAX_FILELEN]; /* buffer in which to expand wild source filespec */
- BYTE dest[MAX_FILELEN]; /* buffer in which to expand wild destination filespec */
- #if defined(PASSWORD)
- BYTE password[10]; /* keep note of src password */
- #endif
- BYTE *olp, *tp;
- BYTE *last_delim;
- WORD ret;
- BOOLEAN scheme1;
- BOOLEAN init = YES; /* do initialisations during 1st loop */
- BOOLEAN pflag;
- BOOLEAN tflag; /* touch flag (special case) */
- BOOLEAN confirmed;
- UWORD dosvf; /* used to save current dos verify state */
- UWORD sflag; /* Source File Options */
- /* scheme2 extra bits */
- BYTE wdfn[13]; /* used by scheme2 to save wild destination filename */
- BYTE *dfptr;
- BYTE *ocmd;
- BYTE src2[MAX_FILELEN]; /* 2nd src buffer for scheme2 */
- DTA search; /* DOS Search Buffer */
- sascii = NO; /* indicates if current source is ascii or not */
- sbin = NO; /* sbin indicates if an explicit /b found */
- concat = NO;
- dfailed = ABswap = NO;
- srcopen = dstopen = NO; /* No file are Open */
- nfiles=0; /* number of files copied */
- cmd = deblank(cmd); /* remove leading spaces */
- strlwr(cmd); /* force it all to lower case first */
- strcpy(heap(),cmd); /* make temp copy of cmd line */
- if(f_check(heap(), "vszcab", &global_flg, NO)) /* check for any bad flags */
- return; /* exit if any (with message) */
- /* also zaps any valid flags but not important is this is a temp copy */
- f_check(cmd,"vszc",&global_flg,YES); /* check for, and zap verify, sys, zero and confirm flags */
- if(COPY_SYS) {
- rmode |= ATTR_SYS; /* read system files also*/
- rmode |= ATTR_HID; /* read hidden files also*/
- } /* nb /s flag acts globally */
- cmd = deblank (cmd); /* deblank incase /v was at start of line */
- while(*cmd == *switchar) { /* process any initial switches */
- if(*(cmd+1)=='a')
- sascii=YES;
- if(*(cmd+1)=='b') {
- sascii=NO;
- sbin=YES;
- }
- cmd = deblank (cmd+2);
- }
- lp = get_pno(cmd,&npara);
- olp =lp; /* save lp ptr (as lp possibly modified later) */
- /* olp is used as the end of the list of source parameters */
- if(npara > 1) /* dont remove switches if npara=1 as they will be processed when fn1 switches are checked */
- f_check( lp, "ab", &dflag, YES); /* check for, and zap destination a and b flags */
- /* store them in dflag for later use */
- last_delim = lp-1;
- while (*last_delim == 32) last_delim--;
- zap_spaces(lp);
- cmd = get_p1(src, deblank(cmd), &delim); /* separate 1st filename spec from rest */
- if(delim == '=') { /* if the user spells PIP as COPY */
- syntax(); /* exit with syntax error */
- return;
- }
- if(npara>2 && delim!='+') {
- printf(MSG_INOP); /* invalid number of parameters */
- return;
- }
- if(!d_check(src))
- return; /* invalid drive */
- f_check( src, "ab", &sflag, YES); /* check for, and zap flags in fn1 */
- if(COPYSRC_ASC)
- sascii=YES;
- if(COPYSRC_BIN) {
- sascii=NO; /* nb /b checked last by default */
- sbin=YES;
- }
- zap_spaces (src);
- /* do adjustments for special cases */
- if (COPYDST_BIN) {
- sbin = YES; /* Does it make sense to have source ascii */
- sascii = NO; /* and dest binary? I think not. */
- }
- if(lp[strlen(lp)-1] == ',')
- lp[strlen(lp)-1] = ' '; /* remove comma from end of lp */
- if(npara==1 && delim!='+')
- if(isfile(lp)) { /* strip drive and path from lp */
- lp = fptr(lp); /* ie pathfile becomes pathfile */
- } /* to file but not if pathfile+ */
- else
- lp=lp+strlen(lp); /* if dir, lp= */
- if(npara==1 && delim=='+') {
- delim=' '; /* not concat if 1 parameter */
- tp=lp;
- while (*tp) { /* remove the + sign from end of lp filespec */
- if(*tp == '+')
- *tp = ' ';
- tp++;
- }
- }
- if(npara>=2 && delim=='+' && *last_delim=='+') {
- /* copy fred+bill dest is fred */
- lp = fptr(src); /* copy pathfred+bill dest is fred */
- olp=cmd+strlen(cmd); /* fiddle olp to end of list of source parameters */
- }
- if(npara==2 && iswild(src) && /* handle special case */
- isfile(lp) && !iswild(lp)) /* of copy *.lst file */
- concat = YES; /* (implied concatination) */
- tflag = (npara>=3 && delim=='+' && *cmd==','); /* touch special case so set tflag */
- if(delim == '+')
- concat = YES;
- if(concat && !sbin) /* concat is ascii unless a /b switch has occured */
- sascii = YES;
- dstdev = NO;
- if (!iswild(lp) && *lp)
- {
- get_filename(dest,lp,YES); /* this turns lpt1: into lpt1 */
- ret = ms_x_open(dest, OPEN_READ); /* Check if destination is */
- if (ret >= 0) /* a device. If so, if /b */
- { /* on src OR dst, copy is */
- if (isdev(ret)) /* binary */
- {
- dstdev = YES;
- if (COPYSRC_BIN || (COPYDST_BIN && !concat) || sbin)
- {
- sbin = YES;
- sascii = NO;
- } /* If no /b, default to */
- else /* ascii */
- {
- sbin = NO;
- sascii = YES;
- }
- }
- ms_x_close (ret);
- }
- }
- mem_alloc(&bufaddr, &bufsize, MIN_COPYBUF, MAX_COPYBUF);
- bufsize <<= 4; /* Allocate the Buffer */
- bufsize &= ~511; /* Force the buffer size to be a*/
- /* multiple of 512 Bytes */
- if(bufsize == 0) { /* If the memory allocation */
- e_check(ED_MEMORY); /* print a memory error and */
- return; /* return to the caller. */
- }
- #if 0 /* UNBODGE */
- /** BODGE **/
- if(dstdev) /* copy to dev 1 char at a time */
- bufsize = 1; /* so retry operates correctly */
- /** BODGE **/
- #endif /* UNBODGE */
- if(batchflg) /* close the BATCH file if OPEN cos */
- batch_close(); /* installation routines copy over */
- /* the current batch file. */
- dosvf = ms_f_getverify(); /* read present dos verify flag*/
- if(COPY_VERIFY)
- ms_f_verify(1); /* set verify */
- if (lp == get_filename(dest, lp, YES)) {
- if (strlen(lp)) {
- printf(MSG_SYNTAX); /* bad filename specified */
- return;
- }
- }
- #if TRUE
- /* ##jc##
- * This Code is a Special for IBM Display Write 4 which attempts
- * to copy "A:DEFAULT.P*T