You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
937 B
39 lines
937 B
#define _GNU_SOURCE
|
|
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
|
|
#include <macros.h>
|
|
#include <ints.h>
|
|
#include <map.h>
|
|
|
|
|
|
bool cmp_find(const map_t *pIN needle, const map_t *pIN haystack, usize *pOUT pos)
|
|
{
|
|
u8* start;
|
|
u8* substr = memmem(start = haystack->origin, haystack->len,
|
|
needle->origin, needle->len);
|
|
if(!substr) return false;
|
|
debug_assert(substr > start);
|
|
*pos = (usize) (substr - start);
|
|
return true;
|
|
}
|
|
|
|
int cmp_find_many(usize nhaystacks; const map_t *pIN needle, usize sizes[pOUT nhaystacks], usize nhaystacks, ...)
|
|
{
|
|
va_list v_haystacks;
|
|
va_start(v_haystacks, nhaystacks);
|
|
|
|
const map_t* pINOUT haystack;
|
|
for(usize i=0;i<nhaystacks;i++)
|
|
{
|
|
usize *pOUT size = sizes + i;
|
|
haystack = va_arg(v_haystacks, const map_t* pIN);
|
|
if(!haystack || !haystack->origin) FATAL("haystack %lu was null or its origin was null", i);
|
|
if(!cmp_find(needle, haystack, size)) return (int)i;
|
|
}
|
|
|
|
va_end(v_haystacks);
|
|
return -1;
|
|
}
|