Exemple #1
0
/*
 * CurrentRegComp - compile current regular expression
 */
int CurrentRegComp( char *str )
{
    MemFree( CurrentRegularExpression );
    CurrentRegularExpression = RegComp( str );
    return( RegExpError );

} /* CurrentRegComp */
Exemple #2
0
Policy::Policy(const std::string &pstr) : port(-1) {
  std::string::size_type colon = pstr.find(':');
  std::string::size_type slash = pstr.find('/');
  if(slash == std::string::npos) {
    if(colon == std::string::npos) {
      host = pstr;
    }
    else {
      host = pstr.substr(0, colon);
      port = atoi(pstr.substr(colon + 1).c_str());
    }
  }
  else {
    if(colon == std::string::npos || colon > slash) {
      host = pstr.substr(0, slash);
      suffix = pstr.substr(slash + 1);
    }
    else {
      host = pstr.substr(0, colon);
      port = atoi(pstr.substr(colon + 1, slash - colon - 1).c_str());
      suffix = pstr.substr(slash + 1);
    }
  }
  RegComp();
}
Exemple #3
0
/* FileMatchInit - start file matching */
char *FileMatchInit( void **crx, char *wild )
{
    char        *tomatch;
    size_t      j;
    regexp      *rx;
    size_t      i, len;

    /*
        Calculate size of regular expression.  We calculate it because it
        can be as large as 3*_MAX_PATH... which is a lot to allocate off
        the stack all the time.
    */
    MagicString = ".";
    MagicFlag = FALSE;
    j = 0;
    len = strlen( wild );
    for( i = 0; i < len; i++ ) { /* this loop is closely related to the next */
        if( wild[i] == '?' ) {
            j += 2;     /* for "\." */
        } 
        else if( wild[i] == '*' ) {
            j += 3;     /* for "\.*" */
        } else {
            ++j;
        }
    }
    tomatch = alloca( j + 3 );  /* for "^" "$" and null char */
    if( tomatch == NULL ) {
        Die( "Out of memory!\n" );
    }
    tomatch[0] = '^';
    j = 1;
    for( i = 0; i < len; i++ ) {
        if( wild[i] == '#' ) {
            tomatch[j++] = '|';
        } else if( wild[i] == '?' ) {
            tomatch[j++] = '\\';
            tomatch[j++] = '.';
        } else if( wild[i] == '*' ) {
            tomatch[j++] = '\\';
            tomatch[j++] = '.';
            tomatch[j++] = '*';
        } else {
            tomatch[j++] = wild[i];
        }
    }
    tomatch[j++] = '$';
    tomatch[j] = 0;

    rx = RegComp( tomatch );
    if( RegExpError ) {
        MemFree( rx );
        *crx = NULL;
    } else {
        *crx = rx;
    }
    return( rxErrorStrings[RegExpError] );
}
Exemple #4
0
Policy& Policy::operator=(const Policy& p){
  if(!host.empty())
    regfree(&host_rx);
  if(!suffix.empty())
    regfree(&suffix_rx);
  host = p.host;
  port = p.port;
  suffix = p.suffix;
  RegComp();
  return *this;
}
Exemple #5
0
void *WndCompileRX( char *expr )
{
    regexp      *rx;

    rx = RegComp( expr );
    if( RegExpError ) {
        WndFreeRX( rx );
        WndRXError( RegExpError );
        return( NULL );
    }
    return( rx );
}
Exemple #6
0
/*
 * DoEGREP - do an extended grep
 */
vi_rc DoEGREP( char *dirlist, char *string )
{
    vi_rc   rc;

    cRx = RegComp( string );
    if( RegExpError ) {
        return( RegExpError );
    }
    sString = string;
    origString = string;
    isFgrep = FALSE;
    rc = doGREP( dirlist );
    MemFree( cRx );
    return( rc );

} /* DoEGREP */
Exemple #7
0
int main()
{
    char *regstr = "^[A-Za-z0-9](([_\\.\\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\\.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$";
    char *str = "*****@*****.**";

    //char *regstr = "^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\\-+)|([A-Za-z0-9]+\\.+)|([A-Za-z0-9]+\\++))*[A-Za-z0-9]+@((\\w+\\-+)|(\\w+\\.))*\\w{1,63}\\.[a-zA-Z]{2,6}$";
    //char *str = "(a)";

    //char *regstr = "@([A-Za-z0-9]*)(([\\.\\-]*[a-zA-Z0-9]*)*)\\.([A-Za-z]{2,3})$";
    //char *str = "@john-doe.i.am.com";

    //char *regstr = "((a*)*)(\\3)";
    //char *str = "aaa3";

    //char *regstr = "\\w?<\\s?/?[^\\s>]+(\\s+[^\"\'=]+(=(\"[^\"]*\")|(\'[^\\\']*\')|([^\\s\"\'>]*))?)*\\s*/?>";
    //char *str = "<world www=\"hello\" />";

    //char *regstr ="0{1}";
    //char *str ="The new Windows 200000 000  Professional Resource Kit, published on MSDN Library and TechNet, is available nowhere else online. \nWith tools, reference materials, and an online version of the Windows 2000 Server Resource Kit Deployment Planning Guide, the kit provides a comprehensive technical resource for installing, configuring, and supporting Windows 2000 Professional. You'll also find extensive troubleshooting tools. With background information on Windows 2000 extensible features, group policy, COM+, and such security features as smart cards and the certificate infrastructure, the kit is an indispensable resource for writing applications for Windows 2000 clients.";

    rx_t rx;
    reg_match_t regmatch[16];

    if(RegComp(regstr, &rx))
    {
        printf("RegComp error\n");
        return 0;
    }

    if(!RegExec(&rx, str, regmatch, 16))
    {
        printf("RegExec error\n");
        return 0;
    }
    else
    {
        printf("Matched!\n");

    }

    for(int i = 0; i < 16; i++)
    {
        char buffer[256] = {0};

        if(regmatch[i].so != -1)
        {
            printf(">>>>>>>>%d<<<<<<<<<<\n", i);
            printf("%d\n", regmatch[i].so);
            printf("%d\n", regmatch[i].eo);
            strncpy(buffer, str+regmatch[i].so, regmatch[i].eo - regmatch[i].so);
            printf("%s\n", buffer);
        }
    }


    if(rx.subexp)
        free(rx.subexp);

    if(rx.regexp)
        RegExpFree(rx.regexp);

    return 0;

}
Exemple #8
0
Policy::Policy(const Policy& p) : host(p.host),
				  port(p.port),
				  suffix(p.suffix) {
  RegComp();
}