Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

678 lines
14 KiB

  1. PAGE 60,132;
  2. TITLE EDLCMD1.ASM
  3. ;/*
  4. ; * Microsoft Confidential
  5. ; * Copyright (C) Microsoft Corporation 1991
  6. ; * All Rights Reserved.
  7. ; */
  8. ;======================= START OF SPECIFICATIONS =========================
  9. ;
  10. ; MODULE NAME: EDLCMD1.SAL
  11. ;
  12. ; DESCRIPTIVE NAME: EDLIN ROUTINES
  13. ;
  14. ; FUNCTION: THIS MODULE PROVIDES ROUTINES NEEDED FOR EDLIN'S EXECUTION.
  15. ;
  16. ; ENTRY POINT: ANY CALLED ROUTINE
  17. ;
  18. ; EXIT NORMAL: NA
  19. ;
  20. ; EXIT ERROR : NA
  21. ;
  22. ; INTERNAL REFERENCES:
  23. ;
  24. ; EXTERNAL REFERENCES:
  25. ;
  26. ; ROUTINE: EDLCMD2 - ROUTINES MAY BE CALLED FROM EDLCMD2
  27. ; EDLMES - ROUTINES MAY BE CALLED FROM EDLMES
  28. ;
  29. ; NOTES: THIS MODULE IS TO BE PREPPED BY SALUT WITH THE "PR" OPTIONS.
  30. ; LINK EDLIN+EDLCMD1+EDLCMD2+EDLMES+EDLPARSE
  31. ;
  32. ; REVISION HISTORY:
  33. ;
  34. ; AN000 VERSION DOS 4.00 - REVISIONS MADE RELATE TO THE FOLLOWING:
  35. ;
  36. ; - IMPLEMENT SYSPARSE
  37. ; - IMPLEMENT MESSAGE RETRIEVER
  38. ; - IMPLEMENT DBCS ENABLING
  39. ; - ENHANCED VIDEO SUPPORT
  40. ; - EXTENDED OPENS
  41. ; - SCROLLING ERROR
  42. ;
  43. ; COPYRIGHT: "MS DOS EDLIN UTILITY"
  44. ; "VERSION 4.00 (C) COPYRIGHT 1988 Microsoft"
  45. ;
  46. ;======================= END OF SPECIFICATIONS ===========================
  47. include syscall.inc
  48. include edlequ.asm
  49. SUBTTL Contants and Data areas
  50. PAGE
  51. CODE SEGMENT PUBLIC
  52. CODE ENDS
  53. CONST SEGMENT PUBLIC WORD
  54. CONST ENDS
  55. cstack segment stack
  56. cstack ends
  57. DATA SEGMENT PUBLIC WORD
  58. DATA ENDS
  59. DG GROUP CODE,CONST,cstack,DATA
  60. CONST SEGMENT PUBLIC WORD
  61. EXTRN DSKFUL:abs,READ_ERR_PTR:word
  62. EXTRN NOSUCH:abs,TOOLNG:abs,EOF:abs
  63. extrn txt1:byte,txt2:byte
  64. CONST ENDS
  65. cstack segment stack
  66. cstack ends
  67. DATA SEGMENT PUBLIC WORD
  68. extrn ParamCt:WORD
  69. extrn current:word,pointer:word,start:word,endtxt:word
  70. extrn wrt_handle:word,editbuf:byte,path_name:byte,fname_len:word
  71. extrn arg_buf:byte,arg_buf_ptr:word
  72. extrn olddat:byte,oldlen:word,newlen:word,param1:word,param2:word
  73. extrn srchflg:byte,srchmod:byte,comline:word,lstfnd:word,numpos:word
  74. extrn lstnum:word,srchcnt:word,amnt_req:word,delflg:byte,lastlin:word
  75. extrn three4th:word,one4th:word,last_mem:word,rd_handle:word,ending:byte
  76. extrn haveof:byte
  77. extrn Disp_Len:Byte
  78. DATA ENDS
  79. CODE SEGMENT PUBLIC
  80. ASSUME CS:DG,DS:DG,SS:CStack,ES:DG
  81. extrn findlin:near,shownum:near,loadbuf:near
  82. extrn delbak:near,unquote:near,lf:near
  83. extrn dispone:near,display:near,query:near
  84. extrn quit:near,scanln:near,scaneof:near
  85. extrn fndfirst:near,fndnext:near,replace:near,memerr:near
  86. extrn std_printf:near,chkrange:near,comerr:near
  87. extrn display_message:near
  88. public zerror
  89. public xerror,bad_read,append,nocom,pager,list
  90. public delete,replac_from_curr,search_from_curr,ewrite,wrt
  91. NOMOREJ:JMP NOMORE
  92. APPEND:
  93. CMP ParamCt,1
  94. JZ AppendOK
  95. JMP ComErr
  96. AppendOK:
  97. TEST BYTE PTR [HAVEOF],-1
  98. JNZ NOMOREJ
  99. MOV DX,[ENDTXT]
  100. CMP [PARAM1],0 ;See if parameter is missing
  101. JNZ PARMAPP
  102. CMP DX,[THREE4TH] ;See if already 3/4ths full
  103. jb parmapp
  104. return ;If so, then done already
  105. PARMAPP:
  106. MOV DI,DX
  107. MOV CX,[LAST_MEM]
  108. SUB CX,DX ;Amount of memory available
  109. jnz sj53
  110. jmp memerr
  111. sj53:
  112. MOV DX,[ENDTXT]
  113. MOV BX,[RD_HANDLE]
  114. mov [amnt_req],cx ;Save number of chars requested
  115. MOV AH,READ
  116. INT 21H ;Fill memory with file data
  117. CMP CX,AX ;Did we read less than we asked for?
  118. JZ SJ55
  119. ; Make sure this is an end-of-file by trying to read more
  120. PUSH AX ;Save old byte count
  121. ADD DX,AX ;Point to next open space in buffer
  122. MOV CX,1 ;Just one character past EOF
  123. MOV AH,READ
  124. INT 21H
  125. CMP AX,0 ;Is it EOF?
  126. POP AX
  127. JNZ SJ54 ;No -- we have one more character
  128. MOV BYTE PTR [HAVEOF],1 ;Yes - set old style system call flag
  129. JMP SHORT SJ55
  130. SJ54:
  131. INC AX ;Include one more char in byte count
  132. sj55:
  133. MOV CX,AX ;Want byte count in CX
  134. PUSH CX ;Save actual byte count
  135. CALL SCANEOF
  136. JNZ NOTEND
  137. MOV BYTE PTR [HAVEOF],1 ;Set flag if 1AH found in file
  138. NOTEND:
  139. XOR DX,DX
  140. MOV BX,[PARAM1]
  141. OR BX,BX
  142. JNZ COUNTLN
  143. MOV AX,DI
  144. ADD AX,CX ;First byte after loaded text
  145. CMP AX,[THREE4TH] ;See if we made 3/4 full
  146. JBE COUNTLN
  147. MOV DI,[THREE4TH]
  148. MOV CX,AX
  149. SUB CX,DI ;Length remaining over 3/4
  150. MOV BX,1 ;Look for one more line
  151. COUNTLN:
  152. CALL SCANLN ;Look for BX lines
  153. CMP [DI-1],AL ;Check for full line
  154. JZ FULLN
  155. CMP HavEof,1
  156. JNZ DoBackScan
  157. ;
  158. ; We have an incomplete line in the buffer at end of file. Fix it up to be
  159. ; pretty.
  160. ;
  161. MOV BYTE PTR [DI],13 ; CR
  162. MOV BYTE PTR [DI+1],10 ; LF
  163. ADD DI,2 ; length is 2 greater
  164. POP CX
  165. ADD CX,2
  166. PUSH CX
  167. JMP SHORT FULLN
  168. DoBackScan:
  169. DEC DI
  170. MOV CX,[LAST_MEM]
  171. STD
  172. REPNE SCASB ;Scan backwards for last line
  173. CLD
  174. INC DI
  175. INC DI
  176. DEC DX
  177. FULLN:
  178. POP CX ;Actual amount read
  179. MOV WORD PTR [DI],1AH ;Place EOF after last line
  180. SUB CX,DI
  181. XCHG DI,[ENDTXT]
  182. ADD DI,CX ;Amount of file read but not used
  183. ; Must seek for old partial line
  184. OR DI,DI
  185. JZ FULLN1
  186. PUSH DX
  187. PUSH BX
  188. MOV BX,[RD_HANDLE]
  189. MOV DX,DI
  190. NEG DX
  191. MOV CX,-1
  192. MOV AL,1
  193. MOV AH,LSEEK
  194. INT 21H
  195. POP BX
  196. POP DX
  197. JC BAD_READ
  198. FULLN1:
  199. CMP BX,DX
  200. JNZ EOFCHK
  201. MOV BYTE PTR [HAVEOF],0
  202. return
  203. NOMORE:
  204. mov ax,EOF
  205. call display_message
  206. ret3: return
  207. BAD_READ:
  208. MOV DX,OFFSET DG:READ_ERR_ptr
  209. MOV DI,offset dg:path_name
  210. ADD DI,[FNAME_LEN]
  211. MOV AL,0
  212. STOSB
  213. JMP XERROR
  214. EOFCHK:
  215. TEST BYTE PTR [HAVEOF],-1
  216. JNZ NOMORE
  217. TEST BYTE PTR [ENDING],-1
  218. retnz ;Suppress memory error during End
  219. JMP MEMERR
  220. EWRITE:
  221. CMP ParamCt,1
  222. JBE EWriteOK
  223. JMP ComErr
  224. EWriteOK:
  225. MOV BX,[PARAM1]
  226. OR BX,BX
  227. JNZ WRT
  228. MOV CX,[ONE4TH]
  229. MOV DI,[ENDTXT]
  230. SUB DI,CX ;Write everything in front of here
  231. JBE RET3
  232. CMP DI,OFFSET DG:START ;See if there's anything to write
  233. JBE RET3
  234. XOR DX,DX
  235. MOV BX,1 ;Look for one more line
  236. CALL SCANLN
  237. JMP SHORT WRTADD
  238. WRT:
  239. INC BX
  240. CALL FINDLIN
  241. WRTADD:
  242. CMP BYTE PTR [DELFLG],0
  243. JNZ WRTADD1
  244. PUSH DI
  245. CALL DELBAK ;Want to delete the .BAK file
  246. ;as soon as the first write occurs
  247. POP DI
  248. WRTADD1:
  249. MOV CX,DI
  250. MOV DX,OFFSET DG:START
  251. SUB CX,DX ;Amount to write
  252. retz
  253. MOV BX,[WRT_HANDLE]
  254. MOV AH,WRITE
  255. INT 21H
  256. JC WRTERR
  257. CMP AX,CX ; MZ correct full disk detection
  258. JNZ WRTERR ; MZ correct full disk detection
  259. MOV SI,DI
  260. MOV DI,OFFSET DG:START
  261. MOV [POINTER],DI
  262. MOV CX,[ENDTXT]
  263. SUB CX,SI
  264. INC CX ;Amount of text remaining
  265. CLD
  266. REP MOVSB
  267. DEC DI ;Point to EOF
  268. MOV [ENDTXT],DI
  269. MOV [CURRENT],1
  270. return
  271. WRTERR:
  272. MOV BX,[WRT_HANDLE]
  273. MOV AH,CLOSE
  274. INT 21H
  275. mov ax,DSKFUL
  276. zerror:
  277. push cs
  278. pop ds
  279. call display_message
  280. xerror1111:
  281. mov al,0ffh
  282. mov ah,exit
  283. int 21h
  284. xERROR:
  285. push cs
  286. pop ds
  287. call std_printf
  288. jmp xerror1111
  289. NOTFNDJ:JMP NOTFND
  290. replac_from_curr:
  291. CMP ParamCt,2
  292. JBE Replace1
  293. JMP ComErr
  294. Replace1:
  295. mov byte ptr [srchmod],1 ;search from curr+1 line
  296. jmp short sj6
  297. REPLAC:
  298. mov byte ptr [srchmod],0 ;search from beg of buffer
  299. sj6:
  300. MOV BYTE PTR [SRCHFLG],0
  301. CALL FNDFIRST
  302. JNZ NOTFNDJ
  303. REPLP:
  304. MOV SI,[NUMPOS]
  305. CALL LOADBUF ;Count length of line
  306. SUB DX,[OLDLEN]
  307. MOV CX,[NEWLEN]
  308. ADD DX,CX ;Length of new line
  309. CMP DX,254
  310. ; jbe len_ok
  311. ; Jmp TOOLONG
  312. ja toolong
  313. len_ok:
  314. MOV BX,[LSTNUM]
  315. PUSH DX
  316. CALL SHOWNUM
  317. POP DX
  318. MOV CX,[LSTFND]
  319. MOV SI,[NUMPOS]
  320. SUB CX,SI ;Get no. of char on line before change
  321. DEC CX
  322. mov di,offset dg:arg_buf ;Initialize the output string buffer
  323. CALL OUTCNT ;Output first part of line
  324. PUSH SI
  325. MOV SI,1+ OFFSET DG:TXT2
  326. MOV CX,[NEWLEN]
  327. CALL OUTCNT ;Output change
  328. POP SI
  329. ADD SI,[OLDLEN] ;Skip over old stuff in line
  330. MOV CX,DX ;DX=no. of char left in line
  331. ADD CX,2 ;Include CR/LF
  332. CALL OUTCNT ;Output last part of line
  333. xor al,al
  334. stosb
  335. mov dx,offset dg:arg_buf_ptr
  336. call std_printf
  337. CALL QUERY ;Check if change OK
  338. JNZ REPNXT
  339. CALL PUTCURS
  340. MOV DI,[LSTFND]
  341. DEC DI
  342. MOV SI,1+ OFFSET DG:TXT2
  343. MOV DX,[OLDLEN]
  344. MOV CX,[NEWLEN]
  345. DEC CX
  346. ADD [LSTFND],CX ;Bump pointer beyond new text
  347. INC CX
  348. DEC DX
  349. SUB [SRCHCNT],DX ;Old text will not be searched
  350. JAE SOMELEFT
  351. MOV [SRCHCNT],0
  352. SOMELEFT:
  353. INC DX
  354. CALL REPLACE
  355. REPNXT:
  356. CALL FNDNEXT
  357. retnz
  358. JMP REPLP
  359. OUTCNT:
  360. JCXZ RET8
  361. OUTLP:
  362. LODSB
  363. stosb
  364. DEC DX
  365. LOOP OUTLP
  366. RET8: return
  367. TOOLONG:
  368. mov ax,TOOLNG
  369. JMP SHORT PERR
  370. search_from_curr:
  371. CMP ParamCt,2
  372. JBE Search1
  373. JMP ComErr
  374. Search1:
  375. mov byte ptr [srchmod],1 ;search from curr+1 line
  376. jmp short sj7
  377. SEARCH:
  378. mov byte ptr [srchmod],0 ;search from beg of buffer
  379. sj7:
  380. MOV BYTE PTR [SRCHFLG],1
  381. CALL FNDFIRST
  382. JNZ NOTFND
  383. SRCH:
  384. MOV BX,[LSTNUM]
  385. MOV SI,[NUMPOS]
  386. CALL DISPONE
  387. MOV DI,[LSTFND]
  388. MOV CX,[SRCHCNT]
  389. MOV AL,10
  390. CLD
  391. REPNE SCASB
  392. JNZ NOTFND
  393. MOV [LSTFND],DI
  394. MOV [NUMPOS],DI
  395. MOV [SRCHCNT],CX
  396. INC [LSTNUM]
  397. CALL QUERY
  398. JZ PUTCURS1
  399. CALL FNDNEXT
  400. JZ SRCH
  401. NOTFND:
  402. mov ax,NOSUCH
  403. PERR:
  404. jmp display_message
  405. ;
  406. ; Replace enters here with LSTNUM pointing to the correct line.
  407. ;
  408. PUTCURS:
  409. MOV BX,[LSTNUM]
  410. jmp short putcursor
  411. ;
  412. ; Search enters here with LSTNUM pointing AFTER the correct line
  413. ;
  414. putcurs1:
  415. MOV BX,[LSTNUM]
  416. DEC BX ;Current <= Last matched line
  417. putcursor:
  418. CALL FINDLIN
  419. MOV [CURRENT],DX
  420. MOV [POINTER],DI
  421. return
  422. ;
  423. ; n,mD deletes a range of lines. Allowable values for n are:
  424. ; 1 ... LAST_MEM. Allowable values for m are:
  425. ; 1 ... LAST_MEM.
  426. ; nD deletes a single line
  427. ; D deletes the current line
  428. ;
  429. DELETE:
  430. CMP ParamCt,2 ; at most two parameters specified.
  431. JA ComErrJ
  432. MOV BX,Param1
  433. OR BX,BX ; default first arg?
  434. JNZ DelParm2
  435. MOV BX,Current ; use current as default
  436. MOV Param1,BX
  437. DelParm2:
  438. MOV BX,Param2 ; did we default second arg?
  439. OR BX,BX
  440. JNZ DelCheck ; no, use it.
  441. MOV BX,Param1 ; use param1 as default
  442. MOV Param2,BX
  443. DelCheck:
  444. MOV BX,Param1
  445. CALL ChkRange ; returns by itself if bad range
  446. ;
  447. ; BX is first line of range to be deleted. Param2 is last line in range to
  448. ; be deleted. Get pointer to beginning of block. Save location
  449. ;
  450. CALL FINDLIN ; Grab line
  451. retnz ; If not found => return
  452. PUSH BX
  453. PUSH DI
  454. ;
  455. ; Get pointer past end of block (Param2+1).
  456. ;
  457. MOV BX,Param2
  458. INC BX
  459. CALL FINDLIN
  460. ;
  461. ; Set up pointers. Compute number of chars to move.
  462. ;
  463. MOV SI,DI ; move from second line+1
  464. POP DI ; restore destination (first line)
  465. POP Current ; Current line is first param
  466. MOV Pointer,DI ; internal current line
  467. MOV CX,EndTxt ; compute count
  468. SUB CX,SI
  469. JB ComErrJ ; should never occur: ChkRange
  470. INC CX ; remember ^Z at end
  471. CLD
  472. REP MOVSB ; move data
  473. DEC DI
  474. MOV EndTxt,DI ; reset end pointer
  475. return
  476. COMERRJ:
  477. JMP COMERR
  478. PAGER:
  479. CMP ParamCt,2
  480. JA ComErrJ
  481. xor bx,bx ;get last line in the buffer
  482. call findlin
  483. mov [lastlin],dx
  484. mov bx,[param1]
  485. or bx,bx ;was it specified?
  486. jnz frstok ;yes, use it
  487. mov bx,[current]
  488. cmp bx,1 ;if current line =1 start from there
  489. je frstok
  490. inc bx ;start from current+1 line
  491. frstok:
  492. cmp bx,[lastlin] ;check that we are in the buffer
  493. jbe frstok1
  494. return ;if not just quit
  495. frstok1:
  496. mov dx,[param2]
  497. or dx,dx ;was param2 specified?
  498. jnz scndok ;yes,....
  499. mov dx,bx ;no, take the end line to be the
  500. ; start line + length of active display
  501. ;=========================================================================
  502. ; This modification is to provide support for screens larger than
  503. ; 24 lines.
  504. ;
  505. ; Date : 6/10/87
  506. ;=========================================================================
  507. push ax ;an000;save affected registers
  508. mov ah,00h ;an000;zero out high byte
  509. mov al,dg:disp_len ;an000;set ax to active display length
  510. sub ax,2 ;an000;adjust for length of screen & current
  511. ; line
  512. add dx,ax ;an000;this gives us the last line to be
  513. ; printed
  514. pop ax ;an000;restore affected registers
  515. ;=========================================================================
  516. scndok:
  517. inc dx
  518. cmp dx,[lastlin] ;check that we are in the buffer
  519. jbe infile
  520. mov dx,[lastlin] ;we are not, take the last line as end
  521. infile:
  522. cmp dx,bx ;is param1 < param2 ?
  523. retz
  524. ja sj33
  525. jmp comerr ;yes, no backwards listing, print error
  526. sj33:
  527. push dx ;save the end line
  528. push bx ;save start line
  529. mov bx,dx ;set the current line
  530. dec bx
  531. call findlin
  532. mov [pointer],di
  533. mov [current],dx
  534. pop bx ;restore start line
  535. call findlin ;get pointer to start line
  536. mov si,di ;save pointer
  537. pop di ;get end line
  538. sub di,bx ;number of lines
  539. jmp short display_lines
  540. LIST:
  541. CMP ParamCt,2
  542. JBE ListOK
  543. JMP ComERR
  544. ListOK:
  545. MOV BX,[PARAM1]
  546. OR BX,BX
  547. JNZ CHKP2
  548. MOV BX,[CURRENT]
  549. SUB BX,11
  550. JA CHKP2
  551. MOV BX,1
  552. CHKP2:
  553. CALL FINDLIN
  554. retnz
  555. MOV SI,DI
  556. MOV DI,[PARAM2]
  557. INC DI
  558. SUB DI,BX
  559. JA DISPLAY_lines
  560. ;=========================================================================
  561. ; This modification is to provide support for screens larger than
  562. ; 24 lines.
  563. ;
  564. ; Date : 6/10/87
  565. ;=========================================================================
  566. push ax ;an000;save affected registers
  567. mov ah,00h ;an000;zero out high byte
  568. mov al,dg:disp_len ;an000;set ax to active display length dec ax ;an000;allow room at bottom for
  569. ; messages
  570. mov di,ax ;an000;number of lines to print an
  571. ; entire screen less 1.
  572. pop ax ;an000;restore affected registers
  573. ;=========================================================================
  574. display_lines:
  575. call DISPLAY
  576. return
  577. Break <NOCOM - edit a single line>
  578. ;
  579. ; NOCOM is called when there is a single line being edited. This occurs when
  580. ; the command letter is CR or is ;.
  581. ;
  582. NOCOM:
  583. CMP ParamCt,2
  584. JB NoComOK
  585. JMP ComErr
  586. NoComOK:
  587. DEC [COMLINE]
  588. MOV BX,[PARAM1]
  589. OR BX,BX
  590. JNZ HAVLIN
  591. MOV BX,[CURRENT]
  592. INC BX ;Default is current line plus one
  593. CALL CHKRANGE
  594. HAVLIN:
  595. CALL FINDLIN
  596. MOV SI,DI
  597. MOV [CURRENT],DX
  598. MOV [POINTER],SI
  599. jz sj12
  600. ret12: return
  601. sj12:
  602. CMP SI,[ENDTXT]
  603. retz
  604. CALL LOADBUF
  605. MOV [OLDLEN],DX
  606. MOV SI,[POINTER]
  607. CALL DISPONE
  608. CALL SHOWNUM
  609. MOV AH,STD_CON_STRING_INPUT ;Get input buffer
  610. MOV DX,OFFSET DG:EDITBUF
  611. INT 21H
  612. CALL lf
  613. MOV CL,[EDITBUF+1]
  614. MOV CH,0
  615. JCXZ RET12
  616. MOV DX,[OLDLEN]
  617. MOV SI,2 + OFFSET DG:EDITBUF
  618. ;-----------------------------------------------------------------------
  619. call unquote ;scan for quote chars if any
  620. ;-----------------------------------------------------------------------
  621. mov cl,[EditBuf+1] ;an000; dms;get new line length
  622. mov ch,0 ;an000; dms;clear high byte
  623. MOV DI,[POINTER]
  624. JMP Replace ; MZ 11/30
  625. CODE ENDS
  626. END
  627.