pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.542 2004/04/29 01:05:29 nilsson Exp $ + || $Id: builtin_functions.c,v 1.543 2004/04/29 19:23:20 nilsson Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.542 2004/04/29 01:05:29 nilsson Exp $"); + RCSID("$Id: builtin_functions.c,v 1.543 2004/04/29 19:23:20 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:3029:       if(from->size != to->size)    Pike_error("Replace must have equal-sized from and to arrays.\n");       if(!from->size)    {    reference_shared_string(str);    return str;    }    -  v=(struct tupel *)xalloc(sizeof(struct tupel)*from->size); -  -  for(num=e=0;e<from->size;e++) -  { -  if(ITEM(from)[e].type != T_STRING) -  { -  free((char *)v); -  Pike_error("Replace: from array is not array(string)\n"); +  if(from->type_field & ~BIT_STRING) { +  array_fix_type_field(from); +  if(from->type_field & ~BIT_STRING) +  Pike_error("replace: from array not array(string).\n");    }    -  if(ITEM(to)[e].type != T_STRING) -  { -  free((char *)v); -  Pike_error("Replace: to array is not array(string)\n"); +  if(to->type_field & ~BIT_STRING) { +  array_fix_type_field(to); +  if(to->type_field & ~BIT_STRING) +  Pike_error("replace: to array not array(string).\n");    }    -  +  v=(struct tupel *)xalloc(sizeof(struct tupel)*from->size); +  +  for(num=e=0;e<from->size;e++) +  {    if(ITEM(from)[e].u.string->size_shift > str->size_shift)    continue;       v[num].ind=ITEM(from)[e].u.string;    v[num].val=ITEM(to)[e].u.string;    v[num].prefix=-2; /* Uninitialized */    num++;    }       fsort((char *)v,num,sizeof(struct tupel),(fsortfun)replace_sortfun);
pike.git/src/builtin_functions.c:3151:    *! @[a] will then be returned.    *!    *! @note    *! Note that @[replace()] on arrays and mappings is a destructive operation.    */   PMOD_EXPORT void f_replace(INT32 args)   {    if(args < 3)    {    if (args==2 && -  Pike_sp[1-args].type==T_MAPPING) +  Pike_sp[-1].type==T_MAPPING)    { -  +  /* FIXME: Check that the mapping is string:string here, otherwise +  the error message will mention the from/to array. */    stack_dup();    f_indices(1);    stack_swap();    f_values(1);    args++;    }    else    SIMPLE_TOO_FEW_ARGS_ERROR("replace", 3);    }   
pike.git/src/builtin_functions.c:3509:    break;    case T_PROGRAM:    res = 1;    break;    case T_OBJECT:    if( Pike_sp[-args].u.object->prog &&    FIND_LFUN( Pike_sp[-args].u.object->prog, LFUN_CALL ) != -1 )    res = 1;    break;    case T_ARRAY: -  /* FIXME: This is not completely finished. E.g. ({ 0 }) is -  callable, but isn't reported as such. */ -  if( Pike_sp[-args].u.array->type_field & (BIT_CALLABLE) || -  !Pike_sp[-args].u.array->type_field) +  array_fix_type_field(Pike_sp[-args].u.array); +  if( (Pike_sp[-args].u.array->type_field==BIT_CALLABLE) || +  !Pike_sp[-args].u.array->type_field) {    res = 1; -  +  } +  else if( !(Pike_sp[-args].u.array->type_field & +  ~(BIT_CALLABLE|BIT_INT)) ) { +  struct array *a = Pike_sp[-args].u.array; +  int i; +  res = 1; +  for(i=0; i<a->size; i++) +  if( ITEM(a)[i].type == T_INT && ITEM(a)[i].u.integer ) { +  res = 0;    break;    } -  +  } +  break; +  }    pop_n_elems(args);    push_int(res);   }   #ifndef HAVE_AND_USE_POLL   #undef HAVE_POLL   #endif      /*! @decl void sleep(int|float s, void|int abort_on_signal)    *!    *! This function makes the program stop for @[s] seconds.
pike.git/src/builtin_functions.c:4775:      /* comb_merge */      /*! @module Array    */      /*! @decl array(int) interleave_array(array(mapping(int:mixed)) tab)    *!    *! Interleave a sparse matrix.    *! -  *! Returns an array with offsets that describe how to interleave -  *! the rows of @[tab]. +  *! Returns an array with offsets that describe how to shift the +  *! rows of @[tab] so that only at most one non-zero value exists in +  *! every column.    */   static void f_interleave_array(INT32 args)   {    struct array *arr = NULL;    struct array *min = NULL;    struct array *order = NULL;    int max = 0;    int ok;    int nelems = 0;    int i;