summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/sequence')
-rw-r--r--src/sequence/sequence.c138
-rw-r--r--src/sequence/sequence.h94
-rw-r--r--src/sequence/sequence_append.c41
-rw-r--r--src/sequence/sequence_creation.c60
-rw-r--r--src/sequence/sequence_from_string.c50
-rw-r--r--src/sequence/sequence_to_string.c23
6 files changed, 198 insertions, 208 deletions
diff --git a/src/sequence/sequence.c b/src/sequence/sequence.c
index f3c3b46..78a5aad 100644
--- a/src/sequence/sequence.c
+++ b/src/sequence/sequence.c
@@ -5,74 +5,6 @@
#include "sequence.h"
-/*
- * Bypass rendundant ZoO_START_OF_SEQUENCE_ID at the start of a sequence.
- */
-/*@
- requires
- (
- \valid(sequence+ (0 .. sequence_length))
- || (sequence_length == 0)
- );
- requires \separated(sequence, sequence_offset);
-
- assigns (*sequence_offset);
-
- ensures (*sequence_offset < sequence_length);
-
- ensures
- (
- (*sequence_offset == 0)
- || (sequence[0 .. *sequence_offset] == ZoO_START_OF_SEQUENCE_ID)
- );
-
- ensures
- (
- (*sequence_offset == sequence_length)
- || (sequence[*sequence_offset + 1] != ZoO_START_OF_SEQUENCE_ID)
- );
-
-@*/
-static void bypass_redundant_sos
-(
- const ZoO_index sequence [const restrict],
- const size_t sequence_length,
- size_t sequence_offset [const restrict static 1]
-)
-{
- ZoO_index i;
-
- *sequence_offset = 0;
-
- /*@
- loop invariant 0 <= i <= sequence_length;
- loop invariant (*sequence_offset <= i);
- loop invariant
- (
- (*sequence_offset == 0)
- || (sequence[*sequence_offset] == ZoO_START_OF_SEQUENCE_ID)
- );
- loop invariant
- (
- (i == 0) || (sequence[0 .. (i - 1)] == ZoO_START_OF_SEQUENCE_ID)
- );
- loop assigns i, *sequence_offset;
- loop variant (sequence_length - i);
- @*/
- for (i = 0; i < sequence_length; ++i)
- {
- if (sequence[i] != ZoO_START_OF_SEQUENCE_ID)
- {
- return;
- }
- else if (sequence[i] == ZoO_START_OF_SEQUENCE_ID)
- {
- *sequence_offset = i;
- }
- }
-}
-
-
/* See "sequence.h" */
/*@
requires
@@ -91,80 +23,28 @@ static void bypass_redundant_sos
@*/
int ZoO_sequence_cmp
(
- const ZoO_index sequence_a [const],
- size_t sequence_a_length,
- const ZoO_index sequence_b [const],
- size_t sequence_b_length
+ const ZoO_index sequence_a [const restrict static 1],
+ const ZoO_index sequence_b [const restrict static 1],
+ const ZoO_index length
)
{
- size_t min_length, a, b;
- size_t a_offset, b_offset;
- size_t i;
- /*@ ghost size_t actual_a_length, actual_b_length; @*/
-
- bypass_redundant_sos(sequence_a, sequence_a_length, &a_offset);
- bypass_redundant_sos(sequence_b, sequence_b_length, &b_offset);
+ ZoO_index i, a, b;
- /*@ ghost actual_a_length = sequence_a_length; @*/
- /*@ ghost actual_b_length = sequence_b_length; @*/
-
- /*@ assert (a_offset <= sequence_a_length); @*/
- sequence_a_length -= a_offset;
- /*@ assert (b_offset <= sequence_b_length); @*/
- sequence_b_length -= b_offset;
-
- if (sequence_a_length < sequence_b_length)
- {
- min_length = sequence_a_length;
- }
- else
+ for (i = 0; i < length; ++i)
{
- min_length = sequence_b_length;
- }
-
- /*@ assert (min_length <= sequence_a_length); @*/
- /*@ assert (min_length <= sequence_b_length); @*/
-
- /*@ assert (min_length + a_offset <= actual_a_length); @*/
- /*@ assert (min_length + b_offset <= actual_b_length); @*/
-
- /*@
- loop invariant 0 <= i <= min_length;
- loop assigns i;
- loop variant (min_length - i);
- @*/
- for (i = 0; i < min_length; ++i)
- {
- /*@ assert ((i + a_offset) < actual_a_length); @*/
- a = sequence_a[i + a_offset];
- /*@ assert ((i + b_offset) < actual_b_length); @*/
- b = sequence_b[i + b_offset];
+ a = sequence_a[i];
+ b = sequence_b[i];
if (a < b)
{
return -1;
}
- else if (b > a)
+ else if (a > b)
{
return 1;
}
- else if ((a == ZoO_END_OF_SEQUENCE_ID) && (b == ZoO_END_OF_SEQUENCE_ID))
- {
- return 0;
- }
}
- if (sequence_a_length > sequence_b_length)
- {
- return 1;
- }
- else if (sequence_a_length < sequence_b_length)
- {
- return -1;
- }
- else
- {
- return 0;
- }
+ return 0;
}
diff --git a/src/sequence/sequence.h b/src/sequence/sequence.h
index 129c457..9239336 100644
--- a/src/sequence/sequence.h
+++ b/src/sequence/sequence.h
@@ -7,7 +7,7 @@
#include "../core/char_types.h"
#include "../core/index_types.h"
-#include "../pipe/pipe.h"
+#include "../error/error.h"
#include "../knowledge/knowledge_types.h"
@@ -15,16 +15,32 @@
/*@
requires \valid(sequence);
- requires \valid(*sequence);
+ requires (\block_length(sequence) >= 1);
requires \valid(sequence_capacity);
+ requires (\block_length(sequence) >= 1);
requires \valid(io);
requires (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
requires ((sequence_required_capacity * sizeof(ZoO_index)) <= SIZE_MAX);
- requires \separated(sequence, *sequence, sequence_capacity, io);
+ requires
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (io+ (0 ..\block_length(io)))
+ );
+
+ ensures
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (io+ (0 ..\block_length(io)))
+ );
- ensures \separated(sequence, *sequence, sequence_capacity, io);
ensures (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
ensures ((sequence_required_capacity * sizeof(ZoO_index)) <= SIZE_MAX);
ensures \valid(sequence);
@@ -70,7 +86,7 @@ int ZoO_sequence_ensure_capacity
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
const size_t sequence_required_capacity,
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
);
int ZoO_sequence_from_undercase_string
@@ -81,7 +97,7 @@ int ZoO_sequence_from_undercase_string
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
);
/*
@@ -114,7 +130,7 @@ int ZoO_sequence_create_from
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
);
/*@
@@ -125,7 +141,15 @@ int ZoO_sequence_create_from
requires \valid(io);
requires (((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX);
requires (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
- requires \separated(sequence, *sequence, sequence_capacity, sequence_length, io);
+ requires
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (sequence_length+ (0 ..\block_length(sequence_length))),
+ (io+ (0 ..\block_length(io)))
+ );
assigns (*sequence_length);
assigns (*sequence[0]);
@@ -138,7 +162,15 @@ int ZoO_sequence_create_from
ensures \valid(io);
ensures (((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX);
ensures (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
- ensures \separated(sequence, *sequence, sequence_capacity, sequence_length, io);
+ ensures
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (sequence_length+ (0 ..\block_length(sequence_length))),
+ (io+ (0 ..\block_length(io)))
+ );
ensures ((\result == 0) || (\result == -1));
@@ -157,7 +189,7 @@ int ZoO_sequence_create_from
ensures ((\result == 0) ==> (*sequence_length > \old(*sequence_length)));
ensures ((\result == -1) ==> ((*sequence_length) == \old(*sequence_length)));
- ensures ((\result == -1) ==> ((*sequence[0]) == \old(*sequence[0])));
+ ensures ((\result == -1) ==> (((*sequence)[0]) == \old((*sequence)[0])));
ensures
(
(\result == -1) ==>
@@ -178,7 +210,7 @@ int ZoO_sequence_append_left
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
);
/*@
@@ -189,10 +221,18 @@ int ZoO_sequence_append_left
requires \valid(io);
requires (((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX);
requires (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
- requires \separated(sequence, *sequence, sequence_capacity, sequence_length, io);
+ requires
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (sequence_length+ (0 ..\block_length(sequence_length))),
+ (io+ (0 ..\block_length(io)))
+ );
assigns (*sequence_length);
- assigns (*sequence[0]);
+ assigns ((*sequence)[0]);
assigns (*sequence_capacity);
ensures \valid(sequence);
@@ -202,7 +242,15 @@ int ZoO_sequence_append_left
ensures \valid(io);
ensures (((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX);
ensures (((*sequence_capacity) * sizeof(ZoO_index)) <= SIZE_MAX);
- ensures \separated(sequence, *sequence, sequence_capacity, sequence_length, io);
+ ensures
+ \separated
+ (
+ (sequence+ (0 .. \block_length(sequence))),
+ ((*sequence)+ (0 .. \block_length(*sequence))),
+ (sequence_capacity+ (0 ..\block_length(sequence_capacity))),
+ (sequence_length+ (0 ..\block_length(sequence_length))),
+ (io+ (0 ..\block_length(io)))
+ );
ensures ((\result == 0) || (\result == -1));
@@ -221,7 +269,7 @@ int ZoO_sequence_append_left
ensures ((\result == 0) ==> (*sequence_length > \old(*sequence_length)));
ensures ((\result == -1) ==> ((*sequence_length) == \old(*sequence_length)));
- ensures ((\result == -1) ==> ((*sequence[0]) == \old(*sequence[0])));
+ ensures ((\result == -1) ==> (((*sequence)[0]) == \old((*sequence)[0])));
ensures
(
(\result == -1) ==>
@@ -242,7 +290,7 @@ int ZoO_sequence_append_right
const ZoO_index word_id,
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
);
/*
@@ -265,9 +313,19 @@ int ZoO_sequence_append_right
int ZoO_sequence_cmp
(
const ZoO_index sequence_a [const],
- size_t sequence_a_length,
const ZoO_index sequence_b [const],
- size_t sequence_b_length
+ const ZoO_index length
+);
+
+int ZoO_sequence_to_undercase_string
+(
+ const ZoO_index sequence [const restrict static 1],
+ const size_t sequence_length,
+ struct ZoO_knowledge k [const restrict static 1],
+ ZoO_char * destination [const restrict static 1],
+ size_t destination_capacity [const restrict static 1],
+ size_t destination_length [const restrict static 1],
+ FILE io [const restrict static 1]
);
#endif
diff --git a/src/sequence/sequence_append.c b/src/sequence/sequence_append.c
index 604d251..81dfa99 100644
--- a/src/sequence/sequence_append.c
+++ b/src/sequence/sequence_append.c
@@ -5,7 +5,7 @@
#include "../core/index.h"
-#include "../pipe/pipe.h"
+#include "../error/error.h"
#include "sequence.h"
@@ -16,10 +16,14 @@
/*@
requires \valid(required_capacity);
requires \valid(io);
- requires \separated(required_capacity, io);
+ requires
+ \separated
+ (
+ (required_capacity+ (0 .. \block_length(required_capacity))),
+ (io+ (0 .. \block_length(io)))
+ );
assigns \result;
-
assigns (*required_capacity);
ensures ((\result == 0) || (\result == -1));
@@ -27,7 +31,12 @@
ensures \valid(required_capacity);
ensures \valid(io);
- ensures \separated(required_capacity, io);
+ ensures
+ \separated
+ (
+ (required_capacity+ (0 .. \block_length(required_capacity))),
+ (io+ (0 .. \block_length(io)))
+ );
ensures
(
@@ -51,7 +60,7 @@
static int increment_required_capacity
(
size_t required_capacity [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
if
@@ -92,7 +101,7 @@ int ZoO_sequence_ensure_capacity
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
const size_t sequence_required_capacity,
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
ZoO_index * new_sequence;
@@ -146,7 +155,7 @@ int ZoO_sequence_append_left
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
if (increment_required_capacity(sequence_length, io) < 0)
@@ -171,17 +180,17 @@ int ZoO_sequence_append_left
return -1;
}
- /*@ assert *sequence_length >= 0; @*/
+ /*@ assert (*sequence_length) >= 0; @*/
- if (*sequence_length > 1)
+ if ((*sequence_length) > 1)
{
/*@ assert(((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX); @*/
#ifndef ZoO_RUNNING_FRAMA_C
memmove
(
- (void *) (*sequence + 1),
- (const void *) sequence,
+ (void *) ((*sequence) + 1),
+ (const void *) (*sequence),
(((*sequence_length) - 1) * sizeof(ZoO_index))
);
#endif
@@ -198,7 +207,7 @@ int ZoO_sequence_append_right
const ZoO_index word_id,
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
if (increment_required_capacity(sequence_length, io) < 0)
@@ -206,7 +215,7 @@ int ZoO_sequence_append_right
return -1;
}
- /*@ assert ((*sequence_length * sizeof(ZoO_index)) <= SIZE_MAX); @*/
+ /*@ assert (((*sequence_length) * sizeof(ZoO_index)) <= SIZE_MAX); @*/
if
(
@@ -224,9 +233,9 @@ int ZoO_sequence_append_right
return -1;
}
- /*@ assert (*sequence_length >= 1); @*/
- (*sequence)[*sequence_length - 1] = word_id;
- /*@ assert (*sequence_length >= 1); @*/
+ /*@ assert ((*sequence_length) >= 1); @*/
+ (*sequence)[(*sequence_length) - 1] = word_id;
+ /*@ assert ((*sequence_length) >= 1); @*/
return 0;
}
diff --git a/src/sequence/sequence_creation.c b/src/sequence/sequence_creation.c
index 1f20262..9556693 100644
--- a/src/sequence/sequence_creation.c
+++ b/src/sequence/sequence_creation.c
@@ -5,7 +5,7 @@
#include "../core/index.h"
-#include "../pipe/pipe.h"
+#include "../error/error.h"
#include "../knowledge/knowledge.h"
@@ -40,7 +40,7 @@ static int extend_left
size_t sequence_length [const restrict static 1],
const ZoO_index markov_order,
struct ZoO_knowledge k [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
ZoO_index sequence_id, word_id;
@@ -62,7 +62,8 @@ static int extend_left
{
(void) ZoO_knowledge_unlock_access(k, io);
- /* TODO: Err message. */
+ ZoO_S_ERROR(io, "Could not find matching TWS sequence.");
+
return -1;
}
@@ -83,7 +84,7 @@ static int extend_left
{
(void) ZoO_knowledge_unlock_access(k, io);
- /* TODO: Err message. */
+ ZoO_S_ERROR(io, "Could not find matching TWS target.");
return -1;
}
@@ -138,7 +139,7 @@ static int complete_left_part_of_sequence
const ZoO_index markov_order,
size_t credits [const restrict],
struct ZoO_knowledge k [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
for (;;)
@@ -159,7 +160,7 @@ static int complete_left_part_of_sequence
)
{
/* We are sure *sequence[0] is defined. */
- if (*sequence[0] == ZoO_START_OF_SEQUENCE_ID)
+ if ((*sequence)[0] == ZoO_START_OF_SEQUENCE_ID)
{
/*
* We failed to add a word, but it was because none should have
@@ -176,7 +177,7 @@ static int complete_left_part_of_sequence
else
{
/* No more credits available, the sequence will have to start here. */
- *sequence[0] = ZoO_START_OF_SEQUENCE_ID;
+ (*sequence)[0] = ZoO_START_OF_SEQUENCE_ID;
return 0;
}
@@ -187,7 +188,7 @@ static int complete_left_part_of_sequence
}
/* We are sure *sequence[0] is defined. */
- switch (*sequence[0])
+ switch ((*sequence)[0])
{
case ZoO_END_OF_SEQUENCE_ID:
ZoO_S_WARNING
@@ -196,7 +197,7 @@ static int complete_left_part_of_sequence
"END OF LINE was added at the left part of an sequence."
);
- *sequence[0] = ZoO_START_OF_SEQUENCE_ID;
+ (*sequence)[0] = ZoO_START_OF_SEQUENCE_ID;
return 0;
case ZoO_START_OF_SEQUENCE_ID:
@@ -237,7 +238,7 @@ static int extend_right
size_t sequence_length [const restrict static 1],
const ZoO_index markov_order,
struct ZoO_knowledge k [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
ZoO_index sequence_id, word_id;
@@ -342,7 +343,7 @@ static int complete_right_part_of_sequence
const ZoO_index markov_order,
size_t credits [const restrict],
struct ZoO_knowledge k [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
for (;;)
@@ -363,7 +364,7 @@ static int complete_right_part_of_sequence
)
{
/* Safe: (> sequence_length 1) */
- if (*sequence[(*sequence_length - 1)] == ZoO_END_OF_SEQUENCE_ID)
+ if ((*sequence)[(*sequence_length - 1)] == ZoO_END_OF_SEQUENCE_ID)
{
/*
* We failed to add a word, but it was because none should have
@@ -380,7 +381,7 @@ static int complete_right_part_of_sequence
else
{
/* No more credits available, we end the sequence. */
- *sequence[(*sequence_length - 1)] = ZoO_END_OF_SEQUENCE_ID;
+ (*sequence)[((*sequence_length) - 1)] = ZoO_END_OF_SEQUENCE_ID;
return 0;
}
@@ -391,7 +392,7 @@ static int complete_right_part_of_sequence
}
/* Safe: (> sequence_length 1) */
- switch (*sequence[(*sequence_length - 1)])
+ switch ((*sequence)[((*sequence_length) - 1)])
{
case ZoO_START_OF_SEQUENCE_ID:
ZoO_S_WARNING
@@ -400,7 +401,7 @@ static int complete_right_part_of_sequence
"END OF LINE was added at the right part of an sequence."
);
- *sequence[(*sequence_length - 1)] = ZoO_END_OF_SEQUENCE_ID;
+ (*sequence)[((*sequence_length) - 1)] = ZoO_END_OF_SEQUENCE_ID;
return 0;
case ZoO_END_OF_SEQUENCE_ID:
@@ -438,7 +439,7 @@ static int initialize_sequence
const ZoO_index initial_word,
const ZoO_index markov_order,
struct ZoO_knowledge k [const static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
sequence[(markov_order - 1)] = initial_word;
@@ -467,6 +468,23 @@ static int initialize_sequence
return -1;
}
+ if (ZoO_DEBUG_SEQUENCE_CREATION_INIT)
+ {
+ ZoO_index i;
+
+ for (i = 0; i < markov_order; ++i)
+ {
+ ZoO_DEBUG
+ (
+ io,
+ ZoO_DEBUG_SEQUENCE_CREATION_INIT,
+ "sequence[%u]: %u",
+ i,
+ sequence[i]
+ );
+ }
+ }
+
(void) ZoO_knowledge_unlock_access(k, io);
return 0;
@@ -486,9 +504,11 @@ int ZoO_sequence_create_from
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
+ size_t i;
+
if
(
ZoO_sequence_ensure_capacity
@@ -517,6 +537,8 @@ int ZoO_sequence_create_from
) < 0
)
{
+ ZoO_S_ERROR(io, "Failed to create start of new sequence.");
+
*sequence_length = 0;
return -2;
@@ -538,6 +560,8 @@ int ZoO_sequence_create_from
) < 0
)
{
+ ZoO_S_ERROR(io, "Failed to create right part of sequence.");
+
*sequence_length = 0;
return -3;
@@ -557,6 +581,8 @@ int ZoO_sequence_create_from
) < 0
)
{
+ ZoO_S_ERROR(io, "Failed to create left part of sequence.");
+
*sequence_length = 0;
return -4;
diff --git a/src/sequence/sequence_from_string.c b/src/sequence/sequence_from_string.c
index 6acfdc2..e493bbc 100644
--- a/src/sequence/sequence_from_string.c
+++ b/src/sequence/sequence_from_string.c
@@ -6,7 +6,7 @@
#include "../core/char.h"
#include "../core/index.h"
-#include "../pipe/pipe.h"
+#include "../error/error.h"
#include "../knowledge/knowledge.h"
@@ -25,17 +25,12 @@ static int add_word_to_sequence
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
struct ZoO_knowledge k [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
ZoO_index word_id;
ZoO_char * stored_word;
- if (word_length == 0)
- {
- return 0;
- }
-
(void) ZoO_knowledge_lock_access(k, io);
if
@@ -105,11 +100,6 @@ static int find_word
i += 1;
}
- if (i >= string_length)
- {
- return -1;
- }
-
*word_length = (i - *word_start);
return 0;
@@ -128,7 +118,7 @@ int ZoO_sequence_from_undercase_string
ZoO_index * sequence [const restrict static 1],
size_t sequence_capacity [const restrict static 1],
size_t sequence_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
size_t word_start, word_length;
@@ -136,9 +126,16 @@ int ZoO_sequence_from_undercase_string
i = 0;
- *sequence = (ZoO_index *) NULL;
*sequence_length = 0;
+ ZoO_DEBUG
+ (
+ io,
+ ZoO_DEBUG_SEQUENCE_FROM_STRING,
+ "Converting string of size %lu to sequence.",
+ string_length
+ );
+
if
(
ZoO_sequence_append_right
@@ -151,16 +148,34 @@ int ZoO_sequence_from_undercase_string
) < 0
)
{
+ *sequence_length = 0;
+
return -1;
}
+ ZoO_S_DEBUG
+ (
+ io,
+ ZoO_DEBUG_SEQUENCE_FROM_STRING,
+ "[SOS] added to sequence."
+ );
+
while (i < string_length)
{
- if (find_word(string, i, string_length, &word_start, &word_length) < 0)
+ if (find_word(string, string_length, i, &word_start, &word_length) < 0)
{
break;
}
+ ZoO_DEBUG
+ (
+ io,
+ ZoO_DEBUG_SEQUENCE_FROM_STRING,
+ "Word of size %lu found in string at index %lu.",
+ word_length,
+ word_start
+ );
+
if
(
add_word_to_sequence
@@ -176,8 +191,6 @@ int ZoO_sequence_from_undercase_string
) < 0
)
{
- free((void *) *sequence);
- *sequence = (ZoO_index *) NULL;
*sequence_length = 0;
return -1;
@@ -198,9 +211,6 @@ int ZoO_sequence_from_undercase_string
) < 0
)
{
- free((void *) *sequence);
-
- *sequence = (ZoO_index *) NULL;
*sequence_length = 0;
return -1;
diff --git a/src/sequence/sequence_to_string.c b/src/sequence/sequence_to_string.c
index 96bd521..919ef0b 100644
--- a/src/sequence/sequence_to_string.c
+++ b/src/sequence/sequence_to_string.c
@@ -6,7 +6,7 @@
#include "../core/char.h"
#include "../core/index.h"
-#include "../pipe/pipe.h"
+#include "../error/error.h"
#include "../knowledge/knowledge.h"
@@ -20,7 +20,7 @@ static int ensure_string_capacity
ZoO_char * string [const restrict static 1],
size_t string_capacity [const restrict static 1],
const size_t string_required_capacity,
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
ZoO_char * new_string;
@@ -61,10 +61,10 @@ static int increment_required_capacity
(
size_t current_capacity [const restrict static 1],
const size_t increase_factor,
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
- if ((ZoO_INDEX_MAX - increase_factor) > *current_capacity)
+ if ((ZoO_INDEX_MAX - increase_factor) < *current_capacity)
{
ZoO_S_ERROR
(
@@ -78,7 +78,7 @@ static int increment_required_capacity
*current_capacity += increase_factor;
- if ((SIZE_MAX / sizeof(ZoO_char)) > *current_capacity)
+ if ((SIZE_MAX / sizeof(ZoO_char)) < *current_capacity)
{
*current_capacity -= increase_factor;
@@ -102,13 +102,18 @@ static int add_word
ZoO_char * destination [const restrict static 1],
size_t destination_capacity [const restrict static 1],
size_t destination_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
const ZoO_char * word;
ZoO_index word_size;
size_t insertion_point;
+ if (word_id < ZoO_RESERVED_IDS_COUNT)
+ {
+ return 0;
+ }
+
(void) ZoO_knowledge_lock_access(k, io);
ZoO_knowledge_get_word(k, word_id, &word, &word_size);
(void) ZoO_knowledge_unlock_access(k, io);
@@ -155,15 +160,17 @@ int ZoO_sequence_to_undercase_string
(
const ZoO_index sequence [const restrict static 1],
const size_t sequence_length,
- ZoO_char * destination [const restrict static 1],
struct ZoO_knowledge k [const restrict static 1],
+ ZoO_char * destination [const restrict static 1],
size_t destination_capacity [const restrict static 1],
size_t destination_length [const restrict static 1],
- const struct ZoO_pipe io [const restrict static 1]
+ FILE io [const restrict static 1]
)
{
size_t i;
+ *destination_length = 0;
+
for (i = 0; i < sequence_length; ++i)
{
if