Blame src/output/slbt_output_config.c

617bbc
/*******************************************************************/
617bbc
/*  slibtool: a skinny libtool implementation, written in C        */
ca7ab6
/*  Copyright (C) 2017  Z. Gilboa                                  */
617bbc
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
617bbc
/*******************************************************************/
617bbc
617bbc
#include <stdio.h>
617bbc
#include <string.h>
617bbc
#include <stdbool.h>
617bbc
617bbc
#include <slibtool/slibtool.h>
522163
#include "slibtool_errinfo_impl.h"
617bbc
617bbc
#ifndef SLBT_TAB_WIDTH
617bbc
#define SLBT_TAB_WIDTH 8
617bbc
#endif
617bbc
617bbc
#ifndef SLBT_KEY_WIDTH
617bbc
#define SLBT_KEY_WIDTH 16
617bbc
#endif
617bbc
617bbc
static bool slbt_output_config_line(
617bbc
	const char *	key,
617bbc
	const char *	value,
617bbc
	const char *	annotation,
617bbc
	int		midwidth)
617bbc
{
617bbc
	return (fprintf(stdout,"%-*s%-*s%s\n",
617bbc
			SLBT_KEY_WIDTH, key,
617bbc
			midwidth, value ? value : "",
617bbc
			annotation ? annotation : "") < 0)
617bbc
		? true : false;
617bbc
}
617bbc
617bbc
int slbt_output_config(const struct slbt_driver_ctx * dctx)
617bbc
{
617bbc
	const struct slbt_common_ctx *	cctx;
617bbc
	const char *			compiler;
617bbc
	const char *			target;
617bbc
	int				len;
617bbc
	int				midwidth;
617bbc
617bbc
	cctx     = dctx->cctx;
617bbc
	compiler = cctx->cargv[0] ? cctx->cargv[0] : "";
617bbc
	target   = cctx->target   ? cctx->target   : "";
617bbc
	midwidth = strlen(compiler);
617bbc
617bbc
	if ((len = strlen(target)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.host)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.flavor)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.ar)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.ranlib)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	if ((len = strlen(cctx->host.dlltool)) > midwidth)
617bbc
		midwidth = len;
617bbc
617bbc
	midwidth += SLBT_TAB_WIDTH;
617bbc
	midwidth &= (~(SLBT_TAB_WIDTH-1));
617bbc
617bbc
	if (slbt_output_config_line("key","value","annotation",midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("---","-----","----------",midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("target",cctx->target,"",midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
617bbc
	if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
522163
		return SLBT_SYSTEM_ERROR(dctx);
617bbc
522163
	return fflush(stdout)
522163
		? SLBT_SYSTEM_ERROR(dctx)
522163
		: 0;
617bbc
}