link-grammar-5.8.0/link-grammar/dict-common/regex-morph.c
/**
 * Compile all the given regexs.
 * Return 0 on success, else an error code.
 */
Compile all the given regexs.
Return 0 on success, else an error code.
Compile all the given regexs . Return 0 on success else an error code .
int compile_regexs(Regex_node *rn, Dictionary dict)
{
	while (rn != NULL)
	{
		if(rn->re == NULL)
		{
			int rc;
			regex_t *re = rn->re = malloc(sizeof(regex_t));
#if HAVE_PCRE2_H
			PCRE2_SIZE erroffset;
			re->re_code =
				pcre2_compile((PCRE2_SPTR)rn->pattern, PCRE2_ZERO_TERMINATED,
				              PCRE2_UTF|PCRE2_UCP, &rc, &erroffset, NULL);
			if (NULL != re->re_code)
			{
				rc = 0;
				re->re_md = pcre2_match_data_create(0, NULL);
				if (NULL == re->re_md) return -1; 
			}
#else
			const int erroffset = -1;
#ifndef REG_ENHANCED
#define REG_ENHANCED 0
#endif
			rc = regcomp(re, rn->pattern, REG_NOSUB|REG_EXTENDED|REG_ENHANCED);
#endif
			if (rc)
			{
				prt_regerror("Failed to compile regex", rn, rc ,erroffset);
				rn->re = NULL;
				return rc;
			}
			if ((NULL != dict) && !dict_has_word(dict, rn->name))
			{
				prt_error("Error: Regex name %s not found in dictionary!\n",
				       rn->name);
			}
		}
		rn = rn->next;
	}
	return 0;
}
int compile_regexs ( Regex_node * rn , Dictionary dict ) { while ( rn != NULL ) { if ( rn -> re == NULL ) { int rc ; regex_t * re = rn -> re = malloc ( sizeof ( regex_t ) ) ; #if HAVE_PCRE2_H PCRE2_SIZE erroffset ; re -> re_code = pcre2_compile ( ( PCRE2_SPTR ) rn -> pattern , PCRE2_ZERO_TERMINATED , PCRE2_UTF | PCRE2_UCP , & rc , & erroffset , NULL ) ; if ( NULL != re -> re_code ) { rc = 0 ; re -> re_md = pcre2_match_data_create ( 0 , NULL ) ; if ( NULL == re -> re_md ) return -1 ; } #else const int erroffset = -1 ; #ifndef REG_ENHANCED #define REG_ENHANCED  0 #endif rc = regcomp ( re , rn -> pattern , REG_NOSUB | REG_EXTENDED | REG_ENHANCED ) ; #endif if ( rc ) { prt_regerror ( " " , rn , rc , erroffset ) ; rn -> re = NULL ; return rc ; } if ( ( NULL != dict ) && ! dict_has_word ( dict , rn -> name ) ) { prt_error ( " \n " , rn -> name ) ; } } rn = rn -> next ; } return 0 ; }
Compile all the given regexs.
Compile all the given regexs .
/* If rn->re non-null, assume compiled already. */ /* Unhandled for now. */ /* REG_ENHANCED is needed for macOS to support \w etc. */ /* Check that the regex name is defined in the dictionary. */ /* TODO: better error handing. Maybe remove the regex? */