# HG changeset patch # User Olaf Wintermann # Date 1757252184 -7200 # Node ID 68ea3a0fe66f572949506ddea89815bb9a460958 # Parent b60487c3ec3612743b890a458e33e25361094ce8 prepare build system for more testing, unify opt parsers diff -r b60487c3ec36 -r 68ea3a0fe66f dav/Makefile --- a/dav/Makefile Sun Aug 31 14:39:13 2025 +0200 +++ b/dav/Makefile Sun Sep 07 15:36:24 2025 +0200 @@ -28,36 +28,7 @@ include ../config.mk -DAV_SRC = main.c -DAV_SRC += config.c -DAV_SRC += optparser.c -DAV_SRC += error.c -DAV_SRC += assistant.c -DAV_SRC += tar.c -DAV_SRC += system.c -DAV_SRC += libxattr.c -DAV_SRC += finfo.c -DAV_SRC += connect.c - -SYNC_SRC = sync.c -SYNC_SRC += config.c -SYNC_SRC += scfg.c -SYNC_SRC += sopt.c -SYNC_SRC += db.c -SYNC_SRC += error.c -SYNC_SRC += assistant.c -SYNC_SRC += libxattr.c -SYNC_SRC += finfo.c -SYNC_SRC += tags.c -SYNC_SRC += system.c -SYNC_SRC += connect.c - -XATTR_SRC = xattrtool.c -XATTR_SRC += libxattr.c - -DAV_OBJ = $(DAV_SRC:%.c=../build/tool/%$(OBJ_EXT)) -SYNC_OBJ = $(SYNC_SRC:%.c=../build/tool/%$(OBJ_EXT)) -XATTR_OBJ = $(XATTR_SRC:%.c=../build/tool/%$(OBJ_EXT)) +include obj.mk DAV_BIN = ../build/bin/dav$(APP_EXT) DAV_SYNC_BIN = ../build/bin/dav-sync$(APP_EXT) @@ -65,13 +36,13 @@ all: ../build/bin/dav ../build/bin/dav-sync ../build/bin/xattrtool -$(DAV_BIN): $(DAV_OBJ) ../build/lib/libidav$(LIB_EXT) - $(CC) -o $(DAV_BIN) $(DAV_OBJ) \ +$(DAV_BIN): $(DAV_MAIN_OBJ) $(DAV_OBJ) $(COMMON_OBJ) ../build/lib/libidav$(LIB_EXT) + $(CC) -o $(DAV_BIN) $(DAV_MAIN_OBJ) $(DAV_OBJ) $(COMMON_OBJ) \ ../build/lib/libidav$(LIB_EXT) ../build/lib/libucx$(LIB_EXT) \ $(LDFLAGS) $(DAV_LDFLAGS) -$(DAV_SYNC_BIN): $(SYNC_OBJ) ../build/lib/libidav$(LIB_EXT) - $(CC) -o $(DAV_SYNC_BIN) $(SYNC_OBJ) \ +$(DAV_SYNC_BIN): $(SYNC_MAIN_OBJ) $(SYNC_OBJ) $(COMMON_OBJ) ../build/lib/libidav$(LIB_EXT) + $(CC) -o $(DAV_SYNC_BIN) $(SYNC_MAIN_OBJ) $(COMMON_OBJ) $(SYNC_OBJ) \ ../build/lib/libidav$(LIB_EXT) ../build/lib/libucx$(LIB_EXT) \ $(LDFLAGS) $(DAV_LDFLAGS) diff -r b60487c3ec36 -r 68ea3a0fe66f dav/obj.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dav/obj.mk Sun Sep 07 15:36:24 2025 +0200 @@ -0,0 +1,58 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2025 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. +# + +DAV_MAIN_SRC = main.c + +SYNC_MAIN_SRC = sync.c + +COMMON_SRC = config.c +COMMON_SRC += error.c +COMMON_SRC += assistant.c +COMMON_SRC += libxattr.c +COMMON_SRC += finfo.c +COMMON_SRC += connect.c +COMMON_SRC += system.c +COMMON_SRC += optparser.c + +DAV_SRC = tar.c + + +SYNC_SRC = scfg.c +SYNC_SRC += db.c +SYNC_SRC += tags.c + +XATTR_SRC = xattrtool.c +XATTR_SRC += libxattr.c + +DAV_OBJ = $(DAV_SRC:%.c=../build/tool/%$(OBJ_EXT)) +SYNC_OBJ = $(SYNC_SRC:%.c=../build/tool/%$(OBJ_EXT)) +COMMON_OBJ = $(COMMON_SRC:%.c=../build/tool/%$(OBJ_EXT)) +XATTR_OBJ = $(XATTR_SRC:%.c=../build/tool/%$(OBJ_EXT)) + +DAV_MAIN_OBJ = $(DAV_MAIN_SRC:%.c=../build/tool/%$(OBJ_EXT)) +SYNC_MAIN_OBJ = $(SYNC_MAIN_SRC:%.c=../build/tool/%$(OBJ_EXT)) diff -r b60487c3ec36 -r 68ea3a0fe66f dav/optparser.c --- a/dav/optparser.c Sun Aug 31 14:39:13 2025 +0200 +++ b/dav/optparser.c Sun Sep 07 15:36:24 2025 +0200 @@ -31,7 +31,6 @@ #include #include "optparser.h" -#include "sopt.h" #include @@ -216,6 +215,86 @@ return a; } +CmdArgs* cmd_parse_sync_args(int argc, char **argv) { + CmdArgs *a = malloc(sizeof(CmdArgs)); + a->options = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); + a->argv = calloc(argc, sizeof(char*)); + a->argc = 0; + + const char *NOARG = ""; + + char *option = NULL; + char optchar = 0; + for(int i=0;i 1 && arg[0] == '-') { + for(int c=1;coptions, "conflict", NOARG); + break; + } + case 'l': { + cmd_map_put(a->options, "lock", NOARG); + break; + } + case 'd': { + cmd_map_put(a->options, "nolock", NOARG); + break; + } + case 'r': { + cmd_map_put(a->options, "remove", NOARG); + break; + } + case 'v': { + cmd_map_put(a->options, "verbose", NOARG); + break; + } + case 's': { + option = "syncdir"; + optchar = 's'; + break; + } + case 't': { + option = "tags"; + optchar = 't'; + break; + } + case 'V': { + option = "version"; + optchar = 'V'; + break; + } + case 'R': { + cmd_map_put(a->options, "restore-removed", NOARG); + break; + } + case 'M': { + cmd_map_put(a->options, "restore-modified", NOARG); + break; + } + case 'S': { + cmd_map_put(a->options, "snapshot", NOARG); + } + } + } + } else if(option) { + cmd_map_put(a->options, option, arg); + option = NULL; + } else { + a->argv[a->argc++] = arg; + } + } + + return a; +} + char* cmd_getoption(CmdArgs *arg, const char *name) { return cxMapGet(arg->options, cx_hash_key_str(name)); } diff -r b60487c3ec36 -r 68ea3a0fe66f dav/optparser.h --- a/dav/optparser.h Sun Aug 31 14:39:13 2025 +0200 +++ b/dav/optparser.h Sun Sep 07 15:36:24 2025 +0200 @@ -37,6 +37,7 @@ #endif CmdArgs* cmd_parse_args(int argc, char **argv); +CmdArgs* cmd_parse_sync_args(int argc, char **argv); char* cmd_getoption(CmdArgs *arg, const char *name); void cmd_args_free(CmdArgs *args); diff -r b60487c3ec36 -r 68ea3a0fe66f dav/sopt.c --- a/dav/sopt.c Sun Aug 31 14:39:13 2025 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,131 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 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 -#include -#include - -#include "sopt.h" - -#include - -void cmd_args_free(CmdArgs *args) { - if(args) { - cxMapFree(args->options); - free(args->argv); - free(args); - } -} - -static void cmd_map_put(CxMap *map, const char *key, const void *value) { - cxMapPut(map, key, (void*)value); -} - -CmdArgs* cmd_parse_args(int argc, char **argv) { - CmdArgs *a = malloc(sizeof(CmdArgs)); - a->options = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); - a->argv = calloc(argc, sizeof(char*)); - a->argc = 0; - - const char *NOARG = ""; - - char *option = NULL; - char optchar = 0; - for(int i=0;i 1 && arg[0] == '-') { - for(int c=1;coptions, "conflict", NOARG); - break; - } - case 'l': { - cmd_map_put(a->options, "lock", NOARG); - break; - } - case 'd': { - cmd_map_put(a->options, "nolock", NOARG); - break; - } - case 'r': { - cmd_map_put(a->options, "remove", NOARG); - break; - } - case 'v': { - cmd_map_put(a->options, "verbose", NOARG); - break; - } - case 's': { - option = "syncdir"; - optchar = 's'; - break; - } - case 't': { - option = "tags"; - optchar = 't'; - break; - } - case 'V': { - option = "version"; - optchar = 'V'; - break; - } - case 'R': { - cmd_map_put(a->options, "restore-removed", NOARG); - break; - } - case 'M': { - cmd_map_put(a->options, "restore-modified", NOARG); - break; - } - case 'S': { - cmd_map_put(a->options, "snapshot", NOARG); - } - } - } - } else if(option) { - cmd_map_put(a->options, option, arg); - option = NULL; - } else { - a->argv[a->argc++] = arg; - } - } - - return a; -} - -char* cmd_getoption(CmdArgs *arg, const char *name) { - return cxMapGet(arg->options, cx_hash_key_str(name)); -} diff -r b60487c3ec36 -r 68ea3a0fe66f dav/sopt.h --- a/dav/sopt.h Sun Aug 31 14:39:13 2025 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2018 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 OPTPARSER_H -#define OPTPARSER_H - -#include -#include "opt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* ArgBool; - -void cmd_args_free(CmdArgs *args); -CmdArgs* cmd_parse_args(int argc, char **argv); -char* cmd_getoption(CmdArgs *arg, const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* OPTPARSER_H */ - diff -r b60487c3ec36 -r 68ea3a0fe66f dav/sync.c --- a/dav/sync.c Sun Aug 31 14:39:13 2025 +0200 +++ b/dav/sync.c Sun Sep 07 15:36:24 2025 +0200 @@ -62,7 +62,7 @@ #include "sync.h" #include "config.h" -#include "sopt.h" +#include "optparser.h" #include "error.h" #include "assistant.h" #include "libxattr.h" @@ -292,7 +292,7 @@ } char *cmd = argv[1]; - CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); + CmdArgs *args = cmd_parse_sync_args(argc - 2, argv + 2); if(!args) { print_usage(argv[0]); return -1; diff -r b60487c3ec36 -r 68ea3a0fe66f dav/sync.h --- a/dav/sync.h Sun Aug 31 14:39:13 2025 +0200 +++ b/dav/sync.h Sun Sep 07 15:36:24 2025 +0200 @@ -36,7 +36,7 @@ #include "scfg.h" #include "config.h" -#include "sopt.h" +#include "optparser.h" #include "system.h" #include "version.h" diff -r b60487c3ec36 -r 68ea3a0fe66f test/Makefile --- a/test/Makefile Sun Aug 31 14:39:13 2025 +0200 +++ b/test/Makefile Sun Sep 07 15:36:24 2025 +0200 @@ -28,12 +28,16 @@ include ../config.mk +include ../dav/obj.mk + TEST_SRC = main.c TEST_SRC += test.c TEST_SRC += base64.c TEST_SRC += crypto.c TEST_SRC += utils.c +TEST_SRC += test_finfo.c + TEST_OBJ = $(TEST_SRC:%.c=../build/test/%$(OBJ_EXT)) @@ -41,8 +45,8 @@ all: $(TEST_TARGET) -$(TEST_TARGET): $(TEST_OBJ) ../build/lib/libidav$(LIB_EXT) - $(CC) -o $(TEST_TARGET) $(TEST_OBJ) \ +$(TEST_TARGET): $(TEST_OBJ) $(DAV_OBJ) $(SYNC_OBJ) $(COMMON_OBJ) ../build/lib/libidav$(LIB_EXT) + $(CC) -o $(TEST_TARGET) $(TEST_OBJ) $(DAV_OBJ) $(SYNC_OBJ) $(COMMON_OBJ) \ ../build/lib/libidav$(LIB_EXT) ../build/lib/libucx$(LIB_EXT) \ $(LDFLAGS) $(DAV_LDFLAGS) diff -r b60487c3ec36 -r 68ea3a0fe66f test/test_finfo.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_finfo.c Sun Sep 07 15:36:24 2025 +0200 @@ -0,0 +1,30 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 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 "test_finfo.h" + diff -r b60487c3ec36 -r 68ea3a0fe66f test/test_finfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/test_finfo.h Sun Sep 07 15:36:24 2025 +0200 @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2025 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 TEST_FINFO_H +#define TEST_FINFO_H + +#include "test.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_FINFO_H */ +