Skip to content
Snippets Groups Projects
Commit 228d01a5 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

replace version_cmp and version_scan from oblibs

to internal version_compare and version_store respectively.
parent 78afc7f9
No related branches found
No related tags found
No related merge requests found
......@@ -52,4 +52,7 @@ extern int set_ownersysdir_stack(char *base, uid_t owner) ;
extern int set_ownerhome_stack_byuid(char *store, uid_t owner) ;
extern void set_treeinfo(ssexec_t *info) ;
extern int version_compare(char const *a, char const *b, uint8_t ndot) ;
extern int version_store(stralloc *sa, char const *str, uint8_t ndot) ;
#endif
......@@ -19,6 +19,7 @@
#include <66/environ.h>
#include <66/constants.h>
#include <66/utils.h>
int env_check_version(stralloc *sa, char const *version)
{
......@@ -26,7 +27,7 @@ int env_check_version(stralloc *sa, char const *version)
int r ;
r = version_scan(sa,version,SS_CONFIG_VERSION_NDOT) ;
r = version_store(sa,version,SS_CONFIG_VERSION_NDOT) ;
if (r == -1)
log_warnusys_return(LOG_EXIT_ZERO,"stralloc") ;
......
......@@ -25,6 +25,7 @@
#include <66/environ.h>
#include <66/constants.h>
#include <66/enum.h>
#include <66/utils.h>
int env_import_version_file(char const *svname, char const *svconf, char const *sversion, char const *dversion, int svtype)
......@@ -42,7 +43,7 @@ int env_import_version_file(char const *svname, char const *svconf, char const *
auto_strings(svname_dot,".",svname) ;
r = version_cmp(sversion,dversion,SS_CONFIG_VERSION_NDOT) ;
r = version_compare(sversion,dversion,SS_CONFIG_VERSION_NDOT) ;
if (!r) {
......@@ -60,7 +61,7 @@ int env_import_version_file(char const *svname, char const *svconf, char const *
}
if (!env_append_version(&src_ver,svconf,sversion) ||
!env_append_version(&dst_ver,svconf,dversion))
!env_append_version(&dst_ver,svconf,dversion))
return 0 ;
char const *exclude[2] = { svname_dot, 0 } ;
......
/*
* version.c
*
* Copyright (c) 2018-2024 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 <stddef.h>
#include <oblibs/string.h>
#include <oblibs/log.h>
#include <oblibs/stack.h>
#include <skalibs/types.h>
#include <skalibs/stralloc.h>
int version_compare(char const *a, char const *b, uint8_t ndot)
{
log_flow() ;
int ar = 0 , br = 0, ap = 0 , bp = 0 ;
uint8_t dot = 0 ;
uint32_t anum, bnum ;
size_t alen = strlen(a) ;
size_t blen = strlen(b) ;
while (dot < ndot + 1)
{
char one[alen + 1], two[blen + 1] ;
auto_strings(one,a+ar) ;
auto_strings(two,b+br) ;
ap = get_len_until(a+ar,'.') ;
bp = get_len_until(b+br,'.') ;
one[ap] = 0 ;
two[bp] = 0 ;
ar += ++ap, br += ++bp ;
if (!uint0_scan(one,&anum)) return -2 ;
if (!uint0_scan(two,&bnum)) return -2 ;
if (anum > bnum) return 1;
if (anum < bnum) return -1 ;
dot++ ;
}
return 0 ;
}
int version_store(stralloc *sa, char const *str, uint8_t ndot)
{
log_flow() ;
int r ;
uint8_t dot = 0 ;
uint32_t num ;
size_t slen = strlen(str) ;
char snum[slen + 1] ;
auto_strings(snum,str) ;
sa->len = 0 ;
while(dot < ndot + 1)
{
size_t len = strlen(snum) ;
r = get_rlen_until(snum,'.',len) ;
if (r == -1 && dot != ndot) return 0 ;
char tmp[len + 1] ;
auto_strings(tmp,snum + r + 1) ;
if (!uint0_scan(tmp,&num)) return 0 ;
if (!stralloc_inserts(sa,0,tmp)) return -1 ;
if (dot < ndot)
if (!stralloc_inserts(sa,0,".")) return -1 ;
dot++ ;
snum[r] = 0 ;
}
if (!stralloc_0(sa)) return -1 ;
sa->len-- ;
return 1 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment