Exemplo n.º 1
0
/* return pointer to copy of substitution template in the command buffer */
static char *extract_subst_template( const char **ibufpp, const char isglobal )
  {
  int i = 0, n = 0;
  char c;
  const char delimiter = **ibufpp;

  ++(*ibufpp);
  if( **ibufpp == '%' && (*ibufpp)[1] == delimiter )
    {
    ++(*ibufpp);
    if( !stbuf ) set_error_msg( "No previous substitution" );
    return stbuf;
    }
  while( **ibufpp != delimiter )
    {
    if( !resize_buffer( &stbuf, &stbufsz, i + 2 ) ) return 0;
    c = stbuf[i++] = *(*ibufpp)++;
    if( c == '\n' && **ibufpp == 0 ) { --i, --(*ibufpp); break; }
    if( c == '\\' && ( stbuf[i++] = *(*ibufpp)++ ) == '\n' && !isglobal )
      {
      while( ( *ibufpp = get_tty_line( &n ) ) &&
             ( n == 0 || ( n > 0 && (*ibufpp)[n-1] != '\n' ) ) )
        clearerr( stdin );
      if( !(*ibufpp) ) return 0;
      }
    }
  if( !resize_buffer( &stbuf, &stbufsz, i + 1 ) ) return 0;
  stbuf[stlen = i] = 0;
  return stbuf;
  }
Exemplo n.º 2
0
/* modify text according to a substitution template; return offset to
   end of modified text */
static int apply_subst_template( const char *boln, const regmatch_t *rm, int off,
                                 const int re_nsub )
  {
  const char *sub = stbuf;

  for( ; sub - stbuf < stlen; ++sub )
    {
    int n;
    if( *sub == '&' )
      {
      int j = rm[0].rm_so; int k = rm[0].rm_eo;
      if( !resize_buffer( &rbuf, &rbufsz, off + k - j ) ) return -1;
      while( j < k ) rbuf[off++] = boln[j++];
      }
    else if( *sub == '\\' && *++sub >= '1' && *sub <= '9' &&
             ( n = *sub - '0' ) <= re_nsub )
      {
      int j = rm[n].rm_so; int k = rm[n].rm_eo;
      if( !resize_buffer( &rbuf, &rbufsz, off + k - j ) ) return -1;
      while( j < k ) rbuf[off++] = boln[j++];
      }
    else
      {
      if( !resize_buffer( &rbuf, &rbufsz, off + 1 ) ) return -1;
      rbuf[off++] = *sub;
      }
    }
  if( !resize_buffer( &rbuf, &rbufsz, off + 1 ) ) return -1;
  rbuf[off] = 0;
  return off;
  }
Exemplo n.º 3
0
/* replace a range of lines with the joined text of those lines */
bool join_lines( const int from, const int to, const bool isglobal )
  {
  static char * buf = 0;
  static int bufsz = 0;
  int size = 0;
  line_t * const ep = search_line_node( inc_addr( to ) );
  line_t * bp = search_line_node( from );

  while( bp != ep )
    {
    const char * const s = get_sbuf_line( bp );
    if( !s || !resize_buffer( &buf, &bufsz, size + bp->len ) ) return false;
    memcpy( buf + size, s, bp->len );
    size += bp->len;
    bp = bp->q_forw;
    }
  if( !resize_buffer( &buf, &bufsz, size + 2 ) ) return false;
  memcpy( buf + size, "\n", 2 );
  size += 2;
  if( !delete_lines( from, to, isglobal ) ) return false;
  current_addr_ = from - 1;
  disable_interrupts();
  if( !put_sbuf_line( buf, size, current_addr_ ) ||
      !push_undo_atom( UADD, current_addr_, current_addr_ ) )
    { enable_interrupts(); return false; }
  modified_ = true;
  enable_interrupts();
  return true;
  }
