summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/COMMAND/TENV2.ASM
diff options
context:
space:
mode:
authorGravatar Mark Zbikowski2024-04-25 21:24:10 +0100
committerGravatar Microsoft Open Source2024-04-25 22:32:27 +0000
commit2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch)
tree80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/CMD/COMMAND/TENV2.ASM
parentMerge pull request #430 from jpbaltazar/typoptbr (diff)
downloadms-dos-main.tar.gz
ms-dos-main.tar.xz
ms-dos-main.zip
MZ is back!HEADmain
Diffstat (limited to 'v4.0/src/CMD/COMMAND/TENV2.ASM')
-rw-r--r--v4.0/src/CMD/COMMAND/TENV2.ASM663
1 files changed, 663 insertions, 0 deletions
diff --git a/v4.0/src/CMD/COMMAND/TENV2.ASM b/v4.0/src/CMD/COMMAND/TENV2.ASM
new file mode 100644
index 0000000..0c47958
--- /dev/null
+++ b/v4.0/src/CMD/COMMAND/TENV2.ASM
@@ -0,0 +1,663 @@
1 page 80,132
2; SCCSID = @(#)tenv2.asm 1.1 85/05/14
3; SCCSID = @(#)tenv2.asm 1.1 85/05/14
4TITLE Part6 COMMAND Transient routines.
5
6; Environment utilities and misc. routines
7
8 INCLUDE comsw.asm
9
10.xlist
11.xcref
12 INCLUDE DOSSYM.INC
13 INCLUDE comseg.asm
14 INCLUDE comequ.asm
15.list
16.cref
17
18
19DATARES SEGMENT PUBLIC BYTE ;AC000;
20 EXTRN pipeflag:byte
21DATARES ENDS
22
23TRANDATA SEGMENT PUBLIC BYTE ;AC000;
24 EXTRN ACRLF_PTR:WORD
25 EXTRN BadCD_Ptr:WORD
26 EXTRN Badmkd_ptr:word
27 EXTRN BADRMD_PTR:WORD
28 EXTRN Extend_buf_ptr:word ;AN000;
29 EXTRN Extend_buf_sub:byte ;AN022;
30 EXTRN MD_exists_ptr:word ;AN006;
31 EXTRN msg_disp_class:byte ;AC000;
32 EXTRN NOSPACE_PTR:WORD
33 EXTRN parse_chdir:byte ;AC000;
34 EXTRN parse_mrdir:byte ;AC000;
35 EXTRN PIPEEMES_PTR:WORD
36 EXTRN string_buf_ptr:word
37TRANDATA ENDS
38
39TRANSPACE SEGMENT PUBLIC BYTE ;AC000;
40 EXTRN CURDRV:BYTE
41 EXTRN DESTINFO:BYTE
42 EXTRN DESTTAIL:WORD
43 EXTRN DIRCHAR:BYTE
44 EXTRN dirflag:byte ;AN015;
45 EXTRN KPARSE:BYTE ;AC000; 3/3/KK
46 EXTRN msg_numb:word ;AN022;
47 EXTRN parse1_addr:dword ;AC000;
48 EXTRN parse1_type:byte ;AC000;
49 EXTRN PATHPOS:WORD
50 EXTRN RESSEG:WORD
51 EXTRN srcxname:byte ;AC000;
52 EXTRN string_ptr_2:word
53 EXTRN SWITCHAR:BYTE
54 EXTRN USERDIR1:BYTE
55TRANSPACE ENDS
56
57TRANCODE SEGMENT PUBLIC byte
58
59ASSUME CS:TRANGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
60
61 EXTRN cerror:near
62
63 PUBLIC $chdir
64 PUBLIC $mkdir
65 PUBLIC $rmdir
66 PUBLIC crlf2
67 PUBLIC crprint
68 PUBLIC delim
69 PUBLIC error_output
70 PUBLIC fcb_to_ascz
71 PUBLIC pathchrcmp
72 PUBLIC pathcrunch
73 PUBLIC savudir
74 PUBLIC savudir1
75 PUBLIC scanoff
76 PUBLIC strcomp
77
78break $Chdir
79
80; ****************************************************************
81; *
82; * ROUTINE: $CHDIR
83; *
84; * FUNCTION: Entry point for CHDIR command. Parse the command
85; * line. If path is found, CHDIR to path. If a drive
86; * letter is found, get and display the current dir
87; * of the specified drive. If nothing is found, get
88; * and display the current dir of the default drive.
89; *
90; * INPUT: command line at offset 81H
91; *
92; * OUTPUT: none
93; *
94; ****************************************************************
95
96assume ds:trangroup,es:trangroup
97
98$CHDIR:
99
100 mov si,81H
101 mov di,offset trangroup:parse_chdir ;AN000; Get adderss of PARSE_CHDIR
102 xor cx,cx ;AN000; clear cx,dx
103 xor dx,dx ;AN000;
104 invoke parse_with_msg ;AC018; call parser
105
106 cmp ax,end_of_line ;AC000; are we at end of line?
107 jz bwdJ ; No args
108 cmp ax,result_no_error ;AC000; did we have an error?
109 jnz ChDirErr ;AC018; yes - exit
110
111 cmp parse1_type,result_drive ;AC000; was a drive entered?
112 jnz REALCD ; no
113;
114; D: was found. See if there is anything more.
115;
116 mov di,offset trangroup:parse_chdir ;AC000; get address of parse_chdir
117 xor dx,dx ;AC000;
118 invoke parse_check_eol ;AC000; call parser
119 jnz ChDirErr ;AC000;
120
121bwdJ:
122 invoke build_dir_for_chdir ; Drive only specified
123 call crlf2
124 return
125
126REALCD:
127
128 push si ;AN000; save position in line
129 lds si,parse1_addr ;AN000; get address of filespec
130 invoke move_to_srcbuf ;AN000; move to srcbuf
131 pop si ;AN000; restore position in line
132 mov di,offset trangroup:parse_chdir ;AC000; get address of parse_chdir
133 xor dx,dx ;AC000;
134 invoke parse_check_eol ;AC000; call parser
135 jnz ChDirErr ;AC000;
136
137 invoke SETPATH
138 TEST [DESTINFO],2
139 JNZ BadChdir
140 MOV AH,CHDIR
141 INT int_command
142 retnc
143
144 invoke get_ext_error_number ;AN022; get the extended error
145 cmp ax,error_path_not_found ;AN022; see if path not found
146 jz BadChDir ;AN022; yes - issue old message
147 call Set_Ext_Error_Subst ;AN022;
148 jmp short chdirerr ;AN022;
149
150BadChDir:
151 MOV DX,OFFSET TRANGROUP:BADCD_ptr
152
153ChDirErr:
154 invoke Std_Eprintf
155 return
156
157break $Mkdir
158
159assume ds:trangroup,es:trangroup
160
161$MKDIR:
162 CALL SETRMMK
163 JC MkDirErr
164 MOV AH,MKDIR
165 INT int_command
166 retnc
167
168 invoke get_ext_error_number ;AN022; get the extended error
169 cmp ax,error_path_not_found ;AN022; see if path not found
170 jz MD_other_err ;AN022; yes - issue old message
171 cmp ax,error_access_denied ;AN022; access denied?
172 jz badmderr ;AN022; yes - see if file exists
173
174 call Set_Ext_Error_Subst ;AN022;
175 jmp short MkDirerr ;AC022; yes - go print it
176
177BADMDERR:
178 mov dx,offset trangroup:srcxname ;AN006; Set Disk transfer address
179 mov ah,Set_DMA ;AN006;
180 int int_command ;AN006;
181 MOV AH,Find_First ;AN006; see if file/dir exists
182 mov cx,attr_directory ;AN006; search for directory
183 INT int_command ;AN006;
184 jc MD_other_err ;AN006; doesn't exist - must be something else
185 mov dl,srcxname.find_buf_attr ;AN006; we found a file/dir
186 test dl,attr_directory ;AN006; was it a directory?
187 jz MD_other_err ;AN006; no - must have been a file
188 mov dx,offset trangroup:MD_exists_ptr ;AN006; set up already exists error
189 jmp short MkDirErr ;AN006; make sure we didn't have network error
190MD_other_err: ;AN006;
191 MOV DX,OFFSET TRANGROUP:BADMKD_ptr
192MkDirErr:
193 invoke Std_Eprintf
194 return
195
196Break <Common MkDir/RmDir set up code>
197
198;****************************************************************
199;*
200;* ROUTINE: SETRMMK
201;*
202;* FUNCTION: Parse routine for the internal MKDIR and RMDIR
203;* commands. Parses the command line for a required
204;* filespec.
205;*
206;* INPUT: command line at offset 81H
207;*
208;* OUTPUT: carry clear
209;* DS:DX points to ASCIIZ argument
210;* carry set
211;* DS:DX has error message pointer
212;*
213;****************************************************************
214
215SETRMMK:
216 mov si,81H
217 mov di,offset trangroup:parse_mrdir ;AN000; Get adderss of PARSE_MRDIR
218 xor cx,cx ;AN000; clear cx,dx
219 xor dx,dx ;AN000;
220 invoke parse_with_msg ;AC000; call parser
221 cmp ax,result_no_error ;AC000; did we have an error?
222 jnz NOARGERR ;AC000; yes - exit
223
224 mov di,offset trangroup:srcxname ;AN000; get address of srcxname
225 push di ;AN000; save address
226 push si ;AN000; save position in line
227 lds si,parse1_addr ;AN000; get address of path
228
229mrdir_move_filename: ;AN000; put filespec in srcxname
230 lodsb ;get a char from buffer
231 stosb ;AN000; store in srcxname
232 cmp al,end_of_line_out ;AC000; it char a terminator?
233 jnz mrdir_move_filename ;AC000; no - keep moving
234 pop si ;AN000; get line position back
235
236;
237; we have scanned an argument. See if any args beyond.
238;
239
240 mov di,offset trangroup:parse_mrdir ;AC000; get address of parse_mrdir
241 invoke parse_check_eol ;AC000; are we at end of line?
242 pop dx ;AC000; get address of SRCXNAME
243 retz ;yes - return no error
244NOARGERR:
245 mov dx,offset TranGroup:Extend_Buf_ptr ;AC000; get extended message pointer
246 XOR AX,AX
247 STC
248 return
249
250break $Rmdir
251
252assume ds:trangroup,es:trangroup
253
254$RMDIR:
255 CALL SETRMMK
256 JC RmDirErr
257 JNZ BADRDERR
258 MOV AH,RMDIR
259 INT int_command
260 retnc
261
262 invoke get_ext_error_number ;AN022; get the extended error
263 cmp ax,error_path_not_found ;AN022; see if path not found
264 jz badrderr ;AN022; yes - issue old message
265 cmp ax,error_access_denied ;AN022; access denied?
266 jz badrderr ;AN022; yes - issue old message
267
268 call Set_Ext_Error_Subst ;AN022;
269 jmp short RmDirerr ;AC022; yes - go print it
270
271BADRDERR:
272 MOV DX,OFFSET TRANGROUP:BADRMD_ptr
273
274RmDirErr:
275 invoke STD_Eprintf
276 return
277
278;****************************************************************
279;*
280;* ROUTINE: Set_ext_error_subst
281;*
282;* FUNCTION: Sets up substitution for extended error
283;*
284;* INPUT: AX - extended error number
285;* DX - offset of string
286;*
287;* OUTPUT: Extend_Buf_Ptr set up for STD_EPRINTF
288;*
289;****************************************************************
290
291Set_ext_error_subst proc near ;AN022;
292
293 mov msg_disp_class,ext_msg_class ;AN022; set up extended error msg class
294 mov string_ptr_2,dx ;AN022; get address of failed string
295 mov Extend_buf_sub,one_subst ;AN022; put number of subst in control block
296 mov dx,offset TranGroup:Extend_Buf_ptr ;AN022; get extended message pointer
297 mov Extend_Buf_ptr,ax ;AN022; get message number in control block
298
299 ret ;AN022; return
300
301Set_ext_error_subst endp ;AN022;
302
303
304
305
306
307Break <SavUDir - preserve the users current directory on a particular drive>
308
309;
310; SavUDir - move the user's current directory on a drive into UserDir1
311; SavUDir1 - move the user's current directory on a drive into a specified
312; buffer
313;
314; Inputs: DL has 1-based drive number
315; ES:DI has destination buffer (SavUDir1 only)
316; Outputs: Carry Clear
317; DS = TranGroup
318; Carry Set
319; AX has error code
320; Registers Modified: AX, SI
321;
322
323SAVUDIR:
324 MOV DI,OFFSET TRANGROUP:USERDIR1
325
326SAVUDIR1:
327 MOV AL,DL
328 ADD AL,'@'
329 CMP AL,'@'
330 JNZ GOTUDRV
331 ADD AL,[CURDRV]
332 INC AL ; A = 1
333
334GOTUDRV:
335 STOSB
336 MOV AH,[DIRCHAR]
337 MOV AL,':'
338 STOSW
339 PUSH ES
340 POP DS
341ASSUME DS:NOTHING
342
343 MOV SI,DI
344 MOV AH,CURRENT_DIR ; Get the Directory Text
345 INT int_command
346 retc
347 PUSH CS
348 POP DS
349ASSUME DS:TRANGROUP
350
351 return
352
353
354CRLF2:
355 PUSH DX
356 MOV DX,OFFSET TRANGROUP:ACRLF_ptr
357
358PR:
359 PUSH DS
360 PUSH CS
361 POP DS
362 invoke std_printf
363 POP DS
364 POP DX
365
366 return
367
368;
369; These routines (SCANOFF, DELIM) are called in batch processing when DS
370; may NOT be TRANGROUP
371;
372ASSUME DS:NOTHING,ES:NOTHING
373
374SCANOFF:
375 LODSB
376 CALL DELIM
377 JZ SCANOFF
378 DEC SI ; Point to first non-delimiter
379 return
380
381;
382; Input: AL is character to classify
383; Output: Z set if delimiter
384; NZ set otherwise
385; Registers modified: none
386;
387
388DELIM:
389 CMP AL,' '
390 retz
391 CMP AL,'='
392 retz
393 CMP AL,','
394 retz
395 CMP AL,';'
396 retz
397 CMP AL,9 ; Check for TAB character
398 retz
399 CMP AL,0ah ; Check for line feed character - BAS
400 return
401
402
403ASSUME DS:TRANGROUP,ES:TRANGROUP
404
405
406FCB_TO_ASCZ: ; Convert DS:SI to ASCIZ ES:DI
407 MOV CX,8
408
409MAINNAME:
410 LODSB
411 CMP AL,' '
412 JZ SKIPSPC
413 STOSB
414
415SKIPSPC:
416 LOOP MAINNAME
417 LODSB
418 CMP AL,' '
419 JZ GOTNAME
420 MOV AH,AL
421 MOV AL,dot_chr
422 STOSB
423 XCHG AL,AH
424 STOSB
425 MOV CL,2
426
427EXTNAME:
428 LODSB
429 CMP AL,' '
430 JZ GOTNAME
431 STOSB
432 LOOP EXTNAME
433
434GOTNAME:
435 XOR AL,AL
436 STOSB
437 return
438
439STRCOMP:
440;
441; Compare ASCIZ DS:SI with ES:DI.
442; SI,DI destroyed.
443;
444 CMPSB
445 retnz ; Strings not equal
446 cmp byte ptr [SI-1],0 ; Hit NUL terminator?
447 retz ; Yes, strings equal
448 jmp short STRCOMP ; Equal so far, keep going
449
450
451CRPRINT:
452 PUSH AX
453 MOV AL,13
454 PUSH CX
455 PUSH DI
456 MOV DI,DX
457 MOV CX,-1
458 PUSH ES
459 PUSH DS
460 POP ES
461
462 REPNZ SCASB ; LOOK FOR TERMINATOR
463 mov byte ptr [di-1],0 ; nul terminate the string
464 POP ES
465 mov string_ptr_2,dx
466 mov dx,offset trangroup:string_buf_ptr
467 invoke std_printf
468 mov ds:byte ptr [di-1],13 ; now put the CR back
469 JC ERROR_OUTPUT
470
471 POP DI
472 POP CX
473 POP AX
474
475 return
476
477ERROR_OUTPUT:
478 PUSH CS
479 POP DS
480ASSUME DS:TRANGROUP
481 MOV ES,[RESSEG]
482ASSUME ES:RESGROUP
483
484 MOV DX,OFFSET TRANGROUP:NOSPACE_ptr
485 CMP [PIPEFLAG],0
486 JZ GO_TO_ERROR
487
488 invoke PipeOff
489 MOV DX,OFFSET TRANGROUP:PIPEEMES_ptr
490GO_TO_ERROR:
491 JMP CERROR
492
493ASSUME DS:TRANGROUP,ES:TRANGROUP
494
495PATHCHRCMP:
496;---- Mod for path invocation ----
497PUBLIC pathchrcmp
498;----
499
500 push ax
501 mov ah,'/'
502 CMP [SWITCHAR],ah
503 JZ NOSLASHT
504 CMP AL,'/'
505 jz pccont
506
507NOSLASHT:
508 CMP AL,'\'
509pccont:
510 pop ax
511
512 return
513
514; Drive taken from FCB
515; User dir saved in userdir1
516;
517; Zero set if path dir, CHDIR to this dir, FCB filled with ?
518; NZ set if path/file, CHDIR to file, FCB has file (parsed fill ' ')
519; [DESTTAIL] points to parse point
520; Carry set if no CHDIRs worked, FCB not altered.
521; DESTISDIR set non zero if PATHCHRs in path (via SETPATH)
522;
523PATHCRUNCH:
524 mov [msg_numb],0 ;AN022; Set up message flag
525 MOV DL,DS:[FCB]
526 CALL SAVUDIR
527 jc pcrunch_cderrJ ;AN022; if error on current dir - report
528
529 invoke SETPATH
530 TEST [DESTINFO],2
531 JNZ TRYPEEL ; If ? or * cannot be pure dir
532
533 MOV AH,CHDIR
534 INT int_command
535 jnc chdir_worked ;AN022; no error - continue
536
537 invoke get_ext_error_number ;AN022; get the extended error
538 cmp ax,error_path_not_found ;AN022; if path not found
539 jz trypeel ;AC022; keep trying
540 cmp ax,error_access_denied ;AN022; if access denied
541 jz trypeel ;AC022; keep trying
542 mov [msg_numb],ax ;AN022; set up message flag
543 jmp peelfail ;AN022; exit with other error
544
545chdir_worked:
546 invoke SETREST1
547 MOV AL,'?' ; *.* is default file spec if pure dir
548 MOV DI,5DH
549 MOV CX,11
550 REP STOSB
551 XOR AL,AL ; Set zero
552 return
553
554pcrunch_cderrj: ;AN022; need this for long jmp
555 jmp pcrunch_cderr ;AN022;
556
557TRYPEEL:
558 MOV SI,[PATHPOS]
559 DEC SI ; Point at NUL
560 MOV AL,[SI-1]
561
562 CMP [KPARSE],0
563 JNZ DELSTRT ; Last char is second KANJI byte, might be '\'
564
565 CALL PATHCHRCMP
566 JZ PEELFAIL ; Trailing '/'
567
568DELSTRT:
569 MOV CX,SI
570 MOV SI,DX
571 PUSH DX
572DELLOOP:
573 CMP SI,CX
574 JZ GOTDELE
575 LODSB
576 invoke TESTKANJ
577 JZ NOTKANJ8
578 INC SI
579 JMP DELLOOP
580
581NOTKANJ8:
582 CALL PATHCHRCMP
583 JNZ DELLOOP
584 MOV DX,SI
585 DEC DX
586 JMP DELLOOP
587
588GOTDELE:
589 MOV SI,DX
590 POP DX
591 CMP SI,DX
592 JZ BADRET
593 MOV CX,SI
594 MOV SI,DX
595DELLOOP2: ; Set value of KPARSE
596 CMP SI,CX
597 JZ TRYCD
598 MOV [KPARSE],0
599 LODSB
600 INVOKE TESTKANJ
601 JZ DELLOOP2
602 INC SI
603 INC [KPARSE]
604 JMP DELLOOP2
605
606TRYCD:
607 push ax
608 mov al,dot_chr
609 CMP BYTE PTR [SI+1],al
610 pop ax
611 JZ PEELFAIL ; If . or .., pure cd should have worked
612 mov al,[si-1]
613 CMP al,':' ; Special case d:\file
614 JZ BADRET
615
616 CMP [KPARSE],0
617 JNZ NOTDOUBLESL ; Last char is second KANJI byte, might be '\'
618
619 CALL PATHCHRCMP
620 JNZ NOTDOUBLESL
621PEELFAIL:
622 STC ; //
623 return
624NOTDOUBLESL:
625 MOV BYTE PTR [SI],0
626 MOV AH,CHDIR
627 INT int_command
628 JNC CDSUCC
629pcrunch_cderr:
630 invoke get_ext_error_number ;AN022; get the extended error
631 mov [msg_numb],ax ;AN022; set up message flag
632 or si,si ;AN022; set up zero flag to not zero
633 stc ;AN022; set up carry flag
634 return
635
636BADRET:
637 MOV AL,[SI]
638 CALL PATHCHRCMP ; Special case 'DIRCHAR'file
639 STC
640 retnz
641 XOR BL,BL
642 XCHG BL,[SI+1]
643 MOV AH,CHDIR
644 INT int_command
645 jc pcrunch_cderr ;AN022; go to error exit
646 MOV [SI+1],BL
647CDSUCC:
648 invoke SETREST1
649 INC SI ; Reset zero
650 MOV [DESTTAIL],SI
651 pushf ;AN015; save flags
652 cmp dirflag,-1 ;AN015; don't do parse if in DIR
653 jz pcrunch_end ;AN015;
654 MOV DI,FCB
655 MOV AX,(PARSE_FILE_DESCRIPTOR SHL 8) OR 02H ; Parse with default drive
656 INT int_command
657pcrunch_end:
658 popf ;AN015; get flags back
659 return
660
661trancode ends
662 end
663 \ No newline at end of file