home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / tnylib.lzh / UNGETC.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-11-14  |  1006 b   |  50 lines

  1. include compiler.inc
  2.  
  3.     ttl    UNGETC, 1.05, 11-14-86, jwk
  4.  
  5. ;single character stream pushback
  6.  
  7. UGC    equ    word ptr [si]
  8. MODE    equ    byte ptr 2[si]
  9. CRFLG    equ    byte ptr 3[si]
  10. ERCODE    equ    byte ptr 4[si]
  11.  
  12. EOF    equ    -1
  13.  
  14. RDBIT    equ    1
  15. WRTBIT    equ    2
  16. RAWBIT    equ    4
  17. EOFBIT    equ    8
  18. ERRBIT    equ    16
  19.  
  20.     dseg
  21.     cseg
  22.  
  23.     xtfs    <$strhand>
  24.  
  25.     procdef    ungetc, <<chr, word>, <streamp, ptr>>
  26.     pushreg
  27.     callit    $strhand <<streamp, ptr>>
  28.     inc    ax
  29.     jz    reteof            ; bad stream pointer
  30.     ldptr    si, streamp
  31.     test    bl, RDBIT
  32.     jz    seterr            ; not open for reading
  33.     test    bl, EOFBIT + ERRBIT
  34.     jnz    reteof            ; error or EOF set
  35.     inc    cx            ; is there already one there?
  36.     jnz    reteof            ; yup - report error
  37.     mov    ax, chr            ; no - get this one
  38.     inc    ax            ; is it EOF?
  39.     jz    reteof            ; yes - do nuthin'
  40.     dec    ax            ; no, undo test
  41.     mov    UGC, ax            ; put it there
  42.     mov    CRFLG, 0        ; clear CR flag byte
  43.     jmp    short retval
  44. seterr:    or    MODE, ERRBIT        ; set error flag in stream
  45. reteof:    mov    ax, EOF            ; return EOF
  46. retval:    pret
  47.     pend    ungetc
  48.  
  49.     finish
  50.