diff --git a/project/common.mk b/project/common.mk index cebaef7..0f638eb 100644 --- a/project/common.mk +++ b/project/common.mk @@ -13,6 +13,7 @@ API_SRCS = \ src/driver/slbt_driver_ctx.c \ src/driver/slbt_host_params.c \ src/driver/slbt_split_argv.c \ + src/driver/slbt_version_info.c \ src/fallback/slbt_archive_import_mri.c \ src/helper/slbt_archive_import.c \ src/helper/slbt_copy_file.c \ diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index 2eee876..8dd463d 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -91,6 +91,11 @@ static void slbt_output_raw_vector(int fderr, char ** argv, char ** envp, bool f slbt_dprintf(fderr,"%s\n\n",fcolor ? aclr_reset : ""); } +const char * slbt_program_name(const char * path) +{ + return argv_program_name(path); +} + uint64_t slbt_argv_flags(uint64_t flags) { uint32_t ret = 0; @@ -222,61 +227,6 @@ static int slbt_get_driver_ctx_fail( } -static int slbt_init_version_info( - struct slbt_driver_ctx_impl * ictx, - struct slbt_version_info * verinfo) -{ - int current; - int revision; - int age; - int colons; - int fmtcnt; - const char * ch; - - if (!verinfo->verinfo && !verinfo->vernumber) - return 0; - - if (verinfo->vernumber) { - sscanf(verinfo->vernumber,"%d:%d:%d", - &verinfo->major, - &verinfo->minor, - &verinfo->revision); - return 0; - } - - current = revision = age = 0; - - for (colons=0, ch=verinfo->verinfo; *ch; ch++) - if (*ch == ':') - colons++; - - fmtcnt = sscanf(verinfo->verinfo,"%d:%d:%d", - ¤t,&revision,&age); - - if (!fmtcnt || (fmtcnt > 3) || (fmtcnt != colons + 1)) { - slbt_dprintf(ictx->fdctx.fderr, - "%s: error: invalid version info: " - "supported argument format is %%d[:%%d[:%%d]].\n", - argv_program_name(ictx->cctx.targv[0])); - return -1; - } - - if (current < age) { - if (ictx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - slbt_dprintf(ictx->fdctx.fderr, - "%s: error: invalid version info: " - " may not be smaller than .\n", - argv_program_name(ictx->cctx.targv[0])); - return -1; - } - - verinfo->major = current - age; - verinfo->minor = age; - verinfo->revision = revision; - - return 0; -} - static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) { const char * program; diff --git a/src/driver/slbt_version_info.c b/src/driver/slbt_version_info.c new file mode 100644 index 0000000..5b28075 --- /dev/null +++ b/src/driver/slbt_version_info.c @@ -0,0 +1,73 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016--2021 SysDeer Technologies, LLC */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include "slibtool_version.h" +#include "slibtool_driver_impl.h" +#include "slibtool_errinfo_impl.h" +#include "argv/argv.h" + + +int slbt_init_version_info( + struct slbt_driver_ctx_impl * ictx, + struct slbt_version_info * verinfo) +{ + int current; + int revision; + int age; + int colons; + int fmtcnt; + const char * ch; + + if (!verinfo->verinfo && !verinfo->vernumber) + return 0; + + if (verinfo->vernumber) { + sscanf(verinfo->vernumber,"%d:%d:%d", + &verinfo->major, + &verinfo->minor, + &verinfo->revision); + return 0; + } + + current = revision = age = 0; + + for (colons=0, ch=verinfo->verinfo; *ch; ch++) + if (*ch == ':') + colons++; + + fmtcnt = sscanf(verinfo->verinfo,"%d:%d:%d", + ¤t,&revision,&age); + + if (!fmtcnt || (fmtcnt > 3) || (fmtcnt != colons + 1)) { + slbt_dprintf(ictx->fdctx.fderr, + "%s: error: invalid version info: " + "supported argument format is %%d[:%%d[:%%d]].\n", + slbt_program_name(ictx->cctx.targv[0])); + return -1; + } + + if (current < age) { + if (ictx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) + slbt_dprintf(ictx->fdctx.fderr, + "%s: error: invalid version info: " + " may not be smaller than .\n", + slbt_program_name(ictx->cctx.targv[0])); + return -1; + } + + verinfo->major = current - age; + verinfo->minor = age; + verinfo->revision = revision; + + return 0; +} diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index 9a32c9b..282659e 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -169,6 +169,9 @@ struct slbt_archive_ctx_impl { }; +const char * slbt_program_name(const char *); + + uint64_t slbt_argv_flags(uint64_t flags); @@ -192,6 +195,11 @@ int slbt_split_argv( int fdcwd); +int slbt_init_version_info( + struct slbt_driver_ctx_impl * ictx, + struct slbt_version_info * verinfo); + + int slbt_init_host_params( const struct slbt_driver_ctx * dctx, const struct slbt_common_ctx * cctx,