Exemplo n.º 4
0
Arquivo: file.c Projeto: nielssp/ctodo
/* Read until the next space, '=', EOL, or EOF. Escape using backslash. */
char *read_option_string(STREAM *file) {
  int buffersize = 10;
  int c, i = 0;
  char *newbuffer = NULL;
  char *buffer = (char *)malloc(buffersize);
  while ((c = stream_getc(file)) != EOF && c != '\n' && c != '=' && c > ' ') {
    if (c == '\\') {
      c = stream_getc(file);
      if (c == EOF) {
        break;
      }
    }
    buffer[i++] = c;
    if (i >= buffersize) {
      newbuffer = resize_buffer(buffer, buffersize, buffersize + buffersize);
      if (!newbuffer) {
        free(buffer);
        return NULL;
      }
      buffer = newbuffer;
      buffersize += buffersize;
    }
  }
  stream_ungetc(c, file);
  buffer[i] = 0;
  return buffer;
}
Exemplo n.º 5
0
void Fl_Device::rtl_draw(const char *str, int n, float x, float y)
{
	// USE BUFFER HERE ALSO
	SetTextColor(fl_gc, fl_colorref);
	SelectObject(fl_gc, current_font);

	int i = 0;
	int lx = 0;
	const WCHAR *skod;
	resize_buffer(n);
	int wn = fl_utf2unicode((const unsigned char *)str, n, wstr);

	while (i < wn) {
	    lx = int(fl_width(wstr[i]));
		x -= lx;
		skod = (const WCHAR*)wstr + i;
#ifndef _WIN32_WCE
		TextOutW(fl_gc, int(floor(x+.5f)), int(floor(y+.5f)), skod, 1);
#else
		RECT rect = {int(floor(x+.5f)),int(floor(y+.5f)), 0,0};
		DrawText(fl_gc, skod, 1, &rect, DT_SINGLELINE | DT_TOP | DT_LEFT | DT_NOCLIP);	
#endif
		if (fl_nonspacing(wstr[i])) {
			x += lx;
		}
		i++;
	}	
}
Exemplo n.º 6
0
/* get a line of text from the scratch file; return pointer to the text */
char * get_sbuf_line( const line_t * const lp )
  {
  static char * buf = 0;
  static int bufsz = 0;
  int len;

  if( lp == &buffer_head ) return 0;
  seek_write = true;			/* force seek on write */
  /* out of position */
  if( sfpos != lp->pos )
    {
    sfpos = lp->pos;
    if( fseek( sfp, sfpos, SEEK_SET ) != 0 )
      {
      show_strerror( 0, errno );
      set_error_msg( "Cannot seek temp file" );
      return 0;
      }
    }
  len = lp->len;
  if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return 0;
  if( (int)fread( buf, 1, len, sfp ) != len )
    {
    show_strerror( 0, errno );
    set_error_msg( "Cannot read temp file" );
    return 0;
    }
  sfpos += len;		/* update file position */
  buf[len] = 0;
  return buf;
  }
Exemplo n.º 7
0
bool CMonitorData::processHierarchyRequest( UdpConnection *con, short & sequence )
{
int x,size;
char temp[215];

	if( m_count == 0 )
	{
		send(con,sequence,MON_MSG_REPLY_HIERARCHY,"NOTREADY");
		return 0;
	}

	if( m_sort )
	{
		qsort(m_data,m_count,sizeof(MON_ELEMENT),compar);
		m_sort = 0;
	}

	memset(m_buffer,0, 16);

	size = 0;
	for(x=0;x<m_count;x++)
	{
		snprintf(temp, sizeof(temp), "%s,%X,%d|", m_data[x].label, m_data[x].id, m_data[x].ping);
		size += strlen(temp);
		if( size >= m_nbuffer )
			resize_buffer(size+BUFFER_RESIZE_VALUE);
		strcat(m_buffer,temp);
	}
	send(con,sequence,MON_MSG_REPLY_HIERARCHY,m_buffer);	
	return 1;
}
Exemplo n.º 8
0
int oa_serialize_buffer(struct oarchive *oa, const char *name,
        const struct buffer *b)
{
    struct buff_struct *priv = oa->priv;
    int rc;
    if (!b) {
        return oa_serialize_int(oa, "len", &negone);
    }
    rc = oa_serialize_int(oa, "len", &b->len);
    if (rc < 0)
        return rc;
    // this means a buffer of NUll 
    // with size of -1. This is 
    // waht we use in java serialization for NULL
    if (b->len == -1) {
      return rc;
    }
    if ((priv->len - priv->off) < b->len) {
        rc = resize_buffer(priv, priv->len + b->len);
        if (rc < 0)
            return rc;
    }
    memcpy(priv->buffer+priv->off, b->buff, b->len);
    priv->off += b->len;
    return 0;
}
Exemplo n.º 9
0
/* Return pointer to copy of filename in the command buffer */
static const char * get_filename( const char ** const ibufpp )
  {
  static char * buf = 0;
  static int bufsz = 0;
  const int pmax = path_max( 0 );
  int n;

  *ibufpp = skip_blanks( *ibufpp );
  if( **ibufpp != '\n' )
    {
    int size = 0;
    if( !get_extended_line( ibufpp, &size, true ) ) return 0;
    if( **ibufpp == '!' )
      {
      ++*ibufpp;
      return get_shell_command( ibufpp );
      }
    else if( size > pmax )
      { set_error_msg( "Filename too long" ); return 0; }
    }
  else if( !traditional() && !def_filename[0] )
    { set_error_msg( "No current filename" ); return 0; }
  if( !resize_buffer( &buf, &bufsz, pmax + 1 ) ) return 0;
  for( n = 0; **ibufpp != '\n'; ++n, ++*ibufpp ) buf[n] = **ibufpp;
  buf[n] = 0;
  while( **ibufpp == '\n' ) ++*ibufpp;			/* skip newline */
  return ( may_access_filename( buf ) ? buf : 0 );
  }
