ui/common/properties.c

branch
newapi
changeset 178
7c3ff86ee9d4
parent 174
0358f1d9c506
child 254
13997c76859b
--- a/ui/common/properties.c	Sun Apr 16 10:20:21 2023 +0200
+++ b/ui/common/properties.c	Tue May 23 11:11:28 2023 +0200
@@ -33,12 +33,13 @@
 #include <errno.h>
 
 #include "properties.h"
-#include <ucx/string.h>
-#include <ucx/buffer.h>
-#include <ucx/properties.h>
+#include <cx/string.h>
+#include <cx/buffer.h>
 
-static UiProperties *application_properties;
-static UiProperties *language;
+#include "ucx_properties.h"
+
+static CxMap *application_properties;
+static CxMap *language;
 
 #ifndef UI_COCOA
 
@@ -61,19 +62,20 @@
         return NULL;
     }
     
-    UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
+    CxBuffer buf;
+    cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     
     // add base dir
     char *homeenv = getenv("HOME");
     if(homeenv == NULL) {
-        ucx_buffer_free(buf);
+        cxBufferDestroy(&buf);
         return NULL;
     }
-    sstr_t home = sstr(homeenv);
+    cxstring home = cx_str(homeenv);
     
-    ucx_buffer_write(home.ptr, 1, home.length, buf);
+    cxBufferWrite(home.ptr, 1, home.length, &buf);
     if(home.ptr[home.length-1] != '/') {
-        ucx_buffer_putc(buf, '/');
+        cxBufferPut(&buf, '/');
     }
     
 #ifdef UI_COCOA
@@ -81,19 +83,19 @@
     ucx_buffer_puts(buf, "Library/Application Support/");
 #else
     // app dir is $HOME/.$APPNAME/
-    ucx_buffer_putc(buf, '.');
+    cxBufferPut(&buf, '.');
 #endif
-    ucx_buffer_puts(buf, appname);
-    ucx_buffer_putc(buf, '/');
+    cxBufferPutString(&buf, appname);
+    cxBufferPut(&buf, '/');
     
     // add file name
     if(name) {
-        ucx_buffer_puts(buf, name);
+        cxBufferPutString(&buf, name);
     }
     
-    char *path = buf->space;
-    free(buf);
-    return path;  
+    cxBufferPut(&buf, 0);
+    
+    return buf.space;
 }
 
 static int ui_mkdir(char *path) {
@@ -105,7 +107,7 @@
 } 
 
 void uic_load_app_properties() {
-    application_properties = ucx_map_new(128);
+    application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128);
     
     if(!ui_appname()) {
         // applications without name cannot load app properties
@@ -167,17 +169,17 @@
 
 
 char* ui_get_property(char *name) {
-    return ucx_map_cstr_get(application_properties, name);
+    return cxMapGet(application_properties, name);
 }
 
 void ui_set_property(char *name, char *value) {
-    ucx_map_cstr_put(application_properties, name, value);
+    cxMapPut(application_properties, name, value);
 }
 
 void ui_set_default_property(char *name, char *value) {
-    char *v = ucx_map_cstr_get(application_properties, name);
+    char *v = cxMapGet(application_properties, name);
     if(!v) {
-        ucx_map_cstr_put(application_properties, name, value);
+        cxMapPut(application_properties, name, value);
     }
 }
 
@@ -186,16 +188,16 @@
 static char* uic_concat_path(const char *base, const char *p, const char *ext) {
     size_t baselen = strlen(base);
     
-    UcxBuffer *buf = ucx_buffer_new(NULL, 32, UCX_BUFFER_AUTOEXTEND);
+    CxBuffer *buf = cxBufferCreate(NULL, 32, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
     if(baselen > 0) {
-        ucx_buffer_write(base, 1, baselen, buf);
+        cxBufferWrite(base, 1, baselen, buf);
         if(base[baselen - 1] != '/') {
-            ucx_buffer_putc(buf, '/');
+            cxBufferPut(buf, '/');
         }
     }
-    ucx_buffer_write(p, 1, strlen(p), buf);
+    cxBufferWrite(p, 1, strlen(p), buf);
     if(ext) {
-        ucx_buffer_write(ext, 1, strlen(ext), buf);
+        cxBufferWrite(ext, 1, strlen(ext), buf);
     }
     
     char *str = buf->space;
@@ -263,7 +265,7 @@
 #endif
 
 int uic_load_language_file(const char *path) {
-    UcxMap *lang = ucx_map_new(256);
+    CxMap *lang = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 256);
     
     FILE *file = fopen(path, "r");
     if(!file) {
@@ -276,7 +278,7 @@
     
     fclose(file);
     
-    ucx_map_rehash(lang);
+    cxMapRehash(lang);
     
     language = lang;
     
@@ -292,6 +294,6 @@
     if(!language) {
         return NULL;
     }
-    return ucx_map_cstr_get(language, name);
+    return cxMapGet(language, name);
 }
 

mercurial