pike.git / src / operators.c

version» Context lines:

pike.git/src/operators.c:1:   /*\   ||| This file a part of Pike, and is copyright by Fredrik Hubinette   ||| Pike is distributed as GPL (General Public License)   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h"   #include <math.h> - RCSID("$Id: operators.c,v 1.40 1998/09/18 21:34:28 hubbe Exp $"); + RCSID("$Id: operators.c,v 1.41 1998/10/11 11:18:52 hubbe Exp $");   #include "interpret.h"   #include "svalue.h"   #include "multiset.h"   #include "mapping.h"   #include "array.h"   #include "stralloc.h"   #include "opcodes.h"   #include "operators.h"   #include "language.h"   #include "pike_memory.h"
pike.git/src/operators.c:134:    PIKE_ERROR("`+", "Bad argument 1\n", sp, args);    }    PIKE_ERROR("`+", "Incompatible types\n", sp, args);    return; /* compiler hint */       case BIT_STRING:    {    struct pike_string *r;    char *buf;    INT32 tmp; +  int max_shift=0;    -  switch(args) -  { -  case 1: return; -  default: +  if(args==1) return; +     size=0; -  for(e=-args;e<0;e++) size+=sp[e].u.string->len; +  for(e=-args;e<0;e++) +  { +  size+=sp[e].u.string->len; +  if(sp[e].u.string->size_shift > max_shift) +  max_shift=sp[e].u.string->size_shift; +  }       tmp=sp[-args].u.string->len; -  r=realloc_shared_string(sp[-args].u.string,size); +  r=new_realloc_shared_string(sp[-args].u.string,size,max_shift);    sp[-args].type=T_INT; -  buf=r->str+tmp; +  buf=r->str+(tmp<<max_shift);    for(e=-args+1;e<0;e++)    { -  MEMCPY(buf,sp[e].u.string->str,sp[e].u.string->len); -  buf+=sp[e].u.string->len; +  pike_string_cpy(buf,max_shift,sp[e].u.string); +  buf+=sp[e].u.string->len << max_shift;    }    sp[-args].u.string=end_shared_string(r);    sp[-args].type=T_STRING;    for(e=-args+1;e<0;e++) free_string(sp[e].u.string);    sp-=args-1; -  } +        break;    }       case BIT_STRING | BIT_INT:    case BIT_STRING | BIT_FLOAT:    case BIT_STRING | BIT_FLOAT | BIT_INT:    {    struct pike_string *r; -  char *buf,*str; +  char *buf; +  char buffer[50]; +  int max_shift=0;    size=0;    for(e=-args;e<0;e++)    {    switch(sp[e].type)    {    case T_STRING:    size+=sp[e].u.string->len; -  +  if(sp[e].u.string->size_shift > max_shift) +  max_shift=sp[e].u.string->size_shift;    break;       case T_INT:    size+=14;    break;       case T_FLOAT:    size+=22;    break;    }    } -  str=buf=xalloc(size+1); +  +  r=begin_wide_shared_string(size,max_shift); +  buf=r->str;    size=0;       for(e=-args;e<0;e++)    {    switch(sp[e].type)    {    case T_STRING: -  MEMCPY(buf,sp[e].u.string->str,sp[e].u.string->len); -  buf+=sp[e].u.string->len; +  pike_string_cpy(buf,max_shift,sp[e].u.string); +  buf+=sp[e].u.string->len<<max_shift;    break;       case T_INT: -  sprintf(buf,"%ld",(long)sp[e].u.integer); -  buf+=strlen(buf); -  break; +  sprintf(buffer,"%ld",(long)sp[e].u.integer); +  goto append_buffer;       case T_FLOAT: -  sprintf(buf,"%f",(double)sp[e].u.float_number); -  buf+=strlen(buf); -  break; +  sprintf(buffer,"%f",(double)sp[e].u.float_number); +  append_buffer: +  switch(max_shift) +  { +  case 0: convert_0_to_0((p_wchar0 *)buf,buffer,strlen(buffer)); break; +  case 1: convert_0_to_1((p_wchar1 *)buf,buffer,strlen(buffer)); break; +  case 2: convert_0_to_2((p_wchar2 *)buf,buffer,strlen(buffer)); break;    } -  +  buf+=strlen(buffer)<<max_shift;    } -  r=make_shared_binary_string(str,buf-str); -  free(str); +  } +  r->len=(buf-r->str)>>max_shift; +  low_set_index(r,r->len,0); +  r=end_shared_string(r);    pop_n_elems(args);    push_string(r);    break;    }       case BIT_INT:    size=0;    for(e=-args; e<0; e++) size+=sp[e].u.integer;    sp-=args-1;    sp[-1].u.integer=size;
pike.git/src/operators.c:1718:    if(from==0) return;    to=sp[-1].u.string->len-1;       if(from>to+1) from=to+1;    }   #ifdef DEBUG    if(from < 0 || (to-from+1) < 0)    fatal("Error in o_range.\n");   #endif    -  s=make_shared_binary_string(sp[-1].u.string->str+from,to-from+1); +  s=string_slice(sp[-1].u.string, from, to-from+1);    free_string(sp[-1].u.string);    sp[-1].u.string=s;    break;    }       case T_ARRAY:    {    struct array *a;    if(to>=sp[-1].u.array->size-1)    {