home *** CD-ROM | disk | FTP | other *** search
- ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- ;
- ; Name - QBCOPY.OBJ
- ;
- ; Revised - 07/22/90 03:36pm
- ;
- ; Purpose - Allows fairly rapid copying of a file without leaving QB.
- ;
- ; This routine should be DECLAREd in your program as an external
- ; FUNCTION, via the QuickBASIC statement -
- ;
- ; DECLARE FUNCTION( InFile$, OutFile$, Segmt%)
- ;
- ; Parms - The three parameters you must pass to this routine are
- ; defined as follows -
- ;
- ; InFile - The name (optionally including drive and path specs)
- ; of the file you wish to copy. THIS MUST END IN CHR$(0)
- ; OutFile - The name (optionally including drive and path specs
- ; which need not be the same as InFile) to give to the
- ; copy.
- ; Note that the copy will carry the same file date and
- ; time as the InFile original.
- ;
- ; The remaining one is, as in the example above, the SEGMENT
- ; portion of the address of the area to use for the copy.
- ; This corresponds to the SEGMENT address of the array you
- ; DIMmed (see below for more details).
- ;
- ; Returns : There are three possible returns -
- ;
- ; 0 = no errors were detected
- ; 1 = could not open InFile
- ; 2 = could not open OutFile
- ; 3 = error writing Outfile
- ; 4 = error reading InFile
- ;
- ; NOTE : This routine REQUIRES you to DIM an array (as a $DYNAMIC array)
- ; defined as DIM array(1 to 16) AS STRING * 4096) prior to
- ; invoking this routine.
- ; The purpose of this statement is to provide a CONTIGUOUS AREA
- ; in RAM MEMORY which is a full segment in length.
- ; This, by the way, also simplifies things later in the routine,
- ; when we can make the assumption that, when a full segment of RAM
- ; is allocated, the starting offset of that segment MUST be = 0.
- ;
- ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- .MODEL MEDIUM,BASIC
- .CODE
-
- QBCopy proc USES DS SI, INFILE:word, OUTFILE:word, ASEG:word
- LOCAL INHANDLE:word, OUTHANDLE:word, ORIGDATE:word, ORIGTIME:word
-
- mov BX,INFILE ; Get start address of InFile spec
- mov DX,[BX+2] ; Put into DX for function
- mov AX,03D00h ; We will attempt to open for READ/ONLY
- int 21h
-
- jnc Open_OutFile ; IF CARRY, then error in opening the
- mov AX,1 ; the InFile, so set AX = error
- jmp short QBCopy_Exit ; code 1, and exit
-
- Open_OutFile:
-
- mov INHANDLE,AX ; If NO CARRY from above open, AX = the
- mov BX,AX ; DOS File Handle, which we will both
- mov AX,5700h ; store and put into BX.
- int 21h
-
- mov ORIGTIME,CX ; Store the original date and time
- mov ORIGDATE,DX ; of InFile so copy will be same
-
- mov AH,03Ch ; "CREATe FILE" service of int 21h
- mov BX,OUTFILE
- xor CX,CX ; Make this a NORMAL file
- mov DX,[BX+2] ; DX = offset of OutFile spec
- int 21h
-
- jnc Start_The_Copy ; If CARRY, then there was an error in
- mov AH,03Eh ; CREATing the OutFile, so
- mov BX,INHANDLE ; put the InFile handle into BX
- int 21h ; and close InFile since we won't
- mov AX,2 ; need it
- ; put error code 2 into
- jmp short QBCopy_Exit ; AX, and exit this routine
-
- Start_The_Copy:
-
- mov OUTHANDLE,AX ; Store file handle for OutFile
- mov BX,ASEG
- mov AX,[BX]
- mov DS,AX ; DS = SEGMENT of PassedArray
-
- Read_InFile_Contents:
-
- xor DX,DX ; DS:DX = SEGMENT:0000 for array
- mov AH,03Fh ; "READ FROM FILE" srvc of INT 21h
- mov BX,INHANDLE ; Read bytes from InFile
- mov CX,65520 ; Maximum # to read = 65,220 bytes
- int 21h
-
- jnc InFile_Read_OK
- mov AX,4 ; Return error as per above
- jmp short QBCopy_Exit
-
- InFile_Read_OK:
-
- cmp AX,0 ; IF NO CARRY, but AX = 0, then we've
- je QBCopy_Finished ; finished reading the InFile
-
- Write_Buffer_Contents:
-
- mov CX,AX ; AX = # bytes actually read above
- xor DX,DX ; DS:DX points at start of buffer again
- mov BX,OUTHANDLE
- mov AH,040h ; Write CX # bytes to OUTHANDLE
- int 21h
-
- jnc Read_InFile_Contents ; If any error, just fall thru and
- mov AX,3 ; close both files
-
- QBCopy_Finished:
-
- push AX ; Save AX, which may contain error code
- mov AH,03Eh
- mov BX,INHANDLE
- int 21h ; Close the InFile
-
- mov AX,5701h ; Set the OutFile Date and Time =
- ; the original
- mov CX,ORIGTIME ; date and time of InFile
- mov DX,ORIGDATE
- mov BX,OUTHANDLE
- int 21h
-
- mov AH,03Eh
- mov BX,OUTHANDLE
- int 21h ; Close the OutFile
- pop AX ; Retrieve entry AX value
-
- QBCopy_Exit:
-
- ret
-
- QBCopy ENDP
- END
-
- ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++