75 if ((c >=
'0') && (c <=
'9') )
77 else if ((c >=
'A') && (c <=
'F') )
79 else if ((c >=
'a') && (c <=
'f') )
84 "Cannot convert char %c in base %u\n",
104 for (
int i = 0; i < n; i++)
105 fprintf (stderr,
"| ");
122 fprintf (stderr,
"%u:'%s'\n",
c2i (ctx->
s[0], ctx->
size), ctx->
s);
125 fprintf (stderr,
"ROOT (base %u)\n", ctx->
size);
126 for (
unsigned int i = 0; i < ctx->
size; i++)
164 ctx->
size = alphabet_size;
180 for (
unsigned int i = 0; i < src->
size; i++)
208 for (i = 0; i < ctx->
size; i++)
214 "adding '%s' to innner %s\n",
234 len = strlen (regex);
242 if (
'|' == regex[len - 1])
243 regex[len - 1] =
'\0';
278 limit = l1 > l2 ? l2 : l1;
280 for (i = 0; i < limit; i++)
310 for (i = 0; i < ctx->
size; i++)
349 for (i = 1UL; i <
l; i++)
351 if ((regex[i] !=
'|') && (regex[i] !=
')') )
356 if (count == ctx->
size)
363 for (i = 1UL; i <
l; i++)
365 if ((regex[i] !=
'|') && (regex[i] !=
')') )
370 if (children != NULL)
373 sizeof(*children) * ctx->
size);
393 unsigned int prefix_l)
409 ctx->
s[prefix_l] =
'\0';
412 if (
'(' == suffix[0])
428 idx =
c2i (suffix[0], ctx->
size);
445 unsigned int prefix_l;
452 "regex_add '%s' into '%s'\n",
470 rest_s = &p->
s[prefix_l];
471 rest_r = ®ex[prefix_l];
486 idx =
c2i (regex[0], ctx->
size);
487 if ((NULL == ctx->
children[idx]) && (NULL != ctx->
s))
516 for (i = 0; i < ctx->
size; i++)
549 for (i = 0; regexes[i]; i++)
551 current = regexes[i];
594 "Can't open file %s for reading\n", filename);
600 "Can't get size of file %s\n", filename);
605 "using file %s, size %llu\n",
606 filename, (
unsigned long long) size);
619 len = (size_t) sscanf (&buffer[offset],
"%s", regex);
622 len = strlen (regex);
630 regexes[nr - 2] = regex;
631 regexes[nr - 1] = NULL;
634 while (offset < size);
652 for (i = 0; regexes[i]; i++)
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
Open the file for reading.
static void space(int n)
Printf spaces to indent the regex tree.
struct RegexCombineCtx ** children
Child nodes with same prefix and token.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Struct to hold the tree formed by prefix-combining the regexes.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
static struct RegexCombineCtx * get_longest_prefix(struct RegexCombineCtx *ctx, const char *regex)
Return the child context with the longest prefix match with the regex.
Nobody is allowed to do anything to the file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void regex_add_multiple(struct RegexCombineCtx *ctx, const char *regex, struct RegexCombineCtx **children)
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
unsigned int size
Alphabet size (how many children there are)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
static void debugctx(struct RegexCombineCtx *ctx, int level)
Printf the combined regex ctx.
static void move_children(struct RegexCombineCtx *dst, const struct RegexCombineCtx *src)
static struct LoggingHandle * l
static void regex_ctx_destroy(struct RegexCombineCtx *ctx)
Free all resources used by the context node and all its children.
char * REGEX_TEST_combine(char *const regexes[], unsigned int alphabet_size)
Combine an array of regexes into a single prefix-shared regex.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
static struct GNUNET_OS_Process * p
Helper process we started.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
static int c2i(char c, int size)
Char 2 int.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static char * regex_combine(struct RegexCombineCtx *ctx)
Extract a string from all prefix-combined regexes.
static void regex_split(struct RegexCombineCtx *ctx, unsigned int len, unsigned int prefix_l)
Add a single regex to a context, splitting the exisiting state.
void REGEX_TEST_free_from_file(char **regexes)
Free all memory reserved for a set of regexes created by read_from_file.
char ** REGEX_TEST_read_from_file(const char *filename)
Read a set of regexes from a file, one per line and return them in an array suitable for REGEX_TEST_c...
#define GNUNET_log(kind,...)
static struct RegexCombineCtx * new_regex_ctx(unsigned int alphabet_size)
Create and initialize a new RegexCombineCtx.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
static void regex_add(struct RegexCombineCtx *ctx, const char *regex)
Add a single regex to a context, combining with exisiting regex by-prefix.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Handle used to access files (and pipes).
static unsigned int get_prefix_length(const char *s1, const char *s2)
Get the number of matching characters on the prefix of both strings.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...