示例#1
0
long file_string_search( const char *p, FILE *f, const char* opt )
{
  int ps = strlen(p);
  ASSERT( ps < MAX_PATTERN );

  int nocase = str_find( opt, 'i' ) > -1;

  long pos = -1;

  if( str_find( opt, 'r' ) > -1 )
    {
    pos = file_grep( p, f, 0, -1 );
    } else
  if( str_find( opt, 'h' ) > -1 )
    {
    char new_p[MAX_PATTERN+1];
    int pl = hex_string_to_pattern( p, new_p );
    if (pl > 0)
      pos = file_pattern_search( new_p, pl, f, nocase ? "i" : "" );
    }
  else
    {
    pos = file_pattern_search( p, strlen(p), f, nocase ? "i" : "" );
    }

  return pos;
}
示例#2
0
int mem_string_search( const char *p, const char* d, const char* opt )
{
    int ps = strlen(p);
    ASSERT( ps < MAX_PATTERN );

    int nocase = str_find( opt, 'i' ) > -1;

    long pos = -1;

    if( str_find( opt, 'r' ) > -1 )
    {
        VRegexp re;
        if ( ! re.comp( p ) ) return -1;
        if ( ! re.m( d ) ) return -1;
        pos = re.sub_sp( 0 );
    } else if( str_find( opt, 'h' ) > -1 )
    {
        char new_p[MAX_PATTERN+1];
        int pl = hex_string_to_pattern( p, new_p );
        if (pl > 0)
            if ( nocase )
                pos = mem_quick_search_nc( new_p, pl, d, strlen(d) );
            else
                pos = mem_quick_search( new_p, pl, d, strlen(d) );
    }
    else
    {
        if ( nocase )
            pos = mem_quick_search_nc( p, ps, d, strlen(d) );
        else
            pos = mem_quick_search( p, ps, d, strlen(d) );
    }

    return pos;
};
示例#3
0
  int VRegexp::comp( const char* pattern, const char *opt )
  {
    if ( re ) pcre_free( re );
    if ( pt ) delete pt;
    re = NULL;
    pt = NULL;
    pl = 0;

    int options = get_options( opt );
    if( options == -1 ) return 0;

    if ( opt_mode == MODE_REGEXP )
      {
      const char *error;
      int erroffset;
      re = pcre_compile( pattern, options, &error, &erroffset, NULL );

      if ( re )
        {
        errstr = "";
        return 1;
        }
      else
        {
        errstr = error;
        return 0;
        }
      }
    else
      {
      pl = strlen( pattern );
      pt = new char[pl+1];
      if ( opt_mode == MODE_HEX )
        pl = hex_string_to_pattern( pattern, pt );
      else
        strcpy( pt, pattern );
      pt[pl] = 0;
      return pl;
      }
  }