Exemplo n.º 10
0
static void OutCharMem(R_outpstream_t stream, int c)
{
    membuf_t mb = (membuf_t) stream->data;
    if (mb->count >= mb->size)
	resize_buffer(mb, mb->count + 1);
    mb->buf[mb->count++] = (char) c;
}
Exemplo n.º 11
0
/* copy a pattern string from the command buffer; return pointer to the copy */
static char *extract_pattern( const char **ibufpp, const int delimiter )
  {
  static char *buf = 0;
  static int bufsz = 0;
  const char *nd = *ibufpp;
  int len;

  while( *nd != delimiter && *nd != '\n' )
    {
    if( *nd == '[' )
      {
      nd = parse_char_class( ++nd );
      if( !nd ) { set_error_msg( "Unbalanced brackets ([])" ); return 0; }
      }
    else if( *nd == '\\' && *++nd == '\n' )
      { set_error_msg( "Trailing backslash (\\)" ); return 0; }
    ++nd;
    }
  len = nd - *ibufpp;
  if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return 0;
  memcpy( buf, *ibufpp, len );
  buf[len] = 0;
  *ibufpp = nd;
  if( isbinary() ) nul_to_newline( buf, len );
  return buf;
  }
Exemplo n.º 12
0
static int
send_buffer(char *aString, int32_t size, struct messaging *m)
{
  int free;
  int err = 0;
  pthread_mutex_lock(&m->mutex);

  if ((CEIL4(size) + 4) > m->capacity) {
    err = resize_buffer(m, size);
  }
  
  free = m->is_full
    ? 0 : (m->free_end - m->free_start + (m->free_start >= m->free_end ? m->capacity : 0));
  if ((CEIL4(size) + 4) > free) {
    err = resize_buffer(m, size);
  }

  if (!err) {
    int first_part_size, second_part_size;
    m->buffer[m->free_start/4] = size;

    m->free_start += 4;
    if (m->free_start == m->capacity) {
      m->free_start = 0;
    }
    
    first_part_size = (size < m->capacity - m->free_start)
      ? size : m->capacity - m->free_start;
    second_part_size = size - first_part_size > 0 ? size - first_part_size : 0;
    memcpy(&m->buffer[m->free_start/4], aString, first_part_size);
    m->free_start += CEIL4(first_part_size);
    if (second_part_size > 0) {
      //assert(b2s_free_start == b2s_capacity);
      m->free_start = 0;
      memcpy(&m->buffer[m->free_start/4], aString + first_part_size, second_part_size);
      m->free_start += CEIL4(second_part_size);
    }
    if (m->free_start == m->capacity) {
      m->free_start = 0;
    }
    if (m->free_start == m->free_end) {
      m->is_full = 1;
    }
  }
  pthread_mutex_unlock(&m->mutex);
  return err;
}
Exemplo n.º 13
0
/* replace text matched by a pattern according to a substitution
   template; return pointer to the modified text */
static int replace_matching_text( const line_t *lp, const int gflags,
                                  const int snum )
  {
  const int se_max = 30;	/* max subexpressions in a regular expression */
  regmatch_t rm[se_max];
  char *txt = get_sbuf_line( lp );
  char *eot;
  int i = 0, off = 0;
  char changed = 0;

  if( !txt ) return -1;
  if( isbinary() ) nul_to_newline( txt, lp->len );
  eot = txt + lp->len;
  if( !regexec( global_pat, txt, se_max, rm, 0 ) )
    {
    int matchno = 0;
    do {
      if( !snum || snum == ++matchno )
        {
        changed = 1; i = rm[0].rm_so;
        if( !resize_buffer( &rbuf, &rbufsz, off + i ) ) return -1;
        if( isbinary() ) newline_to_nul( txt, rm[0].rm_eo );
        memcpy( rbuf + off, txt, i ); off += i;
        off = apply_subst_template( txt, rm, off, global_pat->re_nsub );
        if( off < 0 ) return -1;
        }
      else
        {
        i = rm[0].rm_eo;
        if( !resize_buffer( &rbuf, &rbufsz, off + i ) ) return -1;
        if( isbinary() ) newline_to_nul( txt, i );
        memcpy( rbuf + off, txt, i ); off += i;
        }
      txt += rm[0].rm_eo;
      }
    while( *txt && ( !changed || ( ( gflags & GSG ) && rm[0].rm_eo ) ) &&
           !regexec( global_pat, txt, se_max, rm, REG_NOTBOL ) );
    i = eot - txt;
    if( !resize_buffer( &rbuf, &rbufsz, off + i + 2 ) ) return -1;
    if( i > 0 && !rm[0].rm_eo && ( gflags & GSG ) )
      { set_error_msg( "Infinite substitution loop" ); return -1; }
    if( isbinary() ) newline_to_nul( txt, i );
    memcpy( rbuf + off, txt, i );
    memcpy( rbuf + off + i, "\n", 2 );
    }
  return ( changed ? off + i + 1 : 0 );
  }
Exemplo n.º 14
0
void
buffer_append(struct buffer *b, const char *bytes, int length)
{
	if (length >= (b->size - b->offset - 1))
		resize_buffer(b, length);

	memcpy(&b->buffer[b->offset], bytes, length);
	b->offset += length;
	b->buffer[b->offset] = '\0';  /* XXX - not too general, now is it? */
}
Exemplo n.º 15
0
void
buffer_append(struct buffer *b, const char *bytes, int length)
{
	if (length >= (b->size - b->offset))
		resize_buffer(b, length);

	/* XXX - assumes resize_buffer() always succeeds. */
	memcpy(&b->buffer[b->offset], bytes, length);
	b->offset += length;
}
Exemplo n.º 16
0
Arquivo: macroexp.c Projeto: 5kg/gdb
/* Append the LEN bytes at ADDR to the buffer B.  */
static void
appendmem (struct macro_buffer *b, char *addr, int len)
{
  int new_len = b->len + len;

  if (new_len > b->size)
    resize_buffer (b, new_len);

  memcpy (b->text + b->len, addr, len);
  b->len = new_len;
}
Exemplo n.º 17
0
Arquivo: macroexp.c Projeto: 5kg/gdb
/* Append the character C to the buffer B.  */
static void
appendc (struct macro_buffer *b, int c)
{
  int new_len = b->len + 1;

  if (new_len > b->size)
    resize_buffer (b, new_len);

  b->text[b->len] = c;
  b->len = new_len;
}
Exemplo n.º 18
0
struct growable_buffer
fdrecorder_get_clean(struct fdrecorder* fdr)
{
    fdrecorder_poll(fdr);
    struct growable_buffer buffer = fdr->buffer;
    assert(fdr->nr_bytes_recorded <= buffer.bufsz);
    resize_buffer(&buffer, fdr->nr_bytes_recorded);
    memset(&fdr->buffer, 0, sizeof (fdr->buffer));
    fdr->nr_bytes_recorded = 0;
    return buffer;
}
Exemplo n.º 19
0
int oa_serialize_long(struct oarchive *oa, const char *tag, const int64_t *d)
{
    const int64_t i = htonll(*d);
    struct buff_struct *priv = oa->priv;
    if ((priv->len - priv->off) < sizeof(i)) {
        int rc = resize_buffer(priv, priv->len + sizeof(i));
        if (rc < 0) return rc;
    }
    memcpy(priv->buffer+priv->off, &i, sizeof(i));
    priv->off+=sizeof(i);
    return 0;
}
Exemplo n.º 20
0
/* return unescaped copy of escaped string */
const char * strip_escapes( const char * p )
  {
  static char * buf = 0;
  static int bufsz = 0;
  const int len = strlen( p );
  int i = 0;

  if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return 0;
  /* assert: no trailing escape */
  while( ( buf[i++] = ( (*p == '\\' ) ? *++p : *p ) ) )
    ++p;
  return buf;
  }
