From e8bfda677451c586e5ca8aa54d4499fdc1ef9a62 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Sat, 26 Mar 2022 22:25:31 +1100 Subject: [PATCH] split instance functions --- src/lib66/instance/deps-lib/deps | 4 +- src/lib66/instance/instance_check.c | 32 ++++++++++++ .../{instance.c => instance_create.c} | 51 ++----------------- src/lib66/instance/instance_splitname.c | 48 +++++++++++++++++ 4 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 src/lib66/instance/instance_check.c rename src/lib66/instance/{instance.c => instance_create.c} (53%) create mode 100644 src/lib66/instance/instance_splitname.c diff --git a/src/lib66/instance/deps-lib/deps b/src/lib66/instance/deps-lib/deps index f8257480..aa575536 100644 --- a/src/lib66/instance/deps-lib/deps +++ b/src/lib66/instance/deps-lib/deps @@ -1,4 +1,6 @@ -instance.o +instance_check.o +instance_create.o +instance_splitname.o -ls6rc -ls6 -loblibs diff --git a/src/lib66/instance/instance_check.c b/src/lib66/instance/instance_check.c new file mode 100644 index 00000000..f01ce8c7 --- /dev/null +++ b/src/lib66/instance/instance_check.c @@ -0,0 +1,32 @@ +/* + * instance_check.c + * + * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <string.h> + +#include <oblibs/log.h> +#include <oblibs/string.h> + +#include <66/utils.h> + +int instance_check(char const *svname) +{ + log_flow() ; + + int r ; + r = get_len_until(svname,'@') ; + // avoid empty value after the instance template name + if (strlen(svname+r) <= 1 && r > 0) return 0 ; + + return r ; +} diff --git a/src/lib66/instance/instance.c b/src/lib66/instance/instance_create.c similarity index 53% rename from src/lib66/instance/instance.c rename to src/lib66/instance/instance_create.c index 95a39794..a4534a56 100644 --- a/src/lib66/instance/instance.c +++ b/src/lib66/instance/instance_create.c @@ -1,5 +1,5 @@ /* - * instance.c + * instance_create.c * * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> * @@ -12,60 +12,15 @@ * except according to the terms contained in the LICENSE file./ */ -#include <66/utils.h> - -#include <string.h> +#include <stddef.h> #include <oblibs/log.h> -#include <oblibs/files.h> #include <oblibs/string.h> -#include <oblibs/directory.h> -#include <oblibs/environ.h> #include <oblibs/sastr.h> #include <skalibs/stralloc.h> -#include <skalibs/djbunix.h> - -#include <66/enum.h> - -int instance_check(char const *svname) -{ - log_flow() ; - - int r ; - r = get_len_until(svname,'@') ; - // avoid empty value after the instance template name - if (strlen(svname+r) <= 1 && r > 0) return 0 ; - - return r ; -} - -int instance_splitname(stralloc *sa,char const *name,int len,int what) -{ - log_flow() ; - - char const *copy ; - size_t tlen = len + 1 ; - - char template[tlen + 1] ; - memcpy(template,name,tlen) ; - template[tlen] = 0 ; - - copy = name + tlen ; - sa->len = 0 ; - if (!what) - { - if (!stralloc_cats(sa,template) || - !stralloc_0(sa)) return 0 ; - } - else - { - if (!stralloc_catb(sa,copy,strlen(copy)) || - !stralloc_0(sa)) return 0 ; - } - return 1 ; -} +#include <66/utils.h> int instance_create(stralloc *sasv,char const *svname, char const *regex, int len) { diff --git a/src/lib66/instance/instance_splitname.c b/src/lib66/instance/instance_splitname.c new file mode 100644 index 00000000..81ebde6d --- /dev/null +++ b/src/lib66/instance/instance_splitname.c @@ -0,0 +1,48 @@ +/* + * instance_splitname.c + * + * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <string.h> + +#include <oblibs/log.h> + +#include <skalibs/stralloc.h> + +#include <66/utils.h> + +int instance_splitname(stralloc *sa,char const *name,int len,int what) +{ + log_flow() ; + + char const *copy ; + size_t tlen = len + 1 ; + + char template[tlen + 1] ; + memcpy(template,name,tlen) ; + template[tlen] = 0 ; + + copy = name + tlen ; + + sa->len = 0 ; + if (!what) + { + if (!stralloc_cats(sa,template) || + !stralloc_0(sa)) return 0 ; + } + else + { + if (!stralloc_catb(sa,copy,strlen(copy)) || + !stralloc_0(sa)) return 0 ; + } + return 1 ; +} -- GitLab