Sun, 23 Nov 2025 09:28:22 +0100
move default path elm func to common
| ui/common/objs.mk | file | annotate | diff | comparison | revisions | |
| ui/common/utils.c | file | annotate | diff | comparison | revisions | |
| ui/common/utils.h | file | annotate | diff | comparison | revisions | |
| ui/motif/Fsb.c | file | annotate | diff | comparison | revisions | |
| ui/motif/text.c | file | annotate | diff | comparison | revisions |
--- a/ui/common/objs.mk Sun Nov 23 08:44:41 2025 +0100 +++ b/ui/common/objs.mk Sun Nov 23 09:28:22 2025 +0100 @@ -42,6 +42,7 @@ COMMON_OBJ += condvar$(OBJ_EXT) COMMON_OBJ += args$(OBJ_EXT) COMMON_OBJ += wrapper$(OBJ_EXT) +COMMON_OBJ += utils$(OBJ_EXT) TOOLKITOBJS += $(COMMON_OBJ:%=$(COMMON_OBJPRE)uic_%) TOOLKITSOURCE += $(COMMON_OBJ:%$(OBJ_EXT)=common/%.c)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/utils.c Sun Nov 23 09:28:22 2025 +0100 @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "utils.h" + +#include <cx/string.h> + +UiPathElm* ui_default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) { + cxstring *pathelms; + size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms); + + if (nelm == 0) { + *ret_nelm = 0; + return NULL; + } + + UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); + size_t n = nelm; + int j = 0; + for (int i = 0; i < nelm; i++) { + cxstring c = pathelms[i]; + if (c.length == 0) { + if (i == 0) { + c.length = 1; + } + else { + n--; + continue; + } + } + + cxmutstr m = cx_strdup(c); + elms[j].name = m.ptr; + elms[j].name_len = m.length; + + size_t elm_path_len = c.ptr + c.length - full_path; + cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); + elms[j].path = elm_path.ptr; + elms[j].path_len = elm_path.length; + + j++; + } + *ret_nelm = n; + + return elms; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/utils.h Sun Nov 23 09:28:22 2025 +0100 @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef UIC_UTILS_H +#define UIC_UTILS_H + +#include "../ui/toolkit.h" +#include "../ui/text.h" + +#ifdef __cplusplus +extern "C" { +#endif + +UiPathElm* ui_default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data); + + +#ifdef __cplusplus +} +#endif + +#endif /* UIC_UTILS_H */ +
--- a/ui/motif/Fsb.c Sun Nov 23 08:44:41 2025 +0100 +++ b/ui/motif/Fsb.c Sun Nov 23 09:28:22 2025 +0100 @@ -43,6 +43,8 @@ #include "pathbar.h" +#include "../common/utils.h" + #ifdef FSB_ENABLE_DETAIL #include <XmL/Grid.h> #endif @@ -1848,6 +1850,7 @@ Widget pathBarFrame = XmCreateFrame(form, "pathbar_frame", args, n); XtManageChild(pathBarFrame); w->fsb.pathBar = CreatePathBar(pathBarFrame, args, 0); + w->fsb.pathBar->getpathelm = ui_default_pathelm_func; w->fsb.pathBar->updateDir = (updatedir_callback)filedialog_update_dir; w->fsb.pathBar->updateDirData = w; XtManageChild(w->fsb.pathBar->widget);
--- a/ui/motif/text.c Sun Nov 23 08:44:41 2025 +0100 +++ b/ui/motif/text.c Sun Nov 23 09:28:22 2025 +0100 @@ -34,6 +34,8 @@ #include "container.h" #include "pathbar.h" +#include "../common/utils.h" + #include <cx/string.h> @@ -518,47 +520,6 @@ XtFree((void*)pathbar); } -// TODO: move to common -static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) { - cxstring *pathelms; - size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms); - - if (nelm == 0) { - *ret_nelm = 0; - return NULL; - } - - UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); - size_t n = nelm; - int j = 0; - for (int i = 0; i < nelm; i++) { - cxstring c = pathelms[i]; - if (c.length == 0) { - if (i == 0) { - c.length = 1; - } - else { - n--; - continue; - } - } - - cxmutstr m = cx_strdup(c); - elms[j].name = m.ptr; - elms[j].name_len = m.length; - - size_t elm_path_len = c.ptr + c.length - full_path; - cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); - elms[j].path = elm_path.ptr; - elms[j].path_len = elm_path.length; - - j++; - } - *ret_nelm = n; - - return elms; -} - static void pathbar_activate(void *data, char *path, int index) { UiEventData *event = data; UiEvent evt; @@ -584,7 +545,7 @@ PathBar *pathbar = CreatePathBar(parent, xargs, n); if(!args->getpathelm) { - pathbar->getpathelm= default_pathelm_func; + pathbar->getpathelm= ui_default_pathelm_func; } else { pathbar->getpathelm = args->getpathelm; pathbar->getpathelmdata = args->getpathelmdata;