diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-07-10 14:47:37 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-07-10 14:47:37 (GMT) |
commit | db863244b804cbf4c06399f7c6f8241d91c9ee9b (patch) | |
tree | da7cc911b0f10c5122536271235ab68f2202804a /src/common | |
parent | e8aa314462196cc9e8461ae23eb13f8bffcc983f (diff) |
Fully rewritten the core configuration system.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@381 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/extstr.c | 24 | ||||
-rw-r--r-- | src/common/fnv1a.c | 12 | ||||
-rw-r--r-- | src/common/fnv1a.h | 2 | ||||
-rw-r--r-- | src/common/io.c | 44 | ||||
-rw-r--r-- | src/common/io.h | 6 | ||||
-rw-r--r-- | src/common/xml.c | 15 |
6 files changed, 81 insertions, 22 deletions
diff --git a/src/common/extstr.c b/src/common/extstr.c index caffbcd..851401c 100644 --- a/src/common/extstr.c +++ b/src/common/extstr.c @@ -174,18 +174,15 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2) size_t inlen; /* Taille en entrée */ size_t len1; /* Taille de l'aiguille n°1 */ size_t len2; /* Taille de l'aiguille n°2 */ - regex_t preg; /* Expression régulière */ - size_t curpos; /* Point de recherche */ - regmatch_t pmatch; /* Résultats remontés */ + char *found; /* Position d'une trouvaille */ inlen = strlen(haystack) + 1; len1 = strlen(needle1); len2 = strlen(needle2); - /* On considère que la compilation est toujours bonne... */ - regcomp(&preg, needle1, REG_EXTENDED | REG_ICASE); - - for (curpos = 0; regexec(&preg, &haystack[curpos], 1, &pmatch, 0) != REG_NOMATCH; ) + for (found = strstr(haystack, needle1); + found != NULL; + found = strstr(haystack, needle1)) { if (len1 != len2) { @@ -198,23 +195,16 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2) haystack = (char *)realloc(haystack, inlen * sizeof(char *)); if (len2 > len1) - memmove(&haystack[curpos + pmatch.rm_eo + len2 - len1], &haystack[curpos + pmatch.rm_eo], - inlen - (len2 - len1) - curpos - pmatch.rm_eo); - + memmove(found + len2, found + len1, inlen - len1 - (found - haystack)); else - memmove(&haystack[curpos + pmatch.rm_eo + len1 - len2], &haystack[curpos + pmatch.rm_eo], - inlen - (len1 - len2) - curpos - pmatch.rm_eo); + memmove(found + len1, found + len2, inlen - len1 - (found - haystack)); } - memcpy(&haystack[curpos + pmatch.rm_so], needle2, len2); - - curpos += pmatch.rm_eo + len2; + memcpy(found, needle2, len2); } - regfree(&preg); - return haystack; } diff --git a/src/common/fnv1a.c b/src/common/fnv1a.c index c21a5e1..d017d70 100644 --- a/src/common/fnv1a.c +++ b/src/common/fnv1a.c @@ -40,15 +40,21 @@ * * * Description : Détermine si deux empreintes FNV1a sont indentiques ou non. * * * -* Retour : Bilan de la comparaison. * +* Retour : Bilan de la comparaison : -1, 0 ou 1. * * * * Remarques : - * * * ******************************************************************************/ -bool cmp_fnv_64a(fnv64_t a, fnv64_t b) +int cmp_fnv_64a(fnv64_t a, fnv64_t b) { - return (a == b); + int result; /* Bilan à retourner */ + + if (a < b) result = -1; + else if (a == b) result = 0; + else result = 1; + + return result; } diff --git a/src/common/fnv1a.h b/src/common/fnv1a.h index 294ce12..973781b 100644 --- a/src/common/fnv1a.h +++ b/src/common/fnv1a.h @@ -41,7 +41,7 @@ typedef uint64_t fnv64_t; /* Détermine si deux empreintes FNV1a sont indentiques ou non. */ -bool cmp_fnv_64a(fnv64_t, fnv64_t); +int cmp_fnv_64a(fnv64_t, fnv64_t); /* Détermine l'empreinte FNV1a d'une chaîne de caractères. */ fnv64_t fnv_64a_hash(const char *); diff --git a/src/common/io.c b/src/common/io.c index c3d3231..2275cb4 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -24,4 +24,48 @@ #include "io.h" +#include <libgen.h> +#include <malloc.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> + + +/****************************************************************************** +* * +* Paramètres : path = chemin d'accès à valider. * +* * +* Description : S'assure qu'un chemin donné existe dans le système. * +* * +* Retour : 0 si le chemin est actuellement présent, -1 sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int ensure_path_exists(const char *path) +{ + int result; /* Bilan de l'assurance */ + char *copy; /* Chemin libérable */ + char *tmp; /* Chemin altérable */ + + copy = strdup(path); + tmp = dirname(copy); + + result = access(tmp, W_OK | X_OK); + + if (result != 0) + { + result = ensure_path_exists(tmp); + + if (result == 0) + result = mkdir(tmp, 0700); + + } + + free(copy); + + return result; + +} diff --git a/src/common/io.h b/src/common/io.h index 9145736..491d8d0 100644 --- a/src/common/io.h +++ b/src/common/io.h @@ -40,4 +40,10 @@ #define safe_write write + +/* S'assure qu'un chemin donné existe dans le système. */ +int ensure_path_exists(const char *); + + + #endif /* _COMMON_IO_H */ diff --git a/src/common/xml.c b/src/common/xml.c index 8c4cc81..36171b3 100644 --- a/src/common/xml.c +++ b/src/common/xml.c @@ -223,11 +223,24 @@ char *qck_get_node_text_value(xmlNodePtr node) result = NULL; if (node != NULL) + { if (node->children != NULL) if (node->children->content != NULL) result = strdup((char *)node->children->content); - if (result == NULL) XML_LOG(stderr, "No text value for node '%s'\n", node->name); + /** + * Si le noeud existe mais qu'il n'y pas de contenu, + * il faut marquer la différence entre deux retours NULL. + * + * On choisit donc : + * - NULL : pas de valeur trouvée car noeud non existant. + * - "" : pas de valeur trouvée, mais noeud bien présent. + */ + + if (result == NULL) + result = strdup(""); + + } return result; |