Exemplo n.º 21
0
static void OutBytesMem(R_outpstream_t stream, void *buf, int length)
{
    membuf_t mb = (membuf_t) stream->data;
    R_xlen_t needed = mb->count + (R_xlen_t) length;
    #ifndef LONG_VECTOR_SUPPORT
        /* There is a potential overflow here on 32-bit systems */
        if ((double) mb->count + length > (double) INT_MAX)
            error("serialization is too large to store in a raw vector");
    #endif
    if (needed > mb->size) resize_buffer(mb, needed);
    memcpy(mb->buf + mb->count, buf, length);
    mb->count = needed;
}
Exemplo n.º 22
0
int oa_serialize_bool(struct oarchive *oa, const char *name, const int32_t *i)
{
    //return oa_serialize_int(oa, name, i);
    struct buff_struct *priv = oa->priv;
    if ((priv->len - priv->off) < 1) {
        int rc = resize_buffer(priv, priv->len + 1);
        if (rc < 0)
            return rc;
    }
    priv->buffer[priv->off] = (*i == 0 ? '\0' : '\1');
    priv->off++;
    return 0;
}
Exemplo n.º 23
0
/* apply command list in the command buffer to the active lines in a
   range; return false if error */
static bool exec_global( const char ** const ibufpp, const int gflags,
                         const bool interactive )
  {
  static char * buf = 0;
  static int bufsz = 0;
  const char * cmd = 0;

  if( !interactive )
    {
    if( traditional() && !strcmp( *ibufpp, "\n" ) )
      cmd = "p\n";			/* null cmd_list == 'p' */
    else
      {
      if( !get_extended_line( ibufpp, 0, false ) ) return false;
      cmd = *ibufpp;
      }
    }
  clear_undo_stack();
  while( true )
    {
    const line_t * const lp = next_active_node();
    if( !lp ) break;
    set_current_addr( get_line_node_addr( lp ) );
    if( current_addr() < 0 ) return false;
    if( interactive )
      {
      /* print current_addr; get a command in global syntax */
      int len;
      if( !display_lines( current_addr(), current_addr(), gflags ) )
        return false;
      do { *ibufpp = get_tty_line( &len ); }
      while( *ibufpp && len > 0 && (*ibufpp)[len-1] != '\n' );
      if( !*ibufpp ) return false;
      if( len == 0 )
        { set_error_msg( "Unexpected end-of-file" ); return false; }
      if( len == 1 && !strcmp( *ibufpp, "\n" ) ) continue;
      if( len == 2 && !strcmp( *ibufpp, "&\n" ) )
        { if( !cmd ) { set_error_msg( "No previous command" ); return false; } }
      else
        {
        if( !get_extended_line( ibufpp, &len, false ) ||
            !resize_buffer( &buf, &bufsz, len + 1 ) ) return false;
        memcpy( buf, *ibufpp, len + 1 );
        cmd = buf;
        }
      }
    *ibufpp = cmd;
    while( **ibufpp ) if( exec_command( ibufpp, 0, true ) < 0 ) return false;
    }
  return true;
  }
Exemplo n.º 24
0
/* Return pointer to copy of shell command in the command buffer */
static const char * get_shell_command( const char ** const ibufpp )
  {
  static char * buf = 0;
  static int bufsz = 0;
  static char * shcmd = 0;		/* shell command buffer */
  static int shcmdsz = 0;		/* shell command buffer size */
  static int shcmdlen = 0;		/* shell command length */
  const char * p;			/* substitution char pointer */
  int i = 0, len;

  if( restricted() ) { set_error_msg( "Shell access restricted" ); return 0; }
  if( !get_extended_line( ibufpp, &len, true ) ) return 0;
  p = *ibufpp;
  if( !resize_buffer( &buf, &bufsz, len + 1 ) ) return 0;
  buf[i++] = '!';			/* prefix command w/ bang */
  while( **ibufpp != '\n' )
    {
    if( **ibufpp == '!' )
      {
      if( p != *ibufpp )
        {
        if( !resize_buffer( &buf, &bufsz, i + 1 ) ) return 0;
        buf[i++] = *(*ibufpp)++;
        }
      else if( !shcmd || ( traditional() && !*( shcmd + 1 ) ) )
        { set_error_msg( "No previous command" ); return 0; }
      else
        {
        if( !resize_buffer( &buf, &bufsz, i + shcmdlen ) ) return 0;
        for( p = shcmd + 1; p < shcmd + shcmdlen; ) buf[i++] = *p++;
        p = (*ibufpp)++;
        }
      }
    else if( **ibufpp == '%' )
      {
      if( !def_filename[0] )
        { set_error_msg( "No current filename" ); return 0; }
      p = strip_escapes( def_filename );
      len = strlen( p );
      if( !resize_buffer( &buf, &bufsz, i + len ) ) return 0;
      while( len-- ) buf[i++] = *p++;
      p = (*ibufpp)++;
      }
    else
      {
      if( !resize_buffer( &buf, &bufsz, i + 2 ) ) return 0;
      buf[i++] = **ibufpp;
      if( *(*ibufpp)++ == '\\' ) buf[i++] = *(*ibufpp)++;
      }
    }
  while( **ibufpp == '\n' ) ++*ibufpp;			/* skip newline */
  if( !resize_buffer( &shcmd, &shcmdsz, i + 1 ) ) return 0;
  memcpy( shcmd, buf, i );
  shcmdlen = i; shcmd[i] = 0;
  if( *p == '!' || *p == '%' ) printf( "%s\n", shcmd + 1 );
  return shcmd;
  }
