1 ; SCCSID = @(#)strin.asm 1.2 85/04/18
5 ; DS:DX Point to an input buffer
7 ; Fill buffer from console input until CR
11 procedure $STD_CON_STRING_INPUT
,NEAR ;System call 10
12 ASSUME
DS:NOTHING
,ES:NOTHING
20 ; AL is the buffer length
21 ; AH is the template length
24 retz
;Buffer is 0 length!!?
25 MOV BL,AH ;Init template counter
26 MOV BH,CH ;Init template counter
28 ; BL is the number of bytes in the template
31 JBE NOEDIT
;If length of buffer inconsistent with contents
32 CMP BYTE PTR [BX+SI],c_CR
33 JZ EDITON
;If CR correctly placed EDIT is OK
35 ; The number of chars in the template is >= the number of chars in buffer or
36 ; there is no CR at the end of the template. This is an inconsistant state
37 ; of affairs. Pretend that the template was empty:
40 MOV BL,CH ;Reset buffer
43 DEC DX ;DL is # of bytes we can put in the buffer
45 ; Top level. We begin to read a line in.
49 MOV [STARTPOS
],AL ;Remember position in raw buffer
51 MOV DI,OFFSET DOSGROUP
:INBUF
;Build the new line here
52 MOV [INSMODE
],CH ;Insert mode off
53 MOV BH,CH ;No chars from template yet
54 MOV DH,CH ;No chars to new line yet
55 invoke $STD_CON_INPUT_NO_ECHO
;Get first char
57 JNZ GOTCH
;Filter out LF so < works
59 ; This is the main loop of reading in a character and processing it.
61 ; BH is the index of the next byte in the template
62 ; BL is the length of the template
63 ; DH is the number of bytes in the buffer
64 ; DL is the length of the buffer
67 invoke $STD_CON_INPUT_NO_ECHO
70 ; Brain-damaged TP ignored ^F in case his BIOS did not flush the
76 ; If the leading char is the function-key lead byte
79 JZ ESCape
;change reserved keyword DBM 5-7-87
81 ; Rubout and ^H are both destructive backspaces.
88 ; ^W deletes backward once and then backs up until a letter is before the
92 ; The removal of the comment characters before the jump statement will
93 ; cause ^W to backup a word.
98 ; The removal of the comment characters before the jump statement will
99 ; cause ^U to clear a line.
105 ; CR terminates the line.
110 ; LF goes to a new line and keeps on reading.
115 ; ^X (or ESC) deletes the line and starts over
120 ; Otherwise, we save the input character.
124 JAE BUFFUL
; buffer is full.
126 INC DH ; increment count in buffer.
127 invoke BUFOUT
;Print control chars nicely
128 CMP BYTE PTR [INSMODE
],0
129 JNZ GETCH
; insertmode => don't advance template
131 JAE GETCH
; no more characters in template
132 INC SI ; Skip to next char in template
133 INC BH ; remember position in template
136 BACKSPJ: JMP SHORT BACKSP
139 MOV AL,7 ; Bell to signal full buffer
143 ESCape: ;change reserved keyword DBM 5-7-87
144 transfer OEMFunctionKey
; let the OEM's handle the key dispatch
147 STOSB ; Put the CR in the buffer
148 invoke OUTT
; Echo it
149 POP DI ; Get start of user buffer
150 MOV [DI-1],DH ; Tell user how many bytes
151 INC DH ; DH is length including CR
154 RestoreReg
<DS,ES> ; XCHG ES,DS
155 MOV SI,OFFSET DOSGROUP
:INBUF
156 MOV CL,DH ; set up count
157 REP MOVSB ; Copy final line to user buffer
160 ; Output a CRLF to the user screen and do NOT store it into the buffer
167 ; Delete the previous line
176 ; delete the previous word.
180 Call BackSpace
; backspace the one spot
196 ; The user wants to throw away what he's typed in and wants to start over. We
197 ; print the backslash and then go to the next line and tab to the correct spot
198 ; to begin the buffered input.
202 invoke OUTT ;Print the CANCEL indicator
203 POP SI ;Remember start of edit buffer
205 invoke CRLF ;Go to next line on screen
208 JMP NEWLIN ;Start over again
212 ; Destructively back up one character position
220 JZ OLDBAK ;No chars in line, do nothing to line
221 CALL BACKUP ;Do the backup
222 MOV AL,ES:[DI] ;Get the deleted char
224 JAE OLDBAK ;Was a normal char
226 JZ BAKTAB ;Was a tab, fix up users display
227 ;; 9/27/86 fix for ctrl-U backspace
228 CMP AL,"U
"-"@
" ; ctrl-U is a section symbol not ^U
230 CMP AL,"T
"-"@
" ; ctrl-T is a paragraphs symbol not ^T
232 ;; 9/27/86 fix for ctrl-U backspace
233 CALL BACKMES ;Was a control char, zap the '^'
235 CMP BYTE PTR [INSMODE],0
236 retnz ;In insert mode, done
238 retz ;Not advanced in template, stay where we are
239 DEC BH ;Go back in template
245 DEC DI ;Back up one char
247 MOV CL,DH ;Number of chars currently in line
251 JCXZ FIGTAB ;At start, do nothing
255 CMP BYTE PTR ES:[DI+1],9
256 JZ HAVTAB ;Found a tab
257 DEC BL ;Back one char if non tab control char
265 AND CL,7 ;CX has correct number to erase
269 JZ OLDBAK ;Nothing to erase
272 LOOP TABBAK ;Erase correct number of chars
276 DEC DH ;Back up in line
279 MOV AL,c_BS ;Backspace
283 MOV AL,c_BS ;Backspace
286 ;User really wants an ESC character in his line
291 ;Copy the rest of the template
293 MOV CL,BL ;Total size of template
294 SUB CL,BH ;Minus position in template, is number to move
298 invoke FINDOLD ;Find the char
299 JMP SHORT COPYEACH ;Copy up to it
301 ;Copy one char from template to line
304 ;Copy CX chars from template to line
306 MOV BYTE PTR [INSMODE],0 ;All copies turn off insert mode
308 JZ GETCH2 ;At end of line, can't do anything
310 JZ GETCH2 ;At end of template, can't do anything
314 INC BH ;Ahead in template
315 INC DH ;Ahead in line
320 ;Skip one char in template
323 JZ GETCH2 ;At end of template
324 INC BH ;Ahead in template
329 invoke FINDOLD ;Find out how far to go
334 ;Get the next user char, and look ahead in template for a match
335 ;CX indicates how many chars to skip to get there on output
336 ;NOTE: WARNING: If the operation cannot be done, the return
337 ; address is popped off and a jump to GETCH is taken.
338 ; Make sure nothing extra on stack when this routine
339 ; is called!!! (no PUSHes before calling it).
341 invoke $STD_CON_INPUT_NO_ECHO
342 CMP AL,[ESCCHAR] ; did he type a function key?
343 JNZ FindSetup ; no, set up for scan
344 invoke $STD_CON_INPUT_NO_ECHO ; eat next char
345 JMP NotFnd ; go try again
348 SUB CL,BH ;CX is number of chars to end of template
349 JZ NOTFND ;At end of template
350 DEC CX ;Cannot point past end, limit search
351 JZ NOTFND ;If only one char in template, forget it
356 MOV DI,SI ;Template to ES:DI
361 JNZ NOTFND ;Didn't find the char
362 NOT CL ;Turn how far to go into how far we went
363 ADD CL,BL ;Add size of template
364 SUB CL,BH ;Subtract current pos, result distance to skip
368 POP BP ;Chuck return address
372 MOV AL,"@
" ;Output re-edit character
378 invoke COPYNEW ;Copy current line into template
382 MOV BL,DH ;Size of line is new size template
383 JMP PUTNEW ;Start over again
387 NOT BYTE PTR [INSMODE]
390 ;Put a real live ^Z in the buffer (embedded)
402 EndProc $STD_CON_STRING_INPUT