Esempio n. 1
0
static void zlib_error( z_stream *z, int err ) {
	hl_buffer *b = hl_alloc_buffer();
	vdynamic *d;
	hl_buffer_cstr(b, "ZLib Error : ");
	if( z && z->msg ) {
		hl_buffer_cstr(b,z->msg);
		hl_buffer_cstr(b," (");
	}
	d = hl_alloc_dynamic(&hlt_i32);
	d->v.i = err;
	hl_buffer_val(b,d);
	if( z && z->msg )
		hl_buffer_char(b,')');
	d = hl_alloc_dynamic(&hlt_bytes);
	d->v.ptr = hl_buffer_content(b,NULL);
	hl_throw(d);
}
Esempio n. 2
0
HL_PRIM ereg *regexp_regexp_new_options( vbyte *str, vbyte *opts ) {
	ereg *r;
	const char *error;
	int err_offset;
	int errorcode;
	pcre16 *p;
	uchar *o = (uchar*)opts;
	int options = 0;
	while( *o ) {
		switch( *o++ ) {
		case 'i':
			options |= PCRE_CASELESS;
			break;
		case 's':
			options |= PCRE_DOTALL;
			break;
		case 'm':
			options |= PCRE_MULTILINE;
			break;
		case 'u':
			options |= PCRE_UTF8;
			break;
		case 'g':
			options |= PCRE_UNGREEDY;
			break;
		default:
			return NULL;
		}
	}
	p = pcre16_compile2((PCRE_SPTR16)str,options,&errorcode,&error,&err_offset,NULL);
	if( p == NULL ) {
		hl_buffer *b = hl_alloc_buffer();
		hl_buffer_str(b,USTR("Regexp compilation error : "));
		hl_buffer_cstr(b,error);
		hl_buffer_str(b,USTR(" in "));
		hl_buffer_str(b,(uchar*)str);
		hl_error_msg(USTR("%s"),hl_buffer_content(b,NULL));
	}
	r = (ereg*)hl_gc_alloc_finalizer(sizeof(ereg));
	r->finalize = regexp_finalize;
	r->p = p;
	r->nmatches = 0;
	r->matched = 0;
	pcre16_fullinfo(p,NULL,PCRE_INFO_CAPTURECOUNT,&r->nmatches);
	r->nmatches++;
	r->matches = (int*)malloc(sizeof(int) * 3 * r->nmatches);
	limit.flags = PCRE_EXTRA_MATCH_LIMIT_RECURSION;
	limit.match_limit_recursion = 3500; // adapted based on Windows 1MB stack size
	return r;
}