summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/XCOPY/XCOPY.ASM
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/XCOPY/XCOPY.ASM')
-rw-r--r--v4.0/src/CMD/XCOPY/XCOPY.ASM3866
1 files changed, 3866 insertions, 0 deletions
diff --git a/v4.0/src/CMD/XCOPY/XCOPY.ASM b/v4.0/src/CMD/XCOPY/XCOPY.ASM
new file mode 100644
index 0000000..9a64f22
--- /dev/null
+++ b/v4.0/src/CMD/XCOPY/XCOPY.ASM
@@ -0,0 +1,3866 @@
1 PAGE, 132 ;
2TITLE XCOPY WITH FULL MEMORY USE - Ver. 4.00
3
4;****************** START OF SPECIFICATIONS *****************************
5; MODULE NAME: XCOPY
6;
7; DESCRIPTIVE NAME: selectively copy groups of files, which can include
8; lower level subdirectories.
9;
10; FUNCTION: The modules of XCOPY will be placed in the following order -
11; SSEG, DSEG(MAIN DATA, MAIN MSG), CSEG (MAIN + INIT),
12; DSEG_INIT(INIT DATA, INIT MSG)
13;
14; HEADER - informations needed about the file, subdirectory ...
15; Continue_Info -> 0 - a whole single file in this header
16; segment, or dir.
17; 1 - Continuation of a small file.
18; 2 - Continuation of a Big file
19; 3 - Eof of continuation
20; Next_Ptr -> points to the next header segment
21; Before_Ptr -> points to the old header segment
22;
23; By optionally using the Archive bit in the directory of each
24; file, XCOPY can be used as an alternative method of creating
25; backup files which can be accessed directly by DOS and its
26; applications without the need to "restore" the backup files.
27;
28; XCOPY is especially useful when several files are being copied
29; and there is a generous amount of RAM available, because XCOPY
30; will fill the memory with all the source files it can read in
31; before starting to create output files. If the memory is not
32; enough to hold all the source, this cycle will be repeated until
33; the process is completed. For single drive systems, this maximum
34; usage of the memory greatly reduces the amount of diskette
35; swapping that would be required by the usual COPY command.
36;
37; ENTRY POINT: MAIN
38;
39; INPUT: (DOS COMMAND LINE PARAMETERS)
40;
41; SOURCE OPERAND: TARGET OPERAND:
42;
43; [d:] [path] filename[.ext] [d:] [path] [filename[.ext]]
44; or
45; [d:] path [filename[.ext]]
46; or
47; d: [path] [filename[.ext]]
48;
49;
50; SWITCHES:
51;
52; /A /D /E /M /P /S /V /W
53;
54;The /A switch will copy only those files whose archive bit of the attribute is
55;set to one. The attribute of the source file is not changed. This option is
56;useful when making multiple backups when doing the non-final backup.
57;The archive bit is one when a file has be created or Revised since the last
58;time the bit was turned off. XCOPY /M or BACKUP /M will turn this bit off.
59;The ATTRIB command can also be used to change the setting of the archive bit.
60;
61;The /D switch will copy only those files whose date is the same or later than
62;the date specified. Depending on the country code you selected using the
63;COUNTRY command, the date is specified in the format corresponding to the
64;indicated country.
65;
66;The /E switch will create subdirectories on the target even if they end up
67;being empty after all copying is over. If /E is not specified, empty
68;subdirectories are not created.
69;
70;The /M switch will copy only those files whose archive bit is set in its
71;attribute. Unlike the /A switch, /M will cause the archive bit in the source
72;file to be turned off. This allows XCOPY to be used in making a final backup.
73;The archive bit is one when a file has be created or Revised since the last
74;time the bit was turned off. XCOPY /M or BACKUP /M will turn this bit off.
75;The ATTRIB command can also be used to change the setting of the archive bit.
76;
77;The /P switch will prompt the operator before copying each file. In this
78;situation, each file is copied onto the target before reading in the next
79;file. The multi-file copy into a large memory buffer is not done. The prompt
80;displays the complete filespec it proposes to copy and asks for (Y/N)
81;response, which is then read in from the standard input device.
82;
83;The /S switch will not only copy the files in the current source directory but
84;also those in all the subdirectories below the current one, with XCOPY
85;following the Tree of the subdirectories to access these files. /S does not
86;create an empty subdirectory on the target (unless /E is also specified).
87;If the /S switch is not specified, XCOPY works only within the specified (or
88;current) subdirectory of the source.
89;
90;The /V switch will cause DOS to verify that the sectors written on the target
91;are recorded properly. This option has been provided so you can verify that
92;critical data has been correctly recorded. This option will cause XCOPY to
93;run more slowly, due to the additional overhead of verification.
94;
95;The /W switch will instruct XCOPY to pause before actually starting the
96;movement of data, thus permit the copying of diskettes that do not actually
97;have XCOPY available on them. The diskette containing XCOPY can be mounted
98;first, the XCOPY command given with the /W option, then when the prompt
99;requesting permission to continue is given, that diskette can then be removed
100;and the source diskette mounted in its place, then the operator can press any
101;key to continue after the pause. This feature is especially useful in a
102;non-hardfile system.
103;
104; EXIT-NORMAL: ERRORLEVEL_0 - This is the normal completion code.
105; ERRORLEVEL_2 - This is due to termination via Control-Break.
106; ERRORLEVEL_4 - This is used to indicate an error condition.
107;
108; There are many types of problems that are detected and result in this
109; return code, such as:
110;
111; write failure due to hard disk error
112; disk full
113; conflict between name of new subdirectory and existing filename
114; access denied
115; too many open files
116; sharing violation
117; lock violation
118; general failure
119; file not found
120; path not found
121; directory full
122; invalid parms
123; reserved file name as source
124; insufficient memory
125; incorrect DOS version
126;
127;
128; INTERNAL REFERENCES:
129;
130; ROUTINES:
131;
132;
133; DATA AREAS:
134;
135;
136; EXTERNAL REFERENCES:
137;
138; ROUTINES:
139;
140;
141; DATA AREAS:
142;
143;
144; NOTES: This module should be processed with the SALUT pre-processor
145; with the re-alignment not requested, as:
146;
147; SALUT XCOPY,NUL,;
148;
149; To assemble these modules, the sequential
150; ordering of segments may be used.
151;
152; For LINK instructions:
153; link profile ..\lib
154;
155; REVISION HISTORY: A000 Version 4.00: add PARSER, System Message Handler,
156; Remove the BELL char.,turn off APPEND during TREE
157; search,Extended Attribute processing, Uppercasing
158; and "Out Of Space" during write to standard out.
159; A001 PTM0011 XCOPY not handling path >63 characters.
160; CHK_MAX_LENGTH proc(XCPYINIT) is Revised to err if
161; >63 chrs.
162; A002 PTM0012 XCOPY unnecessarily accessing current drive.
163; ORG_S_T_DEF is Revised to ignore CHDIR if drive
164; is not TARGET or SOURCE.
165; A003 PTM0088 XCOPY (\) missing in 'FILE SHARING ERROR'.
166; This problem is fixed with incorporation of the
167; new message services.
168; A004 PTM0700 9/02/87 Avoid duplicate switches and
169; display parm in error.
170; A005 DCR0201 9/11/87 Incorperate new format for EXTENDED
171; ATTRIBUTES.
172; A006 PTM1490 10/04/87 XCOPY /D CAUSES "INVALID PARAMETER"
173; MSG AND SHOULD BE "INVALID NUMBER OF PARAMETERS" ALSO
174; DATE IS NOT VALIDATED.
175; A007 PTM1657 10/14/87 XCOPY INVALIDLY FAILS TO READ A READ
176; ONLY FILE, AND OUTPUTS THE WRONG MSG.
177; A008 PTM1688 10/15/87 XCOPY NOT CREATING EMPTY SUBDIRS IF
178; THE SOURCE DIR. IS EMPTY.
179; A009 PTM2199 11/02/87 XCOPY NOT HANDELING FILENAMES GREATER
180; THAN 12 CHARACTERS.
181; A010 PTM2203 11/03/87 XCOPY NOT HANDELING DBCS PATH NAMES
182; PROPERLY. (INCORP. CHK. IF 1st BYTE IS DBCS)
183; A011 PTM2271 11/04/87 XCOPY NOT HANDELING FILENAMES GREATER
184; THAN 12 CHARACTERS.(S_FILE BUFFER OVERFLOWES).
185; A012 PTM2347 11/09/87 XCOPY SETTING THE CODE PAGE OF A DEV.
186; AND A DEV. IS NOT ALLOWED FOR A TARGET.
187; A013 PTM2565 11/17/87 XCOPY HANGS AUTOTEST. SET EXTENDED
188; ATTRIBUTE CALL TO DOS POINTS TO INVALID BUFFER.
189; A014 PTM2597 11/20/87 XCOPY REPORTS FILE CREATION ERROR
190; IF TARGET FILE IS GREATER THAN 12 CHARACTERS.
191; A015 PTM2782 12/04/87 XCOPY FILENAME (EXTENSION)
192; TRUNCATION ERROR. INCREASE HEADER BUFFER TO 3 PARA.
193; A016 PTM2783 12/09/87 XCOPY ALLOWS 'ASSIGN' DRIVES TO
194; BE COPIED ONTO THEMSELVS. ADD NEW CODE TO INIT.
195; A017 PTM3139 01/15/88 XCOPY HANGS WHEN TRYING TO OUTPUT
196; "INSUFFICIENT DISK SPACE" FOR MAKE DIRECTORY.
197; A018 PTM3283 02/01/88 XCOPY NEEDS TO CHANGE 'FILE NOT
198; FOUND' MSG TO EXTENDED ERROR MSG FORMAT. ALSO
199; DELETED DEF 28 IN XCOPY.SKL & XMAINMSG.EQU
200; A019 PTM3395 02/08/88 XCOPY FAILING TO SUSPEND THE
201; 'APPEND /X' FUNCTION. FIX IN XCOPY.SAL, XCOPY.EQU,
202; AND DOS.EQU.
203; A020 PTM3344 02/09/88 XCOPY READING PAST TOP_OF_MEMORY,
204; OVER-WRITING VIDIO BUFFER SET BY MODE 13H ON PS2s.
205; A021 PTM3513 02/19/88 XCOPY READING PAST TOP_OF_MEMORY,
206; OVER-WRITING VIDIO BUFFER SET BY MODE 13H ON PS2s.
207; A022 PTM3933 03/18/88 XCOPY NOT RESTORING DIRECTORY OF
208; DEFAULT DRIVE. FIX IN XCOPY.SAL.
209; A023 PTM3904 03/18/88 XCOPY NOT USING PARSE 03 MSG. FOR
210; 'INVALID SWITCH'. FIX IN XCOPY.SKL & XCPYINIT.SAL.
211; A024 PTM3958 03/22/88 XCOPY MSGS DO NOT CONFORM TO SPEC.
212; NEED NULL DELIMITER IN XCPYINIT.SAL.
213; A025 PTM3965 03/23/88 XCOPY LEAVING CURRENT TARGET DIR.
214; CHANGED. FIX IN XCPYINIT.SAL.
215; A026 PTM4920 05/19/88 XCOPY NOT OVERLAYING FILES ON FULL
216; TARGET DISK. FIX IN XCOPY.SAL.
217; A027 PTM5022 06/03/88 'PATH TOO LONG' MSG. WITH TWO CHAR.
218; SOURCE SUBDIR. FILESPEC. FIX IN XCPYINIT.SAL.
219;
220; Label: "The DOS XCOPY Utility"
221; "Version 4.00 (C) Copyright 1988 Microsoft"
222; "Licensed Material - Program Property of Microsoft"
223;
224;****************** END OF SPECIFICATIONS *****************************
225
226;--------------------------------
227; Include Files
228;--------------------------------
229INCLUDE XMAINMSG.EQU ;AN000;message file
230INCLUDE DOS.EQU ;AN000;
231INCLUDE XCOPY.EQU ;AN000;
232
233INCLUDE SYSMSG.INC ;AN000;
234
235MSG_UTILNAME <XCOPY> ;AN000;
236
237;-------------------------------
238; Structures
239;-------------------------------
240;HEADER - informations needed about the file, subdirectory ...
241;Continue_Info -> 0 - a whole single file in this header segment, or dir.
242; 1 - Continuation of a small file.
243; 2 - Continuation of a Big file
244; 3 - EOF of continuation
245;Next_Ptr -> points to the next header segment
246;Before_Ptr -> points to the old header segment
247
248HEADER STRUC
249 CONTINUE_INFO DB 0 ;set for filesize bigger then 0FFD0h
250 NEXT_PTR DW ? ;next buffer ptr in para
251 BEFORE_PTR DW ? ;before ptr in para
252 DIR_DEPTH DB ? ;same as S_DEPTH
253 CX_BYTES DW 0 ;actual # of bytes in this buffer seg.
254 ATTR_FOUND DB ? ;attribute found
255 FILE_TIME_FOUND DW ?
256 FILE_DATE_FOUND DW ?
257 LOW_SIZE_FOUND DW ?
258 HIGH_SIZE_FOUND DW ?
259 TARGET_DRV_LET DB " :" ;used for writing
260 FILENAME_FOUND DB 13 DUP (0) ;AC015; FILENAME
261 TERMINATE_STRING DB 16 DUP (0) ;AC015;TERM FILENAME STRING FOR DOS
262 ATTRIB_LIST DW ? ;AC005;EXTENDED ATTRIBUTE BUFFER
263;-------------------------------------------------------------------
264; extended attribute list used by extended open & get extended
265;-------------------------------------------------------------------
266; ATTRIB_LIST LABEL BYTE extended attribute buffer
267;
268;EA STRUC ; EXTENDED ATTRIBUTE
269;EA_TYPE DB ? ; TYPE
270;EAISUNDEF EQU 0 ; UNDEFINED TYPE (ATTRIB SKIPS)
271; ; (OR TYPE NOT APPLICABLE)
272; ; LENGTH: 0 TO 64K-1 BYTES
273;EAISLOGICAL EQU 1 ; LOGICAL (0 OR 1) (ATTRIB DISPLAYS) ; LENGTH: 1 BYTE
274;EAISBINARY EQU 2 ; BINARY INTEGER (ATTRIB DISPLAYS)
275; ; LENGTH: 1, 2, 4 BYTES
276;EAISASCII EQU 3 ; ASCII TYPE (ATTRIB DISPLAYS)
277; ; LENGTH: 0 TO 128 BYTES
278;EAISDATE EQU 4 ; DOS FILE DATE FORMAT (ATTRIB DISPLAYS)
279; ; LENGTH: 2 BYTES
280;EAISTIME EQU 5 ; DOS FILE TIME FORMAT (ATTRIB DISPLAYS)
281; ; LENGTH: 2 BYTES
282; ; OTHER VALUES RESERVED
283;EA_FLAGS DW ? ; FLAGS
284;EASYSTEM EQU 8000H ; EA IS SYSTEM DEFINED
285; ; (BUILTIN, NOT APPLICATION DEFINED)
286;EAREADONLY EQU 4000H ; EA IS READ ONLY (CANT BE CHANGED)
287;EAHIDDEN EQU 2000H ; EA IS HIDDEN FROM ATTRIB
288;EACREATEONLY EQU 1000H ; EA IS SETABLE ONLY AT CREATE TIME
289; ; OTHER BITS RESERVED
290;EA_RC DB ? ; FAILURE REASON CODE (SET BY DOS)
291;EARCNOTFOUND EQU 1 ; NAME NOT FOUND
292;EARCNOSPACE EQU 2 ; NO SPACE TO HOLD NAME OR VALUE
293;EARCNOTNOW EQU 3 ; NAME CAN'T BE SET ON THIS FUNCTION
294;EARCNOTEVER EQU 4 ; NAME CAN'T BE SET
295;EARCUNDEF EQU 5 ; NAME KNOWN TO THIS FS BUT NOT SUPPORTED
296;EARCDEFBAD EQU 6 ; EA DEFINTION BAD (TYPE, LENGTH, ETC)
297;EARCACCESS EQU 7 ; EA ACCESS DENIED
298;EARCUNKNOWN EQU -1 ; UNDETERMINED CAUSE
299;EA_NAMELEN DB ? ; LENGTH OF NAME
300;EA_VALLEN DW ? ; LENGTH OF VALUE
301;EA_NAME DB ? ; FIRST BYTE OF NAME
302;
303;EA_VALUE DB ? ; FIRST BYTE OF VALUE
304;
305HEADER ENDS
306
307SUB_LIST STRUC
308 DB 11 ;AN000;
309 DB 0 ;AN000;
310DATA_OFF DW 0 ;AN000; offset of data to be inserted
311DATA_SEG DW 0 ;AN000; offset of data to be inserted
312MSG_ID DB 0 ;AN000; n of %n
313FLAGS DB 0 ;AN000; Flags
314MAX_WIDTH DB 0 ;AN000; Maximum field width
315MIN_WIDTH DB 0 ;AN000; Minimum field width
316PAD_CHAR DB 0 ;AN000; character for pad field
317
318SUB_LIST ENDS
319
320
321
322
323;******************************************************************************
324SSEG SEGMENT PARA STACK
325 DB 64 DUP ('STACK ') ;256 words
326SSEG ENDS
327
328
329
330;******************************************************************************
331DGROUP GROUP DSEG,DSEG_INIT ;FOR CONVENIENT ADDRESSIBLITY OF
332 ;DSEG_INIT in INIT routine
333;******************************************************************************
334DSEG SEGMENT PARA PUBLIC ; DATA Segment
335;--- EXTERNAL VARIABLES ---
336EXTRN PARM_FLAG: BYTE
337EXTRN COMMAND_LINE: BYTE ;AN000;THE COMMAND LINE FOR THE PARSER
338;--- PUBLIC VARIABLES ---
339PUBLIC ERRORLEVEL
340
341PUBLIC DISP_S_PATH
342PUBLIC DISP_T_PATH
343PUBLIC S_DRV
344PUBLIC S_DRV_1
345PUBLIC T_DRV
346PUBLIC T_DRV_1
347PUBLIC T_DRV_2
348PUBLIC S_DRV_PATH
349PUBLIC S_PATH
350PUBLIC T_DRV_PATH
351PUBLIC T_PATH
352PUBLIC S_FILE
353PUBLIC T_FILENAME
354PUBLIC T_TEMPLATE
355PUBLIC T_MKDIR_LVL
356PUBLIC S_ARC_DRV
357PUBLIC S_ARC_PATH
358;
359PUBLIC PSP_SEG
360PUBLIC SAV_DEFAULT_DRV
361PUBLIC SAV_DEFAULT_DIR
362PUBLIC SAV_S_DRV
363PUBLIC SAV_S_CURDIR
364PUBLIC SAV_T_DRV
365PUBLIC SAV_T_CURDIR
366PUBLIC S_DRV_NUMBER
367PUBLIC T_DRV_NUMBER
368PUBLIC TOP_OF_MEMORY
369PUBLIC BUFFER_PTR
370PUBLIC BUFFER_BASE
371PUBLIC BUFFER_LEFT
372PUBLIC MAX_BUFFER_SIZE
373PUBLIC MAX_CX
374;
375PUBLIC MY_FLAG
376PUBLIC SYS_FLAG
377PUBLIC COPY_STATUS
378PUBLIC OPTION_FLAG
379PUBLIC INPUT_DATE
380PUBLIC INPUT_TIME
381
382PUBLIC SUBST_COUNT ;AN000;
383PUBLIC MSG_CLASS ;AN000;
384PUBLIC INPUT_FLAG ;AN000;
385PUBLIC MSG_NUM ;AN000;
386
387PUBLIC SUBLIST1 ;AN000;MSG SUBLIST USED BY INIT
388
389
390;--- VARIABLES DEFINED ---
391
392 MSG_SERVICES <MSGDATA> ;AN000;
393
394ERRORLEVEL DB 0 ;errorlevel
395INPUT_DATE DW 0
396INPUT_TIME DW 0
397PSP_SEG DW ?
398SAV_DEFAULT_DRV DB ? ;1 = A, 2 = B etc. saved default
399SAV_DEF_DIR_ROOT DB '\'
400SAV_DEFAULT_DIR DB 80 DUP (0)
401SAV_S_DRV DB 'A:\'
402SAV_S_CURDIR DB 80 DUP (0)
403SAV_T_DRV DB 'B:\'
404SAV_T_CURDIR DB 80 DUP (0)
405;
406
407DISP_S_PATH DB 67 DUP (0) ;mirror image of source path. used for display message when copying
408DISP_S_FILE DB 13 DUP (0)
409DISP_T_PATH DB 67 DUP (0) ;mirror image of target path
410DISP_T_FILE DB 13 DUP (0)
411;
412B_SLASH DB '\',0 ;AN000;
413
414
415FILE_COUNT LABEL WORD ;AN000;
416FILE_CNT_LOW DW 0 ;copied file count
417FILE_CNT_HIGH DW 0
418;
419
420;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
421APPENDFLAG DW 0 ;AN000;append /X status save area
422FOUND_FILE_FLAG DB 0 ;used for showing the message "File not found"
423;
424S_DRV_NUMBER DB 0 ;source, target drv #
425T_DRV_NUMBER DB 0
426;
427S_DRV_PATH LABEL BYTE ;source drv, path used for single_drv_copy
428S_DRV DB 'A:\'
429S_PATH DB 80 DUP (0) ;AN000;Initialized by calling GET CUR DIR
430S_DEPTH DB 0
431S_DRV_1 DB 'A:'
432S_FILE DB '????????.???',0 ;default filename to find file
433S_FILE_OVERFLO DB 20 DUP (0) ;AN011;BUFFER IF MORE THAN 12 CHARS.
434S_DIR DB '????????.???',0 ;to find any subdirectory name
435S_DIR_OVERFLO DB 20 DUP (0) ;AN011;BUFFER IF MORE THAN 12 CHARS.
436
437S_PARENT DB '..',0 ;source parent used for non single_drv_copy
438S_HANDLE DW 0 ;file handle opened
439
440S_ARC_DRV_PATH LABEL BYTE ;informations used to change source file's
441S_ARC_DRV DB 'A:\' ;archieve bits.
442S_ARC_PATH DB 64 DUP (0)
443S_ARC_DEPTH DB 0
444
445T_DRV_PATH LABEL BYTE ;target drv, path used all the time
446T_DRV DB 'B:\'
447T_PATH DB 80 DUP (0) ;AC016;init by call GET CUR DIR in INIT
448T_DEPTH DB 0
449T_FILE LABEL BYTE ;target filename for file creation
450T_DRV_1 DB 'B:' ;target drv letter
451T_FILENAME DB 15 DUP (0) ;target filename
452T_TEMPLATE DB 15 DUP (0) ;if global chr entered, this will be used instead of filename.
453
454T_PARENT LABEL BYTE
455T_DRV_2 DB 'B:'
456T_PARENT_1 DB '..',0
457T_HANDLE DW 0 ;target handle created
458T_MKDIR_LVL DB 0 ;# of target starting directories created.
459;
460;------------------------------------------
461; PRINT_STDOUT input parameter save area
462;------------------------------------------
463SUBST_COUNT DW 0 ;AN000; message substitution count
464MSG_CLASS DB 0 ;AN000; message class
465INPUT_FLAG DB 0 ;AN000; Type of INT 21 used for KBD input
466MSG_NUM DW 0 ;AN000; message number
467
468
469INPUT_BUFF db 20 dup(0) ;AN000; keyboard input buffer used
470 ;for user response (Y/N)
471
472;--------------------------------------------------------------
473; Following three sublists are used by the Message Retriever
474;--------------------------------------------------------------
475SUBLIST1 LABEL DWORD ;AN000;SUBSTITUTE LIST 1
476 DB 11 ;AN000;sublist size
477 DB 0 ;AN000;reserved
478 DD 0 ;AN000;substition data Offset
479 DB 1 ;AN000;n of %n
480 DB 0 ;AN000;data type
481 DB 0 ;AN000;maximum field width
482 DB 0 ;AN000;minimum field width
483 DB 0 ;AN000;characters for Pad field
484
485
486SUBLIST2 LABEL DWORD ;AN000;SUBSTITUTE LIST 2
487 DB 11 ;AN000;sublist size
488 DB 0 ;AN000;reserved
489 DD 0 ;AN000;substition data Offset
490 DB 2 ;AN000;n of %n
491 DB 0 ;AN000;data type
492 DB 0 ;AN000;maximum field width
493 DB 0 ;AN000;minimum field width
494 DB 0 ;AN000;characters for Pad field
495
496
497SUBLIST3 LABEL DWORD ;AN000;SUBSTITUTE LIST 3
498 DB 11 ;AN000;sublist size
499 DB 0 ;AN000;reserved
500 DD 0 ;AN000;substition data Offset
501 DB 3 ;AN000;n of %n
502 DB 0 ;AN000;data type
503 DB 0 ;AN000;maximum field width
504 DB 0 ;AN000;minimum field width
505 DB 0 ;AN000;characters for Pad field
506
507
508FILE_SEARCH_ATTR DW NORM_ATTR
509DIR_SEARCH_ATTR DW INCL_H_S_DIR_ATTR
510;
511OPEN_MODE DB Read_Only_Deny_Write ;READ_ONLY_DENY_WRITE ;access, sharing mode
512;
513;Equates are defined in XCOPY.EQU
514
515MY_FLAG DB 0 ;informations for a tree walk
516; find_first_flag equ 01h ;set MY_FLAG by "OR"
517; findfile_flag equ 02h
518; no_more_file equ 04h
519; single_copy_flag equ 08h ;single copy instead of multi copy
520; visit_parent_flag equ 10h ;visit parent node
521; found_flag equ 20h ;found flag - for find subdir
522; missing_link_flag equ 40h ;insuffiecient info. for not creating empty dir
523; is_source_flag equ 80h ;if set, dealing with source
524; reset_find_first equ 0FEh ;reset by AND
525; reset_findfile equ 0FDh
526; reset_no_more equ 0FBh
527; reset_visit_parent equ 0EFh
528; reset_found equ 0DFh
529; reset_missing_link equ 0BFh
530; reset_is_source equ 07Fh
531
532FILE_FLAG DB 0
533; cont_flag equ 01h
534; eof_flag equ 02h
535; big_file_flag equ 04h
536; file_bigger_flag equ 08h
537; created_flag equ 10h
538; reset_cont equ 0FEh
539; reset_eof equ 0FDh
540; reset_big_file equ 0FBh
541; reset_file_bigger equ 0F7h
542; reset_created equ 0EFh
543; reset_readfile equ 0F0h ;reset FILE_FLAG for read a file
544;
545COPY_STATUS DB 0
546; open_error_flag equ 01h
547; read_error_flag equ 02h
548; create_error_flag equ 04h
549; write_error_flag equ 08h
550; mkdir_error_flag equ 10h
551; chdir_error_flag equ 20h
552; maybe_itself_flag equ 40h
553; disk_full_flag equ 80h
554; reset_open_error equ 0FEh
555; reset_read_error equ 0FDh
556; reset_create_error equ 0FBh
557; reset_write_error equ 0F7h
558; reset_close_error equ 0EFh
559; reset_chdir_error equ 0DFh
560;
561ACTION_FLAG DB 0
562; reading_flag equ 01h ;display "Reading source files..."
563; reset_reading equ 0FEh ;do not display.
564;
565SYS_FLAG DB 0 ;system information
566; one_disk_copy_flag equ 01h ;xcopy with only one logical drive.
567; default_drv_set_flag equ 02h ;default drive has been changed by this program
568; default_s_dir_flag equ 04h ;source current directory saved.
569; default_t_dir_flag equ 08h ;target current directory saved.
570; removalble_drv_flag equ 10h
571; sharing_source_flag equ 20h ;source shared
572; sharing_target_flag equ 40h
573; turn_verify_off_flag equ 80h ;turn the verify off when exit to dos
574; reset_default_s_dir equ 0FBh ;reset default_s_dir_flag
575;
576OPTION_FLAG DB 0
577; slash_a equ 01h ;soft archieve ?
578; slash_d equ 02h ;date?
579; slash_e equ 04h ;create empty dir?
580; slash_m equ 08h ;hard archieve ? (turn off source archieve bit)
581; slash_p equ 10h ;prompt?
582; slash_s equ 20h ;walk the tree?
583; slash_v equ 40h ;verify on?
584; slash_w equ 80h ;show "Press any key to begin copying" msg)
585; reset_slash_a equ 0FEh ;turn off soft archieve
586; reset_slash_m equ 0F7h ;turn off hard archieve
587
588MAX_CX DW 0 ;less than 0FFD0h
589ACT_BYTES DW 0 ;actual bytes read.
590HIGH_FILE_SIZE DW 0
591LOW_FILE_SIZE DW 0
592;
593TOP_OF_MEMORY DW 0 ;para
594BUFFER_BASE DW 0 ;para
595MAX_BUFFER_SIZE DW 0 ;para. BUFFER_LEFT at INIT time.
596BUFFER_LEFT DW 0 ;para
597BUFFER_PTR DW 0 ;para. If buffer_left=0 then invalid value
598DATA_PTR DW 0 ;buffer_ptr + HEADER
599OLD_BUFFER_PTR DW 0 ;last buffer_ptr
600SIZ_OF_BUFF DW ? ;AN005;para. EXTENDED ATTRIB BUFF SIZE
601BYTS_OF_HDR DW ? ;AN005;bytes TOTAL HEADER SIZE
602PARA_OF_HDR DW 3 ;AC008;para. TOTAL HDR SIZE INIT TO 3
603OPEN_FILE_COUNT DW ? ;AN005;TRACKING OF OPEN FLS FOR BUFFER
604; ;SIZE CALCULATION.
605DBCSEV_OFF DW 0 ;AN010; remember where dbcs vector is
606DBCSEV_SEG DW 0 ;AN010;next time I don't have to look
607;
608;structured data storage allocation
609FILE_DTA Find_DTA <> ;DTA for find file
610DTAS Find_DTA 32 dup (<>) ;DTA STACK for find dir
611;** Througout the program BP will be used for referencing fieldsname in DTAS.
612;For example, DS:[BP].dta_filename.
613DSEG ENDS
614
615;******************************************************************************
616
617CSEG SEGMENT PUBLIC
618 ASSUME CS:CSEG, DS:DGROUP, SS:SSEG
619
620 MSG_SERVICES <LOADmsg,GETmsg,DISPLAYmsg,INPUTmsg,CHARmsg,NUMmsg> ;AN000;
621 MSG_SERVICES <XCOPY.CLA,XCOPY.CL1,XCOPY.CL2> ;AN000;
622
623
624
625
626;--- EXTERNAL PROCEDURES ---
627EXTRN INIT: NEAR ;INIT PROC
628;
629;--- PUBLIC PROCEDURES --- ;USED BY INIT
630PUBLIC SET_BUFFER_PTR
631PUBLIC STRING_LENGTH
632PUBLIC CONCAT_ASCIIZ
633PUBLIC LAST_DIR_OUT
634PUBLIC CHK_DRV_LETTER
635PUBLIC COMPRESS_FILENAME
636PUBLIC PRINT_STDOUT
637PUBLIC PRINT_STDERR
638PUBLIC SET_DEFAULT_DRV
639PUBLIC MAIN_EXIT
640PUBLIC MAIN_EXIT_A
641PUBLIC CTRL_BREAK_EXIT
642PUBLIC SWITCH_DS_ES
643PUBLIC MY_INT24
644
645;--- INT 24 ADDR ----------
646PUBLIC SAV_INT24_OFF
647PUBLIC SAV_INT24_SEG
648
649PUBLIC SYSLOADMSG ;AN000;
650PUBLIC SYSDISPMSG
651PUBLIC SYSGETMSG
652
653SAV_INT24 LABEL DWORD
654SAV_INT24_OFF DW 0 ;original int 24 addr holder
655SAV_INT24_SEG DW 0
656;--- START OF A PROGRAM ---
657 ASSUME DS:NOTHING ;AN000;
658 ASSUME ES:NOTHING ;AN000;
659MAIN PROC FAR
660 PUSH AX ;AN000;PRESERVE FOR INIT DRV VALIDITY
661 MOV BX,DGROUP
662 MOV ES,BX ;AN000;SET UP ADDRESS OF DSEG IN ES
663 ASSUME ES:DGROUP ;AN000;
664 MOV SI,81H ;AN000;POINT TO THE INPUT STRING
665 LEA DI,COMMAND_LINE ;AN000;POINT TO THE SAVE AREA IN PARSER
666 MOV CX,127 ;AN000;GET ALL THE DATA(LOOP COUNT)
667 REP MOVSB ;AN000;MOVE IT
668 MOV PSP_SEG,DS ;AN000;REMEMBER WHERE THE PSP IS
669 MOV DS,BX ;AN000;SET UP ADDRESS OF DSEG IN DS
670 ASSUME DS:DGROUP ;AN000;
671
672 CALL SYSLOADMSG ;AN000; preload all messages
673 jnc XCOPY_INIT ;AN000; no error, do xcopy init
674
675 CALL SYSDISPMSG ;AN000; else display error message
676 POP AX ;AN000;WAS PRESERVED FOR DRV VALIDATION
677 JMP JUST_EXIT ;AN000; exit
678
679XCOPY_INIT:
680 POP AX ;AN000;WAS PRESERVED FOR DRV VALIDATION
681 CALL INIT ;initialization
682 JC MAIN_EXIT ;error. (Already message has been displayed)
683 MOV BP, OFFSET DTAS ;initialize BP
684 OR ACTION_FLAG, READING_FLAG ;set reading flag for copy message
685
686;Before walking the tree, find out the /X status of APPEND and save it.
687;Then terminate the /X feature. After the tree search, restore the
688;original /X status. This is done at EXIT time.
689
690 MOV AX,CHK_APPEND ;AN000;CHECK IF APPEND INSTALLED
691 INT 2FH ;AN000;
692 OR AL,AL ;AN000;INSTALLED?
693; $IF NZ ;AN000;YES
694 JZ $$IF1
695 MOV AX,VER_APPEND ;AN019;ASK IF DOS VERSION OF APPEND
696 INT 2FH ;AN019;CALL THE FUNCTION
697 CMP AX,D_V_APPEND ;AN000;DOS VERSION?
698; $IF E ;AN000;YES
699 JNE $$IF2
700 MOV AX,GET_APPEND ;AN000;GET THE APPEND STATE
701 INT 2FH ;AN000;
702 MOV APPENDFLAG,BX ;AN000;SAVE THE STATE TO RESTORE
703 TEST APPENDFLAG,F_APPEND ;AN019;IS THE /X BIT ON?
704; $IF NZ ;AN000;YES
705 JZ $$IF3
706 MOV AX,SET_APPEND ;AN000;SET THE APPEND STATE
707 MOV BX,APPENDFLAG ;AN000;GET THE SAVED STATE
708 XOR BX,F_APPEND ;AN000;TURN OFF THE /X BIT
709 INT 2FH ;AN000;DO IT
710; $ENDIF ;AN000;
711$$IF3:
712; $ENDIF ;AN000;
713$$IF2:
714; $ENDIF ;AN000;
715$$IF1:
716
717 CALL TREE_COPY
718 CALL ORG_S_DEF ;restore the original source default dir
719 CALL WRITE_FROM_BUFFER ;write from buffer if we missed it.
720
721MAIN_EXIT:
722 MOV BX, DGROUP
723 MOV DS, BX ;re initialize ds, es
724 MOV ES, BX ;exit here if the status of source, target or default drv has been changed.
725 CALL CHK_FILE_NOT_FOUND ;if no files has been found, show the message.
726 ;
727; Set message substitution list
728 LEA SI,SUBLIST1 ;AN000; get addressability to sublist
729 LEA DX,FILE_COUNT ;AN000; offset to file count
730 MOV [SI].DATA_OFF,DX ;AN000; save data offset
731 MOV [SI].DATA_SEG,DS ;AN000; save data segment
732 MOV [SI].MSG_ID,1 ;AN000; message ID
733 MOV [SI].FLAGS,RIGHT_ALIGN+UNSGN_BIN_DWORD ;AN018;
734 MOV [SI].MAX_WIDTH,9 ;AN018; MAXIMUM FIELD WITH
735 MOV [SI].MIN_WIDTH,9 ;AN018; MINIMUM FIELD WITH
736 MOV [SI].PAD_CHAR,SPACE ;AN018; MINIMUM FIELD WITH
737
738; Set message parameters
739 MOV AX,MSG_FILES_COPIED ;AN000; message number
740 MOV MSG_NUM,AX ;AN000; set message number
741 MOV SUBST_COUNT,PARM_SUBST_ONE ;AN000; one message substitution
742 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
743 MOV INPUT_FLAG,NO_INPUT ;AN000; no user input
744 CALL PRINT_STDOUT ;AN000; display file count
745
746MAIN_EXIT_A:
747 MOV BX, DGROUP
748 MOV DS, BX ;re initialize ds, es
749 MOV ES, BX ;exit here if the status of source, target or default drv has been changed.
750 CALL CHK_MKDIR_LVL ;starting target directory has been created?
751 CALL ORG_S_T_DEF ;restore original target, source, default drv, and verify status
752
753JUST_EXIT: ;unconditional immediate exit
754
755; Restore the original status of APPEND if active.
756
757
758 MOV BX,APPENDFLAG ;AN000;GET THE STATUS WORD
759 OR BX,BX ;AN019;IF FLAGS SAVED, THIS IS DOS VER.
760; $IF NZ ;AN019;IF ACTIVE,
761 JZ $$IF7
762 MOV AX,SET_APPEND ;AN000;SET TO THE ORIGINAL STATE
763 INT 2FH ;AN000; turn on the /X feature
764; $ENDIF ;AN000;
765$$IF7:
766;
767 MOV AH, 4Ch ;return to dos
768 MOV AL, ERRORLEVEL ;set return code whatever
769 INT 21H
770CTRL_BREAK_EXIT:
771 MOV ERRORLEVEL, 2 ;set errorlevel to 2 for control break
772 JMP MAIN_EXIT_A
773
774MAIN ENDP
775;
776
777
778;----------------- SUBROUTINES ---------------------------------------------
779
780TREE_COPY PROC NEAR
781
782;Walk the source tree to read files and subdirectories
783
784 OR MY_FLAG, FINDFILE_FLAG ;deals with files
785 OR MY_FLAG, FIND_FIRST_FLAG ;find first
786 CALL SET_MY_DTA ;set DTA to FILE_DTA
787; $DO
788$$DO9:
789 CALL FIND_FILE ;find first (next)
790 TEST MY_FLAG, NO_MORE_FILE ;no more file?
791; $LEAVE NZ ;then exit loop
792 JNZ $$EN9
793 CALL READ_INTO_BUFFER ;else read the file into the buffer
794; $ENDDO
795 JMP SHORT $$DO9
796$$EN9:
797
798 TEST OPTION_FLAG, SLASH_S ;walk the tree?
799; $IF NZ,LONG
800 JNZ $$XL1
801 JMP $$IF12
802$$XL1:
803
804 AND MY_FLAG, RESET_FINDFILE ;now, deals with directory
805 OR MY_FLAG, FIND_FIRST_FLAG ;find first
806; $DO
807$$DO13:
808 CALL SET_MY_DTA ;set DTA to DTAS according to BP
809 CALL FIND_DIR ;find first (next)
810 TEST MY_FLAG, NO_MORE_FILE ;no more subdirectory?
811; $LEAVE NZ ;then leave this loop to return to caller
812 JNZ $$EN13
813 LEA DI, S_DRV_PATH
814 LEA SI, [BP].DTA_FILENAME
815 CMP S_PATH, 0 ;root directory?
816; $IF E
817 JNE $$IF15
818 MOV AL, 0FFh ;then '\' is already provided. Just concat.
819; $ELSE
820 JMP SHORT $$EN15
821$$IF15:
822 MOV AL, PATH_DELIM ;put delimiter
823; $ENDIF
824$$EN15:
825 CALL CONCAT_ASCIIZ ;make new path
826 test option_flag, slash_p ;prompt mode?
827; $IF NZ
828 JZ $$IF18
829 call p_concat_display_path
830; $ENDIF
831$$IF18:
832 INC S_DEPTH ;increase depth
833 CALL MAKE_HEADER ;make header in the buffer
834 OR MY_FLAG, IS_SOURCE_FLAG ;dealing with source
835 AND MY_FLAG, RESET_VISIT_PARENT ;going to visit child node
836 CALL CHANGE_S_DIR ;change source dir
837 ADD BP, type FIND_DTA ;increase DTAS stack pointer
838 CALL TREE_COPY ;tree copy the sub directory
839; $ENDDO
840 JMP SHORT $$DO13
841$$EN13:
842
843 CMP S_DEPTH, 0 ;starting directory? then exit
844; $IF NE ;else
845 JE $$IF21
846 DEC S_DEPTH ;dec depth
847 TEST OPTION_FLAG, SLASH_E ;copy subdirectories even if empty?
848; $IF Z
849 JNZ $$IF22
850 CALL DEL_EMPTY ;then check the old_buffer_ptr and
851 ;if it is a directory, then restore
852 ;buffer_ptr to old.
853; $ENDIF
854$$IF22:
855 LEA DI, S_DRV_PATH
856 CALL LAST_DIR_OUT ;change environments
857 test option_flag, slash_p ;prompt mode?
858; $IF NZ
859 JZ $$IF24
860 call p_cut_display_path
861; $ENDIF
862$$IF24:
863 LEA DX, S_DRV_PATH ;before returning to the caller
864 OR MY_FLAG, IS_SOURCE_FLAG
865 OR MY_FLAG, VISIT_PARENT_FLAG
866 CALL CHANGE_S_DIR
867 SUB BP, type FIND_DTA
868; $ENDIF
869$$IF21:
870; $ENDIF ;walk the tree
871$$IF12:
872 RET
873TREE_COPY ENDP
874;
875
876DEL_EMPTY PROC NEAR
877;If buffer is not full, and the tree walk is going to return to the parents,
878;this routine should be called.
879;If old_buffer_ptr points to a directory, then set buffer_ptr to this, and
880;increase buffer_left by HEADER (para) and set old_buffer_ptr to that of
881;BEFORE_PTR. i.e. delete the empty directory entry from the buffer.
882
883 PUSH ES
884
885 PUSH CS
886 POP AX
887 CMP OLD_BUFFER_PTR, AX ;buffer is empty?
888 JE DE_EXIT ;yes, exit
889
890 MOV ES, OLD_BUFFER_PTR
891 TEST ES:ATTR_FOUND, 10h ;directory?
892 JZ DE_EXIT ;if not, exit
893 MOV AX, OLD_BUFFER_PTR
894 MOV BUFFER_PTR, AX ;set new BUFFER_PTR
895 MOV AX, ES:BEFORE_PTR
896 MOV OLD_BUFFER_PTR, AX ;set new OLD_BUFFER_PTR
897 MOV AX, PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
898 ADD BUFFER_LEFT, AX ;AC005;dir entry must be only hdr SIZE.
899
900DE_EXIT:
901 POP ES
902 RET
903DEL_EMPTY ENDP
904;
905
906
907P_concat_display_path proc near
908;concatenate subdirectory name found from DTAS to the
909;DISP_S_PATH which will be used for prompts
910;DS - data seg
911 MOV DI, OFFSET DISP_S_PATH
912 LEA SI, [BP].DTA_FILENAME
913 CMP S_DEPTH, 0 ;this will be the first subdir?
914; $IF E
915 JNE $$IF28
916 MOV AL, 0FFh ;then do not put '\'
917; $ELSE
918 JMP SHORT $$EN28
919$$IF28:
920 MOV AL, Path_delim
921; $ENDIF
922$$EN28:
923 CALL CONCAT_ASCIIZ
924 RET
925P_concat_display_path endp
926;
927
928
929P_cut_display_path proc near
930;take the last dir out from the DISP_S_PATH for prompt.
931;DS,ES - data seg
932 MOV SI, OFFSET DISP_S_PATH
933 MOV DI, OFFSET DISP_S_PATH
934 CALL LAST_DIR_OUT
935; $IF C
936 JNC $$IF31
937 CALL CHK_DRV_LETTER
938; $IF NC
939 JC $$IF32
940 MOV BYTE PTR DS:[SI], 0
941; $ELSE
942 JMP SHORT $$EN32
943$$IF32:
944 MOV BYTE PTR [DI], 0
945; $ENDIF
946$$EN32:
947; $ELSE
948 JMP SHORT $$EN31
949$$IF31:
950 CMP S_DEPTH, 0
951; $IF E
952 JNE $$IF36
953 MOV DI, AX
954 DEC DI
955 MOV BYTE PTR [DI], '\'
956 MOV BYTE PTR [DI+1], 0
957; $ENDIF
958$$IF36:
959; $ENDIF
960$$EN31:
961 RET
962P_cut_display_path endp
963;
964
965
966READ_INTO_BUFFER PROC NEAR
967;Read *** a *** file into buffer
968 TEST MY_FLAG, SINGLE_COPY_FLAG ;single copy?
969; $IF Z,AND ;no, multi copy
970 JNZ $$IF39
971 TEST ACTION_FLAG, READING_FLAG ;show message?
972; $IF NZ ;yes.
973 JZ $$IF39
974 MOV AX,MSG_READING_SOURCE ;AN000; message number
975 MOV MSG_NUM,AX ;AN000; set message number
976 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
977 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
978 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
979 CALL PRINT_STDOUT ;AN000;show message "Reading source files"
980
981 AND ACTION_FLAG, RESET_READING ;reset it
982; $ENDIF
983$$IF39:
984
985 AND FILE_FLAG, RESET_READFILE ;reset file_flag to read a file
986 MOV AX,FILE_DTA.DTA_FILE_SIZE_HIGH
987 MOV HIGH_FILE_SIZE, AX
988 MOV AX,FILE_DTA.DTA_FILE_SIZE_LOW
989 MOV LOW_FILE_SIZE, AX
990 CALL CMP_FILESIZE_TO_BUFFER_LEFT ;compare sizes
991
992 MOV AX, PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
993 CMP MAX_BUFFER_SIZE, AX ;AN005;IS EA BUFFER TOO LARGE?
994; $IF B
995 JNB $$IF41
996 CLC ;AN005;CLEAR CARRY
997 MOV AX, MSG_INSUF_MEMORY ;AC005;GET THE MESSAGE ID
998 MOV MSG_NUM,AX ;AN005;NEED MESSAGE ID FOR PRINT
999 MOV SUBST_COUNT,NO_SUBST ;AN005;NO SUBSTITUTION TEXT
1000 MOV INPUT_FLAG,NO_INPUT ;AN005;NO INPUT = 0
1001 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN005;MESSAGE CLASS = -1
1002 CALL PRINT_STDERR ;AN005;print error. AX points to msg ID
1003; $ENDIF ;AN005;WE HAVE ENOUGH MEMORY
1004$$IF41:
1005 MOV AX, PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
1006 CMP MAX_BUFFER_SIZE,AX ;AN005;IS EA BUFFER TOO LARGE?
1007 JB RIB_ERROR ;AN005;CLOSE THE FILE AND GET THE NEXT
1008
1009 TEST FILE_FLAG, FILE_BIGGER_FLAG ;filesize > buffer_left - HEADER ?
1010 JZ RIB_SMALL ;if not, then small file
1011 MOV BX, S_HANDLE ;AN005;
1012 CALL CLOSE_A_FILE ;AN005;ONLY OPENED TO GET BUFFER SIZE
1013 CALL WRITE_FROM_BUFFER
1014 CALL CMP_FILESIZE_TO_BUFFER_LEFT ;compare again
1015 TEST FILE_FLAG, FILE_BIGGER_FLAG ;still bigger?
1016 JNZ RIB_BIG ;yes. Big file
1017RIB_SMALL:
1018 CALL SMALL_FILE
1019 JC RIB_ERROR
1020 JMP RIB_EXIT
1021RIB_BIG:
1022 MOV BX, S_HANDLE ;AN005;
1023 CALL CLOSE_A_FILE ;AN005;ONLY OPENED TO GET BUFFER SIZE
1024 CALL BIG_FILE
1025 JNC RIB_EXIT
1026RIB_ERROR:
1027 TEST COPY_STATUS, OPEN_ERROR_FLAG ;open error?
1028 JNZ RIB_EXIT ;just exit. find next file
1029 MOV BX, S_HANDLE ;else write error
1030 CALL CLOSE_A_FILE ;close the troubled file
1031 ;and find next file
1032RIB_EXIT:
1033 TEST MY_FLAG, SINGLE_COPY_FLAG ;single copy?
1034; $IF NZ
1035 JZ $$IF43
1036 CALL WRITE_FROM_BUFFER ;then write a file
1037; $ENDIF
1038$$IF43:
1039 RET
1040READ_INTO_BUFFER ENDP
1041;
1042
1043
1044SMALL_FILE PROC NEAR
1045;handles a file smaller than max_buffer_size or buffer_left, i.e. fit in memory.
1046;This routine will call MAKE_HEADER, SET_BUFFER_PTR< READ_A_FILE,
1047;CALC_FILE_SIZE, CMP_FILE_FFD0h, CLOSE_A_FILE.
1048
1049SMF_CONT:
1050 CALL CMP_FILE_FFD0h ;filesize > 0FFD0h ?
1051 TEST FILE_FLAG, FILE_BIGGER_FLAG
1052 JZ SMF_EOF ;filesize <= 0FFD0h
1053 OR FILE_FLAG, CONT_FLAG ;filesize > 0FFD0h. set cont_flag
1054 MOV CX, 0FFD0h ;# of bytes to read
1055 CALL READ_A_FILE
1056 JC SMF_ERROR ;unsuccessful read?
1057 CALL MAKE_HEADER ;else make header and ready for next
1058 CALL CALC_FILE_SIZE ;filesize = filesize - bytes read
1059 JMP SMF_CONT ;loop. compare again with the rest
1060
1061SMF_EOF:
1062 MOV CX, LOW_FILE_SIZE ;rest of the bytes to read
1063 OR FILE_FLAG, EOF_FLAG ;AN000;set EOF
1064 CALL READ_A_FILE
1065 JC SMF_ERROR
1066 CALL MAKE_HEADER
1067 MOV BX, S_HANDLE
1068 CALL CLOSE_A_FILE
1069 JMP SMF_EXIT
1070SMF_ERROR:
1071 ;
1072SMF_EXIT:
1073 RET
1074SMALL_FILE ENDP
1075;
1076
1077
1078BIG_FILE PROC NEAR
1079;handles a file which is bigger than max_buffer_size
1080;Needs 2 file handles open concurrently for read and write
1081
1082 OR FILE_FLAG, BIG_FILE_FLAG
1083 OR FILE_FLAG, CONT_FLAG
1084 CALL OPEN_A_FILE
1085 JC BIF_ERROR ;error in open?
1086 CMP MAX_BUFFER_SIZE, 0FFFh ;max buffer size > 0FFFh in para ?
1087 JA BIF_BIG ;yes. large buffer system
1088 ;else small buffer
1089 MOV CX, MAX_CX ;CX = max_buffer_size * 16 - HEADER
1090BIF_SM:
1091 CALL READ_A_FILE
1092 JC BIF_ERROR ;read error?
1093 CALL MAKE_HEADER
1094 CALL WRITE_FROM_BUFFER
1095 JC BIF_ERROR ;write error?
1096 TEST FILE_FLAG, EOF_FLAG ;end of file set by READ_A_FILE?
1097 JZ BIF_SM ;if not, read again
1098 MOV BX, S_HANDLE
1099 CALL CLOSE_A_FILE
1100 JMP BIF_EXIT ;finished.
1101BIF_BIG:
1102 MOV CX, 0FFD0h ;max # of data bytes this program supports
1103BIF_BIG1:
1104 CALL READ_A_FILE
1105 JC BIF_ERROR
1106 CALL MAKE_HEADER
1107 CALL CALC_FILE_SIZE ;modify file size
1108BIF_BIG2:
1109 CALL CMP_FILESIZE_TO_BUFFER_LEFT ;filesize > buffer_left?
1110 TEST FILE_FLAG, FILE_BIGGER_FLAG ;yes.
1111 JZ BIF_END ;if it is not, call small_file
1112 MOV AX, PARA_OF_HDR ;AN021;GET THE ATTR. HDR SIZE
1113 ADD AX, 0FFFh ;AN021;
1114 CMP BUFFER_LEFT, AX ;AC021;BUFFER_LEFT >= 0FFF0h+HDR SIZE?
1115 JAE BIF_BIG ;then loop again.
1116 MOV AX, PARA_OF_HDR ;AN021;GET THE ATTR. HDR SIZE
1117 ADD AX, 140H ;AN021;
1118 CMP BUFFER_LEFT, AX ;AC021;BUFFER_LEFT >= 5Kbytes+HDR SIZE?
1119 ;minimum buffer size this pgm supports.
1120 JL BIF_BIG3 ;then flush buffer and try again. **IF system buffer left < 5 K then infinit loop can happen.
1121 MOV AX,BUFFER_LEFT
1122 SUB AX,PARA_OF_HDR ;AC005;FOR HEADER SIZE para.
1123 MOV CX,16
1124 MUL CX ;AN020;MAKE IT NUMBER OF BYTES
1125 MOV CX,AX ;AN020;FOR READ
1126 JMP BIF_BIG1 ;read again
1127BIF_BIG3:
1128 CALL WRITE_FROM_BUFFER
1129 JC BIF_ERROR
1130 JMP BIF_BIG2 ;flush buffer and compare again.
1131BIF_END:
1132 CALL SMALL_FILE ;when filesize <= buffer_left then SMALL_FILE will finish it.
1133 JC BIF_ERROR ;something wrong?
1134 CALL WRITE_FROM_BUFFER ;else finish copying this file
1135 JNC BIF_EXIT
1136BIF_ERROR:
1137 ;what happened?
1138BIF_EXIT:
1139 RET
1140BIG_FILE ENDP
1141;
1142
1143
1144MAKE_HEADER PROC NEAR
1145;When called by READ_A_FILE after the data had been read into the buffer, this
1146;routine will put the header which is just below the data area where the
1147;current BUFFER_PTR points. The header E.A.BUFFER SIZE + (3 para) long. And
1148;this routine will also call SET_BUFFER_PTR to set the BUFFER_PTR, BUFFER_LEFT
1149;for the next process.
1150;If called by TREE_COPY for a SUBDIRECTORY handle, this routine should
1151;check the BUFFER_LEFT (when called by READ_A_FILE, the caller is assumed
1152;to check the size of buffer_left before calling.) In this case, this
1153;routine will set the next BUFFER_PTR, BUFFER_LEFT, OLD_BUFFER_PTR
1154;instead of SET_BUFFER_PTR routine.
1155;Informations are obtained from the DTA area (for file - FILE_DTA.xxx
1156;dir - DS:[BP].xxx ) and stored into the header by referencing ES:field;s name.
1157;DS - Program Data area
1158;ES - will be used for a header segment in the buffer.
1159;
1160 PUSH ES ;save ES
1161 PUSH AX
1162
1163MH_AGAIN:
1164 MOV AX,BUFFER_PTR ;buffer_ptr is a segment
1165 MOV ES, AX ;now, ES is a header seg.
1166;
1167
1168 MOV AX, PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
1169 CMP BUFFER_LEFT,AX ;AC005;buffer_left=less than NEEDED?
1170 JAE MH_START
1171 CALL WRITE_FROM_BUFFER ;if so, flush buffer
1172 JC MH_ERROR_BRIDGE ;write error?
1173 JMP SHORT MH_AGAIN ;reinitialize ES to new buffer ptr
1174MH_START:
1175 TEST MY_FLAG, FINDFILE_FLAG ;identify caller.
1176 JNZ MH_FILE ;if a file, jmp to MH_FILE
1177 ;else deals with directory.
1178 MOV ES:CONTINUE_INFO, 0 ;not a continuation.
1179 MOV AX,OLD_BUFFER_PTR
1180 MOV ES:BEFORE_PTR, AX ;set before_ptr in header
1181 MOV AX,BUFFER_PTR
1182 MOV OLD_BUFFER_PTR, AX ;set variable OLD_BUFFER_PTR
1183 ADD AX,PARA_OF_HDR ;AC005;AX = BUFFER_PTR+HEADER(para)
1184 MOV BUFFER_PTR, AX ;set new BUFFER_PTR
1185 MOV ES:NEXT_PTR, AX ;set NEXT_PTR in the header
1186 MOV AX, PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
1187 SUB BUFFER_LEFT,AX ;AC005;adjust BUFFER_LEFT
1188 CMP BUFFER_LEFT,AX ;AC005;less than HEADER SIZE (para) ?
1189; $IF B
1190 JNB $$IF45
1191 MOV BUFFER_LEFT, 0 ;indicate buffer_full
1192; $ENDIF
1193$$IF45:
1194 MOV AL, S_DEPTH
1195 MOV ES:DIR_DEPTH, AL ;now save other info's
1196 MOV AL, DS:[BP].DTA_ATTRIBUTE
1197 MOV ES:ATTR_FOUND, AL ;in this case, DIR
1198 MOV AL, BYTE PTR T_DRV
1199 MOV ES:TARGET_DRV_LET, AL ;mov target drive letter
1200 MOV ES:TARGET_DRV_LET+1, DRV_delim ; ':'
1201 MOV CX, 13
1202 LEA SI, [BP].DTA_FILENAME ;DS:SI
1203 MOV DI, OFFSET ES:FILENAME_FOUND ;ES:DI
1204 REP MOVSB ;mov sting until cx = 0
1205 JMP MH_EXIT
1206MH_ERROR_BRIDGE: JMP MH_ERROR
1207MH_FILE: ;handles a file header hereafter.
1208 TEST FILE_FLAG, CONT_FLAG ;continuation?
1209 JZ MH_WHOLE_FILE ;no, just a whole file
1210 TEST FILE_FLAG, EOF_FLAG ;Eof flag set?
1211 JNZ MH_CONT_END ;yes, must be end of continuation
1212 TEST FILE_FLAG, BIG_FILE_FLAG ;Is this a big file?
1213 JNZ MH_BIG ;yes
1214 MOV ES:CONTINUE_INFO, 1 ;else small file continuation.
1215 JMP MH_A_FILE
1216MH_WHOLE_FILE:
1217 MOV ES:CONTINUE_INFO, 0
1218 JMP MH_A_FILE
1219MH_CONT_END:
1220 MOV ES:CONTINUE_INFO, 3
1221 JMP MH_A_FILE
1222MH_BIG:
1223 MOV ES:CONTINUE_INFO, 2
1224MH_A_FILE:
1225 MOV AX,FILE_DTA.DTA_FILE_TIME
1226 MOV ES:FILE_TIME_FOUND, AX
1227 MOV AX, FILE_DTA.DTA_FILE_DATE
1228 MOV ES:FILE_DATE_FOUND, AX
1229 MOV AX, FILE_DTA.DTA_FILE_SIZE_LOW
1230 MOV ES:LOW_SIZE_FOUND, AX
1231 MOV AX, FILE_DTA.DTA_FILE_SIZE_HIGH
1232 MOV ES:HIGH_SIZE_FOUND, AX
1233 MOV AL, BYTE PTR T_DRV
1234 MOV ES:TARGET_DRV_LET, AL
1235 MOV ES:TARGET_DRV_LET+1, DRV_DELIM
1236 MOV CX, 13
1237 MOV SI, OFFSET FILE_DTA.DTA_FILENAME
1238 MOV DI, OFFSET ES:FILENAME_FOUND
1239 REP MOVSB
1240
1241; Get Extended Attribute list of the opened file and save in attribute buff.
1242
1243 MOV BX,S_HANDLE ;AN005; BX = handle
1244 MOV SI,ALL_ATTR ;AN005; SELECT ALL ATTRIBUTES SIZE
1245 MOV CL, PARAGRAPH ;AN005; PARAGRAPH = 4 FOR DIV BY 16
1246 MOV AX,SIZ_OF_BUFF ;AN005; GET THE SIZE EXPRESSED IN para.
1247 SHL AX, CL ;AN005; GET # OF BYTES FROM para.
1248 MOV CX, AX ;AN005; NEEDS TO BE IN CX
1249 MOV DI, OFFSET ES:ATTRIB_LIST ;AN005; ES:DI = E A LIST IN BUFFER
1250 MOV AX, GET_ATTRIB ;AN005; extended attribute code 5702H
1251 INT 21H ;AN005; get extended attribute list
1252
1253 JC MH_ERROR ;AN000; jump if error
1254
1255 MOV AX, OLD_BUFFER_PTR
1256 MOV ES:BEFORE_PTR, AX
1257 MOV AX, ACT_BYTES
1258 MOV ES:CX_BYTES, AX
1259 CALL SET_BUFFER_PTR ;set buffer_ptr for next. AX is already set.
1260 MOV AX, BUFFER_PTR
1261 MOV ES:NEXT_PTR, AX ;next buffer_ptr is next_ptr
1262 MOV AL, S_DEPTH
1263 MOV ES:DIR_DEPTH, AL ;same as source depth
1264 MOV AL, FILE_DTA.DTA_ATTRIBUTE
1265 MOV ES:ATTR_FOUND, AL ;attribute found
1266 JMP MH_EXIT ;AN000;
1267MH_ERROR:
1268 OR COPY_STATUS, OPEN_ERROR_FLAG ;AN000;
1269 CALL EXTENDED_ERROR_HANDLER ;AN000;
1270MH_EXIT:
1271 POP AX
1272 POP ES
1273 RET
1274MAKE_HEADER ENDP
1275;
1276
1277
1278OPEN_A_FILE PROC NEAR
1279
1280;-------------------------------------------------------------------------
1281; Use extended open DOS call to open source file,
1282; if successfully open, then save filehand to S_HANDLE.
1283; And update the open file count.
1284;-------------------------------------------------------------------------
1285
1286 LEA SI,FILE_DTA.DTA_FILENAME ;AN005; DS:SI-->NAME TO OPEN
1287 MOV DX,OPN_FLAG ;AN000; flag = 0101H
1288 MOV CX,OPN_ATTR ;AN000; attribute = 0
1289 MOV BX,OPN_MODE ;AN007; open mode = 0000H (READ)
1290 MOV DI, NUL_LIST ;AN005; ES:DI = -1
1291 MOV AX, Ext_Open ;AN000; = 6Ch
1292 INT 21H ;AN000; OPEN SOURCE FILE
1293
1294 JC OF_ERROR
1295 MOV S_HANDLE, AX ;save filehandle
1296 INC OPEN_FILE_COUNT ;AN005;UPDATE THE OPEN FILE COUNTER
1297
1298 JMP OF_EXIT ;AN000; exit
1299
1300OF_ERROR:
1301 OR COPY_STATUS, OPEN_ERROR_FLAG
1302 CALL EXTENDED_ERROR_HANDLER
1303OF_EXIT:
1304 RET
1305OPEN_A_FILE ENDP
1306;
1307
1308
1309CMP_FILE_FFD0h PROC NEAR
1310;check whether the filesize in HIGH_FILE_SIZE, LOW_FILE_SIZE is bigger than
1311;0FFD0h. If it is, then set FILE_BIGGER_FLAG, else reset it.
1312 CMP HIGH_FILE_SIZE, 0
1313; $IF E,AND
1314 JNE $$IF47
1315 CMP LOW_FILE_SIZE, 0FFD0h
1316; $IF BE
1317 JNBE $$IF47
1318 AND FILE_FLAG, RESET_FILE_BIGGER ;filesize <= 0FFD0h
1319; $ELSE
1320 JMP SHORT $$EN47
1321$$IF47:
1322 OR FILE_FLAG, FILE_BIGGER_FLAG
1323; $ENDIF
1324$$EN47:
1325 RET
1326CMP_FILE_FFD0h ENDP
1327;
1328
1329CALC_FILE_SIZE PROC NEAR
1330;subtract the bytes read (ACT_BYTES) from the filesize in HIGH_FILE_SIZE,
1331;LOW_FILE_SIZE.
1332 MOV AX, ACT_BYTES
1333 SUB LOW_FILE_SIZE, AX
1334 SBB HIGH_FILE_SIZE, 0
1335 RET
1336CALC_FILE_SIZE ENDP
1337;
1338
1339
1340READ_A_FILE PROC NEAR
1341;read a file.
1342;if after reading, AX < CX or AX = 0 the set EOF_FLAG.
1343;INPUT:CX - # of bytes to read
1344; BUFFER_PTR
1345; S_HANDLE
1346;OUTPUT: ACT_BYTES
1347
1348 PUSH DS ;save program data seg
1349 MOV AH, Read
1350 MOV BX, S_HANDLE
1351 MOV DX, BUFFER_PTR ;current buffer header seg
1352 ADD DX, PARA_OF_HDR ;AC005;skip the header part
1353 MOV DS, DX ;now DS = buffer_ptr + HDR, data area
1354 XOR DX, DX ;offset DX = 0
1355 INT 21H
1356 POP DS ;restore program data area
1357 JC RF_ERROR ;read error?
1358 CMP AX, CX
1359 JE RF_OK
1360 OR FILE_FLAG, EOF_FLAG ;EOF reached. AX = 0 or AX < CX
1361RF_OK:
1362 CLC ;clear carry caused from CMP
1363 MOV ACT_BYTES, AX ;save actual bytes read
1364 JMP RF_EXIT
1365RF_ERROR:
1366 OR COPY_STATUS, READ_ERROR_FLAG
1367 CALL EXTENDED_ERROR_HANDLER
1368RF_EXIT:
1369 RET
1370READ_A_FILE ENDP
1371;
1372
1373
1374FIND_IT PROC NEAR
1375;set first or next depending on FIND_FIRST_FLAG.
1376;once called, reset FIND_FIRST_FLAG.
1377 TEST MY_FLAG, FIND_FIRST_FLAG
1378; $IF NZ ;yes
1379 JZ $$IF50
1380 MOV AH, Find_First
1381; $ELSE
1382 JMP SHORT $$EN50
1383$$IF50:
1384 MOV AH, Find_Next
1385; $ENDIF
1386$$EN50:
1387 AND MY_FLAG, RESET_FIND_FIRST ;reset FIND_FIRST_FLAG
1388 INT 21H
1389 RET
1390FIND_IT ENDP
1391;
1392
1393
1394FIND_FILE PROC NEAR
1395;find a file
1396;set NO_MORE_FILE if carry.
1397; $SEARCH
1398$$DO53:
1399 TEST MY_FLAG, FIND_FIRST_FLAG ;find first ?
1400; $IF NZ
1401 JZ $$IF54
1402 MOV DX, OFFSET S_FILE
1403 MOV CX, File_Search_Attr ;normal = 0
1404; $ELSE
1405 JMP SHORT $$EN54
1406$$IF54:
1407 MOV DX, OFFSET FILE_DTA
1408; $ENDIF
1409$$EN54:
1410 CALL FIND_IT
1411; $EXITIF C
1412 JNC $$IF53
1413 OR MY_FLAG, NO_MORE_FILE ;no more file in this directory
1414; $ORELSE
1415 JMP SHORT $$SR53
1416$$IF53:
1417 MOV FOUND_FILE_FLAG, 1 ;set the flag for "File not found" msg.
1418 CALL FILTER_FILES ;found. filter it with options
1419 TEST MY_FLAG, FOUND_FLAG
1420; $ENDLOOP NZ ;if found, leave this loop else start again
1421 JZ $$DO53
1422 AND MY_FLAG, RESET_NO_MORE
1423; $ENDSRCH
1424$$SR53:
1425 RET
1426FIND_FILE ENDP
1427;
1428FIND_DIR PROC NEAR
1429;find directory entry
1430;set NO_MORE_FLAG if carry.
1431; $SEARCH
1432$$DO61:
1433 TEST MY_FLAG, FIND_FIRST_FLAG
1434; $IF NZ
1435 JZ $$IF62
1436 MOV DX, OFFSET S_DIR
1437 MOV CX, DIR_SEARCH_ATTR
1438; $ELSE
1439 JMP SHORT $$EN62
1440$$IF62:
1441 MOV DX, BP
1442; $ENDIF
1443$$EN62:
1444 CALL FIND_IT
1445; $EXITIF C ;no more file
1446 JNC $$IF61
1447 OR MY_FLAG, NO_MORE_FILE ;set MY_FLAG and exit this loop
1448; $ORELSE ;otherwise found a file
1449 JMP SHORT $$SR61
1450$$IF61:
1451 CMP DS:[BP].DTA_ATTRIBUTE, Is_subdirectory ; directory?
1452; $IF E,AND
1453 JNE $$IF67
1454 CMP DS:[BP].DTA_FILENAME, A_dot ;starts with . ?
1455; $IF NE ;if not, then desired subdir
1456 JE $$IF67
1457 OR MY_FLAG, FOUND_FLAG ;found
1458; $ELSE
1459 JMP SHORT $$EN67
1460$$IF67:
1461 AND MY_FLAG, RESET_FOUND
1462; $ENDIF
1463$$EN67:
1464 TEST MY_FLAG, FOUND_FLAG
1465; $ENDLOOP NZ ;if found, leave this loop else start again
1466 JZ $$DO61
1467 AND MY_FLAG, RESET_NO_MORE ;found. set my_flag and exit
1468; $ENDSRCH
1469$$SR61:
1470 RET
1471FIND_DIR ENDP
1472;
1473
1474
1475FILTER_FILES PROC NEAR
1476;FILE_DTA.XXX HAS INFORMATIONS
1477;this routine also show the prompt of source path, filename, if SLASH_P is on.
1478
1479 TEST OPTION_FLAG, SLASH_A ;soft archieve?
1480 JNZ SLASH_AM_RTN ;yes
1481 TEST OPTION_FLAG, SLASH_M ;then hard archieve?
1482 JNZ SLASH_AM_RTN ;yes
1483FF_D:
1484 TEST OPTION_FLAG, SLASH_D ;date?
1485 JNZ SLASH_D_RTN
1486FF_P:
1487 TEST OPTION_FLAG, SLASH_P ;prompt mode? ** this should be placed last.
1488 JNZ SLASH_P_RTN
1489 JMP SHORT FF_FOUND ;no more selective options. copy this file.
1490SLASH_AM_RTN: ;soft or hard archieve.
1491 CALL CHK_ARCHIEVE_BIT
1492 JC FF_NOT_FOUND
1493 JMP SHORT FF_D ;check other options
1494SLASH_D_RTN:
1495 CALL CHK_DATE_FILE ;check file's date
1496 JC FF_NOT_FOUND
1497 JMP SHORT FF_P
1498slash_p_rtn:
1499 call prompt_path_file ;show message and get input from the user
1500 jc ff_not_found ;user does not want this file
1501FF_FOUND:
1502 OR MY_FLAG, FOUND_FLAG ;set found_flag
1503 JMP SHORT FF_EXIT
1504FF_NOT_FOUND:
1505 AND MY_FLAG, RESET_FOUND ;this file is not what we want to copy
1506FF_EXIT:
1507 RET
1508FILTER_FILES ENDP
1509;
1510CHK_ARCHIEVE_BIT PROC NEAR
1511;check the current FILE.DTA area and if archieve bit is on, found.
1512 TEST FILE_DTA.DTA_ATTRIBUTE, 20h ;archieve on?
1513; $IF NZ ;yes
1514 JZ $$IF72
1515 CLC ;clear carry
1516; $ELSE
1517 JMP SHORT $$EN72
1518$$IF72:
1519 STC ;archieve bit is off. Don't
1520; $ENDIF ;have to copy this file
1521$$EN72:
1522 RET
1523CHK_ARCHIEVE_BIT ENDP
1524;
1525CHK_DATE_FILE PROC NEAR
1526;
1527 MOV CX, FILE_DTA.DTA_FILE_DATE
1528 CMP CX, INPUT_DATE ;FILE_DATE < INPUT_DATE
1529; $IF B
1530 JNB $$IF75
1531 STC ;not found
1532; $ELSE
1533 JMP SHORT $$EN75
1534$$IF75:
1535 CLC ;found desired file
1536; $ENDIF
1537$$EN75:
1538 RET
1539CHK_DATE_FILE ENDP
1540;
1541
1542
1543PROMPT_PATH_FILE PROC NEAR
1544
1545;show the current source path, filename found, and get the user input.
1546;if it is yes, then reset carry, no, set carry otherwise show
1547;the whole message again.
1548;DS, ES - data seg
1549
1550 MOV CX, 13 ;13 max
1551 LEA SI, FILE_DTA.DTA_FILENAME
1552 MOV DI, OFFSET DISP_S_FILE
1553 REP MOVSB ;filename => disp_s_file
1554PPF_AGAIN:
1555 LEA SI,SUBLIST1 ;AN000; get addressability to sublist
1556 LEA DX,DISP_S_PATH ;AN000; offset to PATH NAME
1557 MOV [SI].DATA_OFF,DX ;AN000; save offset
1558 MOV [SI].DATA_SEG,DS ;AN000; save data segment
1559 MOV [SI].MSG_ID,1 ;AN000; message ID
1560 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
1561 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
1562 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
1563
1564 LEA SI,SUBLIST2 ;AN000; get addressability to sublist
1565 LEA DX,DISP_S_FILE ;AN000; offset to FILE NAME
1566 MOV [SI].DATA_OFF,DX ;AN000; save offset
1567 MOV [SI].DATA_SEG,DS ;AN000; save data segment
1568 MOV [SI].MSG_ID,2 ;AN000; message ID
1569 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
1570 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
1571 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
1572 LEA SI,SUBLIST1 ;AN000;
1573
1574 CMP S_DEPTH,0 ;now dealing with starting dir?
1575 JE PATH_FILE_QUERY ;ask (Y/N)
1576 JMP PPF_1
1577
1578PATH_FILE_QUERY:
1579
1580 MOV AX,P_S_PATH_FILE0 ;no back slash, since it is already there
1581 JMP PPF_PRT ;AN000;
1582
1583PPF_1:
1584
1585 MOV AX,P_S_PATH_FILE1 ; Path and file name with
1586 ; back slash delemeter
1587PPF_PRT:
1588 MOV MSG_NUM,AX ;AN000; set message number
1589 MOV SUBST_COUNT,PARM_SUBST_TWO ;AN000; substitution count
1590 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
1591 MOV INPUT_FLAG,DOS_KEYB_INP ;AN000; Y or N INPUT
1592 CALL PRINT_STDOUT ;AN000; Display message
1593 PUSH AX ;AN000; SAVE IT
1594
1595 MOV AX,MSG_CR_LF_STR ;AN000; JUST CR,LF
1596 MOV MSG_NUM,AX ;AN000; set message number
1597 MOV SUBST_COUNT,NO_SUBST ;AN000; substitution count = 0
1598 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
1599 MOV INPUT_FLAG,NO_INPUT ;AN000; NO INPUT
1600 CALL PRINT_STDOUT ;AN000; Display message
1601
1602 POP AX ;AN000; GET IT BACK
1603; On return from prompt msg, AX contains Y or N response character
1604 MOV DL,AL ;AN000;
1605 MOV AH,65H ;AN000;
1606 MOV AL,023H ;AN000; Y/N check function
1607 INT 21H ;AN000; Issue Extended country to
1608 ; capitalize the Y/N response
1609 JC PPF_RETRY ;AN000; NOT Y OR N, ASK AGAIN
1610 CMP AX,1 ;AN000; look for Y
1611 JG PPF_RETRY ;AN000; NOT Y OR N, ASK AGAIN
1612
1613 CMP AX,0 ;AN000; look for N
1614 JE PPF_NO ;AN000;
1615PPF_YES:
1616 CLC ;AN000;CLEAR CARRY
1617 JMP SHORT PPF_EXIT
1618PPF_RETRY:
1619 JMP PPF_AGAIN ;AN000;ASK AGAIN
1620PPF_NO:
1621 STC ;AN000;set carry
1622PPF_EXIT:
1623 RET
1624PROMPT_PATH_FILE ENDP
1625;
1626
1627
1628
1629SET_MY_DTA PROC NEAR
1630;set DS:DX for find_first(next). If MY_FLAG is set to FINDFILE_FLAG then
1631;set it to the offset FILE_DTA, otherwise to BP.
1632;DS should be set to the area whre FILE_DTA, DTAS are.
1633 PUSH DX ;save current DX
1634 TEST MY_FLAG, FINDFILE_FLAG ;handling file?
1635; $IF NZ
1636 JZ $$IF78
1637 MOV DX, OFFSET FILE_DTA
1638; $ELSE
1639 JMP SHORT $$EN78
1640$$IF78:
1641 MOV DX, BP
1642; $ENDIF
1643$$EN78:
1644 MOV AH, Set_DTA
1645 INT 21H
1646 POP DX
1647 RET
1648SET_MY_DTA ENDP
1649;
1650
1651CHANGE_S_DIR PROC NEAR
1652;change source directory
1653;DS points to program data seg.
1654
1655 CMP S_DRV[2], 0 ;LAST_DIR_OUT have took '\' out?
1656; $IF E
1657 JNE $$IF81
1658 MOV S_DRV[2], '\' ;then restore '\' for root dir
1659 MOV S_DRV[3], 0
1660; $ENDIF
1661$$IF81:
1662
1663 TEST SYS_FLAG, ONE_DISK_COPY_FLAG ;one drive letter copy?
1664; $IF NZ,OR ;yes
1665 JNZ $$LL83
1666 TEST OPTION_FLAG, SLASH_M ;hard archive option? (should use full path
1667; $IF NZ ; since hard archieve operation will corrupt the current directory)
1668 JZ $$IF83
1669$$LL83:
1670 MOV DX, OFFSET S_DRV_PATH ;always use full path
1671; $ELSE
1672 JMP SHORT $$EN83
1673$$IF83:
1674 TEST MY_FLAG, VISIT_PARENT_FLAG ;now going toward the root?
1675; $IF NZ ;yes
1676 JZ $$IF85
1677 MOV DX, OFFSET S_PARENT ;just '..',0
1678; $ELSE
1679 JMP SHORT $$EN85
1680$$IF85:
1681 LEA DX, [BP].DTA_FILENAME ;use the subdir name just found
1682; $ENDIF
1683$$EN85:
1684; $ENDIF
1685$$EN83:
1686 MOV AH, Chdir ; = 3Bh
1687 INT 21H
1688; $IF C
1689 JNC $$IF89
1690 OR COPY_STATUS, CHDIR_ERROR_FLAG ;chdir error in source. critical
1691 CALL EXTENDED_ERROR_HANDLER
1692; $ENDIF
1693$$IF89:
1694
1695 RET
1696CHANGE_S_DIR ENDP
1697;
1698
1699CHANGE_T_DIR PROC NEAR
1700;change target dir according to t_drv_path.
1701;Since this routine is called by WRITE_FROM_BUFFER and DS now points
1702;to buffer area while ES points to the program data area, we set DS
1703;to data seg again here for the function call Chdir.
1704 PUSH DS ;save current buffer seg
1705 PUSH ES ;currentpy es is a data seg
1706 POP DS ;restore DS value as program data seg
1707
1708 CMP T_DRV[2], 0 ;LAST_DIR_OUT took '\' out?
1709; $IF E
1710 JNE $$IF91
1711 MOV T_DRV[2], '\' ;then put it back for root dir
1712 MOV T_DRV[3], 0
1713; $ENDIF
1714$$IF91:
1715
1716 MOV DX, OFFSET T_DRV_PATH
1717 MOV AH, CHDIR
1718 INT 21H
1719
1720 POP DS ;restore caller's DS value
1721 RET
1722CHANGE_T_DIR ENDP
1723;
1724
1725CMP_FILESIZE_TO_BUFFER_LEFT PROC NEAR
1726;Compare buffer_left (paragraph) with filesize (high_file_size, low_file_size.)
1727;if filesize is bigger than buffer_left, then set FILE_BIGGER_FLAG
1728;indicating filesize > buffer_left.
1729;
1730 PUSH DX
1731 PUSH AX
1732
1733 CMP OPEN_FILE_COUNT,NUL ;AN005;ARE THERE ANY OPEN FILES
1734; $IF Z ;AN005;NO, THEN GO AHEAD AND OPEN
1735 JNZ $$IF93
1736 CALL OPEN_A_FILE ;AN005;OPEN A FILE USING FILE_DTA
1737
1738; Get extended Attribute list size.
1739
1740 MOV BX,S_HANDLE ;AN005; BX = handle
1741 MOV AX, GET_ATTRIB ;AN005; extended attribute code 5702H
1742 MOV SI,ALL_ATTR ;AN005; SELECT ALL ATTRIBUTES SIZE
1743 XOR CX,CX ;AN005; JUST QUERY SIZE NEEDED
1744 MOV DI,NUL_LIST ;AN005; DI = LIST FOR NO DATA RETURNED
1745 INT 21H ;AN005; get extended attribute SIZE
1746 ADD CX,PARA_BOUND ;AN005; TO FIGURE THE NEXT PARAGRAPH
1747 MOV AX,CX ;AN005;
1748 MOV CL,PARAGRAPH ;AN005; GET PARAGRAPHS (DIV BY 16)
1749 SHR AX,CL ;AN005;
1750 MOV SIZ_OF_BUFF,AX ;AN005;SAVE BUFF SIZE FOR THE HEADER
1751 ADD AX,FIXD_HD_SIZ ;AN005;GET THE TOTAL HEADER SIZE
1752 MOV PARA_OF_HDR,AX ;AN005;SAVE FOR LATER
1753 SHL AX, CL ;AN005;CONVERT BACK TO TOTAL BYTES
1754 MOV BYTS_OF_HDR,AX ;AN005;SAVE FOR LATER
1755; $ENDIF ;AN005;
1756$$IF93:
1757
1758 AND FILE_FLAG, RESET_FILE_BIGGER
1759 MOV AX,PARA_OF_HDR ;AN005;GET THE HEADER SIZE (para.)
1760 CMP BUFFER_LEFT,AX ;AC005;buffer_left >= HEADER SIZE
1761; $IF AE
1762 JNAE $$IF95
1763 MOV AX, BUFFER_LEFT ;buffer_left in para
1764 SUB AX,PARA_OF_HDR ;AC005;consider header size in advance
1765 MOV CX, 16
1766 MUL CX ;* 16. result in DX;AX
1767 CMP HIGH_FILE_SIZE, DX
1768; $IF A ;if high_filesize > dx
1769 JNA $$IF96
1770 OR FILE_FLAG, FILE_BIGGER_FLAG
1771; $ELSE
1772 JMP SHORT $$EN96
1773$$IF96:
1774; $IF E
1775 JNE $$IF98
1776 CMP LOW_FILE_SIZE, AX
1777; $IF A
1778 JNA $$IF99
1779 OR FILE_FLAG, FILE_BIGGER_FLAG
1780; $ENDIF
1781$$IF99:
1782; $ENDIF
1783$$IF98:
1784; $ENDIF
1785$$EN96:
1786; $ELSE
1787 JMP SHORT $$EN95
1788$$IF95:
1789 OR FILE_FLAG, FILE_BIGGER_FLAG ;buffer_left < HEADER SIZE
1790; $ENDIF
1791$$EN95:
1792
1793 POP AX
1794 POP DX
1795 RET
1796CMP_FILESIZE_TO_BUFFER_LEFT ENDP
1797;
1798
1799SET_BUFFER_PTR PROC NEAR
1800;set BUFFER_PTR, BUFFER_LEFT, OLD_BUFFER_PTR in paragraph boundary
1801;to be used when reading a file into buffer.
1802;this routine uses current BUFFER_PTR to figure out the next BUFFER_PTR.
1803;So, at initialization time set BUFFER_PTR to CS, and set AX to the offset
1804;of INIT, then the resultant BUFFER_PTR indicates the BUFFER_BASE and
1805;OLD_BUFFER_PTR indicates CS.(This means if old_buffer_ptr = cs, then
1806;it is the start of buffer)
1807;To get the next BUFFER_PTR during multi-copy, just set the AX to the
1808;number of bytes read. This routine will add E.A.BUFFER SIZE + 3 para.
1809;for header size and will set the next BUFFER_PTR.
1810;input: AX - offset of buffer
1811; Top_of_memory in segment
1812; current BUFFER_PTR
1813; current OLD_BUFFER_PTR
1814; current BUFFER_LEFT
1815;output: BUFFER_PTR for next reading
1816; OLD_BUFFER_PTR
1817; BUFFER_LEFT (Top_of_memory - Buffer_Ptr. If it is 0, then indicates
1818; the BUFFER is FULL. In this case, the BUFFER_PTR is
1819; invalid, but OLD_BUFFER_PTR keep the former buffer_ptr
1820; value which says that it is the last header in the buffer)
1821;** Currently this program support maxium top of memory in seg 0FFFF - resident
1822; area. This routine will check the overflow case to gaurd the next buffer_ptr
1823; not to exceed FFFF.
1824
1825 PUSH CX
1826 MOV CX, BUFFER_PTR
1827 MOV OLD_BUFFER_PTR, CX ;set old_buffer_ptr
1828 MOV CL, 4
1829 SHR AX, CL ;get paragraphs
1830 INC AX ;get next paragraph
1831 ADD AX,PARA_OF_HDR ;AC005;consider header size
1832 ADD BUFFER_PTR, AX ;add this to the current buffer_ptr
1833
1834; $IF NC,AND ;not exceed 16 bit.
1835 JC $$IF105
1836 MOV AX, Top_of_memory
1837 SUB AX, BUFFER_PTR ;AX = Top_of_memory - Buffer_ptr
1838; $IF A ;if buffer_left > 0
1839 JNA $$IF105
1840 MOV BUFFER_LEFT, AX
1841; $ELSE
1842 JMP SHORT $$EN105
1843$$IF105:
1844 MOV BUFFER_LEFT, 0 ;indication of buffer full
1845; $ENDIF
1846$$EN105:
1847 POP CX
1848 RET
1849SET_BUFFER_PTR ENDP
1850;
1851
1852WRITE_FROM_BUFFER PROC NEAR
1853;Write from the first header starting at buffer_base until finishes
1854;the last header which, actually, happens to be the old_buffer_ptr
1855;at the time of the call. After the writing, reset the buffer_ptr
1856;to buffer_base again for the next read_into_buffer.
1857;If continue_info is 1 or 2 (Continue of small, bigfile) then after
1858;the creation of a target file, it will set the CREATED_FLAG.
1859;This flag will be reset when it found the continue_info to be 3
1860;(End of contine).
1861;For convenience of use of function call, ES will be used for
1862;the program data seg while DS will be used for the BUFFER seg.
1863;
1864 PUSH DS
1865 PUSH ES ;save ds, es
1866
1867 PUSH DS
1868 POP ES ;set ES to program data seg
1869
1870 OR ACTION_FLAG, READING_FLAG ;show reading message next time
1871; AND ES:MY_FLAG, RESET_IS_SOURCE ;now, deals with target
1872 ;set this for change_dir
1873 MOV AX, ES:BUFFER_BASE
1874 MOV DS, AX
1875 PUSH CS
1876 POP AX
1877 CMP ES:OLD_BUFFER_PTR, AX ;if old_buffer_ptr = CS then
1878 ;buffer is empty. Just exit
1879 JE WFB_EXIT_BRIDGE
1880WFB_CD:
1881 CALL CHANGE_T_DIR
1882 JC WFB_ERROR_BRIDGE ;error?
1883WFB_CHATT:
1884 CMP DS:ATTR_FOUND, Is_subdirectory ;a subdirectory? = 10H
1885 JNE WFB_FILE ;no. a file
1886WFB_CMP_DEPTH:
1887 MOV AH, ES:T_DEPTH ;yes. a subdir.
1888 CMP DS:DIR_DEPTH, AH ;DIR_DEPTH > T_DEPTH ?
1889 JBE WFB_DEC_DEPTH ;if not, go to parent node
1890 LEA DI, ES:T_DRV_PATH ;else goto child node
1891 LEA SI, DS:FILENAME_FOUND
1892 CMP ES:T_PATH, 0 ;root directory?
1893; $IF E
1894 JNE $$IF108
1895 MOV AL, 0FFh ;then don't need to put delim since it is already there
1896; $ELSE
1897 JMP SHORT $$EN108
1898$$IF108:
1899 MOV AL, Path_delim ;path_delim '\'
1900; $ENDIF
1901$$EN108:
1902 CALL CONCAT_ASCIIZ
1903 call concat_display_path ;modify the path for display
1904 INC ES:T_DEPTH
1905 CALL MAKE_DIR ;try to make a new sub directory
1906 JC WFB_EXIT_A_BRIDGE ;there exists a file with same name.
1907 MOV AX, DS ;current buffer seg = old_buffer_ptr?
1908 CMP ES:OLD_BUFFER_PTR, AX
1909 JNE WFB_NEXT ;not finished yet. jmp to next
1910 OR ES:MY_FLAG, MISSING_LINK_FLAG ;Finished. Missing link condition occurred regarding empty sub dir
1911 JMP WFB_EXIT_A ;check archieve options.
1912WFB_NEXT:
1913 MOV DS, DS:NEXT_PTR ;let's handles next header.
1914 JMP WFB_CD ;change directory first.
1915WFB_EXIT_BRIDGE: JMP WFB_EXIT
1916WFB_ERROR_BRIDGE: JMP WFB_ERROR
1917WFB_EXIT_A_BRIDGE: JMP WFB_EXIT_A
1918WFB_DEC_DEPTH:
1919 LEA DI, ES:T_DRV_PATH
1920 CALL RM_EMPTY_DIR ;check flags and remove empty dir
1921 CALL LAST_DIR_OUT ;take off the last dir from path
1922 call cut_display_path ;modify path for display purpose
1923 DEC ES:T_DEPTH ;and decrease depth
1924 JMP WFB_CD ;CHANGE DIR AND compare the depth again.
1925
1926WFB_FILE: ;Handling a file
1927 AND ES:MY_FLAG, RESET_MISSING_LINK ;if found a file, then current dir is not empty.
1928 TEST ES:FILE_FLAG, CREATED_FLAG ; A file handle is created ?
1929 JNZ WFB_WRITE ;yes, skip create again.
1930 CALL CREATE_A_FILE ;create a file in the cur dir
1931 JC WFB_ERROR ;file creation error?
1932WFB_WRITE:
1933 CALL WRITE_A_FILE
1934 JC WFB_EXIT_A ;target file has been already deleted.
1935 CMP DS:CONTINUE_INFO, 0
1936; $IF E,OR ;if continue_info = 0 or 3
1937 JE $$LL111
1938 CMP DS:CONTINUE_INFO, 3
1939; $IF E
1940 JNE $$IF111
1941$$LL111:
1942 MOV BX, ES:T_HANDLE
1943 CALL SET_FILE_DATE_TIME ;then set file's date, time
1944 PUSH DS ;AN005;SAVE THE BUFFER PTR
1945 PUSH ES ;AN005;WE NEED THE DATA PTR
1946 POP DS ;AN005;DS = THE DATA PTR
1947 CALL CLOSE_A_FILE ;and close the handle
1948 POP DS ;AN005;DS = THE BUFFER PTR AGAIN
1949 CALL RESTORE_FILENAME_FOUND ;if filename_found has been changed, restore it for reset_s_archieve.
1950 AND ES:FILE_FLAG, RESET_CREATED ;and reset created_flag
1951 CALL INC_FILE_COUNT ;increase file count
1952; $ENDIF
1953$$IF111:
1954 MOV AX, DS
1955 CMP ES:OLD_BUFFER_PTR, AX ;current header is the last one?
1956 JE WFB_EXIT_A ;then exit
1957 MOV DS, DS:NEXT_PTR ;else set ds to the next ptr
1958 JMP WFB_CHATT ;handle the next header
1959WFB_ERROR:
1960 jmp main_exit ;meaningful when MKDIR failed because
1961 ;of there already exist same named file,
1962 ;or disk_full case.
1963WFB_EXIT_A:
1964 test ES:option_flag, slash_m ;hard archieve ? - turn off source archieve bit.
1965 jz wfb_exit_B ;no, chk error flag and exit
1966 call reset_s_archieve ;reset source file(s) archieve bit using header info(s).
1967WFB_EXIT_B:
1968 test ES:copy_status, mkdir_error_flag ;mkdir error happened?
1969 JNZ WFB_ERROR ;yes, exit
1970 test ES:copy_status, disk_full_flag ;disk full happened?
1971 JNZ WFB_ERROR ;yes, exit
1972WFB_EXIT:
1973 MOV ES:OLD_BUFFER_PTR, CS ;set old_buffer_ptr to CS
1974 MOV AX, ES:BUFFER_BASE
1975 MOV ES:BUFFER_PTR, AX ;set buffer_ptr to base
1976 MOV AX, ES:MAX_BUFFER_SIZE
1977 MOV ES:BUFFER_LEFT, AX ;set buffer_left
1978 POP ES
1979 POP DS
1980 TEST SYS_FLAG, ONE_DISK_COPY_FLAG ;one drive letter copy?
1981; $IF NZ ;yes
1982 JZ $$IF113
1983 CALL CHANGE_S_DIR ;then change current dir to s dir
1984; $ENDIF
1985$$IF113:
1986 RET
1987WRITE_FROM_BUFFER ENDP
1988;
1989INC_FILE_COUNT PROC NEAR
1990;increase the file count by one.
1991;increase file_cnt_low, file_cnt_high.
1992;input: DS - buffer
1993; ES - data seg
1994 INC ES:FILE_CNT_LOW
1995 JNZ IFC_EXIT
1996 INC ES:FILE_CNT_HIGH ;if carry over, then inc file_cnt_high
1997IFC_EXIT:
1998 RET
1999INC_FILE_COUNT ENDP
2000;
2001RM_EMPTY_DIR PROC NEAR
2002;check the slash_E option, missing_link_flag. Remove the empty directory
2003;from the target disk.
2004;INPUT: DS - buffer
2005; ES - data seg
2006; DI - points to the current target drv, path
2007
2008 TEST ES:OPTION_FLAG, SLASH_E ;user want to copy empty subdir?
2009 JNZ RED_EXIT ;then exit
2010 TEST ES:MY_FLAG, MISSING_LINK_FLAG ;missing informations for not to copying empty dir
2011 ;at the tree travesal phase?
2012 JZ RED_EXIT ;no.
2013 CALL SWITCH_DS_ES ;ds - data, es - buffer
2014 MOV DX, OFFSET T_PARENT ;chdir to parent dir
2015 MOV AH, 3Bh ;Chdir
2016 INT 21h
2017 PUSH DI
2018 POP DX ;DS:DX points to drv, path
2019 MOV AH, 3Ah ;REMOVE SUBDIR
2020 INT 21h
2021 CALL SWITCH_DS_ES ;restore ds, es
2022RED_EXIT:
2023 RET
2024RM_EMPTY_DIR ENDP
2025;
2026RESTORE_FILENAME_FOUND PROC NEAR
2027;when the filename_found has been Revised according to the user's specified
2028;input parm, then restore the original source filename in filename_found.
2029;This will be used when reset_s_archieve routine reset the source file's
2030;archieve bit.
2031;input: DS - buffer
2032; ES - data seg
2033
2034 CMP ES:T_FILENAME, 0 ;if t_filename ot t_template is not blank,
2035; $IF NE,OR ;then filename_found has been Revised.
2036 JNE $$LL115
2037 CMP ES:T_TEMPLATE, 0
2038; $IF NE
2039 JE $$IF115
2040$$LL115:
2041 CALL SWITCH_DS_ES ;DS - data seg, ES - buffer
2042 MOV CX, 13
2043 LEA SI, DS:DISP_S_FILE ;we know filename_found has been save into DISP_S_FILE when create the file.
2044 LEA DI, ES:FILENAME_FOUND ;use this to restore source filename this time.
2045 REP MOVSB ;disp_s_file => filename_found
2046 CALL SWITCH_DS_ES ;restore ds, es
2047; $ENDIF
2048$$IF115:
2049 RET
2050RESTORE_FILENAME_FOUND ENDP
2051;
2052RESET_S_ARCHIEVE PROC NEAR
2053;INPUT: DS - buffer
2054; ES - data seg
2055
2056 TEST ES:COPY_STATUS, DISK_FULL_FLAG ;called when disk full?
2057 JZ RSA_START ;no, just goto start
2058 ;else disk_full.
2059 MOV AX, DS ;current DS when called
2060 CMP ES:BUFFER_BASE, AX ;current DS(BUFFER) is the first one?
2061 JE RSA_EXIT_BRIDGE ;yes, just exit
2062 MOV AX, DS:BEFORE_PTR ;set old_buffer_ptr to the header
2063 MOV ES:OLD_BUFFER_PTR, AX ;that is just before the troubled one.
2064RSA_START:
2065 MOV AX, ES:BUFFER_BASE
2066 MOV DS, AX ;set DS to buffer base again to start traveling
2067RSA_CD:
2068 CALL CHANGE_ARC_S_DIR ;change souce dir
2069RSA_CHATT:
2070 CMP DS:ATTR_FOUND, Is_subdirectory ; = 10h
2071 JNE RSA_FILE ;no a file
2072RSA_CMP_DEPTH:
2073 MOV AH, ES:S_ARC_DEPTH ;yes, a subdir
2074 CMP DS:DIR_DEPTH, AH ;dir_depth > s_arc_depth?
2075 JBE RSA_DEC_DEPTH ;if not, goto parent node
2076 LEA DI, ES:S_ARC_DRV_PATH
2077 LEA SI, DS:FILENAME_FOUND
2078 CMP ES:S_ARC_PATH, 0 ;root dir?
2079; $IF E
2080 JNE $$IF117
2081 MOV AL, 0FFh
2082; $ELSE
2083 JMP SHORT $$EN117
2084$$IF117:
2085 MOV AL, Path_delim ;path_delim '\'
2086; $ENDIF
2087$$EN117:
2088 CALL CONCAT_ASCIIZ
2089 INC ES:S_ARC_DEPTH
2090 MOV AX, DS
2091 CMP ES:OLD_BUFFER_PTR, AX
2092 JE RSA_EXIT_A ;finished. Set the source current dir and return to caller
2093 MOV DS, DS:NEXT_PTR ;else let's handles next header
2094 JMP RSA_CD ;chdir first.
2095RSA_EXIT_A:
2096 CALL CHANGE_ARC_S_DIR ;to restore the same current source dir
2097 ;as that of the READ_INTO_BUFFER proc.
2098RSA_EXIT_BRIDGE:JMP RSA_EXIT
2099RSA_DEC_DEPTH:
2100 LEA DI, ES:S_ARC_DRV_PATH
2101 CALL LAST_DIR_OUT
2102 DEC ES:S_ARC_DEPTH
2103 JMP RSA_CD
2104RSA_FILE:
2105 CMP DS:CONTINUE_INFO, 0
2106; $IF E,OR
2107 JE $$LL120
2108 CMP DS:CONTINUE_INFO, 3
2109; $IF E
2110 JNE $$IF120
2111$$LL120:
2112 CALL CHANGE_S_FILEMODE ;change source file mode
2113; $ENDIF
2114$$IF120:
2115 MOV AX, DS
2116 CMP ES:OLD_BUFFER_PTR, AX ;current header is the last one?
2117 JE RSA_EXIT
2118 MOV DS, DS:NEXT_PTR
2119 JMP RSA_CHATT
2120RSA_EXIT:
2121 OR ES:SYS_FLAG, DEFAULT_S_DIR_fLAG ;this is for restoring default source dir before exit to DOS.
2122 RET ;return to caller
2123RESET_S_ARCHIEVE ENDP
2124;
2125CHANGE_S_FILEMODE PROC NEAR
2126;input: DS - buffer
2127; ES - data seg
2128
2129 LEA DX, DS:FILENAME_FOUND
2130 MOV AH, 43h ;chmod
2131 MOV AL, 0 ;get attribute in CX
2132 INT 21h
2133 MOV AH, 43h
2134 MOV AL, 1
2135 AND CX, 0FFDFh ;turn off the archieve bit
2136 INT 21h
2137 RET
2138CHANGE_S_FILEMODE ENDP
2139;
2140CHANGE_ARC_S_DIR PROC NEAR
2141;change the source directory according to S_ARC_DRV_PATH
2142;INPUT: DS - buffer
2143; ES - data seg
2144 call switch_ds_es
2145 CMP S_ARC_DRV[2], 0
2146; $IF E
2147 JNE $$IF122
2148 MOV S_ARC_DRV[2], '\' ;LAST_DIR_OUT have took '\' out?
2149 MOV S_ARC_DRV[3],0 ;then restore it
2150; $ENDIF
2151$$IF122:
2152 MOV DX, OFFSET S_ARC_DRV_PATH ;use full drv, path
2153 MOV AH, CHDIR ; = 3Bh
2154 INT 21h
2155; $IF C
2156 JNC $$IF124
2157 OR COPY_STATUS, CHDIR_ERROR_FLAG
2158 CALL EXTENDED_ERROR_HANDLER
2159; $ENDIF
2160$$IF124:
2161 call switch_ds_es
2162 RET
2163CHANGE_ARC_S_DIR ENDP
2164
2165;
2166CONCAT_DISPLAY_PATH PROC NEAR
2167;concatenate subdirectory name found from the header to DISP_S_PATH which
2168;will be used for display copying file messages.
2169;if slash_p option has been set, then just return.
2170;DS: buffer header
2171;ES: data seg
2172;
2173 TEST ES:OPTION_FLAG, SLASH_P ;prompt option?
2174; $IF Z ;no
2175 JNZ $$IF126
2176 LEA DI, ES:DISP_S_PATH
2177 LEA SI, DS:FILENAME_FOUND
2178 CMP ES:T_DEPTH, 0 ;this will be the first child directory?
2179; $IF E ;yes
2180 JNE $$IF127
2181 MOV AL, 0FFh ;then do not put '\' between them
2182; $ELSE
2183 JMP SHORT $$EN127
2184$$IF127:
2185 MOV AL, Path_delim ;else put '\'
2186; $ENDIF
2187$$EN127:
2188 CALL CONCAT_ASCIIZ
2189; $ENDIF ;else just return
2190$$IF126:
2191 RET
2192CONCAT_DISPLAY_PATH ENDP
2193;
2194CUT_DISPLAY_PATH PROC NEAR
2195;take the last dir out from the DISP_S_PATH for display copy messages.
2196;if prompt option has been set, just return.
2197;INPUT: DS - buffer header
2198; ES - data seg
2199;
2200
2201 TEST ES:OPTION_FLAG, SLASH_P ;prompt?
2202; $IF Z ;no.
2203 JNZ $$IF131
2204 PUSH DS ;save DS
2205 PUSH ES
2206 POP DS ;ds = es = data seg
2207 MOV SI, OFFSET DISP_S_PATH ;for CHK_DRV_LETTER
2208 MOV DI, OFFSET DISP_S_PATH ;for LASR_DIR_OUT
2209
2210 CALL LAST_DIR_OUT
2211; $IF C ;failure? no '\' found
2212 JNC $$IF132
2213 CALL CHK_DRV_LETTER ;drive letter?
2214; $IF NC ;yes. "D:filename",0 case
2215 JC $$IF133
2216 MOV BYTE PTR DS:[SI], 0 ;make it "D:",0 since SI now points to the next chr
2217; $ELSE ;no. "filename",0 case
2218 JMP SHORT $$EN133
2219$$IF133:
2220 MOV BYTE PTR [DI], 0 ;set DISP_S_PATH to 0
2221; $ENDIF
2222$$EN133:
2223; $ELSE ;found '\' and last '\' became 0
2224 JMP SHORT $$EN132
2225$$IF132:
2226 CMP T_DEPTH, 1 ;now going to the starting path?
2227; $IF E ;yes. restore it for concat_display_path routine.
2228 JNE $$IF137
2229 MOV DI, AX ;we want to restore '\' and put 0 just after that.
2230 DEC DI ;for ex, "D:\DIR1"=>"D:"=>"D:\" -- original starting path
2231 MOV BYTE PTR [DI], '\' ; "D:dir1\dir2"=>"D:dir1"(starting path) => "D:dir1\"
2232 MOV BYTE PTR [DI+1], 0
2233; $ENDIF
2234$$IF137:
2235; $ENDIF
2236$$EN132:
2237 POP DS ;restore ds to buffer header
2238; $ENDIF
2239$$IF131:
2240 RET
2241CUT_DISPLAY_PATH ENDP
2242;
2243
2244
2245;***************************************************************************
2246CHK_DRV_LETTER PROC NEAR
2247; ** CHECK CURRENT CHR IS ALPHA CHR FOLLOWED BY COLON. *
2248; INPUT: DS:SI POINTS TO THE CURRENT CHR TO BE CHECKED. *
2249; OUTPUT: FOUND - SI POINTS TO THE NEXT CHR. *
2250; IF THIS HAD BEEN A LAST WORD, ZERO FLAG WILL BE SET. *
2251; NOT FOUND - CARRY IS SET. DI, CX UNCHANGED. *
2252;***************************************************************************
2253
2254 PUSH AX
2255 PUSH SI ;AN010;IN CASE DRIVE LETTER NOT FOUND
2256; $DO ;AN010;
2257$$DO141:
2258 CLC ;AN010;INITIALIZE TO NOT DBCS
2259 MOV AL,DS:BYTE PTR [SI] ;AN010;GET THE 1st CHAR TO TEST
2260 CALL CHK_DBCS ;AN010;SEE IF WE ARE IN DBCS
2261; $LEAVE NC ;AN010;THIS IS NOT DBCS
2262 JNC $$EN141
2263 INC SI ;AN010;GO TO THE NEXT CHAR TO CHECK
2264 INC SI ;AN010;DITO
2265; $ENDDO ;AN010;
2266 JMP SHORT $$DO141
2267$$EN141:
2268 CMP AL, 'A'
2269 JB CK_DR_1 ;LESS THAN 'A', THEN NOT FOUND.
2270 CMP AL, 'Z'
2271 JA CK_DR_1 ;ABOVE 'Z', THEN NOT FOUND.
2272 MOV AL, DS:BYTE PTR [SI+1] ;LOOK AHEAD THE FOLLOWING CHR.
2273 CMP AL, ':' ;SHOULD BE A COLON.
2274 JNZ CK_DR_1 ;NOT FOUND.
2275 POP AX ;AN010;THROW AWAY SAVED SI
2276 INC SI ;FOUND. SI TO THE NEXT CHR.
2277 INC SI
2278 JMP CK_DR_2
2279CK_DR_1:
2280 STC ;SET CARRY
2281 POP SI ;AN010;RESTORE SI TO ENTRY VALUE
2282CK_DR_2:
2283 POP AX
2284 RET
2285CHK_DRV_LETTER ENDP
2286;
2287
2288
2289CREATE_A_FILE PROC NEAR
2290;create a file in the header and return the file handle in T_HANDLE.
2291;Set CREATED_FLAG. This will be reset by WRITE_FROM_BUFFER when it
2292;close the handle.
2293;this routine will check the T_FILENAME and T_TEMPLATE if any target
2294;filename has been entered. If T_FILENAME is there, then DX will
2295;points to this (This is the case when the user has specified non_global
2296;chr filename and any source filename be changed to this name.)
2297;If T_TEMPLATE is present, then modify the filename found in the
2298;header part.
2299;Also, this routine show copy messages just before a file creation using
2300;FILENAME_FOUND.
2301;ES - data seg
2302;DS - buffer seg
2303
2304 PUSH DS
2305 PUSH ES
2306
2307 ;save the original filename from the header
2308 MOV CX, 13 ;max 13 chr
2309 LEA SI, DS:FILENAME_FOUND ;original source file name
2310 LEA DI, ES:DISP_S_FILE ;filename to be displayed
2311 REP MOVSB ;filename_found => disp_s_file
2312 test es:option_flag, slash_p
2313; $IF Z
2314 JNZ $$IF144
2315 CALL SHOW_COPY_MESSAGE ;show the source path, file
2316; $ENDIF
2317$$IF144:
2318
2319 CMP ES:T_FILENAME, 0
2320; $IF NE ;non_global target filename entered.
2321 JE $$IF146
2322 TEST ES:COPY_STATUS, MAYBE_ITSELF_FLAG
2323; $IF NZ
2324 JZ $$IF147
2325 LEA SI, DS:FILENAME_FOUND
2326 LEA DI, ES:T_FILENAME
2327 CALL COMP_FILENAME ;compare it. if same then show
2328 ;file cannot be copied onto itself and
2329 ;abort
2330; $ENDIF
2331$$IF147:
2332
2333 CALL SWITCH_DS_ES ;now ds - data, es - buffer
2334 MOV CX, 13
2335 LEA SI, DS:T_FILENAME
2336 LEA DI, ES:FILENAME_FOUND
2337 REP MOVSB ; t_filename => filename_found
2338 MOV AL, NUL ;AN014;DOS NEEDS A NUL TO TERM.
2339 MOV ES:TERMINATE_STRING,AL ;AN014;PUT IT IN THE HEADER
2340 CALL SWITCH_DS_ES ;now ds - buffer, es - data seg
2341
2342; $ELSE
2343 JMP SHORT $$EN146
2344$$IF146:
2345 CMP ES:T_TEMPLATE, 0 ;global chr target filename entered?
2346; $IF NE ;yes, entered. modify the filename found
2347 JE $$IF150
2348 CALL MODIFY_FILENAME
2349 TEST ES:COPY_STATUS, MAYBE_ITSELF_FLAG
2350; $IF NZ
2351 JZ $$IF151
2352 LEA SI, DS:FILENAME_FOUND ;compare the Revised filename
2353 LEA DI, ES:DISP_S_FILE ;with original name
2354 CALL COMP_FILENAME ;if same, then issue error message and exit
2355; $ENDIF
2356$$IF151:
2357; $ELSE
2358 JMP SHORT $$EN150
2359$$IF150:
2360 TEST ES:COPY_STATUS, MAYBE_ITSELF_FLAG ;*.* CASE
2361; $IF NZ
2362 JZ $$IF154
2363 PUSH ES
2364 POP DS ;ds - data seg
2365
2366 ; Set message parameters
2367 MOV AX,MSG_COPY_ITSELF ;AN000;
2368 MOV MSG_NUM,AX ;AN000; set message number
2369 MOV SUBST_COUNT,NO_SUBST ;AN000; no message subst.
2370 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2371 MOV INPUT_FLAG,NO_INPUT ;AN000; no user input
2372 CALL PRINT_STDERR ;AN000; display error
2373 JMP MAIN_EXIT
2374; $ENDIF
2375$$IF154:
2376; $ENDIF
2377$$EN150:
2378; $ENDIF
2379$$EN146:
2380;-------------------------------------------------------------------------
2381; Use extended open DOS call to create the target file, use attribute list
2382; obtained from the previous Get Extended attribute DOS call
2383;-------------------------------------------------------------------------
2384 MOV AX, Ext_Open ;AN000; = 6Ch
2385 MOV BX,CREATE_MODE ;AN000;CREATE MODE = 0002H
2386 MOV CX,CREATE_ATTR ;AN000; attribute = 0
2387 MOV DX,CREATE_FLAG ;AN000; flag = 0112H
2388 MOV SI,OFFSET TARGET_DRV_LET ;AN005; DS:SI-->NAME TO CREATE
2389 MOV DI,NUL_LIST ;AN012; ES:DI = -1
2390 INT 21H ;AN000; create file
2391
2392 JC CAF_ERROR ;AN000;
2393 MOV ES:T_HANDLE, AX ;AN000;save handle
2394
2395 CALL CHK_T_RES_DEVICE ;check target handle is a reserved dev
2396
2397 MOV AX,SET_ATTRIB ;AN012;5704H
2398 CALL SWITCH_DS_ES ;AN013;now ds - data, es - buffer
2399 MOV BX,T_HANDLE ;AC013;THE FILE HANDLE
2400 LEA DI,ES:ATTRIB_LIST ;AN013;PARAMETER LIST (ES:DI)
2401 INT 21H ;AN012;SET EXTENDED ATTRIBUTES
2402 CALL SWITCH_DS_ES ;AN013;now es - data, ds - buffer
2403 JC CAF_ERROR ;AN012;
2404
2405 OR ES:FILE_FLAG, CREATED_FLAG ;set created_flag
2406 JMP CAF_EXIT
2407CAF_ERROR:
2408 PUSH DS
2409 PUSH ES
2410 POP DS
2411 OR COPY_STATUS, CREATE_ERROR_FLAG
2412 CALL EXTENDED_ERROR_HANDLER
2413 POP DS
2414CAF_EXIT:
2415 POP ES
2416 POP DS
2417 RET
2418CREATE_A_FILE ENDP
2419;
2420chk_t_res_device proc near
2421;check the target handle if it is for reserved device
2422;input: ES - data seg
2423; DS - buffer
2424; AX - filehandle created
2425
2426 cmp es:t_filename,0 ;if no user specified filename
2427 jne ctrd_ioctl ;then should not be a reserved device name
2428 cmp es:t_template,0
2429 je ctrd_exit
2430ctrd_ioctl:
2431 mov bx, ax ;file handle
2432 mov ax, 4400h ;IOCTL get device info.
2433 int 21h
2434 test dx, 80h ;is device? (not a block device?)
2435 jz ctrd_exit
2436 PUSH ES ;AN000;
2437 POP DS ;AN000;ds - data seg
2438
2439; Set message parameters
2440 MOV AX,MSG_RES_T_NAME ;AN000; message number
2441 MOV MSG_NUM,AX ;AN000; set message number
2442 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
2443 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2444 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2445 CALL PRINT_STDOUT ;AN000; display message
2446 jmp main_exit
2447ctrd_exit:
2448 ret
2449chk_t_res_device endp
2450;
2451MODIFY_FILENAME PROC NEAR
2452;modify the filename in the header using T_TEMPLATE.
2453;INPUT:
2454;DS: BUFFER
2455;ES: DATA SEG
2456
2457 PUSH DS ;save ds, es = data seg
2458 PUSH ES
2459
2460 PUSH DS
2461 PUSH ES
2462 MOV ES, ES:PSP_SEG ;ES points to PSP
2463 MOV DI, PSPFCB2_DRV ;DI points to FCB2, 6c
2464 MOV SI, OFFSET DS:TARGET_DRV_LET ;filename found, DS = buffer header
2465 MOV AH, 29H ;parse a filename
2466 MOV AL, 0 ;control bits
2467 INT 21h ;unfold the filename found into PSP FCB2 area
2468
2469 POP DS ;now DS=data seg, ES=PSP seg
2470 MOV SI, OFFSET T_TEMPLATE ;SI points to template
2471 MOV DI, PSPFCB2_DRV
2472 INC DI ;DI points to the formatted filename
2473 MOV CX, 11
2474 CLD
2475; $DO
2476$$DO158:
2477 CMP CX, 0 ;done?
2478; $LEAVE E ;yes. exit
2479 JE $$EN158
2480 LODSB ;[SI] => AL, SI = SI + 1
2481 CMP AL, '?' ;global chr?
2482; $IF E ;yes
2483 JNE $$IF160
2484 INC DI ;just skip the corresponding target chr
2485; $ELSE ;no
2486 JMP SHORT $$EN160
2487$$IF160:
2488 STOSB ;change the target chr to this. DI = DI + 1
2489; $ENDIF
2490$$EN160:
2491 DEC CX
2492; $ENDDO
2493 JMP SHORT $$DO158
2494$$EN158:
2495
2496 POP ES ;now ES = Buffer
2497 MOV DI, OFFSET ES:FILENAME_FOUND ; di points to filename in the header
2498 MOV DS, PSP_SEG ;DS = PSP seg
2499 MOV SI, PSPFCB2_DRV
2500 INC SI ;di points to Revised filename
2501 CALL COMPRESS_FILENAME ;fold it
2502
2503 POP ES
2504 POP DS
2505 RET
2506MODIFY_FILENAME ENDP
2507;
2508
2509COMP_FILENAME PROC NEAR
2510;this routine is called when MAYBE_COPY_ITSELF flag in on.
2511;SI, DI asciiz string will be compared and if they are identical
2512;the show "Cannot copy onto itself" msg and jmp to main_exit.
2513;INPUT: DS - buffer
2514; ES - data seg
2515
2516 CLD
2517 MOV AL, 0
2518 PUSH DI ;save DI
2519 CALL STRING_LENGTH ;CX get the length of string
2520 MOV BX, CX ;now, BX got the length of the target filename entered.
2521 PUSH BX ;save BX
2522 PUSH ES ;save ES
2523
2524 PUSH DS
2525 POP ES ;now ES set to DS
2526 PUSH SI
2527 POP DI ;now DI points to the source filename found.
2528
2529 MOV AL, 0
2530 CALL STRING_LENGTH ;CX got the length of the string
2531
2532 POP ES ;restore ES
2533 POP BX ;restore BX
2534 POP DI ;restore DI
2535
2536 CMP BX, CX ;COMPARE LENGTH
2537 JNE CF_EXIT ;IF THEY ARE DIFFERENT, EXIT
2538
2539 REPE CMPSB ;compare SI, DI until not equal,
2540 CMP CX, 0 ;finish at cx = 0?
2541 JE CF_SAME
2542 JMP SHORT CF_EXIT
2543CF_SAME:
2544 PUSH ES
2545 POP DS ;ds = data seg
2546
2547; Set message parameters
2548 MOV AX,MSG_COPY_ITSELF ;AN000; message number
2549 MOV MSG_NUM,AX ;AN000; set message number
2550 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
2551 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2552 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2553 CALL PRINT_STDERR ;AN000; display error message
2554 JMP MAIN_EXIT
2555CF_EXIT:
2556 RET
2557COMP_FILENAME ENDP
2558
2559;
2560SHOW_COPY_MESSAGE PROC NEAR
2561;show the source path, filename that is ready for creation in the target disk.
2562;INPUT: ES - data seg
2563; DS - buffer header seg
2564 PUSH DS ;save DS
2565
2566 PUSH ES
2567 POP DS ;DS = data seg
2568
2569 LEA SI,SUBLIST1 ;AN000; get addressability to list
2570 LEA DX,DISP_S_PATH ;AN000; offset to path name
2571 MOV [SI].DATA_OFF,DX ;AN000; save offset
2572 MOV [SI].DATA_SEG,DS ;AN000; save data segment
2573 MOV [SI].MSG_ID,1 ;AN000; message ID
2574 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
2575 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
2576 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
2577
2578 LEA SI,SUBLIST2 ;AN000; get addressability to list
2579 LEA DX,DISP_S_FILE ;AN000; offset to file name
2580 MOV [SI].DATA_OFF,DX ;AN000; save offset
2581 MOV [SI].DATA_SEG,DS ;AN000; save data segment
2582 MOV [SI].MSG_ID,2 ;AN000; message ID
2583 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
2584 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
2585 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
2586
2587 LEA SI,SUBLIST1 ;AN000;
2588 CMP ES:T_DEPTH, 0 ;starting directory?
2589; $IF E ;yes
2590 JNE $$IF164
2591 MOV AX,S_PATH_FILE0 ;AN000;NO BACK SLASH BETWEEN PATH,FNAME
2592
2593; $ELSE
2594 JMP SHORT $$EN164
2595$$IF164:
2596 MOV AX,S_PATH_FILE1 ;AN000;BACK SLASH IS BETWEEN PATH,FNAME
2597
2598; $ENDIF
2599$$EN164:
2600 MOV MSG_NUM,AX ;AN000; set message number
2601 MOV SUBST_COUNT,PARM_SUBST_TWO ;AN000; substitution count = 2
2602 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2603 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2604 CALL PRINT_STDOUT ;show message "Reading source
2605 POP DS ;restore DS
2606 RET
2607SHOW_COPY_MESSAGE ENDP
2608;
2609WRITE_A_FILE PROC NEAR
2610;write a file from the data area in the buffer.
2611;Remember the caller is WRITE_FROM_BUFFER which use ES for
2612;the program data area and DS for the header in the buffer.
2613
2614 MOV AH, Write ; = 40h
2615 MOV BX, ES:T_HANDLE ;handle saved in the program data area
2616 MOV DX, ES:BYTS_OF_HDR ;AC005;skip header
2617 MOV CX, DS:CX_BYTES ;get the # from the header
2618 INT 21h
2619 JC WAF_ERROR ;write error
2620 CMP AX, DS:CX_BYTES
2621 JNE WAF_DISKFULL
2622 JMP WAF_EXIT
2623WAF_ERROR:
2624 CALL CLOSE_DELETE_FILE ;close delete troubled file
2625 OR COPY_STATUS, WRITE_ERROR_FLAG
2626 CALL SWITCH_DS_ES ;AN000;DS = DATA SEG, ES = BUFFER
2627 CALL EXTENDED_ERROR_HANDLER
2628 CALL SWITCH_DS_ES ;AN000;ES = DATA SEG, DS = BUFFER
2629WAF_DISKFULL:
2630 MOV ERRORLEVEL, 4 ;set errorlevel
2631
2632; Set message parameters
2633; Target disk full, critical error
2634
2635 PUSH DS ;AN000;DS = BUFFER
2636 PUSH ES ;AN000;ES = DATA SEG
2637 POP DS ;AN000;ES => DS = DATA SEG
2638 MOV AX,MSG_DISK_FULL ;AN000; message number
2639 MOV MSG_NUM,AX ;AN000; set message number
2640 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
2641 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2642 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2643 CALL PRINT_STDERR ;AN000; display error message
2644 OR COPY_STATUS, DISK_FULL_FLAG ;set disk_full_flag
2645 POP DS ;AN000;RESTORE DS = BUFFER
2646 CALL CLOSE_DELETE_FILE
2647 STC ;set carry and return to caller
2648WAF_EXIT:
2649 RET
2650WRITE_A_FILE ENDP
2651;
2652SET_FILE_DATE_TIME PROC NEAR
2653;input: BX - target file handle
2654;
2655 MOV AH, File_date_time ; = 57h
2656 MOV AL, Set_file_time ; = 1
2657 MOV CX, DS:FILE_TIME_FOUND
2658 MOV DX, DS:FILE_DATE_FOUND
2659 INT 21h
2660 RET
2661SET_FILE_DATE_TIME ENDP
2662;
2663CLOSE_A_FILE PROC NEAR
2664;
2665;CLOSE A FILE AND UPDATE COUNT OF OPEN FILES
2666;
2667;INPUT: BX - file handle to be closed
2668;
2669 CMP OPEN_FILE_COUNT,NUL ;AN005;ARE THERE ANY OPEN FILES?
2670; $IF A ;AN005;
2671 JNA $$IF167
2672 DEC OPEN_FILE_COUNT ;AN005;IF SO, REDUCE THE COUNT BY 1.
2673; $ENDIF ;AN005;
2674$$IF167:
2675 MOV AH, Close ; = 3Eh
2676 INT 21H
2677 RET
2678CLOSE_A_FILE ENDP
2679;
2680DELETE_A_FILE PROC NEAR
2681;input: DS:DX - points to ASCIIZ string
2682
2683 MOV AH, 41h ; = 41h
2684 INT 21H
2685 RET
2686DELETE_A_FILE ENDP
2687;
2688MAKE_DIR PROC NEAR
2689;make a subdirectory in the current target directory.
2690;The directory name is in the header part Target_drv_Let
2691;with the drive letter.
2692;input:DS - buffer
2693; ES - data seg
2694
2695 MOV AH, Mkdir ; = 39h
2696 MOV DX, OFFSET DS:TARGET_DRV_LET ;target drv and filename
2697 INT 21h
2698 JC MD_ERROR
2699 JMP MD_EXIT
2700MD_ERROR:
2701;cannot distinguish between cases of: 1. already there exists a directory.
2702; 2. there has been a file exist with the same name in the target.
2703; 3. no disk space to make dir.
2704; Case 1, should ignore and just exit this routine
2705; Case 2, critical error.
2706; Case 3, critical error.
2707 call chk_disk_full ;check disk full condition first
2708 jc MD_EXIST ;AC026;yes, disk full, check if exist
2709 push es ;else check a file with the same name.
2710 push ds
2711 push dx
2712 mov ah, 2fH ;get current DTA addr in ES:BX
2713 int 21h
2714 mov ds, es:psp_seg
2715 mov dx, 80h
2716 mov ah, 1ah
2717 int 21h ;set dta to psp default dta area
2718 pop dx ;restore DX - target drv and filename
2719 pop ds ;restore DS - buffer
2720 mov cx, 6 ;HIDDEN + SYSTEM inclusive search
2721 mov ah, 4Eh ;FIND FIRST MATCHING FILE
2722 int 21h
2723 jc md_ok ;not found. There exists subdir. ignore
2724 stc ;else found a file with same name.
2725 jmp short MD_RESTORE
2726
2727MD_OK:
2728 clc ;else there exists dir., ignore error.
2729MD_RESTORE:
2730 pushf
2731 push ds ;save ds again - buffer
2732 push es ;es - save dta seg
2733 pop ds ;ds = saved DTA seg
2734 mov dx, bx ; saved DTA off
2735 mov ah, 1ah
2736 int 21h ;restore DTA
2737 pop ds ;restore ds
2738 popf
2739 pop es ;restore ES
2740 jnc md_exit ;if no error, then exit
2741 jmp md_err ;AN026;
2742
2743;else check a file with the same name.
2744
2745MD_EXIST:
2746 push es ;AN026;
2747 push ds ;AN026;
2748 push dx ;AN026;
2749 mov ah, 2fH ;AN026;get current DTA addr in ES:BX
2750 int 21h ;AN026;
2751 mov ds, es:psp_seg ;AN026;
2752 mov dx, 80h ;AN026;
2753 mov ah, 1ah ;AN026;
2754 int 21h ;AN026;set dta to psp default dta area
2755 pop dx ;AN026;restore DX - tar drv and filenm
2756 pop ds ;AN026;restore DS - buffer
2757 mov cx, 10h ;AN026;sub-directory search
2758 mov ah, 4Eh ;AN026;FIND FIRST MATCHING dir.
2759 int 21h ;AN026;
2760
2761 pushf ;AN026;save carry state
2762 push ds ;AN026;save ds again - buffer
2763 push es ;AN016;es - save dta seg
2764 pop ds ;AN026;ds = saved DTA seg
2765 mov dx, bx ;AN026; saved DTA off
2766 mov ah, 1ah ;AN026;
2767 int 21h ;AN026;restore DTA
2768 pop ds ;AN026;restore ds
2769 popf ;AN026;get carry state from find
2770 pop es ;AN026;restore ES
2771 jnc md_exit ;AN026;if no error, then dir. exits
2772
2773MD_ERR:
2774 call switch_ds_es ;switch ds, es
2775 mov errorlevel, 4 ;set the errorlevel to 4
2776 test copy_status, disk_full_flag ;disk full?
2777 jnz MD_FULL ;yes, full.
2778 mov ax,msg_unable_create ; else make dir fails because of
2779 ; the same file name
2780 or copy_status, mkdir_error_flag ;set make dir error flag
2781 jmp short MD_PRT
2782MD_FULL:
2783 mov ax,msg_disk_full
2784MD_PRT:
2785; Set message parameters
2786 PUSH ES ;AN017;ES = BUFFER
2787 PUSH DS ;AN017;DS = DATA SEG
2788 POP ES ;AN017;DS => ES = DATA SEG
2789 MOV MSG_NUM,AX ;AN000; set message number
2790 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
2791 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2792 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2793 CALL PRINT_STDERR ;AN000; display message
2794 POP ES ;AN017;RESTORE ES = BUFFER
2795
2796 call switch_ds_es ;restore ds, es
2797 stc ;error - set carry
2798MD_EXIT:
2799 RET
2800MAKE_DIR ENDP
2801;
2802CHK_DISK_FULL PROC NEAR
2803;check target disk space, and if no more clusters then set carry, disk_full_flag.
2804;this routine is called by MAKE_DIR routine.
2805;INPUT: DS - buffer
2806; ES - data seg
2807 PUSH AX
2808 PUSH BX
2809 PUSH CX
2810 PUSH DX
2811 MOV AH, 36h ;GET DISK FREE SPACE
2812 MOV DL, ES:T_DRV_NUMBER ;OF TARGET
2813 INT 21h
2814 CMP BX, 0 ;NO MORE CLUSTER?
2815 JE CDF_FULL
2816 CLC
2817 JMP SHORT CDF_EXIT
2818CDF_FULL:
2819 OR ES:COPY_STATUS, DISK_FULL_FLAG ;SET DISK FULL FLAG
2820 STC ;SET CARRY
2821CDF_EXIT:
2822 POP DX
2823 POP CX
2824 POP BX
2825 POP AX
2826 RET
2827
2828CHK_DISK_FULL ENDP
2829;
2830
2831CHK_FILE_NOT_FOUND PROC NEAR
2832;if FILE_CNT_LOW=FILE_CNT_HIGH=FOUND_FILE_FLAG=0 AND NO INIT ERROR,
2833; then show "File not found" msg
2834;INPUT: ES, DS = data seg
2835
2836 TEST PARM_FLAG, INIT_ERROR_FLAG
2837; $IF Z,AND ;no init error
2838 JNZ $$IF169
2839 CMP FILE_CNT_LOW, 0
2840; $IF E,AND
2841 JNE $$IF169
2842 CMP FILE_CNT_HIGH, 0
2843; $IF E,AND
2844 JNE $$IF169
2845 CMP FOUND_FILE_FLAG, 0
2846; $IF E
2847 JNE $$IF169
2848 MOV ES, PSP_SEG ;use PSP area for parsing
2849 MOV DI, PSPFCB1_DRV
2850 MOV SI, OFFSET S_FILE
2851 MOV AH, 29h
2852 MOV AL, 0 ;control byte
2853 INT 21h
2854 CALL SWITCH_DS_ES ;now, ds - psp seg, es - data seg
2855 MOV DI,OFFSET DISP_S_FILE
2856 MOV SI,PSPFCB1_DRV
2857 INC SI ;now SI points to the formatted filename area
2858 CALL COMPRESS_FILENAME ;[pspfcb1_drv+1] => disp_s_file
2859 PUSH ES
2860 POP DS ;now DS=ES=data seg
2861 LEA SI,SUBLIST1 ;AN000;
2862 MOV DI,OFFSET DISP_S_FILE ;AN000;
2863 MOV [SI].DATA_OFF,DI ;AN000; SI-->File name
2864 MOV [SI].DATA_SEG,DS ;AN000; DS-->Segment
2865 MOV [SI].MSG_ID,0 ;AN018; message ID
2866 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
2867 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
2868 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
2869 MOV AX,MSG_FILE_NOT_ERR ;AN018;
2870 MOV MSG_NUM,AX ;AN000; set message number
2871 MOV SUBST_COUNT,PARM_SUBST_ONE ;AN000; substitution count
2872 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
2873 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
2874 CALL PRINT_STDOUT ;AN000; display message
2875; $ENDIF
2876$$IF169:
2877
2878 RET
2879
2880CHK_FILE_NOT_FOUND ENDP
2881
2882;
2883subttl string_length
2884page
2885;******************************************************************************
2886;PURPOSE: Get the length of a string pointed by ES:DI until it encounters
2887; the same character given by the user in AL.
2888; The length will be an output in CX. The number includes the
2889; charater found.
2890; For example, if you want to determine the length of an ASCIIZ string,
2891; set ES:DI to that string and set AL to 0. The output CX is the
2892; total length of the ASCIIZ string including 0.
2893; So, if the first character pointed by DI is the same as that of AL,
2894; then the length will be 1.
2895; !!! It is the user's responsibility to make it sure that the string
2896; contains the character given in AL. If not, unpredictable
2897; results will occur.!!!
2898;
2899; DATA INPUT
2900; REGISTERS: AL - ASCII CHARACTER
2901; ES:DI - POINTER TO THE STRING.
2902; DATA OUTPUT
2903; REGISTERS: AX,DX,SI etc - PRESERVED.
2904; BX - DISTROYED
2905; CX - STRING LENGTH UNTIL FOUND THE GIVEN CHARACTER.
2906; DI - POINTS TO THE NEXT CHARACTER AFTER THE STRING.
2907; DIRECTION FLAG - CLEARED
2908; ZERO FLAG - RESET
2909;******************************************************************************
2910;
2911STRING_LENGTH PROC NEAR
2912PUBLIC STRING_LENGTH
2913 CLD ;CLEAR DIRECTION
2914 MOV BX,DI ;SAVE ORIGINAL DI VALUE
2915 MOV CX,80H ;TRY MAX 128 BYTES
2916 REPNE SCASB ;SCAN THE STRING UNTIL FOUND
2917 PUSH DI ;SAVE CURRENT DI VALUE WHICH POINTS TO NEXT CHR AFTER STRING
2918 SUB DI,BX ;GET THE LENGTH
2919 MOV CX,DI ;MOV THE LENGTH TO CX
2920 POP DI
2921 RET
2922STRING_LENGTH ENDP
2923;
2924subttl concat_asciiz
2925page
2926;******************************************************************************
2927;PURPOSE: Concatenate two ASCIIZ string into one ASCIIZ string.
2928; The ASCIIZ string pointed by DS:SI will be concatenated to
2929; the one pointed by ES:DI. The result string will be pointed by
2930; ES:DI.
2931; AL is used to put the delimeter character in between the strings.
2932; If you *DON'T* like to put the delimeter ***make AL to 0FFh***.
2933; For example, assume sting1 "ABCDE",0 pointed by DI and string2
2934; "FGHI",0 pointed by SI.
2935; If you want a delimeter "\" between two string, set AL to "\"
2936; before calling. The result will "ABCDE\FGHI",0 pointed by DI.
2937; If you set AL to "0FFh", then it becomes "ABCDEFGHI",0.
2938; This feature is useful for handling PATH if you set AL to "\"
2939; and, for any general string processes if you set AL to "0FFh".
2940; This routine will call subroutine STRING_LENGTH.
2941;DATA INPUT
2942; REGISTERS: AL - DELIMETER OR 0FFh
2943; ES:DI - POINTER TO THE DESTINATION STRING.
2944; DS:SI - POINTER TO THE SOURCE TO BE CONCATENATED.
2945;DATA OUTPUT
2946; REGISTERS: AL, DX - preserved
2947; DI - preserved. POINTER TO THE RESULT STRING
2948; SI - DISTROYED
2949; CX - RESULT ASCIIZ STRING LENGTH INCLUDE 0
2950; DIRECTION FLAG - CLEARED
2951;******************************************************************************
2952CONCAT_ASCIIZ PROC NEAR
2953
2954PUBLIC CONCAT_ASCIIZ
2955 PUSH DI ;SAVE POINTER VALUE WHICH WILL BE RETRUNED TO CALLER.
2956 PUSH AX ;SAVE VALUE IN AL.
2957 MOV AL, 0 ;DEALING WITH ASCIIZ STRING
2958 CALL STRING_LENGTH ;LET DI POINTS TO THE NEXT CHR AFTER THIS STRING
2959 ;DIRECTION WILL BE CLEARED.
2960 DEC DI ;MAKE DI POINT TO THE LAST CHARACTER 0
2961 POP AX ;RESTORE AL.
2962 CMP AL, 0FFh
2963; $IF NE ;IF THE USER WANTS TO PUT DIMIMETER,
2964 JE $$IF171
2965 STOSB ; REPLACE 0 WITH IT.
2966; $ELSE
2967 JMP SHORT $$EN171
2968$$IF171:
2969 DEC CX ;ELSE DECREASE LENGTH BY 1
2970; $ENDIF
2971$$EN171:
2972; $DO
2973$$DO174:
2974 LODSB ;MOV [SI] TO AL
2975 STOSB ;STORE AL TO [DI]
2976 INC CX ;INCREASE LENGTH
2977 CMP AL, 0 ;WAS IT A LAST CHARACTER?
2978; $ENDDO E ;THEN EXIT THIS LOOP
2979 JNE $$DO174
2980 POP DI
2981 RET
2982CONCAT_ASCIIZ ENDP
2983;
2984
2985subttl last_dir_out
2986page
2987;******************************************************************************
2988;PURPOSE: Take off the last directory name from the path pointed by DI.
2989; This routine assumes the pattern of a path to be an ASCIIZ string
2990; in the form of "[d:][\]dir1\dir2". Notice that this path does not
2991; have entailing "\". This routine will simply travel the string
2992; until it found last "\" which will, then, be replaced with 0.
2993; If no "\" found, then carry will be set.
2994; *** This should be not be used for the path in the form of
2995; *** "d:\", 0 for the root directory, since in this case the returned
2996; *** string will be "d:",0 and AX value returned be meaningless (Just
2997; *** points to 0.)
2998;DATA INPUT
2999; REGISTERS: DI - points to an ASCIIZ path string.
3000; ES - assumed default segment for DI
3001;DATA OUTPUT
3002; REGISTERS: DI - points to the resultant path string.
3003; AX - offset value of the last subdirectory name taken out, in case
3004; of the user's need.
3005; Other register will be unchanged.
3006; CARRY FLAG WILL SET IF NOT FOUND.
3007;******************************************************************************
3008
3009LAST_DIR_OUT PROC NEAR
3010PUBLIC LAST_DIR_OUT
3011
3012 PUSH DI
3013 PUSH SI ;save current DI, SI
3014 CLD ;clear direction
3015 MOV SI, 0FFFFh ;used as a not_found flag if unchanged.
3016; $DO
3017$$DO176:
3018; $DO ;AN010;
3019$$DO177:
3020 CLC ;AN010;INITIALIZE TO NOT DBCS
3021 MOV AL,BYTE PTR [DI] ;AN010;GET THE 1st CHAR TO TEST
3022 CALL CHK_DBCS ;AN010;SEE IF WE ARE IN DBCS
3023; $LEAVE NC ;AN010;THIS IS NOT DBCS
3024 JNC $$EN177
3025 INC DI ;AN010;GO TO THE NEXT CHAR TO CHECK
3026 INC DI ;AN010;DITO
3027; $ENDDO ;AN010;
3028 JMP SHORT $$DO177
3029$$EN177:
3030 MOV AL, 0
3031 SCASB
3032; $LEAVE Z ;if [DI] = 0, then end of string. Ends this loop.
3033 JZ $$EN176
3034 DEC DI ;if [DI] <> 0, then go back and scan char again
3035 MOV AL, "\" ;to see it was a back slash.
3036 SCASB
3037; $IF Z ;if it was, then save the addr to SI.
3038 JNZ $$IF181
3039 PUSH DI
3040 POP SI
3041
3042 DEC SI
3043; $ENDIF ;else do loop again.
3044$$IF181:
3045; $ENDDO
3046 JMP SHORT $$DO176
3047$$EN176:
3048 CLC ;clear carry flag.
3049 CMP SI, 0FFFFh ;Had SI been changed?
3050; $IF E
3051 JNE $$IF184
3052 STC ;No, set the carry. Not found.
3053; $ELSE
3054 JMP SHORT $$EN184
3055$$IF184:
3056 MOV BYTE PTR ES:[SI], 0 ;Yes, replace "\" with 0. Seg override to get default DI seg.
3057 MOV AX, SI
3058 INC AX ;let AX have the last dir offset value.
3059 CLC ;clear carry
3060; $ENDIF
3061$$EN184:
3062 POP SI ;restore original value
3063 POP DI ;original string offset
3064 RET
3065LAST_DIR_OUT ENDP
3066;
3067; HEADER <CHK_DBCS -SEE IF SPECIFIED BYTE IS A DBCS LEAD BYTE>
3068;*****************************************************************************
3069; Check DBCS environment
3070;*****************************************************************************
3071
3072; Function: Check if a specified byte is in ranges of the DBCS lead bytes
3073; Input: AL = Code to be examined
3074; Output: If CF is on then a lead byte of DBCS
3075; Register: FL is used for the output, others are unchanged.
3076
3077 PUBLIC CHK_DBCS
3078Chk_DBCS PROC ;AN010;
3079 PUSH DS ;AN010; save these regs, about to be clobbered
3080 PUSH SI ;AN010;
3081 CMP DBCSEV_SEG,0 ;AN010; ALREADY SET ?
3082; $IF E ;AN010; if the vector not yet found
3083 JNE $$IF187
3084 PUSH AX ;AN010;
3085 MOV AX,6300H ;AN010; GET DBCS EV CALL
3086 INT 21H ;AN010; ds:si points to the dbcs vector
3087
3088 ASSUME DS:NOTHING ;AN010; that function clobbered old DS
3089
3090 MOV DBCSEV_OFF,SI ;AN010; remember where the dbcs vector is
3091 MOV DBCSEV_SEG,DS ;AN010; so next time I don't have to look for it
3092 POP AX ;AN010;
3093; $ENDIF ;AN010;
3094$$IF187:
3095 LDS SI,DWORD PTR DBCSEV_OFF ;AN010;SET DS:SI TO POINT TO THE DBCS VECTOR
3096; $SEARCH ;AN010;
3097$$DO189:
3098 CMP WORD PTR [SI],0 ;AN010; vector ends with a nul terminator entry
3099; $LEAVE E ;AN010; if that was the terminator entry, quit
3100 JE $$EN189
3101 CMP AL,[SI] ;AN010; look at LOW value of vector
3102; $EXITIF NB,AND ;AN010; if this byte is in range with respect to LOW
3103 JB $$IF189
3104 CMP AL,[SI+1] ;AN010; look at HIGH value of vector
3105; $EXITIF NA ;AN010; if this byte is still in range
3106 JA $$IF189
3107 STC ;AN010; set flag to say, found a DBCS char.
3108; $ORELSE ;AN010; since char not in this vector
3109 JMP SHORT $$SR189
3110$$IF189:
3111 ADD SI,2 ;AN010; go look at next vector in dbcs table
3112; $ENDLOOP ;AN010; go back and check out new vector entry
3113 JMP SHORT $$DO189
3114$$EN189:
3115 CLC ;AN010; set flag to say, this is not a DBCS character
3116; $ENDSRCH ;AN010;
3117$$SR189:
3118 POP SI ;AN010; restore the regs
3119 POP DS ;AN010;
3120
3121; ASSUME DS:DSEG ;AN010; tell masm, DS back to normal
3122
3123 RET ;AN010;
3124chk_DBCS ENDP ;AN010;
3125;
3126;
3127
3128subttl Compress_Filename
3129page
3130
3131;
3132;******************************************************************************
3133;
3134; PURPOSE:
3135; --------
3136; Compress the FCB style filename into an ASCIIZ packed name.
3137; For example, 'ABC?????EXE' = > 'ABC?????.EXE',0
3138; or 'ABC EXE' = > 'ABC.EXE',0
3139; Note that the length of the source is *** 11 *** byte long.
3140; The max length of result is *** 13 *** bytes long.
3141; In the usual practice, the source filename with extention can be obtained
3142; by using function call 29h (Parse a Filename). So this routine is
3143; an inverse function of fun. 29h except DI should be the *** starting point
3144; of destination string *** instead of that of an unopened FCB (When you use
3145; fun 29h together with this routine, keep this thing in mind. Also if ES, DS
3146; values are different in your program, be careful to use them correctly.)
3147;------------------------------------------------------------------------------
3148; REGISTERS INPUT
3149; ----------------
3150; AX:
3151; BX:
3152; CX:
3153; DX:
3154; SI: offset of source unpacked filename with extention
3155; DI: offset where the resultant asciiz filename(.ext) will be placed.
3156; SP:
3157; BP:
3158; DS: source seg
3159; ES: result seg
3160; SS:
3161;
3162; DATA INPUT
3163; -----------
3164; Memory_Label -
3165;
3166;-----------------------------------------------------------------------------
3167; REGISTERS OUTPUT
3168; ----------------
3169; AX:
3170; BX:
3171; CX:
3172; DX:
3173; SI:
3174; DI:
3175; SP:
3176; BP:
3177; DS:
3178; ES:
3179; SS:
3180;
3181; DATA OUTPUT
3182; -----------
3183;
3184; FLAG OUTPUT
3185; -----------
3186;******************************************************************************
3187
3188COMPRESS_FILENAME PROC NEAR
3189PUBLIC COMPRESS_FILENAME
3190 PUSH DI
3191 XOR CX, CX ;CX = 0
3192; $DO
3193$$DO195:
3194 LODSB ;[SI] => AL, SI = SI + 1
3195 CMP CX, 10 ;CX > 10 then exit
3196; $LEAVE A
3197 JA $$EN195
3198 CMP CX, 8 ;filename extention position
3199; $IF B ;CX < 8. handling filename
3200 JNB $$IF197
3201 CMP AL, ' ' ;AL = blank ?
3202; $IF E
3203 JNE $$IF198
3204 MOV AX, 7
3205 SUB AX, CX
3206 ADD SI, AX ;SI = SI + (7 - CX)
3207 MOV CX, 8 ;then skip to handles extention
3208; $ELSE
3209 JMP SHORT $$EN198
3210$$IF198:
3211 STOSB ;AL => [DI], DI = DI + 1
3212 INC CX ;CX = CX + 1
3213; $ENDIF
3214$$EN198:
3215; $ELSE ;extention part
3216 JMP SHORT $$EN197
3217$$IF197:
3218 CMP AL, ' '
3219; $IF E
3220 JNE $$IF202
3221 MOV CX, 11 ;exit this loop
3222; $ELSE
3223 JMP SHORT $$EN202
3224$$IF202:
3225 CMP CX, 8 ;the first chr of extention?
3226; $IF E ;yes
3227 JNE $$IF204
3228 PUSH AX ;save cur chr
3229 MOV AL, '.' ;and put a dot
3230 STOSB ; . => [DI], DI = DI + 1
3231 POP AX ;restore AX
3232; $ENDIF
3233$$IF204:
3234 STOSB ;AL => [DI], DI = DI + 1
3235 INC CX ;CX = CX + 1
3236; $ENDIF
3237$$EN202:
3238; $ENDIF
3239$$EN197:
3240; $ENDDO
3241 JMP SHORT $$DO195
3242$$EN195:
3243 MOV AL, 0
3244 STOSB ;put 0 at the current [DI]
3245
3246 POP DI ;restore DI
3247 RET
3248COMPRESS_FILENAME ENDP
3249;
3250
3251
3252SET_DEFAULT_DRV PROC NEAR
3253;change source drv as a default drv for conveniece of find, read operation
3254;of source. (handling target should be more specific as for as drive letter
3255;goes.)
3256;input: DL - drive # (0 = A, 1 = B ...)
3257
3258 MOV AH, Select_Disk ; = 0Eh
3259 INT 21H
3260 OR SYS_FLAG, DEFAULT_DRV_SET_FLAG ;indicates default drv has been changed
3261 ;Used for exit the program to restore default drv
3262 RET
3263SET_DEFAULT_DRV ENDP
3264;
3265
3266
3267ORG_S_DEF PROC NEAR
3268;restore the original source directory.
3269 PUSH ES
3270 PUSH DS
3271
3272 PUSH DS
3273 POP ES ;DS=ES=data seg
3274
3275 TEST SYS_FLAG, DEFAULT_S_DIR_FLAG ;source default direcotry saved?
3276; $IF NZ
3277 JZ $$IF209
3278 MOV DX, OFFSET SAV_S_DRV ;saved source drive letter & directory
3279 MOV AH, 3Bh
3280 INT 21h ;restore source
3281 AND SYS_FLAG, RESET_DEFAULT_S_DIR ;reset the flag
3282; $ENDIF
3283$$IF209:
3284
3285 POP DS
3286 POP ES
3287
3288 RET
3289ORG_S_DEF ENDP
3290;
3291ORG_S_T_DEF PROC NEAR
3292;retore original target, source and default drv and directory
3293;check default_s(t)_dir_flag, default_drv_set_flag to restore source,
3294;or target directory and default drive.
3295
3296 TEST SYS_FLAG, TURN_VERIFY_OFF_FLAG ;turn off verify?
3297; $IF NZ ;yes
3298 JZ $$IF211
3299 MOV AX, 2E00h ;turn it off
3300 INT 21H
3301; $ENDIF
3302$$IF211:
3303 TEST SYS_FLAG, DEFAULT_DRV_SET_FLAG ;default drive has been changed?
3304; $IF NZ ;yes
3305 JZ $$IF213
3306 MOV DL, SAV_DEFAULT_DRV
3307 DEC DL
3308 CALL SET_DEFAULT_DRV ;restore default drv.
3309
3310; Following is a fix for PTR 0000012 . The fix is to skip changing default
3311; drive directory if source drive is not the default drive.
3312
3313 MOV AL, S_DRV_NUMBER ;AN002; get source drive number
3314 CMP AL, SAV_DEFAULT_DRV ;AN002; src drive is the default drv ?
3315; $IF NE ;AC022;NO, SO SEE IF DEF. DRV. IS CHGD.
3316 JE $$IF214
3317 TEST SYS_FLAG, DEFAULT_DRV_SET_FLAG ;AN022;DEF DRV CHGD?
3318; $IF NZ ;AN022;YES, RESET IT
3319 JZ $$IF215
3320 MOV DX, OFFSET SAV_DEF_DIR_ROOT ;AN022;GET THE SETTING
3321 MOV AH, Chdir ;AN022;MAKE THE CALL
3322 INT 21H ;AN022;
3323; $ENDIF ;AN022;
3324$$IF215:
3325; $ELSE ;AN022;SRC IS DEF DRIVE!
3326 JMP SHORT $$EN214
3327$$IF214:
3328 MOV DX, OFFSET SAV_DEF_DIR_ROOT
3329 MOV AH, Chdir
3330 INT 21H ;restore current dir of default dir
3331; $ENDIF ;AN022;
3332$$EN214:
3333; $ENDIF
3334$$IF213:
3335
3336
3337 TEST SYS_FLAG, DEFAULT_S_DIR_FLAG ;source default direcotry saved?
3338; $IF NZ
3339 JZ $$IF220
3340 MOV DX, OFFSET SAV_S_DRV ;saved source drive letter & directory
3341 MOV AH, 3Bh
3342 INT 21h ;restore source. This is for the case of ERROR exit.
3343; $ENDIF
3344$$IF220:
3345
3346 TEST SYS_FLAG, DEFAULT_T_DIR_FLAG ;target default directory saved?
3347; $IF NZ ;then assume both source, target default saved
3348 JZ $$IF222
3349 MOV DX, OFFSET SAV_T_DRV ;saved target drive letter & directory
3350 MOV AH, 3Bh
3351 INT 21h ;restore target
3352; $ENDIF
3353$$IF222:
3354
3355 RET
3356ORG_S_T_DEF ENDP
3357;
3358
3359CHK_MKDIR_LVL PROC NEAR
3360;if starting target directories has been created, and no files has been found to copy,
3361;and /E option is not specified, then remove the directories created.
3362;
3363 CMP T_MKDIR_LVL, 0 ;target starting directory created?
3364; $IF A,AND ;yes.
3365 JNA $$IF224
3366 TEST OPTION_FLAG, SLASH_E ;/E option taken?
3367; $IF Z,AND ;no.
3368 JNZ $$IF224
3369 CMP FOUND_FILE_FLAG, 0 ;found any file?
3370; $IF E
3371 JNE $$IF224
3372 CALL T_RM_STARTING_DIR ;then, remove created directories.
3373; $ENDIF
3374$$IF224:
3375 RET
3376CHK_MKDIR_LVL ENDP
3377;
3378
3379T_RM_STARTING_DIR PROC NEAR
3380;based on the current target directory, remove directories T_MKDIR_LVL times
3381;INPUT: T_MKDIR_LVL
3382; T_DRV_NUMBER
3383; T_DRV_PATH
3384; T_PATH
3385
3386
3387 MOV DL, T_DRV_NUMBER
3388 LEA SI, T_PATH
3389 MOV AH, Get_Current_Directory
3390 INT 21h
3391
3392TRSD_AGAIN:
3393 MOV DX, OFFSET T_PARENT ;chdir to the parent directory
3394 MOV AH, 3Bh ;Chdir
3395 INT 21h
3396 MOV DX, OFFSET T_DRV_PATH
3397 MOV AH, 3Ah ;Rmdir
3398 INT 21h
3399 MOV DI, OFFSET T_DRV_PATH
3400 CALL LAST_DIR_OUT ;take out the last removed dir name
3401 DEC T_MKDIR_LVL ;decrease the number
3402 CMP T_MKDIR_LVL, 0 ;no more?
3403 JA TRSD_AGAIN
3404
3405 RET
3406T_RM_STARTING_DIR ENDP
3407;
3408
3409
3410;************************************************************
3411;*
3412;* SUBROUTINE NAME: PRINT_STDOUT
3413;*
3414;* SUBROUTINE FUNCTION:
3415;* Display the requested message to the specified handle
3416;*
3417;* INPUT:
3418;* Paramters in parater storage area
3419;* DS:SI-->Substitution List
3420;* ES:DI-->PTR to input buffer if buffered keyboard
3421;* input is specified (DL = 0A)
3422;* OUTPUT:
3423;* AX = Single character entered if DL=01
3424;* OR
3425;* ES:DI-->input buffer where string is returned if DL=0A
3426;*
3427;* The message corresponding to the requested msg number will
3428;* be written to Standard Out. Message substitution will
3429;* be performed if specified
3430;*
3431;* NORMAL EXIT:
3432;* Message will be successfully written to requested handle.
3433;*
3434;* ERROR EXIT:
3435;* None. Note that theoretically an error can be returned from
3436;* SYSDISPMSG, but there is nothing that the application can do.
3437;*
3438;* INTERNAL REFERENCES: SysDispMsg
3439;*
3440;* EXTERNAL REFERENCES:
3441;* None
3442;*
3443;************************************************************
3444PRINT_STDOUT PROC NEAR ;AN000:
3445
3446 PUSH BX ;AN000;
3447 PUSH CX ;AN000;
3448 PUSH DX
3449
3450 MOV AX,MSG_NUM ;AN000; Message ID
3451 MOV BX,STDOUT ;AN000; standard input message handle
3452 MOV CX,SUBST_COUNT ;AN000; message substitution count
3453 MOV DH,MSG_CLASS ;AN000; message class
3454 MOV DL,INPUT_FLAG ;AN000; Type of INT 10 for KBD input
3455
3456 CALL SYSDISPMSG ;AN000: AX=Extended key value if wait
3457 ;for key
3458 JNC DISP_DONE ;AN000: If CARRY SET then registers
3459 ;will contain extended error info
3460 ; AX - Extended error Number
3461 ; BH - Error Class
3462 ; BL - Suggested action
3463DISP_DONE: ;AN000: CH - Locus
3464 POP DX
3465 POP CX ;AN000;
3466 POP BX ;AN000;
3467
3468 RET ;AN000:
3469PRINT_STDOUT ENDP ;AN000:
3470
3471
3472
3473
3474;************************************************************
3475;*
3476;* SUBROUTINE NAME: PRINT_STDERR
3477;*
3478;* FUNCTION: Display the requested message to Standard Out
3479;*
3480;* INPUT:
3481;* Parameters in parameter storage area
3482;* DS:SI-->Substitution List
3483;* ES:DI-->PTR to input buffer if buffered keyboard
3484;* input is specified (DL = 0A)
3485;*
3486;* OUTPUT:
3487;* AX = Single character entered if DL=01
3488;* OR
3489;* ES:DI-->input buffer where string is returned if DL=0A
3490;* The message corresponding to the requested msg number will
3491;* be written to the Standard Error. Message substitution will
3492;* be performed if specified
3493;*
3494;* NORMAL EXIT:
3495;* Message will be successfully written to requested handle.
3496;*
3497;* ERROR EXIT:
3498;* None. Note that theoretically an error can be returned from
3499;* SYSDISPMSG, but there is nothing that the application can do.
3500;*
3501;* INTERNAL REFERENCES: SysDispMsg
3502;*
3503;* EXTERNAL REFERENCES: None
3504;*
3505;************************************************************
3506PRINT_STDERR PROC NEAR ;AN000:
3507
3508 PUSH AX ;AN000;
3509 PUSH BX ;AN000;
3510 PUSH CX ;AN000;
3511 PUSH DX
3512
3513 MOV AX,MSG_NUM ;AN000; Message ID
3514 MOV BX,STDERR ;AN000; Handle
3515 MOV CX,SUBST_COUNT ;AN000; message substitution count
3516 MOV DH,MSG_CLASS ;AN000; message class
3517 MOV DL,INPUT_FLAG ;AN000; INT 10 KBD input type
3518
3519 CALL SYSDISPMSG ;AN000: AX=Extended key value if wait
3520 ;for key
3521 JNC DISP_EXIT ;AN000: If CARRY SET then registers
3522 ;will contain extended error info
3523 ; AX - Extended error Number
3524 ; BH - Error Class
3525 ; BL - Suggested action
3526DISP_EXIT: ;AN000: CH - Locus
3527 POP DX
3528 POP CX ;AN000;
3529 POP BX ;AN000;
3530 POP AX ;AN000;
3531 RET ;AN000:
3532
3533PRINT_STDERR ENDP ;AN000:
3534
3535
3536
3537
3538
3539;
3540EXTENDED_ERROR_HANDLER PROC NEAR
3541;This routine calls fun 59(Get extended error) and
3542;check the actions returned. If it is Immediate exit, then jmp to JUST_EXIT
3543;If it is abort, then jmp to MAIN_EXIT.
3544;Or else, it check the COPY_STATUS flag. If is not open, read, create or
3545;write, then it is considered as a critical error and jmp to MAIN_EXIT.
3546;If access denied
3547; too many open files
3548; sharing violation
3549; lock violation
3550; general failure
3551;then show the message and jmp to the MAIN_EXIT.
3552; *** Currently, this routine directly jump to the main_exit instead of
3553; *** returing to the caller. The reason is we regard the above error conditions
3554; *** as being not suitable to continue copying and, hence, to simplify
3555; *** the error process.
3556;INPUT:
3557; DS - DATA SEG
3558;OUTPUT:
3559; ALL THE REG PRESERVED
3560
3561 PUSH ES ;save ES
3562 PUSH AX
3563 PUSH BX
3564 PUSH CX
3565 PUSH DS ;AN000;
3566 POP ES ;AN000;DS = ES = DATA SEG
3567 PUSHF ;save flags
3568
3569 PUSH ES
3570 MOV AH, 59h ;get extended error
3571 MOV BX, 0 ;version 3.0
3572 INT 21h
3573 POP ES
3574
3575 MOV ERRORLEVEL, 4 ;error in operation
3576 TEST COPY_STATUS, OPEN_ERROR_FLAG ;open error?
3577 JNZ OPEN_ERROR_RTN ;yes
3578 TEST COPY_STATUS, READ_ERROR_FLAG ;read error?
3579 JNZ READ_ERROR_RTN
3580 TEST COPY_STATUS, CREATE_ERROR_FLAG ;create error?
3581 JNZ CREATE_ERROR_RTN
3582 TEST COPY_STATUS, WRITE_ERROR_FLAG ;write error?
3583 JNZ WRITE_ERROR_RTN
3584 TEST COPY_STATUS, CHDIR_ERROR_FLAG ;chdir error?
3585 JNZ CHDIR_ERROR_RTN
3586 JMP SHORT GOTO_MAIN_EXIT
3587
3588OPEN_ERROR_RTN: ;open error. show error message and exit
3589 CALL SHOW_S_PATH_FILE_ERR ;show the troubled path filename
3590 CALL SHOW_ERROR_MESSAGE
3591 JMP SHORT GOTO_MAIN_EXIT ;abort
3592
3593READ_ERROR_RTN:
3594 CALL SHOW_S_PATH_FILE_ERR
3595 CALL SHOW_ERROR_MESSAGE ;show message and abort
3596 JMP SHORT GOTO_MAIN_EXIT
3597
3598CREATE_ERROR_RTN:
3599 CMP AX, 2 ;"file not found" to create?
3600 JNE CER_1
3601; Set message parameters
3602 MOV AX,MSG_FILE_CREATE_ERR ;AN000; message number
3603 MOV MSG_NUM,AX ;AN000; set message number
3604 MOV SUBST_COUNT,NO_SUBST ;AN000; no message substitution
3605 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
3606 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
3607 CALL PRINT_STDERR ;show "File creation error" message
3608 ;instead of "File not found"
3609 JMP SHORT GOTO_MAIN_EXIT
3610CER_1:
3611 CALL SHOW_ERROR_MESSAGE ;show error_message
3612 JMP SHORT GOTO_MAIN_EXIT
3613WRITE_ERROR_RTN:
3614 CALL SHOW_ERROR_MESSAGE ;show message
3615 JMP SHORT GOTO_MAIN_EXIT
3616CHDIR_ERROR_RTN:
3617
3618 PUSH AX ;AN000;
3619; Set substitution list
3620 LEA SI,SUBLIST1 ;AN000; get addressability to sublist
3621 LEA DX,S_DRV_PATH ;AN000; offset to PATH NAME
3622 MOV [SI].DATA_OFF,DX ;AN000; save offset
3623 MOV [SI].DATA_SEG,DS ;AN000; save data segment
3624 MOV [SI].MSG_ID,1 ;AN000; message ID
3625 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
3626 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
3627 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
3628
3629; Set message parameters
3630 MOV AX,DISPLAY_S_PATH ;AN000; message number
3631 MOV MSG_NUM,AX ;AN000; set message number
3632 MOV SUBST_COUNT,PARM_SUBST_ONE ;AN000; one message substitution
3633 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
3634 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
3635 CALL PRINT_STDERR ;show source drv,path
3636 POP AX ;AN000;
3637 CALL SHOW_ERROR_MESSAGE ;display error message
3638
3639GOTO_MAIN_EXIT:
3640 JMP MAIN_EXIT ;restore conditions
3641 ;and exit
3642QUICK_EXIT:
3643 JMP JUST_EXIT ;immediate exit
3644
3645EEH_EXIT:
3646 MOV ERRORLEVEL, 0 ;reset errorlevel
3647 POPF
3648 POP CX
3649 POP BX
3650 POP AX
3651 POP ES
3652 RET
3653
3654EXTENDED_ERROR_HANDLER ENDP
3655;
3656
3657
3658SHOW_ERROR_MESSAGE PROC NEAR
3659;called immediately after Get_extended error
3660;This will show simple error message according to error_code in AX
3661;If the message is not what it wanted, just exit without message- Set carry.
3662;input: DS - data seg
3663;output: Carry flag is distroyed.
3664
3665 clc ;clear carry
3666 CMP AX, 5 ;access denied?
3667 JE ACCESS_DENIED_MESSAGE
3668 CMP AX, 4 ;too many open files?
3669 JE TOO_MANY_OPEN_MESSAGE
3670 CMP AX, 31 ;general failure?
3671 JE GENERAL_FAIL_MESSAGE
3672 CMP AX, 32 ;sharing violation?
3673 JE SHARING_VIOL_MESSAGE
3674 CMP AX, 33 ;lock violation?
3675 JE LOCK_VIOL_MESSAGE
3676 CMP AX, 3 ;path not found?
3677 JE PATH_NOT_MESSAGE
3678 CMP AX, 2 ;file not found error?
3679 JE FILE_NOT_ERR_MESSAGE
3680 CMP AX, 65 ;access denied on the network?
3681 JE ACCESS_DENIED_MESSAGE
3682 CMP AX, 82 ;no more directory entry to create a file?
3683 JE FILE_CREATE_ERR_MESSAGE
3684
3685 STC ;else set carry
3686
3687
3688 JMP GOTO_MAIN_EXIT ;and exit
3689
3690ACCESS_DENIED_MESSAGE:
3691 MOV AX, MSG_ACCESS_DENIED ;AN000;
3692 JMP SHORT SHOW_MESSAGE
3693TOO_MANY_OPEN_MESSAGE:
3694 MOV AX, MSG_TOO_MANY_OPEN ;AN000;
3695 JMP SHORT SHOW_MESSAGE
3696GENERAL_FAIL_MESSAGE:
3697 MOV AX, MSG_GENERAL_FAIL ;AN000;
3698 JMP SHORT SHOW_MESSAGE
3699SHARING_VIOL_MESSAGE:
3700 MOV AX, MSG_SHARING_VIOL ;AN000;
3701 JMP SHORT SHOW_MESSAGE
3702LOCK_VIOL_MESSAGE:
3703 MOV AX, MSG_LOCK_VIOL ;AN000;
3704 JMP SHORT SHOW_MESSAGE
3705PATH_NOT_MESSAGE:
3706 MOV AX, MSG_PATH_NOT ;AN000;
3707
3708 JMP SHORT SHOW_MESSAGE
3709FILE_NOT_ERR_MESSAGE:
3710 MOV AX, MSG_FILE_NOT_ERR ;AN000;
3711 JMP SHORT SHOW_MESSAGE
3712FILE_CREATE_ERR_MESSAGE:
3713 MOV AX, MSG_FILE_CREATE_ERR ;AN000;
3714
3715
3716SHOW_MESSAGE: ; Display error message
3717; Set message parameters
3718 MOV MSG_NUM,AX ;AN000; set message number
3719 MOV SUBST_COUNT,NO_SUBST ;AN000; NO message substitution
3720 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
3721 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
3722 CALL PRINT_STDERR ;AN000; print it
3723 RET
3724
3725SHOW_ERROR_MESSAGE ENDP
3726;
3727
3728
3729SHOW_S_PATH_FILE_ERR PROC NEAR
3730;show current source path(drv, full path), and filename to the
3731;standard error display device.
3732;input: ds: data seg
3733 PUSH ES ;save ES
3734 PUSH AX ;save ERROR_CODE
3735 push ds
3736 pop es ;es = ds
3737 MOV DI,OFFSET S_DRV_PATH
3738 CALL STRING_LENGTH ;cx got the length
3739 MOV SI,OFFSET S_DRV_PATH ;full path of source
3740 MOV DI,OFFSET DISP_S_PATH
3741 REP MOVSB ;S_DRV_PATH => DISP_S_PATH
3742 MOV CX, 13 ;max 13 chr
3743 MOV SI,OFFSET FILE_DTA.DTA_FILENAME
3744 MOV DI,OFFSET DISP_S_FILE
3745 REP MOVSB ;dta_filename => disp_s_file
3746
3747 LEA SI,SUBLIST1 ;AN000; get addressability to list
3748 LEA DX,DISP_S_PATH ;AN000; offset to path name
3749 MOV [SI].DATA_OFF,DX ;AN000; save offset
3750 MOV [SI].DATA_SEG,DS ;AN000; save data segment
3751 MOV [SI].MSG_ID,1 ;AN000; message ID
3752 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
3753 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
3754 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
3755
3756 LEA SI,SUBLIST2 ;AN000; get addressability to list
3757 LEA DX,DISP_S_FILE ;AN000; offset to file name
3758 MOV [SI].DATA_OFF,DX ;AN000; save offset
3759 MOV [SI].DATA_SEG,DS ;AN000; save data segment
3760 MOV [SI].MSG_ID,2 ;AN000; message ID
3761 MOV [SI].FLAGS,010H ;AN000; ASCIIZ string, left align
3762 MOV [SI].MAX_WIDTH,0 ;AN000; MAXIMUM FIELD WITH
3763 MOV [SI].MIN_WIDTH,0 ;AN000; MINIMUM FIELD WITH
3764
3765
3766 CMP S_DEPTH,0 ;AN000;it happened, when dealing with the starting dir?
3767; $IF E
3768 JNE $$IF226
3769 LEA SI,SUBLIST2 ;AN007;PIONT TO THE FIRST LIST
3770 MOV [SI].MSG_ID,1 ;AN007; message ID
3771 MOV AX,DISPLAY_S_PATH ;AC007;ITS ONLY A FILE NAME
3772 MOV SUBST_COUNT,PARM_SUBST_ONE ;AN007; ONE message sub
3773; $ELSE
3774 JMP SHORT $$EN226
3775$$IF226:
3776 LEA SI,SUBLIST1 ;AN007;PIONT TO THE FIRST LIST
3777 MOV AX,S_PATH_FILE1 ;AN000;put '\'
3778 MOV SUBST_COUNT,PARM_SUBST_TWO ;AN007;TWO message subs
3779; $ENDIF
3780$$EN226:
3781
3782; Set message parameters
3783
3784 MOV MSG_NUM,AX ;AN000; set message number
3785 MOV MSG_CLASS,UTILITY_MSG_CLASS ;AN000; message class
3786 MOV INPUT_FLAG,NO_INPUT ;AN000; no input
3787 CALL PRINT_STDERR ;display error message
3788
3789 POP AX ;restore ERROR_CODE
3790 POP ES
3791 RET
3792
3793SHOW_S_PATH_FILE_ERR ENDP
3794;
3795
3796
3797CLOSE_DELETE_FILE PROC NEAR
3798;when writing error occurs, then this routine is called to
3799;clean up the troubled target file.
3800;INPUT: DS - buffer seg
3801; ES - data seg
3802
3803 MOV BX, ES:T_HANDLE ;close target file
3804 PUSH DS ;AN005;SAVE THE BUFFER PTR
3805 PUSH ES ;AN005;WE NEED THE DATA PTR
3806 POP DS ;AN005;DS = THE DATA PTR
3807 CALL CLOSE_A_FILE ;and close the handle
3808 POP DS ;AN005;DS = THE BUFFER PTR AGAIN
3809 LEA DX, DS:target_drv_let ;target drv, filename
3810 CALL DELETE_A_FILE ;delete it
3811 RET
3812CLOSE_DELETE_FILE ENDP
3813;
3814;
3815
3816SWITCH_DS_ES PROC NEAR
3817; switch DS, ES
3818 PUSH DS
3819 PUSH ES
3820 POP DS
3821 POP ES
3822 RET
3823SWITCH_DS_ES ENDP
3824
3825
3826
3827MY_INT24:
3828 CMP CS:INT24_ABORT_CNT, 0 ;if aborted more than once, then just exit.
3829 JNE MI_JUST_EXIT
3830 PUSHF ;we are calling interrupt handler
3831 CALL DWORD PTR CS:SAV_INT24 ;call original int 24 handler
3832 CMP AL, 1 ;retry?
3833 JE MI_RETRY
3834 CMP AL, 0 ;ignore? Cannot ignore. Try again
3835 JE MI_RETRY
3836 POP CX ;remove IP, CS, FLAGS
3837 POP CX ;since we are not going back
3838 POP CX ;to the place int 24 was called.
3839 CMP AL, 2 ;abort?
3840 JE MI_ABORT
3841 CMP AL, 3 ;AN000;fail?
3842 JE MI_ABORT
3843 JMP MAIN_EXIT ;show files copied message
3844 ;restore default value and exit
3845MI_ABORT:
3846 INC CS:INT24_ABORT_CNT ;increase the count of int24_abort
3847 JMP MAIN_EXIT_A ;restore default value and exit
3848MI_JUST_EXIT:
3849 POP CX
3850 POP CX
3851 POP CX
3852 JMP JUST_EXIT
3853MI_RETRY:
3854 IRET ;return where it happened
3855 ;and retry that operation.
3856;
3857INT24_ABORT_CNT DB 0
3858;
3859include msgdcl.inc
3860
3861CSEG ENDS
3862DSEG_INIT SEGMENT PARA PUBLIC ;AN000;
3863DSEG_INIT ENDS ;AN000;
3864 END MAIN
3865
3866 \ No newline at end of file