Define regex_t data structure and write build script
This commit is contained in:
43
lib/regex.c
Normal file
43
lib/regex.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) Camden Dixie O'Brien
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
#include "regex.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void class_free(class_t *c)
|
||||
{
|
||||
if (NULL != c->contents)
|
||||
free(c->contents);
|
||||
}
|
||||
|
||||
static void sequence_free(sequence_t *s)
|
||||
{
|
||||
if (NULL != s->contents) {
|
||||
for (int i = 0; i < s->len; ++i) {
|
||||
switch (s->contents[i].type) {
|
||||
case TERM_TYPE_CLASS:
|
||||
class_free(&s->contents[i].class);
|
||||
break;
|
||||
case TERM_TYPE_REGEX:
|
||||
regex_free_children(&s->contents[i].regex);
|
||||
break;
|
||||
case TERM_TYPE_WILDCARD:
|
||||
case TERM_TYPE_LITERAL:
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(s->contents);
|
||||
}
|
||||
}
|
||||
|
||||
void regex_free_children(regex_t *r)
|
||||
{
|
||||
sequence_free(&r->sequence);
|
||||
if (NULL != r->alternative) {
|
||||
regex_free_children(r->alternative);
|
||||
free(r->alternative);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user