int get_bulk_match_result__( void ) { #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif if (perlObjectStatus == UNLOADED ) { load_perl__(); return(FAILURE); } if ( bulkMatchList[ptoc_int(CTXTc 1)] == NULL ) return FAILURE; /*no match*/ else{ int match_seq_number= ptoc_int(CTXTc 1); int match_array_sz= ptoc_int(CTXTc 3); if (match_seq_number < match_array_sz) { /* c2p_string(CTXTc bulkMatchList[match_seq_number], reg_term(CTXTc 2)); */ ctop_string(CTXTc 2, (char *)string_find(bulkMatchList[match_seq_number],1)); return SUCCESS; } else return FAILURE; } }
/*---------------------------------------------------------------------------- perl_substitute__() The pattern substitution function which includes loading perl interpreter and doing the pattern substitution, then returning the replaced string. arguments: input: char* string, input text char* pattern, match pattern output:char* string, output text ----------------------------------------------------------------------------*/ int perl_substitute__( void ) { SV *text; /* Perl representation for the string to be modified by substitution */ char *subst_cmd = ptoc_string(CTXTc 2); #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif /* first load the perl interpreter, if unloaded */ if (perlObjectStatus == UNLOADED) load_perl__(); text = newSV(0); sv_setpv(text, ptoc_string(CTXTc 1)); /* put the string to the SV */ if( !substitute(&text, subst_cmd) ) return(FAILURE); global_pattern_mode = is_global_pattern(subst_cmd); if (substituteString != NULL ) free(substituteString); substituteString = malloc(strlen(SvPV(text,PL_na))+1); strcpy(substituteString,SvPV(text,PL_na)); SvREFCNT_dec(text); /*release space*/ ctop_string(CTXTc 3, string_find(substituteString,1)); /*return changed text*/ return SUCCESS; }
/*---------------------------------------------------------------------------- try_match__() The pattern matching function which includes loading perl interpreter and trying the perl pattern matching. arguments: input: char* string, -- input text char* pattern -- match pattern output:if no match found, return FAILURE (0). ----------------------------------------------------------------------------*/ int try_match__( void ) { SV *text; /* the storage for the string in embedded Perl */ SV *string_buff; /* the storage for the string in embedded Perl */ int was_match; /* number of the matches */ #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif char *string = ptoc_string(CTXTc 1), *pattern = ptoc_string(CTXTc 2); /* first load the perl interpreter, if unloaded */ if (perlObjectStatus == UNLOADED) load_perl__(); text = newSV(0); string_buff = newSV(0); sv_setpv(text, string); /* store the string in the SV */ was_match = match(text, pattern ); global_pattern_mode = is_global_pattern(pattern); SvREFCNT_dec(string_buff); SvREFCNT_dec(text); return(was_match); }
/*---------------------------------------------------------------------------- do_bulk_match__() The pattern match function which includes loading perl interpreter and doing the global perl pattern match, and storing the results in the global array of bulkMatchList. argument: input: char* string -- input text char* pattern -- match pattern output: int* num_match -- the number of the matches ----------------------------------------------------------------------------*/ int do_bulk_match__( void ) { AV *match_list; /* AV storage of matches list*/ SV *text; /* storage for the embedded perl cmd */ SV *string_buff; /* storage for the embedded perl cmd */ int num_match; /* the number of the matches */ int i; #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif /* first load the perl interpreter, if unloaded */ if (perlObjectStatus == UNLOADED) load_perl__(); text = newSV(0); string_buff = newSV(0); sv_setpv(text, ptoc_string(CTXTc 1)); /*put the string into an SV */ /*------------------------------------------------------------------------ free the old match list space and allocate new space for current match list -----------------------------------------------------------------------*/ for ( i=0; i<preBulkMatchNumber; i++ ) free(bulkMatchList[i]); if (bulkMatchList != NULL ) free(bulkMatchList); bulkMatchList = NULL; /*------------------------------------------------------------------------ do bulk match ----------------------------------------------------------------------*/ num_match = all_matches(text, ptoc_string(CTXTc 2),&match_list); /* allocate the space to store the matches */ if ( num_match != 0 ) { preBulkMatchNumber = num_match; /* reset the pre bulk match number */ bulkMatchList = (char **)malloc(num_match*sizeof(char *)); if ( bulkMatchList == NULL ) xsb_abort("Cannot alocate memory to store the results for bulk match"); } /*get the matches from the AV */ for ( i=0;i<num_match;i++ ) { string_buff = av_shift(match_list); bulkMatchList[i] = (char *)malloc( strlen(SvPV(string_buff,PL_na))+1 ); strcpy((char *)bulkMatchList[i], SvPV(string_buff,PL_na) ); } SvREFCNT_dec(string_buff); /* release space*/ SvREFCNT_dec(text); ctop_int(CTXTc 3, num_match); /*return the number of matches*/ return SUCCESS; }
int get_bulk_match_result__( void ) { if (perlObjectStatus == UNLOADED ) { load_perl__(); return(FAILURE); } if ( bulkMatchList[ptoc_int(1)] == NULL ) return FAILURE; /*no match*/ else{ int match_seq_number= ptoc_int(1); int match_array_sz= ptoc_int(3); if (match_seq_number < match_array_sz) { /* c2p_string( bulkMatchList[match_seq_number], reg_term(2)); */ ctop_string(2, (char *)string_find(bulkMatchList[match_seq_number],1)); return SUCCESS; } else return FAILURE; } }
/*---------------------------------------------------------------------------- try_match__() The pattern matching function which includes loading perl interpreter and trying the perl pattern matching. arguments: input: char* string, -- input text char* pattern -- match pattern output:if no match found, return FAILURE (0). ----------------------------------------------------------------------------*/ int try_match__( void ) { SV *text; /* the storage for the string in embedded Perl */ SV *string_buff; /* the storage for the string in embedded Perl */ int was_match; /* number of the matches */ char *string = ptoc_string(1), *pattern = ptoc_string(2); /* first load the perl interpreter, if unloaded */ if (perlObjectStatus == UNLOADED) load_perl__(); text = newSV(0); string_buff = newSV(0); sv_setpv(text, string); /* store the string in the SV */ was_match = match(text, pattern ); global_pattern_mode = is_global_pattern(pattern); SvREFCNT_dec(string_buff); SvREFCNT_dec(text); return(was_match); }