pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:8:   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "error.h"   #include "gc.h"   #include "stuff.h"      #include <ctype.h>    - RCSID("$Id: stralloc.c,v 1.46 1998/10/15 02:38:49 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.47 1998/10/22 00:33:33 hubbe Exp $");      #define BEGIN_HASH_SIZE 997   #define MAX_AVG_LINK_LENGTH 3   #define HASH_PREFIX 64      unsigned INT32 htable_size=0;   static unsigned int hashprimes_entry=0;   static struct pike_string **base_table=0;   static unsigned INT32 full_hash_value;   unsigned INT32 num_strings=0;
pike.git/src/stralloc.c:76:    return 2;   }      static INLINE unsigned INT32 generic_extract (const void *str, int size, int pos)   {    switch(size)    {    case 0: return ((unsigned char *)str)[pos];    case 1: return ((unsigned INT16 *)str)[pos];    case 2: return ((unsigned INT32 *)str)[pos]; -  default: +  }    fatal("Illegal shift size!\n"); -  +  return 0;   } - } +       INLINE unsigned INT32 index_shared_string(struct pike_string *s, int pos)   {   #ifdef DEBUG    if(pos > s->len || pos<0) {    if (s->len) {    fatal("String index %d is out of range [0 - %d]!\n", pos, s->len-1);    } else {    fatal("Attempt to index the empty string with %d!\n", pos);    }
pike.git/src/stralloc.c:502:    s=begin_shared_string(len);    MEMCPY(s->str, str, len);    link_pike_string(s, h);    }       add_ref(s);       return s;   }    - struct pike_string * debug_make_shared_binary_string1(const INT16 *str,int len) + struct pike_string * debug_make_shared_binary_string1(const p_wchar1 *str,int len)   {    struct pike_string *s;    int h;       if(!find_magnitude1(str,len))    {    /* Wrong size, convert */    s=begin_shared_string(len); -  convert_1_to_0(s->str,str,len); +  convert_1_to_0(STR0(s),str,len);    return end_shared_string(s);    }       h=low_do_hash(str, len, 1);       s = internal_findstring((char *)str,len,1,h);    if (!s)    {    s=begin_wide_shared_string(len,1);    MEMCPY(s->str, str, len<<1);    link_pike_string(s, h);    }       add_ref(s);       return s;   }    - struct pike_string * debug_make_shared_binary_string2(const INT32 *str,int len) + struct pike_string * debug_make_shared_binary_string2(const p_wchar2 *str,int len)   {    struct pike_string *s;    int h;       switch(find_magnitude2(str,len))    {    case 0:    /* Wrong size, convert */    s=begin_shared_string(len); -  convert_2_to_0(s->str,str,len); +  convert_2_to_0(STR0(s),str,len);    return end_shared_string(s);       case 1:    /* Wrong size, convert */    s=begin_wide_shared_string(len,1);    convert_2_to_1(STR1(s),str,len);    return end_shared_string(s); /* not entirely optimal */    }       h=low_do_hash(str, len, 2);
pike.git/src/stralloc.c:570:    add_ref(s);       return s;   }      struct pike_string *debug_make_shared_string(const char *str)   {    return make_shared_binary_string(str, strlen(str));   }    - struct pike_string *debug_make_shared_string1(const INT16 *str) + struct pike_string *debug_make_shared_string1(const p_wchar1 *str)   {    INT32 len;    for(len=0;str[len];len++);    return debug_make_shared_binary_string1(str,len);   }    - struct pike_string *debug_make_shared_string2(const INT32 *str) + struct pike_string *debug_make_shared_string2(const p_wchar2 *str)   {    INT32 len;    for(len=0;str[len];len++);    return debug_make_shared_binary_string2(str,len);   }      /*** Free strings ***/      void unlink_pike_string(struct pike_string *s)   {
pike.git/src/stralloc.c:1264:    switch(s->size_shift)    {    case 0:    return make_shared_binary_string(STR0(s)+start,len);       case 1:    return make_shared_binary_string1(STR1(s)+start,len);       case 2:    return make_shared_binary_string2(STR2(s)+start,len); -  -  default: +  }    fatal("Illegal shift size!\n"); -  +  return 0;   } - } +       /*** replace function ***/   struct pike_string *string_replace(struct pike_string *str,    struct pike_string *del,    struct pike_string *to)   {    struct pike_string *ret;    char *s,*tmp,*end;    PCHARP r;    int shift;
pike.git/src/stralloc.c:1625:    if(s->known_shift == s->s->size_shift)    return low_end_shared_string(s->s);    return end_shared_string(s->s);   }      PCHARP MEMCHR_PCHARP(PCHARP ptr, int chr, int len)   {    switch(ptr.shift)    {    case 0: return MKPCHARP(MEMCHR0(ptr.ptr,chr,len),0); -  case 1: return MKPCHARP(MEMCHR1(ptr.ptr,chr,len),1); -  case 2: return MKPCHARP(MEMCHR2(ptr.ptr,chr,len),2); -  default: +  case 1: return MKPCHARP(MEMCHR1((p_wchar1 *)ptr.ptr,chr,len),1); +  case 2: return MKPCHARP(MEMCHR2((p_wchar2 *)ptr.ptr,chr,len),2); +  }    fatal("Illegal shift in MEMCHR_PCHARP.\n"); -  +  return MKPCHARP(0,0); /* make wcc happy */   } - } +       #define DIGIT(x) (isdigit(x) ? (x) - '0' : \    islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')   #define MBASE ('z' - 'a' + 1 + 10)      long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base)   {    register long val;    register int c;    int xx, neg = 0;
pike.git/src/stralloc.c:1690:    while(1)    {    INC_PCHARP(str,1);    c=EXTRACT_PCHARP(str);    if(!(isalnum(c) && (xx=DIGIT(c)) < base)) break;    val = base * val - xx;    }    if (ptr) *ptr = str;    return (neg ? val : -val);   } +  + p_wchar0 *require_wstring0(struct pike_string *s, +  char **to_free) + { +  switch(s->size_shift) +  { +  case 0: +  *to_free=0; +  return STR0(s); +  case 1: +  case 2: +  return 0; +  +  default: +  fatal("Illegal shift size in string.\n"); +  } +  return 0; + } +  + p_wchar1 *require_wstring1(struct pike_string *s, +  char **to_free) + { +  switch(s->size_shift) +  { +  case 0: +  *to_free=xalloc((s->len+1)*2); +  convert_0_to_1((p_wchar1 *)*to_free, STR0(s),s->len+1); +  return (p_wchar1 *)*to_free; +  +  case 1: +  *to_free=0; +  return STR1(s); +  +  case 2: +  return 0; +  +  default: +  fatal("Illegal shift size in string.\n"); +  } +  return 0; + } +  +  + p_wchar2 *require_wstring2(struct pike_string *s, +  char **to_free) + { +  switch(s->size_shift) +  { +  case 0: +  *to_free=xalloc((s->len+1)*4); +  convert_0_to_2((p_wchar2 *)*to_free, STR0(s),s->len+1); +  return (p_wchar2 *)*to_free; +  +  case 1: +  *to_free=xalloc((s->len+1)*4); +  convert_1_to_2((p_wchar2 *)*to_free, STR1(s),s->len+1); +  return (p_wchar2 *)*to_free; +  +  case 2: +  *to_free=0; +  return STR2(s); +  +  default: +  fatal("Illegal shift size in string.\n"); +  } +  return 0; + } +