Blame src/driver/slbt_version_info.c

99c275
/*******************************************************************/
99c275
/*  slibtool: a skinny libtool implementation, written in C        */
99c275
/*  Copyright (C) 2016--2021  SysDeer Technologies, LLC            */
99c275
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
99c275
/*******************************************************************/
99c275
99c275
#include <stdint.h>
99c275
#include <string.h>
99c275
#include <unistd.h>
99c275
#include <stdlib.h>
99c275
#include <stdbool.h>
99c275
99c275
#include <slibtool/slibtool.h>
99c275
#include "slibtool_version.h"
99c275
#include "slibtool_driver_impl.h"
99c275
#include "slibtool_errinfo_impl.h"
99c275
#include "argv/argv.h"
99c275
99c275
99c275
int slbt_init_version_info(
99c275
	struct slbt_driver_ctx_impl *	ictx,
99c275
	struct slbt_version_info *	verinfo)
99c275
{
99c275
	int	current;
99c275
	int	revision;
99c275
	int	age;
99c275
	int	colons;
99c275
	int	fmtcnt;
99c275
	const char * ch;
99c275
99c275
	if (!verinfo->verinfo && !verinfo->vernumber)
99c275
		return 0;
99c275
99c275
	if (verinfo->vernumber) {
99c275
		sscanf(verinfo->vernumber,"%d:%d:%d",
99c275
			&verinfo->major,
99c275
			&verinfo->minor,
99c275
			&verinfo->revision);
99c275
		return 0;
99c275
	}
99c275
99c275
	current = revision = age = 0;
99c275
99c275
	for (colons=0, ch=verinfo->verinfo; *ch; ch++)
99c275
		if (*ch == ':')
99c275
			colons++;
99c275
99c275
	fmtcnt = sscanf(verinfo->verinfo,"%d:%d:%d",
99c275
		&current,&revision,&age;;
99c275
99c275
	if (!fmtcnt || (fmtcnt > 3) || (fmtcnt != colons + 1)) {
99c275
		slbt_dprintf(ictx->fdctx.fderr,
99c275
			"%s: error: invalid version info: "
99c275
			"supported argument format is %%d[:%%d[:%%d]].\n",
99c275
			slbt_program_name(ictx->cctx.targv[0]));
99c275
		return -1;
99c275
	}
99c275
99c275
	if (current < age) {
99c275
		if (ictx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
99c275
			slbt_dprintf(ictx->fdctx.fderr,
99c275
				"%s: error: invalid version info: "
99c275
				"<current> may not be smaller than <age>.\n",
99c275
				slbt_program_name(ictx->cctx.targv[0]));
99c275
		return -1;
99c275
	}
99c275
99c275
	verinfo->major    = current - age;
99c275
	verinfo->minor    = age;
99c275
	verinfo->revision = revision;
99c275
99c275
	return 0;
99c275
}