bit_read_RC (Bit_Chain *dat)
{
  unsigned char result;
  unsigned char byte;

  if (dat->byte >= dat->size)
    {
      loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
      LOG_ERROR ("%s buffer overflow at %lu", __FUNCTION__, dat->byte)
#ifdef DWG_ABORT
      if (++errors > DWG_ABORT_LIMIT)
        abort();
#endif
      return 0;
    }
  byte = dat->chain[dat->byte];
  if (dat->bit == 0)
    result = byte;
  else
    {
      result = byte << dat->bit;
      if (dat->byte < dat->size - 1)
        {
          byte = dat->chain[dat->byte + 1];
          result |= byte >> (8 - dat->bit);
        }
      else
        {
          loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
          LOG_ERROR ("%s buffer overflow at %lu", __FUNCTION__, dat->byte + 1)
          return 0;
        }
    }

  bit_advance_position (dat, 8);
  return ((unsigned char)result);
}
bit_read_RC (Bit_Chain *dat)
{
  unsigned char result;
  unsigned char byte;

  if (dat->byte >= dat->size)
    {
      loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
      LOG_ERROR ("%s buffer overflow at %lu", __FUNCTION__, dat->byte)
#ifdef DWG_ABORT
      if (++errors > DWG_ABORT_LIMIT)
        abort();
#endif
      return 0;
    }
  byte = dat->chain[dat->byte];
  if (dat->bit == 0)
    result = byte;
  else
    {
      result = byte << dat->bit;
      if (dat->byte < dat->size - 1)
        {
          byte = dat->chain[dat->byte + 1];
          result |= byte >> (8 - dat->bit);
        }
      else
        {
          loglevel = dat->opts & DWG_OPTS_LOGLEVEL;
          LOG_ERROR ("%s buffer overflow at %lu", __FUNCTION__, dat->byte + 1)
          return 0;
        }
    }

  bit_advance_position (dat, 8);
  return ((unsigned char)result);
}