X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/83d9f3aaf8206aa081ead0ff630a1c33ed670d71:/ucx/properties.c..848befbcc166fff6fdde6a635cf7a31f9f9185e0:/application/properties.c diff --git a/ucx/properties.c b/application/properties.c similarity index 86% rename from ucx/properties.c rename to application/properties.c index 1cb4de0..ef2e1b5 100644 --- a/ucx/properties.c +++ b/application/properties.c @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "ucx/properties.h" +#include "properties.h" #include #include @@ -77,12 +77,12 @@ static void parser_tmp_append(UcxProperties *parser, char *buf, size_t len) { parser->tmplen += len; } -int ucx_properties_next(UcxProperties *parser, sstr_t *name, sstr_t *value) { +int ucx_properties_next(UcxProperties *parser, cxstring *name, cxstring *value) { if(parser->tmplen > 0) { char *buf = parser->buffer + parser->pos; size_t len = parser->buflen - parser->pos; - sstr_t str = sstrn(buf, len); - sstr_t nl = sstrchr(str, '\n'); + cxstring str = cx_strn(buf, len); + cxstring nl = cx_strchr(str, '\n'); if(nl.ptr) { size_t newlen = (size_t)(nl.ptr - buf) + 1; parser_tmp_append(parser, buf, newlen); @@ -167,20 +167,20 @@ int ucx_properties_next(UcxProperties *parser, sstr_t *name, sstr_t *value) { return 0; } - sstr_t line = has_comment ? sstrn(buf, comment_index) : sstrn(buf, i); + cxstring line = has_comment ? cx_strn(buf, comment_index) : cx_strn(buf, i); // check line if(delimiter_index == 0) { - line = sstrtrim(line); + line = cx_strtrim(line); if(line.length != 0) { parser->error = 1; } } else { - sstr_t n = sstrn(buf, delimiter_index); - sstr_t v = sstrn( + cxstring n = cx_strn(buf, delimiter_index); + cxstring v = cx_strn( buf + delimiter_index + 1, line.length - delimiter_index - 1); - n = sstrtrim(n); - v = sstrtrim(v); + n = cx_strtrim(n); + v = cx_strtrim(v); if(n.length != 0 || v.length != 0) { *name = n; *value = v; @@ -197,16 +197,16 @@ int ucx_properties_next(UcxProperties *parser, sstr_t *name, sstr_t *value) { return 0; } -int ucx_properties2map(UcxProperties *parser, UcxMap *map) { - sstr_t name; - sstr_t value; +int ucx_properties2map(UcxProperties *parser, CxMap *map) { + cxstring name; + cxstring value; while(ucx_properties_next(parser, &name, &value)) { - value = sstrdup_a(map->allocator, value); - if(!value.ptr) { + cxmutstr mutvalue = cx_strdup_a(map->allocator, value); + if(!mutvalue.ptr) { return 1; } - if(ucx_map_sstr_put(map, name, value.ptr)) { - alfree(map->allocator, value.ptr); + if(cxMapPut(map, cx_hash_key_cxstr(name), mutvalue.ptr)) { + cxFree(map->allocator, mutvalue.ptr); return 1; } } @@ -219,7 +219,7 @@ int ucx_properties2map(UcxProperties *parser, UcxMap *map) { // buffer size is documented - change doc, when you change bufsize! #define UCX_PROPLOAD_BUFSIZE 1024 -int ucx_properties_load(UcxMap *map, FILE *file) { +int ucx_properties_load(CxMap *map, FILE *file) { UcxProperties *parser = ucx_properties_new(); if(!(parser && map && file)) { return 1; @@ -239,22 +239,21 @@ int ucx_properties_load(UcxMap *map, FILE *file) { return error; } -int ucx_properties_store(UcxMap *map, FILE *file) { - UcxMapIterator iter = ucx_map_iterator(map); - void *v; - sstr_t value; +int ucx_properties_store(CxMap *map, FILE *file) { + CxIterator iter = cxMapIterator(map); + cxstring value; size_t written; - UCX_MAP_FOREACH(k, v, iter) { - value = sstr((char*)v); + cx_foreach(CxMapEntry *, v, iter) { + value = cx_str(v->value); written = 0; - written += fwrite(k.data, 1, k.len, file); + written += fwrite(v->key->data.bytes, 1, v->key->len, file); written += fwrite(" = ", 1, 3, file); written += fwrite(value.ptr, 1, value.length, file); written += fwrite("\n", 1, 1, file); - if (written != k.len + value.length + 4) { + if (written != v->key->len + value.length + 4) { return 1; } }