/* --------------------------------------------------------------------- * ExpMatch * This function performs a test with the data in parameter 'string' * and returns REG_MATCH if 'string' matches the regular expression specified * with 'name' * --------------------------------------------------------------------- */ int ExpMatch(EXPFILE* expfile, const wchar_t* name, const wchar_t* string) { int result = EXP_ERROR; int size = ExpGetExpressionSize(expfile, name); if (size > 0) { regex_t expr; int res; wchar_t* data = (wchar_t*) malloc((size + 1 + 4) * sizeof(wchar_t)); if (data) { wcscpy(data,_T("^(")); ExpGetExpressionData(expfile, name, &data[2]); wcscat(data, _T(")$")); res = RegCompile(&expr, data, REG_EXTENDED | REG_NOSUB | REG_NEWLINE); if (res == 0) { res = RegExec (&expr, string, 0, NULL, 0); result = (res != 0) ? EXP_NOMATCH : EXP_MATCH; } else { result = EXP_ERROR; } RegFree(&expr); free(data); } } return result; }
static bool CheckEntry( drmem_hdl abbrev, drmem_hdl mod, mod_scan_info *minfo, void *data ) /*****************************************************************************************/ { int index; sym_search_data *sinfo; dr_sym_context symctxt; sinfo = (sym_search_data *)data; symctxt.handle = minfo->handle; symctxt.context = minfo->context; symctxt.name = NULL; if( sinfo->name != NULL ) { symctxt.name = DWRGetName( abbrev, mod ); if( symctxt.name == NULL ) return( true ); if( !RegExec( sinfo->name, symctxt.name, true ) ) { DWRFREE( symctxt.name ); return( true ); } } symctxt.type = DR_SYM_MACRO; for( index = 0; index < DR_SYM_NOT_SYM; index++ ) { if( DWRSearchArray( SearchTags[index], minfo->tag ) ) { symctxt.type = index; break; } } return( sinfo->callback( &symctxt, sinfo->data ) ); }
bool KeySymbol::matches( dr_handle hdl, const char * name ) //--------------------------------------------------------- // perform a partial comparison (no containers) { dr_sym_type type; type = DRGetSymType( hdl ); if( !(SymTypeConvert[ type ] & _searchFor) ) { return( FALSE ); } if( !_anonymous ) { if( name == NULL || *name == 0 ) { return( FALSE ); } } if( !_artificial ) { if( DRIsArtificial( hdl ) ) { return( FALSE ); } } if( !_declaration ) { if( !DRIsSymDefined( hdl ) ) { return( FALSE ); } } if( _nameProg ) { if( name ) { if( !RegExec( (regexp *) _nameProg, (char *) name, TRUE ) ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _nameProg, "", TRUE ) ) { return( FALSE ); } } } if( !_fileFilter->matches( hdl ) ) { return FALSE; } return( TRUE ); }
/* FileMatch - check if a file matches a wild card */ int FileMatch( void *crx, char *name ) { int i; i = RegExec( crx, name, TRUE ); if( i ) { return( TRUE ); } return( FALSE ); }
bool WndRXFind( void * _rx, char **pos, char **endpos ) { regexp * rx = (regexp *)_rx; if( (*pos)[0] == '\0' ) return( FALSE ); if( !RegExec( rx, *pos, *endpos == NULL ) ) return( FALSE ); *pos = rx->startp[0]; *endpos = rx->endp[0]; return( TRUE ); }
static int searchBuffer( char *buf ) { unsigned ui; #ifdef FGREP if( Flags & M_SEARCH_EXACT ) { for( ui = 0; ui < PatCount; ui++ ) if( strcmp( fPatterns[ ui ], buf ) == 0 ) return( 1 ); } else { for( ui = 0; ui < PatCount; ui++ ) { char *s = buf; char const *p = fPatterns[ ui ]; char const first = *p++; for( ;; ) { if( CharTrans[ *(unsigned char *)s ] == first ) { char * const next = ++s; for( ; ; s++, p++ ) { if( *p == '\0' ) return( 1 ); if( CharTrans[ *(unsigned char *)s ] != *p ) { if( *s == '\0' ) { goto outer; } else if( CharExist[ CharTrans[ *(unsigned char *)s ] ] == 0 ) { s++; } else { s = next; } break; } } p = fPatterns[ ui ] + 1; } else if( *s == '\0' ) { break; } else { s++; } } outer: ; } } #else for( ui = 0; ui < PatCount; ui++ ) if( RegExec( ePatterns[ ui ], buf, 1 ) ) return( 1 ); #endif return( 0 ); }
/* * eSearch - scan a file for a search string (extended) */ static vi_rc eSearch( char *fn, char *res ) { int i; char *buff; FILE *f; /* * init for file i/o */ f = fopen( fn, "r" ); if( f == NULL ) { return( ERR_FILE_NOT_FOUND ); } /* * read lines from the file, and search through them */ buff = StaticAlloc(); while( fgets( buff, EditVars.MaxLine, f ) != NULL ) { for( i = strlen( buff ); i && isEOL( buff[i - 1] ); --i ) { buff[i - 1] = 0; } i = RegExec( cRx, buff, TRUE ); if( RegExpError != ERR_NO_ERR ) { StaticFree( buff ); return( RegExpError ); } if( i ) { for( i = 0; i < MAX_DISP; i++ ) { res[i] = buff[i]; } res[i] = 0; fclose( f ); StaticFree( buff ); return( FGREP_FOUND_STRING ); } } fclose( f ); StaticFree( buff ); return( ERR_NO_ERR ); } /* eSearch */
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; }
/* * FindRegularExpression - do a forward search for a regular expression */ vi_rc FindRegularExpression( char *pat, i_mark *pos1, char **linedata, linenum termline, find_type flags ) { vi_rc rc; int found; linenum ilineno = 0; bool wrapped = false; char *data; line *cline; fcb *cfcb; int scol; linenum sline; /* * initialize for search */ if( wrapMsgPrinted ) { wrapMsgPrinted = false; ClearWindow( message_window_id ); } sline = pos1->line; if( flags & FINDFL_WRAP ) { ilineno = sline; } rc = CGimmeLinePtr( sline, &cfcb, &cline ); if( rc != ERR_NO_ERR ) { return( rc ); } scol = pos1->column; if( pat != NULL ) { rc = CurrentRegComp( pat ); if( rc != ERR_NO_ERR ) { return( rc ); } } /* * loop until string found */ data = &cline->data[scol]; while( (found = RegExec( CurrentRegularExpression, data, (data == cline->data) )) == 0 ) { if( RegExpError != ERR_NO_ERR ) { return( RegExpError ); } /* * get next line */ rc = CGimmeNextLinePtr( &cfcb, &cline ); if( rc == ERR_NO_ERR ) { ++sline; } else if( rc == ERR_NO_MORE_LINES ) { if( (flags & FINDFL_WRAP) == 0 ) { return( ERR_FIND_END_OF_FILE ); } else { Message1( wrapMsg, "bottom" ); MyBeep(); wrapMsgPrinted = true; } if( wrapped ) { return( ERR_FIND_NOT_FOUND ); } sline = 1; rc = CGimmeLinePtr( sline, &cfcb, &cline ); if( rc != ERR_NO_ERR ) { return( rc ); } wrapped = true; } else { return( rc ); } if( sline > termline ) { return( ERR_FIND_PAST_TERM_LINE ); } if( wrapped ) { if( sline > ilineno ) { return( ERR_FIND_NOT_FOUND ); } } scol = 0; data = cline->data; } *linedata = cline->data; pos1->column = GetCurrRegExpColumn( cline->data ); pos1->line = sline; return( ERR_NO_ERR ); } /* FindRegularExpression */
/* * FindRegularExpressionBackwards - do a reverse search for a regular expression */ vi_rc FindRegularExpressionBackwards( char *pat, i_mark *pos1, char **linedata, linenum termline, find_type flags ) { vi_rc rc; char *data; bool wrapped = false; bool found; linenum ilineno = 0; line *cline; fcb *cfcb; regexp rcpy; int scol; linenum sline; /* * initialize for search */ if( wrapMsgPrinted ) { wrapMsgPrinted = false; ClearWindow( message_window_id ); } sline = pos1->line; rc = CGimmeLinePtr( sline, &cfcb, &cline ); if( rc != ERR_NO_ERR ) { return( rc ); } if( flags & FINDFL_WRAP ) { ilineno = sline; } scol = pos1->column; if( pat != NULL ) { rc = CurrentRegComp( pat ); if( rc != ERR_NO_ERR ) { return( rc ); } } memset( &rcpy, 0, sizeof( rcpy ) ); /* * loop until string found */ for( ;; ) { data = cline->data; found = false; /* * run through all possible matches on the line, accepting * only the last one */ if( scol >= 0 ) { while( *data != '\0' && RegExec( CurrentRegularExpression, data, (data == cline->data) ) ) { int col, len; if( RegExpError != ERR_NO_ERR ) { return( RegExpError ); } col = GetCurrRegExpColumn( cline->data ); len = GetCurrRegExpLength(); if( col + len > scol ) { break; } found = true; memcpy( &rcpy, CurrentRegularExpression, sizeof( regexp ) ); data = &(cline->data[col + 1]); } if( found ) { break; } } /* * get next line */ rc = GimmePrevLinePtr( &cfcb, &cline ); if( rc == ERR_NO_ERR ) { --sline; } else if( rc == ERR_NO_MORE_LINES ) { if( (flags & FINDFL_WRAP) == 0 ) { return( ERR_FIND_TOP_OF_FILE ); } else { Message1( wrapMsg, "top" ); MyBeep(); wrapMsgPrinted = true; } if( wrapped ) { return( ERR_FIND_NOT_FOUND ); } rc = CFindLastLine( &sline ); if( rc != ERR_NO_ERR ) { return( rc ); } rc = CGimmeLinePtr( sline, &cfcb, &cline ); if( rc != ERR_NO_ERR ) { return( rc ); } wrapped = true; } else { return( rc ); } if( sline < termline ) { return( ERR_FIND_PAST_TERM_LINE ); } if( wrapped ) { if( sline < ilineno ) { return( ERR_FIND_NOT_FOUND ); } } scol = cline->len; } *linedata = cline->data; memcpy( CurrentRegularExpression, &rcpy, sizeof( regexp ) ); pos1->column = GetCurrRegExpColumn( cline->data ); pos1->line = sline; return( ERR_NO_ERR ); } /* FindRegularExpressionBackwards */
bool KeySymbol::matches( dr_sym_context * ctxt ) //---------------------------------------------- { bool accept; char * container; if( !(SymTypeConvert[ ctxt->type ] & _searchFor) ) { return( FALSE ); } if( !_anonymous ) { if( ctxt->name == NULL || *ctxt->name == 0 ) { return( FALSE ); } } if( !_artificial ) { if( DRIsArtificial( ctxt->handle ) ) { return( FALSE ); } } if( !_declaration ) { if( !DRIsSymDefined( ctxt->handle ) ) { return( FALSE ); } } if( _nameProg && ctxt->name ) { if( ctxt->name ) { if( !RegExec( (regexp *) _nameProg, ctxt->name, TRUE ) ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _nameProg, "", TRUE ) ) { return( FALSE ); } } } if( _contClassProg ) { if( ctxt->context->classhdl ) { container = DRGetName( ctxt->context->classhdl ); if( container ) { accept = (bool) RegExec( (regexp *) _contClassProg, container, TRUE ); WBRFree( container ); if( !accept ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _contClassProg, "", TRUE ) ) { return( FALSE ); } } } else { return( FALSE ); // not local to anything } } if( _contFunctionProg ) { if( ctxt->context->functionhdl ) { container = DRGetName( ctxt->context->functionhdl ); if( container ) { accept = (bool) RegExec( (regexp *) _contFunctionProg, container, TRUE ); WBRFree( container ); if( !accept ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _contFunctionProg, "", TRUE ) ) { return( FALSE ); } } } else { return( FALSE ); // not local to anything } } if( !_fileFilter->matches( ctxt->handle ) ) { return FALSE; } return( TRUE ); }
bool KeySymbol::matches( Symbol * sym ) //------------------------------------- // FIXME -- check the parent against both // functions and classes { bool accept; char * container; if( !(SymTypeConvert[ sym->symtype() ] & _searchFor) ) { return( FALSE ); } if( !_anonymous ) { if( sym->isAnonymous() ) { return( FALSE ); } } if( !_artificial ) { if( sym->isArtificial() ) { return( FALSE ); } } if( !_declaration ) { if( !sym->isDefined() ) { return( FALSE ); } } if( _nameProg ) { if( sym->name() ) { if( !RegExec( (regexp *) _nameProg, (char *) sym->name(), TRUE ) ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _nameProg, "", TRUE ) ) { return( FALSE ); } } } if( _contClassProg ) { if( sym->getParent() ) { container = DRGetName( sym->getParent() ); if( container ) { accept = (bool) RegExec( (regexp *) _contClassProg, container, TRUE ); WBRFree( container ); if( !accept ) { return( FALSE ); } } else { if( !RegExec( (regexp *) _contClassProg, "", TRUE ) ) { return( FALSE ); } } } else { return( FALSE ); // not local to anything } } // NYI -- can't check for containing function as this is not // stored in the symbol if( !_fileFilter->matches( sym->getHandle() ) ) { return FALSE; } return( TRUE ); }