lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
# Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
# or when out of input.  When called, *have is the number of pattern bytes
# found in order so far, in 0..3.  On return *have is updated to the new
# state.  If on return *have equals four, then the pattern was found and the
# return value is how many bytes were read including the last byte of the
# pattern.  If *have is less than four, then the pattern has not been found
# yet and the return value is len.  In the latter case, syncsearch() can be
# called again with more data and the *have state.  *have is initialized to
# zero for the first call.
Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.  Return when found
or when out of input.  When called, *have is the number of pattern bytes
found in order so far, in 0..3.  On return *have is updated to the new
state.  If on return *have equals four, then the pattern was found and the
return value is how many bytes were read including the last byte of the
pattern.  If *have is less than four, then the pattern has not been found
yet and the return value is len.  In the latter case, syncsearch() can be
called again with more data and the *have state.  *have is initialized to
zero for the first call.
Search buf [ 0 .. len - 1 ] for the pattern : 0 0 0xff 0xff . Return when found or when out of input . When called * have is the number of pattern bytes found in order so far in 0 .. 3 . On return * have is updated to the new state . If on return * have equals four then the pattern was found and the return value is how many bytes were read including the last byte of the pattern . If * have is less than four then the pattern has not been found yet and the return value is len . In the latter case syncsearch () can be called again with more data and the * have state . * have is initialized to zero for the first call .
def syncsearch(have, buf, len)
    got = have
    _next = 0
    while (_next < len && got < 4)
        if ((buf[_next]) == (got < 2 ? 0 : 0xff))
            got+=1
        elsif buf[_next] != 0
            got = 0
        else
            got = 4 - got
        end
        _next+=1
    end
    have = got
    return [_next,have]
  end
def syncsearch ( have , buf , len ) got = have _next = 0 while ( _next < len && got < 4 ) if ( ( buf [ _next ] ) == ( got < 2 ? 0 : 0xff ) ) got += 1 elsif buf [ _next ] != 0 got = 0 else got = 4 - got end _next += 1 end have = got return [ _next , have ] end
Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff.
Search buf [ 0 .. len - 1 ] for the pattern : 0 0 0xff 0xff .
have
<not_specific>
buf
<not_specific>
len
<not_specific>