home *** CD-ROM | disk | FTP | other *** search
- include compiler.inc
-
- ttl UNGETC, 1.05, 11-14-86, jwk
-
- ;single character stream pushback
-
- UGC equ word ptr [si]
- MODE equ byte ptr 2[si]
- CRFLG equ byte ptr 3[si]
- ERCODE equ byte ptr 4[si]
-
- EOF equ -1
-
- RDBIT equ 1
- WRTBIT equ 2
- RAWBIT equ 4
- EOFBIT equ 8
- ERRBIT equ 16
-
- dseg
- cseg
-
- xtfs <$strhand>
-
- procdef ungetc, <<chr, word>, <streamp, ptr>>
- pushreg
- callit $strhand <<streamp, ptr>>
- inc ax
- jz reteof ; bad stream pointer
- ldptr si, streamp
- test bl, RDBIT
- jz seterr ; not open for reading
- test bl, EOFBIT + ERRBIT
- jnz reteof ; error or EOF set
- inc cx ; is there already one there?
- jnz reteof ; yup - report error
- mov ax, chr ; no - get this one
- inc ax ; is it EOF?
- jz reteof ; yes - do nuthin'
- dec ax ; no, undo test
- mov UGC, ax ; put it there
- mov CRFLG, 0 ; clear CR flag byte
- jmp short retval
- seterr: or MODE, ERRBIT ; set error flag in stream
- reteof: mov ax, EOF ; return EOF
- retval: pret
- pend ungetc
-
- finish
-