Exemplo n.º 25
0
// ------------------   Game Data Object ----------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMonitorData::CMonitorData()
{

	m_sequence	= 1;
	m_buffer	= NULL;
	m_nbuffer	= 0;
	m_count		= 0;
	m_max		= ELEMENT_START_VALUE;
	m_data		= new MON_ELEMENT[m_max];
	for(int x=0;x<m_max;x++) 
	{
		memset(&m_data[x],0,sizeof(MON_ELEMENT));
	}
	resize_buffer(BUFFER_SIZE_START);
}
Exemplo n.º 26
0
static void fullscreen_cb(void)
{
	if (!isfullscreen)
	{
		window_geometry_valid = true;
		GetWindowRect(window, &window_geometry);
		write_window_geometry();
	}

	isfullscreen = !isfullscreen;
	if (isfullscreen)
		switch_to_full_screen();
	else
		switch_to_windowed();

	resize_buffer();
}
Exemplo n.º 27
0
void ci_cached_file_reset(ci_cached_file_t * body, int new_size)
{

     if (body->fd > 0) {
          do_close(body->fd);
          unlink(body->filename);       /*Comment out for debuging reasons */
     }

     body->endpos = 0;
     body->readpos = 0;
     body->flags = 0;
     body->unlocked = 0;
     body->fd = -1;

     if (!resize_buffer(body, new_size)) {
          /*free memory and open a file. */
     }
}
Exemplo n.º 28
0
FLAC__StreamDecoderWriteStatus flac_write(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data){

	flac_file_t* flac = (flac_file_t*)client_data;

    int samples = frame->header.blocksize;
    int channels = frame->header.channels;
    int bits_per_sample = frame->header.bits_per_sample;
    int i, j;

    //Create a buffer to hold the entire frame
    resize_buffer(flac, channels, samples);

    for (i = 0; i < channels; i++)
        for (j = 0; j < samples; j++)
        	//Convert interger to float using fixed-point arithmetic where the scaller is equal to the 2 to the power of the bits per sample
            flac->buf[i][j] = buffer[i][j] / (float) (1 << (bits_per_sample - 1));

    flac->buffer_sample_count = samples;

	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
Exemplo n.º 29
0
static void setfont_cb(void)
{
	CHOOSEFONT cf;
	memset(&cf, 0, sizeof(cf));
	cf.lStructSize = sizeof(cf);
	cf.hwndOwner = window;
	cf.lpLogFont = &fontlf;
	cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_FIXEDPITCHONLY | CF_SCREENFONTS;
	cf.nFontType = SCREEN_FONTTYPE;

	if (ChooseFont(&cf))
	{
		write_default_font();

		HDC dc = GetDC(window);
		glyphcache_deinit();
		glyphcache_init(dc, &fontlf);
		ReleaseDC(window, dc);

		resize_buffer();
	}
}
Exemplo n.º 30
0
int oa_serialize_string(struct oarchive *oa, const char *name, char **s)
{
    struct buff_struct *priv = oa->priv;
    int32_t len;
    int rc;
    if (!*s) {
        oa_serialize_int(oa, "len", &negone);
        return 0;
    }
    len = strlen(*s);
    rc = oa_serialize_int(oa, "len", &len);
    if (rc < 0)
        return rc;
    if ((priv->len - priv->off) < len) {
        rc = resize_buffer(priv, priv->len + len);
        if (rc < 0)
            return rc;
    }
    memcpy(priv->buffer+priv->off, *s, len);
    priv->off += len;
    return 0;
}