summaryrefslogtreecommitdiff
path: root/src/analysis/db/misc/rlestr.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-04-19 19:25:04 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-04-19 19:25:04 (GMT)
commitc177597d6da5dedb32aa176e8370db8ffb7f87aa (patch)
tree26f7eb2702ba4aa3dfd7267d74fe78ad79791a8c /src/analysis/db/misc/rlestr.c
parent35f37c72e9d81e478395914da6c10b3c546761a7 (diff)
Handled static strings as well as dynamic strings in comments.
Diffstat (limited to 'src/analysis/db/misc/rlestr.c')
-rw-r--r--src/analysis/db/misc/rlestr.c107
1 files changed, 100 insertions, 7 deletions
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c
index 39e2d99..c1d2d95 100644
--- a/src/analysis/db/misc/rlestr.c
+++ b/src/analysis/db/misc/rlestr.c
@@ -43,12 +43,73 @@
* *
******************************************************************************/
-void init_rle_string(rle_string *str, const char *data)
+void init_dynamic_rle_string(rle_string *str, char *data)
+{
+ if (data != NULL)
+ {
+ str->data = data;
+ str->length = strlen(data);
+ str->dynamic = true;
+ }
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Définit une représentation de chaîne de caractères constante.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void init_static_rle_string(rle_string *str, const char *data)
+{
+ if (data != NULL)
+ {
+ str->cst_data = data;
+ str->length = strlen(data);
+ str->dynamic = false;
+ }
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Copie une chaîne de caractères existante. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void dup_into_rle_string(rle_string *str, const char *data)
{
if (data != NULL)
{
str->data = strdup(data);
str->length = strlen(data);
+ str->dynamic = true;
}
else
{
@@ -72,15 +133,44 @@ void init_rle_string(rle_string *str, const char *data)
* *
******************************************************************************/
-void set_rle_string(rle_string *str, const char *data)
+void set_dynamic_rle_string(rle_string *str, char *data)
{
if (str->data != NULL)
unset_rle_string(str);
if (data != NULL)
{
- str->data = strdup(data);
+ str->data = data;
+ str->length = strlen(data);
+ str->dynamic = true;
+ }
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : str = représentation de chaîne à traiter. *
+* data = données à conserver en mémoire. *
+* *
+* Description : Constitue une représentation de chaîne de caractères stable. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void set_static_rle_string(rle_string *str, const char *data)
+{
+ if (str->data != NULL)
+ unset_rle_string(str);
+
+ if (data != NULL)
+ {
+ str->cst_data = data;
str->length = strlen(data);
+ str->dynamic = false;
}
}
@@ -102,9 +192,10 @@ void unset_rle_string(rle_string *str)
{
if (str->data != NULL)
{
- free(str->data);
- str->data = NULL;
+ if (str->dynamic)
+ free(str->data);
+ str->data = NULL;
str->length = 0;
}
@@ -184,6 +275,7 @@ bool unpack_rle_string(rle_string *str, packed_buffer *pbuf)
if (result && str->length > 0)
{
str->data = (char *)malloc(str->length + 1);
+ str->dynamic = true;
result = extract_packed_buffer(pbuf, str->data, str->length + 1, false);
@@ -323,11 +415,12 @@ bool load_rle_string(rle_string *str, const char *name, const bound_value *value
switch (value->type)
{
case SQLITE_TEXT:
- set_rle_string(str, value->cstring);
+ unset_rle_string(str);
+ dup_into_rle_string(str, value->cstring);
break;
case SQLITE_NULL:
- set_rle_string(str, NULL);
+ unset_rle_string(str);
break;
default: