]>
wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/EDLIN/EDLCMD1.ASM
4 ;======================= START OF SPECIFICATIONS =========================
6 ; MODULE NAME: EDLCMD1.SAL
8 ; DESCRIPTIVE NAME: EDLIN ROUTINES
10 ; FUNCTION: THIS MODULE PROVIDES ROUTINES NEEDED FOR EDLIN'S EXECUTION.
12 ; ENTRY POINT: ANY CALLED ROUTINE
18 ; INTERNAL REFERENCES:
20 ; EXTERNAL REFERENCES:
22 ; ROUTINE: EDLCMD2 - ROUTINES MAY BE CALLED FROM EDLCMD2
23 ; EDLMES - ROUTINES MAY BE CALLED FROM EDLMES
25 ; NOTES: THIS MODULE IS TO BE PREPPED BY SALUT WITH THE "PR" OPTIONS.
26 ; LINK EDLIN+EDLCMD1+EDLCMD2+EDLMES+EDLPARSE
30 ; AN000 VERSION DOS 4.00 - REVISIONS MADE RELATE TO THE FOLLOWING:
32 ; - IMPLEMENT SYSPARSE
33 ; - IMPLEMENT MESSAGE RETRIEVER
34 ; - IMPLEMENT DBCS ENABLING
35 ; - ENHANCED VIDEO SUPPORT
39 ; COPYRIGHT: "MS DOS EDLIN UTILITY"
40 ; "VERSION 4.00 (C) COPYRIGHT 1988 Microsoft"
42 ;======================= END OF SPECIFICATIONS ===========================
46 SUBTTL Contants
and Data areas
53 CONST
SEGMENT PUBLIC WORD
59 DATA SEGMENT PUBLIC WORD
62 DG GROUP
CODE,CONST
,cstack
,DATA
64 CONST
SEGMENT PUBLIC WORD
65 EXTRN DSKFUL_ptr
:word,READ_ERR_PTR
:word
66 EXTRN NOSUCH_ptr
:word,TOOLNG_ptr
:word,EOF_ptr
:word
67 extrn txt1
:byte,txt2
:byte
73 DATA SEGMENT PUBLIC WORD
75 extrn current
:word,pointer
:word,start
:word,endtxt
:word
76 extrn wrt_handle
:word,editbuf
:byte,path_name
:byte,fname_len
:word
77 extrn arg_buf
:byte,arg_buf_ptr
:word
78 extrn olddat
:byte,oldlen
:word,newlen
:word,param1
:word,param2
:word
79 extrn srchflg
:byte,srchmod
:byte,comline
:word,lstfnd
:word,numpos
:word
80 extrn lstnum
:word,srchcnt
:word,amnt_req
:word,delflg
:byte,lastlin
:word
81 extrn three4th
:word,one4th
:word,last
:word,rd_handle
:word,ending
:byte
88 ASSUME
CS:DG
,DS:DG
,SS:CStack
,ES:DG
90 extrn findlin
:near,shownum
:near,loadbuf
:near
91 extrn delbak
:near,unquote
:near,lf
:near
92 extrn dispone
:near,display:near,query
:near
93 extrn quit
:near,scanln
:near,scaneof
:near
94 extrn fndfirst
:near,fndnext
:near,replace
:near,memerr
:near
95 extrn std_printf
:near,chkrange
:near,comerr
:near
97 public xerror
,bad_read
,append
,nocom
,pager
,list
98 public delete
,replac_from_curr
,search_from_curr
,ewrite
,wrt
107 TEST BYTE PTR [HAVEOF
],-1
110 CMP [PARAM1
],0 ;See if parameter is missing
112 CMP DX,[THREE4TH
] ;See if already 3/4ths full
114 return
;If so, then done already
118 SUB CX,DX ;Amount of memory available
124 mov [amnt_req
],cx ;Save number of chars requested
126 INT 21H
;Fill memory with file data
127 CMP CX,AX ;Did we read less than we asked for?
129 ; Make sure this is an end-of-file by trying to read more
130 PUSH AX ;Save old byte count
131 ADD DX,AX ;Point to next open space in buffer
132 MOV CX,1 ;Just one character past EOF
137 JNZ SJ54
;No -- we have one more character
138 MOV BYTE PTR [HAVEOF
],1 ;Yes - set old style system call flag
141 INC AX ;Include one more char in byte count
143 MOV CX,AX ;Want byte count in CX
144 PUSH CX ;Save actual byte count
147 MOV BYTE PTR [HAVEOF
],1 ;Set flag if 1AH found in file
154 ADD AX,CX ;First byte after loaded text
155 CMP AX,[THREE4TH
] ;See if we made 3/4 full
159 SUB CX,DI ;Length remaining over 3/4
160 MOV BX,1 ;Look for one more line
162 CALL SCANLN
;Look for BX lines
163 CMP [DI-1],AL ;Check for full line
168 ; We have an incomplete line in the buffer at end of file. Fix it up to be
171 MOV BYTE PTR [DI],13 ; CR
172 MOV BYTE PTR [DI+1],10 ; LF
173 ADD DI,2 ; length is 2 greater
183 REPNE SCASB ;Scan backwards for last line
189 POP CX ;Actual amount read
190 MOV WORD PTR [DI],1
AH ;Place EOF after last line
193 ADD DI,CX ;Amount of file read but not used
194 ; Must seek for old partial line
212 MOV BYTE PTR [HAVEOF
],0
215 MOV DX,OFFSET DG
:EOF_ptr
220 MOV DX,OFFSET DG
:READ_ERR_ptr
221 MOV DI,offset dg
:path_name
228 TEST BYTE PTR [HAVEOF
],-1
230 TEST BYTE PTR [ENDING
],-1
231 retnz
;Suppress memory error during End
244 SUB DI,CX ;Write everything in front of here
246 CMP DI,OFFSET DG
:START
;See if there's anything to write
249 MOV BX,1 ;Look for one more line
256 CMP BYTE PTR [DELFLG
],0
259 CALL DELBAK
;Want to delete the .BAK file
260 ;as soon as the first write occurs
264 MOV DX,OFFSET DG
:START
265 SUB CX,DX ;Amount to write
271 CMP AX,CX ; MZ correct full disk detection
272 JNZ WRTERR
; MZ correct full disk detection
274 MOV DI,OFFSET DG
:START
278 INC CX ;Amount of text remaining
290 MOV DX,OFFSET DG
:DSKFUL_ptr
306 mov byte ptr [srchmod
],1 ;search from curr+1 line
310 mov byte ptr [srchmod
],0 ;search from beg of buffer
312 MOV BYTE PTR [SRCHFLG
],0
317 CALL LOADBUF
;Count length of line
320 ADD DX,CX ;Length of new line
331 SUB CX,SI ;Get no. of char on line before change
333 mov di,offset dg
:arg_buf
;Initialize the output string buffer
334 CALL OUTCNT
;Output first part of line
336 MOV SI,1+ OFFSET DG
:TXT2
338 CALL OUTCNT
;Output change
340 ADD SI,[OLDLEN
] ;Skip over old stuff in line
341 MOV CX,DX ;DX=no. of char left in line
342 ADD CX,2 ;Include CR/LF
343 CALL OUTCNT
;Output last part of line
346 mov dx,offset dg
:arg_buf_ptr
348 CALL QUERY
;Check if change OK
353 MOV SI,1+ OFFSET DG
:TXT2
357 ADD [LSTFND
],CX ;Bump pointer beyond new text
360 SUB [SRCHCNT
],DX ;Old text will not be searched
381 MOV DX,OFFSET DG
:TOOLNG_ptr
389 mov byte ptr [srchmod
],1 ;search from curr+1 line
393 mov byte ptr [srchmod
],0 ;search from beg of buffer
395 MOV BYTE PTR [SRCHFLG
],1
417 MOV DX,OFFSET DG
:NOSUCH_ptr
423 ; Replace enters here with LSTNUM pointing to the correct line.
429 ; Search enters here with LSTNUM pointing AFTER the correct line
433 DEC BX ;Current <= Last matched line
442 ; n,mD deletes a range of lines. Allowable values for n are:
443 ; 1 ... LAST. Allowable values for m are:
445 ; nD deletes a single line
446 ; D deletes the current line
449 CMP ParamCt
,2 ; at most two parameters specified.
452 OR BX,BX ; default first arg?
454 MOV BX,Current
; use current as default
457 MOV BX,Param2
; did we default second arg?
459 JNZ DelCheck
; no, use it.
460 MOV BX,Param1
; use param1 as default
464 CALL ChkRange
; returns by itself if bad range
466 ; BX is first line of range to be deleted. Param2 is last line in range to
467 ; be deleted. Get pointer to beginning of block. Save location
469 CALL FINDLIN
; Grab line
470 retnz
; If not found => return
474 ; Get pointer past end of block (Param2+1).
480 ; Set up pointers. Compute number of chars to move.
482 MOV SI,DI ; move from second line+1
483 POP DI ; restore destination (first line)
484 POP Current
; Current line is first param
485 MOV Pointer
,DI ; internal current line
486 MOV CX,EndTxt
; compute count
488 JB ComErrJ
; should never occur: ChkRange
489 INC CX ; remember ^Z at end
491 REP MOVSB ; move data
493 MOV EndTxt
,DI ; reset end pointer
502 xor bx,bx ;get last line in the buffer
507 or bx,bx ;was it specified?
508 jnz frstok
;yes, use it
510 cmp bx,1 ;if current line =1 start from there
512 inc bx ;start from current+1 line
514 cmp bx,[lastlin
] ;check that we are in the buffer
516 return
;if not just quit
519 or dx,dx ;was param2 specified?
521 mov dx,bx ;no, take the end line to be the
522 ; start line + length of active display
524 ;=========================================================================
525 ; This modification is to provide support for screens larger than
529 ;=========================================================================
531 push ax ;an000;save affected registers
533 mov ah,00h ;an000;zero out high byte
534 mov al,dg
:disp_len
;an000;set ax to active display length
535 sub ax,2 ;an000;adjust for length of screen & current
537 add dx,ax ;an000;this gives us the last line to be
539 pop ax ;an000;restore affected registers
541 ;=========================================================================
545 cmp dx,[lastlin
] ;check that we are in the buffer
547 mov dx,[lastlin
] ;we are not, take the last line as end
549 cmp dx,bx ;is param1 < param2 ?
552 jmp comerr
;yes, no backwards listing, print error
554 push dx ;save the end line
555 push bx ;save start line
556 mov bx,dx ;set the current line
561 pop bx ;restore start line
562 call findlin
;get pointer to start line
563 mov si,di ;save pointer
565 sub di,bx ;number of lines
566 jmp short display_lines
590 ;=========================================================================
591 ; This modification is to provide support for screens larger than
595 ;=========================================================================
597 push ax ;an000;save affected registers
599 mov ah,00h ;an000;zero out high byte
600 mov al,dg
:disp_len
;an000;set ax to active display length dec ax ;an000;allow room at bottom for
602 mov di,ax ;an000;number of lines to print an
603 ; entire screen less 1.
604 pop ax ;an000;restore affected registers
606 ;=========================================================================
612 Break <NOCOM
- edit a single line
>
615 ; NOCOM is called when there is a single line being edited. This occurs when
616 ; the command letter is CR or is ;.
628 INC BX ;Default is current line plus one
645 MOV AH,STD_CON_STRING_INPUT
;Get input buffer
646 MOV DX,OFFSET DG
:EDITBUF
653 MOV SI,2 + OFFSET DG
:EDITBUF
654 ;-----------------------------------------------------------------------
655 call unquote
;scan for quote chars if any
656 ;-----------------------------------------------------------------------
657 mov cl,[EditBuf
+1] ;an000; dms;get new line length
658 mov ch,0 ;an000; dms;clear high byte
660 JMP Replace
; MZ 11/30