private static void rgc_buffer_reserve_space(input_port p, int amount)
{
int bufsize = p.bufsiz;
int bufpos = p.bufpos;
int matchstop = p.matchstop;
if ( matchstop >= amount ) return;
if ( (matchstop + (bufsize - (bufpos-1))) >= amount ) {
// shift the buffer to the right
int diff = amount - matchstop;
bcopy( p.buffer, matchstop, p.buffer, amount, bufpos-1 - matchstop);
p.bufpos += diff;
p.matchstop += diff;
} else {
p.rgc_double_buffer();
rgc_buffer_reserve_space(p, amount);
}
}