pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:5819:    }       pop_n_elems(args);   #if SIZEOF_TIME_T > SIZEOF_INT_TYPE    push_int64 (retval);   #else    push_int(retval);   #endif   }    + #define DOES_MATCH_CLASS(EXTRACT_M,EXTRACT_S,ML) \ +  { \ +  unsigned against = EXTRACT_S; \ +  int inverted=0,matched=0; \ +  j++; \ +  i++; \ +  if(EXTRACT_M == '!' || EXTRACT_M == '^') \ +  { \ +  i++; \ +  inverted=1; \ +  matched =1; \ +  } \ +  while(i<ML) \ +  { \ +  unsigned c = EXTRACT_M; \ +  unsigned e = 0; \ +  if(c==']') \ +  break; \ +  i++; \ +  if( EXTRACT_M == '-' ) \ +  { \ +  i++; \ +  e = EXTRACT_M; \ +  i++; \ +  } \ +  else \ +  e=c; \ +  \ +  if( c <= against && e >= against ) \ +  { \ +  if(inverted) \ +  return 0; \ +  matched=1; \ +  } \ +  } \ +  if (!matched || i>=ML) return 0; \ +  break; \ +  } +  +    /* Common case: both strings are 8bit. */   static int does_match_8_8( const unsigned char *s, int j, int sl,    const unsigned char *m, int i, int ml)   {    for (; i<ml; i++)    {    switch (m[i])    {    case '?':    if(j++>=sl) return 0;
pike.git/src/builtin_functions.c:5849:    if (i==ml) return 1;       for (;j<sl;j++)    {    if( s[j] == m[i] &&    does_match_8_8(s,j,sl,m,i,ml))    return 1;    }    return 0;    +  +  case '[': +  DOES_MATCH_CLASS(m[i],s[j],ml); +  break; +  +  case '\\': +  if (++i==ml) return 0; +  /* falthrough */ +     default:    if(j>=sl || m[i] != s[j] )    return 0;    j++;    }    }    return j==sl;   }      static int does_match_16_8( const unsigned short *s, int j, int sl,
pike.git/src/builtin_functions.c:5887:    if (i==ml) return 1;       for (;j<sl;j++)    {    if( s[j] == m[i] &&    does_match_16_8(s,j,sl,m,i,ml))    return 1;    }    return 0;    +  +  case '[': +  DOES_MATCH_CLASS(m[i],s[j],ml); +  break; +  +  case '\\': +  if (++i==ml) return 0; +  /* falthrough */ +     default:    if(j>=sl || m[i] != s[j] )    return 0;    j++;    }    }    return j==sl;   }      
pike.git/src/builtin_functions.c:5919:    case '*':    i++;    if (i==m->len) return 1; /* slut */       for (;j<s->len;j++)    if (does_match_x_x(s,j,m,i))    return 1;       return 0;    +  case '[': +  DOES_MATCH_CLASS(index_shared_string(m,i),index_shared_string(s,j),m->len); +  break; +  +  case '\\': +  if (++i==m->len) return 0; +  /* falthrough */    default:    if(j>=s->len ||    index_shared_string(m,i)!=index_shared_string(s,j)) return 0;    j++;    }    }    return j==s->len;   }      static int does_match(struct pike_string *s,int j,
pike.git/src/builtin_functions.c:5940:   {    if( s->size_shift + m->size_shift == 0 )    return does_match_8_8((const unsigned char*)s->str, j, s->len,    (const unsigned char*)m->str, i, m->len);    if( s->size_shift==1 && m->size_shift == 0 )    return does_match_16_8((const unsigned short*)s->str, j, s->len,    (const unsigned char*)m->str, i, m->len);    return does_match_x_x( s,j,m,i );   }   /*! @decl int(0..1) glob(string glob, string str) -  *! @decl int(0..1) glob(array(string) glob, string str) +  *! @decl string glob(array(string) glob, string str)    *! @decl array(string) glob(string glob, array(string) str)    *! @decl array(string) glob(array(string) glob, array(string) str)    *!    *! Match strings against a glob pattern.    *!    *! @param glob    *! @mixed    *! @type string    *! The glob pattern. A question sign ('?') matches any character    *! and an asterisk ('*') matches a string of arbitrary length. All    *! other characters only match themselves.    *! @type array(string) -  *! the function returns true, or keeps a string, if any of the given -  *! patterns match +  *! the function returns the matching glob if any of the given +  *! patterns match. Otherwise 0. If the second argument is an array +  *! it will behave as if the first argument is a string (see +  *! below)    *! @endmixed    *!    *! @param str    *! @mixed    *! @type string    *! @expr{1@} is returned if the string @[str] matches @[glob],    *! @expr{0@} (zero) otherwise.    *!    *! @type array(string)    *! All strings in the array @[str] are matched against @[glob],    *! and those that match are returned in an array (in the same    *! order).    *! @endmixed    *!    *! @seealso    *! @[sscanf()], @[Regexp]    */    - static int any_does_match( struct svalue *items, int nglobs, struct pike_string *str ) + static struct pike_string *any_does_match( struct svalue *items, int nglobs, struct pike_string *str )   {    INT32 i;    for( i =0; i<nglobs; i++ )    {    struct pike_string *str2 = items[i].u.string;    if( str == str2 ) -  return 1; +  return str;    if( does_match(str,0,str2,0) ) -  return 1; +  return str2;    }    return 0;   }      PMOD_EXPORT void f_glob(INT32 args)   {    INT32 i;    struct array *a;    struct svalue *glob; -  +  struct pike_string *tmp;    int nglobs;       if(args != 2)    SIMPLE_WRONG_NUM_ARGS_ERROR("glob", 2);       if (TYPEOF(Pike_sp[-args]) == T_STRING)    {    glob=Pike_sp-args;    nglobs = 1;    }
pike.git/src/builtin_functions.c:6018:    if( TYPEOF(ga->item[i]) != PIKE_T_STRING )    SIMPLE_ARG_TYPE_ERROR("glob", 1, "string|array(string)");    }    else    SIMPLE_ARG_TYPE_ERROR("glob", 1, "string|array(string)");          switch(TYPEOF(Pike_sp[1-args]))    {    case T_STRING: -  i = any_does_match(glob,nglobs,Pike_sp[1-args].u.string); -  pop_n_elems(2); -  push_int(i); +  tmp = any_does_match(glob,nglobs,Pike_sp[1-args].u.string); +  if(TYPEOF(Pike_sp[-args]) == PIKE_T_ARRAY && tmp) +  ref_push_string(tmp); +  else +  push_int(!!tmp); +  stack_pop_n_elems_keep_top(2);    break;       case T_ARRAY: {    INT32 j;    unsigned matches = 0;    struct svalue *res;    a=Pike_sp[1-args].u.array;       if( (a->type_field & ~BIT_STRING) &&    (array_fix_type_field(a) & ~BIT_STRING) )
pike.git/src/builtin_functions.c:9280:    ADD_EFUN("floatp", f_floatp,tFunc(tMix,tInt01),OPT_TRY_OPTIMIZE);       /* function(mixed:int) */    ADD_EFUN("functionp", f_functionp,tFunc(tMix,tInt01),OPT_TRY_OPTIMIZE);       /* function(mixed:int) */    ADD_EFUN("callablep", f_callablep,tFunc(tMix,tInt01),OPT_TRY_OPTIMIZE);       /* function(string,string:int(0..1))|function(string,string*:array(string)) */    ADD_EFUN("glob",f_glob, -  tOr(tFunc(tOr(tStr,tArr(tStr)) tStr,tInt01), +  tOr3(tFunc(tStr tStr,tInt01), +  tFunc(tArr(tStr) tStr,tStr),    tFunc(tOr(tStr,tArr(tStr)) tSetvar(1,tArr(tStr)),tVar(1))),    OPT_TRY_OPTIMIZE);       /* function(string,int|void:int) */    ADD_EFUN("hash",f_hash,tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE);       ADD_EFUN("hash_7_0",f_hash_7_0,    tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE);       ADD_EFUN("hash_7_4",f_hash_7_4,