pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.42 2001/06/19 22:48:14 per Exp $ +  * $Id: builtin.cmod,v 1.43 2001/06/20 01:13:00 per Exp $    */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "opcodes.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"
pike.git/src/builtin.cmod:1094:    apply( res, "add", 1 );    RETURN res;    }       PIKEFUN object `+=( string what )    {    f_Buffer_add( 1 );    REF_RETURN fp->current_object;    }    -  PIKEFUN int add( string a ) - /*! @decl void add(string data) +  PIKEFUN int add( string ... arg1 ) + /*! @decl void add(string ... data)    *!    *! Adds @[data] to the buffer. Returns the size of the buffer.    *!    */    {    struct Buffer_struct *str = THIS;    size_t l; -  +  int j; +  struct pike_string *a;    -  +  for( j = 0; j<args; j++ ) +  { +  a = Pike_sp[-args+j].u.string; +  if( Pike_sp[-args+j].type != T_STRING ) +  Pike_error("Illegal argument %d, expected string\n", j );    if(!(l = (size_t)a->len) ) -  return; +  continue;    -  +     if( !str->size )    {    str->shift = a->size_shift;    str->size = str->initial +    (sizeof( struct pike_string ) - PIKE_STRING_STR_SIZE);    str->data = xalloc( str->size );    str->len = (sizeof( struct pike_string ) - PIKE_STRING_STR_SIZE);    }    else if( str->shift < a->size_shift )    {    /* This will not win the "most optimal code of the year"    award, but it works, and is rather fast. */    f_Buffer_get( 0 );    stack_swap();    f_add( 2 ); -  f_Buffer_add( 1 ); +  f_Buffer_add( args-j );    return;    }       l<<=str->shift;       while( str->size < ((unsigned)l+str->len) )    {    str->size *= 2;    str->data = realloc( str->data, str->size );    if( !str->data )    {    int sz = str->size;    str->len = 0;    str->size = 0;    Pike_error( "Malloc %d failed!\n", sz );    }    }    - #ifdef PIKE_DEBUG -  if( str->shift < a->size_shift ) -  fatal("Impossible!\n"); - #endif -  +     if( a->size_shift == str->shift )    MEMCPY( (str->data+str->len), a->str, l );    else    if( a->size_shift )    convert_1_to_2((p_wchar2 *)(str->data+str->len),    (p_wchar1 *)a->str, a->len);    else    if( str->shift & 1 )    convert_0_to_1((p_wchar1 *)(str->data+str->len),    (p_wchar0 *)a->str, a->len);    else    convert_0_to_2((p_wchar2 *)(str->data+str->len),    (p_wchar0 *)a->str, a->len);    str->len += l; -  RETURN str->len; +     } -  +  RETURN str->len-sizeof( struct pike_string )+PIKE_STRING_STR_SIZE; +  }       PIKEFUN string get_copy()    /*! @decl string get_copy()    *!    *! Get the data from the buffer. Significantly slower than @[get],    *! but does not clear the buffer.    */    {    struct Buffer_struct *str = THIS;    ptrdiff_t len = str->len-(sizeof(struct pike_string)-PIKE_STRING_STR_SIZE);