Re: unbuffered getc() ?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Chris,

  I used the following functions to bypass Euphoria's buffering.  I
don't know if they'll work for your situation, but give them a try and
let me know.

Michael J. Sabal

------ code follows ---------

function old_getc(object z)
  return getc(z)
end function

function getc(integer z)

  object temp

  if length(inbuffer)<100 then
    inbuffer = inbuffer & get_bytes(z,4096)
  end if
  if length(inbuffer)=0 then
    return 0
  end if
  temp = inbuffer[1]
  if length(inbuffer)>1 then
    inbuffer = inbuffer[2..length(inbuffer)]
  else
    if temp = 26 then temp = 0 end if -- if the only char in the buffer
is CTRL-Z, call it end of file.
    inbuffer = ""
  end if
  return temp

end function

--------- end code -------------

>>> tubby.toast at ntlworld.com 05/12/03 04:00PM >>>
line
feed or an EOF.  So my question (if you've read this far): how can I
get a
Euphoria program to read a single byte, immediately and without dealing
with
buffers, from a file descriptor.  Is there a standard C function I can
easily wrap? (I'm not very good with C)

I hope that made some sort of sense,
chris.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu