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",
105 for (
int i = 0; i < n; i++)
106 fprintf (stderr,
"| ");
126 fprintf (stderr,
"%u:'%s'\n",
c2i (
ctx->s[0],
ctx->size),
ctx->s);
129 fprintf (stderr,
"ROOT (base %u)\n",
ctx->size);
130 for (
unsigned int i = 0; i <
ctx->size; i++)
132 if (NULL !=
ctx->children[i])
168 ctx->size = alphabet_size;
184 for (
unsigned int i = 0; i < src->
size; i++)
212 for (i = 0; i <
ctx->size; i++)
214 p =
ctx->children[i];
218 "adding '%s' to innner %s\n",
238 len = strlen (regex);
246 if (
'|' == regex[len - 1])
247 regex[len - 1] =
'\0';
282 limit = l1 > l2 ? l2 : l1;
284 for (i = 0; i < limit; i++)
314 for (i = 0; i <
ctx->size; i++)
316 p =
ctx->children[i];
353 for (i = 1UL; i < l; i++)
355 if ((regex[i] !=
'|') && (regex[i] !=
')') )
360 if (count ==
ctx->size)
367 for (i = 1UL; i < l; i++)
369 if ((regex[i] !=
'|') && (regex[i] !=
')') )
378 ctx->children[
c2i (tmp[0],
ctx->size)] = newctx;
397 unsigned int prefix_l)
413 ctx->s[prefix_l] =
'\0';
416 if (
'(' == suffix[0])
432 idx =
c2i (suffix[0],
ctx->size);
433 ctx->children[idx] = newctx;
449 unsigned int prefix_l;
456 "regex_add '%s' into '%s'\n",
474 rest_s = &
p->s[prefix_l];
475 rest_r = ®ex[prefix_l];
490 idx =
c2i (regex[0],
ctx->size);
491 if ((NULL ==
ctx->children[idx]) && (NULL !=
ctx->s))
496 ctx->children[idx] = newctx;
503 ctx->children[idx] = newctx;
520 for (i = 0; i <
ctx->size; i++)
553 for (i = 0; regexes[i]; i++)
555 current = regexes[i];
598 "Can't open file %s for reading\n",
filename);
604 "Can't get size of file %s\n",
filename);
609 "using file %s, size %llu\n",
623 len = (size_t) sscanf (&buffer[offset],
"%s", regex);
626 len = strlen (regex);
634 regexes[nr - 2] = regex;
635 regexes[nr - 1] = NULL;
638 while (offset <
size);
656 for (i = 0; regexes[i]; i++)
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_OS_Process * p
Helper process we started.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size(struct GNUNET_DISK_FileHandle *fh, off_t *size)
Get the size of an open file.
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
static unsigned int size
Size of the "table".
static void regex_split(struct RegexCombineCtx *ctx, unsigned int len, unsigned int prefix_l)
Add a single regex to a context, splitting the existing state.
static void move_children(struct RegexCombineCtx *dst, const struct RegexCombineCtx *src)
static char * regex_combine(struct RegexCombineCtx *ctx)
Extract a string from all prefix-combined regexes.
static void regex_ctx_destroy(struct RegexCombineCtx *ctx)
Free all resources used by the context node and all its children.
void REGEX_TEST_free_from_file(char **regexes)
Free all memory reserved for a set of regexes created by read_from_file.
static struct RegexCombineCtx * new_regex_ctx(unsigned int alphabet_size)
Create and initialize a new RegexCombineCtx.
static int c2i(char c, int size)
Char 2 int.
static void regex_add(struct RegexCombineCtx *ctx, const char *regex)
Add a single regex to a context, combining with existing regex by-prefix.
static void debugctx(struct RegexCombineCtx *ctx, int level)
Printf the combined regex ctx.
char * REGEX_TEST_combine(char *const regexes[], unsigned int alphabet_size)
Combine an array of regexes into a single prefix-shared regex.
static unsigned int get_prefix_length(const char *s1, const char *s2)
Get the number of matching characters on the prefix of both strings.
static struct RegexCombineCtx * get_longest_prefix(struct RegexCombineCtx *ctx, const char *regex)
Return the child context with the longest prefix match with the regex.
static void regex_add_multiple(struct RegexCombineCtx *ctx, const char *regex, struct RegexCombineCtx **children)
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...
Handle used to access files (and pipes).
Struct to hold the tree formed by prefix-combining the regexes.
struct RegexCombineCtx ** children
Child nodes with same prefix and token.
unsigned int size
Alphabet size (how many children there are)