mirror of
https://git.sr.ht/~sircmpwn/gmnisrv
synced 2025-02-02 15:08:11 -05:00
regexp.c: ditch unused test code
This commit is contained in:
parent
4b6f5a1c61
commit
0ba984b841
170
src/regexp.c
170
src/regexp.c
@ -1046,111 +1046,6 @@ int lre_parse_escape(const uint8_t **pp, int allow_utf16)
|
||||
return c;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ALL_UNICODE
|
||||
/* XXX: we use the same chars for name and value */
|
||||
static bool is_unicode_char(int c)
|
||||
{
|
||||
return ((c >= '0' && c <= '9') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c == '_'));
|
||||
}
|
||||
|
||||
static int parse_unicode_property(REParseState *s, CharRange *cr,
|
||||
const uint8_t **pp, bool is_inv)
|
||||
{
|
||||
const uint8_t *p;
|
||||
char name[64], value[64];
|
||||
char *q;
|
||||
bool script_ext;
|
||||
int ret;
|
||||
|
||||
p = *pp;
|
||||
if (*p != '{')
|
||||
return re_parse_error(s, "expecting '{' after \\p");
|
||||
p++;
|
||||
q = name;
|
||||
while (is_unicode_char(*p)) {
|
||||
if ((q - name) > sizeof(name) - 1)
|
||||
goto unknown_property_name;
|
||||
*q++ = *p++;
|
||||
}
|
||||
*q = '\0';
|
||||
q = value;
|
||||
if (*p == '=') {
|
||||
p++;
|
||||
while (is_unicode_char(*p)) {
|
||||
if ((q - value) > sizeof(value) - 1)
|
||||
return re_parse_error(s, "unknown unicode property value");
|
||||
*q++ = *p++;
|
||||
}
|
||||
}
|
||||
*q = '\0';
|
||||
if (*p != '}')
|
||||
return re_parse_error(s, "expecting '}'");
|
||||
p++;
|
||||
// printf("name=%s value=%s\n", name, value);
|
||||
|
||||
if (!strcmp(name, "Script") || !strcmp(name, "sc")) {
|
||||
script_ext = false;
|
||||
goto do_script;
|
||||
} else if (!strcmp(name, "Script_Extensions") || !strcmp(name, "scx")) {
|
||||
script_ext = true;
|
||||
do_script:
|
||||
cr_init(cr, s->mem_opaque, lre_realloc);
|
||||
ret = unicode_script(cr, value, script_ext);
|
||||
if (ret) {
|
||||
cr_free(cr);
|
||||
if (ret == -2)
|
||||
return re_parse_error(s, "unknown unicode script");
|
||||
else
|
||||
goto out_of_memory;
|
||||
}
|
||||
} else if (!strcmp(name, "General_Category") || !strcmp(name, "gc")) {
|
||||
cr_init(cr, s->mem_opaque, lre_realloc);
|
||||
ret = unicode_general_category(cr, value);
|
||||
if (ret) {
|
||||
cr_free(cr);
|
||||
if (ret == -2)
|
||||
return re_parse_error(s, "unknown unicode general category");
|
||||
else
|
||||
goto out_of_memory;
|
||||
}
|
||||
} else if (value[0] == '\0') {
|
||||
cr_init(cr, s->mem_opaque, lre_realloc);
|
||||
ret = unicode_general_category(cr, name);
|
||||
if (ret == -1) {
|
||||
cr_free(cr);
|
||||
goto out_of_memory;
|
||||
}
|
||||
if (ret < 0) {
|
||||
ret = unicode_prop(cr, name);
|
||||
if (ret) {
|
||||
cr_free(cr);
|
||||
if (ret == -2)
|
||||
goto unknown_property_name;
|
||||
else
|
||||
goto out_of_memory;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unknown_property_name:
|
||||
return re_parse_error(s, "unknown unicode property name");
|
||||
}
|
||||
|
||||
if (is_inv) {
|
||||
if (cr_invert(cr)) {
|
||||
cr_free(cr);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*pp = p;
|
||||
return 0;
|
||||
out_of_memory:
|
||||
return re_parse_out_of_memory(s);
|
||||
}
|
||||
#endif /* CONFIG_ALL_UNICODE */
|
||||
|
||||
/* return -1 if error otherwise the character or a class range
|
||||
(CLASS_RANGE_BASE). In case of class range, 'cr' is
|
||||
initialized. Otherwise, it is ignored. */
|
||||
@ -1209,17 +1104,6 @@ static int get_class_atom(REParseState *s, CharRange *cr,
|
||||
c = '\\';
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_ALL_UNICODE
|
||||
case 'p':
|
||||
case 'P':
|
||||
if (s->is_utf16) {
|
||||
if (parse_unicode_property(s, cr, &p, (c == 'P')))
|
||||
return -1;
|
||||
c = CLASS_RANGE_BASE;
|
||||
break;
|
||||
}
|
||||
/* fall thru */
|
||||
#endif
|
||||
default:
|
||||
p--;
|
||||
ret = lre_parse_escape(&p, s->is_utf16 * 2);
|
||||
@ -2988,57 +2872,3 @@ const char *lre_get_groupnames(const uint8_t *bc_buf)
|
||||
re_bytecode_len = get_u32(bc_buf + 3);
|
||||
return (const char *)(bc_buf + 7 + re_bytecode_len);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
bool lre_check_stack_overflow(void *opaque, size_t alloca_size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void *lre_realloc(void *opaque, void *ptr, size_t size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int len, ret, i;
|
||||
uint8_t *bc;
|
||||
char error_msg[64];
|
||||
uint8_t *capture[CAPTURE_COUNT_MAX * 2];
|
||||
const char *input;
|
||||
int input_len, capture_count;
|
||||
|
||||
if (argc < 3) {
|
||||
printf("usage: %s regexp input\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
bc = lre_compile(&len, error_msg, sizeof(error_msg), argv[1],
|
||||
strlen(argv[1]), 0, NULL);
|
||||
if (!bc) {
|
||||
fprintf(stderr, "error: %s\n", error_msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
input = argv[2];
|
||||
input_len = strlen(input);
|
||||
|
||||
ret = lre_exec(capture, bc, (uint8_t *)input, 0, input_len, 0, NULL);
|
||||
printf("ret=%d\n", ret);
|
||||
if (ret == 1) {
|
||||
capture_count = lre_get_capture_count(bc);
|
||||
for(i = 0; i < 2 * capture_count; i++) {
|
||||
uint8_t *ptr;
|
||||
ptr = capture[i];
|
||||
printf("%d: ", i);
|
||||
if (!ptr)
|
||||
printf("<nil>");
|
||||
else
|
||||
printf("%u", (int)(ptr - (uint8_t *)input));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user