2008-11-13 12:53:16 -08:00
|
|
|
#if defined (_MSC_VER) || defined (__MINGW32__) || defined (__MINGW32CE__)
|
2008-10-11 00:23:55 -07:00
|
|
|
|
2008-07-24 11:18:55 -07:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-09 14:56:31 -07:00
|
|
|
#include "evil_fnmatch_private.h"
|
2008-07-24 11:18:55 -07:00
|
|
|
|
|
|
|
struct list_of_states*
|
2008-10-09 14:56:31 -07:00
|
|
|
fnmatch_list_of_states_alloc(size_t n,
|
|
|
|
size_t pattern_len)
|
2008-07-24 11:18:55 -07:00
|
|
|
{
|
|
|
|
struct list_of_states *l;
|
|
|
|
|
2008-10-09 14:56:31 -07:00
|
|
|
const size_t reserved = pattern_len + 1;
|
|
|
|
const size_t states_size = sizeof (*l->states) * reserved;
|
|
|
|
const size_t has_size = sizeof (*l->has) * reserved;
|
2008-07-24 11:18:55 -07:00
|
|
|
const size_t states_has_size = states_size + has_size;
|
2008-10-09 14:56:31 -07:00
|
|
|
const size_t struct_size = sizeof (*l) + states_has_size;
|
2008-07-24 11:18:55 -07:00
|
|
|
|
2008-09-14 23:56:14 -07:00
|
|
|
unsigned char *states;
|
|
|
|
unsigned char *has;
|
2008-10-09 14:56:31 -07:00
|
|
|
size_t i;
|
2008-07-24 11:18:55 -07:00
|
|
|
|
2009-08-27 01:19:06 -07:00
|
|
|
l = malloc(n * struct_size);
|
|
|
|
if (!l)
|
2008-07-24 11:18:55 -07:00
|
|
|
return 0;
|
|
|
|
|
2008-09-14 23:56:14 -07:00
|
|
|
states = (unsigned char *) (l + n);
|
2008-07-24 11:18:55 -07:00
|
|
|
has = states + states_size;
|
|
|
|
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
l[i].reserved = reserved;
|
|
|
|
l[i].states = (size_t *) states;
|
2008-10-09 14:56:31 -07:00
|
|
|
l[i].has = (e_bool *) has;
|
2008-07-24 11:18:55 -07:00
|
|
|
states += states_has_size;
|
|
|
|
has += states_has_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-09 14:56:31 -07:00
|
|
|
fnmatch_list_of_states_free(struct list_of_states *lists,
|
|
|
|
size_t n)
|
2008-07-24 11:18:55 -07:00
|
|
|
{
|
|
|
|
assert(lists);
|
|
|
|
|
|
|
|
(void) n;
|
|
|
|
free(lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-09 14:56:31 -07:00
|
|
|
fnmatch_list_of_states_insert(struct list_of_states *list,
|
|
|
|
size_t state)
|
2008-07-24 11:18:55 -07:00
|
|
|
{
|
|
|
|
assert(list);
|
|
|
|
assert(state < list->reserved);
|
|
|
|
|
|
|
|
if (list->has[state])
|
|
|
|
return;
|
|
|
|
|
|
|
|
list->states[list->size++] = state;
|
|
|
|
list->has[state] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fnmatch_list_of_states_clear(struct list_of_states *list)
|
|
|
|
{
|
|
|
|
assert(list);
|
|
|
|
|
|
|
|
list->size = 0;
|
|
|
|
memset(list->has, 0, list->reserved * sizeof (*list->has));
|
|
|
|
}
|
2008-10-11 00:23:55 -07:00
|
|
|
|
2008-11-13 12:53:16 -08:00
|
|
|
#endif /* _MSC_VER || __MINGWCE__ || __MINGW32CE__ */
|