Hash :
ee55121b
Author :
Thomas de Grivel
Date :
2022-11-10T16:51:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/* c3
* Copyright 2022 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted
* the above copyright notice and this permission paragraph
* are included in all copies and substantial portions of this
* software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <assert.h>
#include <stdlib.h>
#include "facts_cursor.h"
#include "facts_spec.h"
#include "facts_with.h"
#include "facts_with_cursor.h"
void facts_with_cursor_clean (s_facts_with_cursor *cursor)
{
assert(cursor);
free(cursor->l);
free(cursor->spec);
}
s_fact * facts_with_cursor_next (s_facts_with_cursor *cursor)
{
s_fact *fact = NULL;
s_facts_with_cursor_level *level;
p_facts_spec parent_spec;
assert(cursor);
if (! cursor->facts_count)
return NULL;
if (cursor->level == cursor->facts_count) {
level = cursor->l + (cursor->facts_count - 1);
level->fact = facts_cursor_next(&level->cursor);
if (level->fact)
return level->fact;
free(level->spec);
level->spec = NULL;
cursor->level--;
if (!cursor->level) {
cursor->facts_count = 0;
return NULL;
}
cursor->level--;
}
while (cursor->level < cursor->facts_count) {
level = cursor->l + cursor->level;
if (! level->spec) {
parent_spec = cursor->level ?
cursor->l[cursor->level - 1].spec + 4 :
cursor->spec;
level->spec = facts_spec_new_expand(parent_spec);
facts_with_tags(cursor->facts, &level->cursor, level->spec[0],
level->spec[1], level->spec[2]);
}
level->fact = fact = facts_cursor_next(&level->cursor);
if (fact) {
cursor->level++;
continue;
}
free(level->spec);
level->spec = NULL;
if (! cursor->level) {
cursor->facts_count = 0;
return NULL;
}
cursor->level--;
}
return fact;
}