From 617bbc525f41157e525819a613ea822ffa2e1b44 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 18 Mar 2016 12:19:30 -0400 Subject: utility: slbt_output_config(): initial implementation. --- include/slibtool/slibtool.h | 1 + project/common.mk | 1 + src/output/slbt_output_config.c | 96 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 src/output/slbt_output_config.c diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h index b40d623..ab337a8 100644 --- a/include/slibtool/slibtool.h +++ b/include/slibtool/slibtool.h @@ -159,6 +159,7 @@ slbt_api int slbt_map_input (int fd, const char * path, int prot, struct slbt_ slbt_api int slbt_unmap_input (struct slbt_input *); /* utility api */ +slbt_api int slbt_output_config (const struct slbt_driver_ctx *); #ifdef __cplusplus } diff --git a/project/common.mk b/project/common.mk index 8bc227a..bd342f8 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,6 +4,7 @@ COMMON_SRCS = \ src/logic/slbt_exec_compile.c \ src/logic/slbt_exec_ctx.c \ src/logic/slbt_map_input.c \ + src/output/slbt_output_config.c \ src/skin/slbt_skin_default.c \ APP_SRCS = \ diff --git a/src/output/slbt_output_config.c b/src/output/slbt_output_config.c new file mode 100644 index 0000000..321ec20 --- /dev/null +++ b/src/output/slbt_output_config.c @@ -0,0 +1,96 @@ +/*******************************************************************/ +/* slibtool: a skinny libtool implementation, written in C */ +/* Copyright (C) 2016 Z. Gilboa */ +/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */ +/*******************************************************************/ + +#include +#include +#include + +#include + +#ifndef SLBT_TAB_WIDTH +#define SLBT_TAB_WIDTH 8 +#endif + +#ifndef SLBT_KEY_WIDTH +#define SLBT_KEY_WIDTH 16 +#endif + +static bool slbt_output_config_line( + const char * key, + const char * value, + const char * annotation, + int midwidth) +{ + return (fprintf(stdout,"%-*s%-*s%s\n", + SLBT_KEY_WIDTH, key, + midwidth, value ? value : "", + annotation ? annotation : "") < 0) + ? true : false; +} + +int slbt_output_config(const struct slbt_driver_ctx * dctx) +{ + const struct slbt_common_ctx * cctx; + const char * compiler; + const char * target; + int len; + int midwidth; + + cctx = dctx->cctx; + compiler = cctx->cargv[0] ? cctx->cargv[0] : ""; + target = cctx->target ? cctx->target : ""; + midwidth = strlen(compiler); + + if ((len = strlen(target)) > midwidth) + midwidth = len; + + if ((len = strlen(cctx->host.host)) > midwidth) + midwidth = len; + + if ((len = strlen(cctx->host.flavor)) > midwidth) + midwidth = len; + + if ((len = strlen(cctx->host.ar)) > midwidth) + midwidth = len; + + if ((len = strlen(cctx->host.ranlib)) > midwidth) + midwidth = len; + + if ((len = strlen(cctx->host.dlltool)) > midwidth) + midwidth = len; + + midwidth += SLBT_TAB_WIDTH; + midwidth &= (~(SLBT_TAB_WIDTH-1)); + + if (slbt_output_config_line("key","value","annotation",midwidth)) + return -1; + + if (slbt_output_config_line("---","-----","----------",midwidth)) + return -1; + + if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth)) + return -1; + + if (slbt_output_config_line("target",cctx->target,"",midwidth)) + return -1; + + if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth)) + return -1; + + if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth)) + return -1; + + if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth)) + return -1; + + if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth)) + return -1; + + if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth)) + return -1; + + return 0; +} -- cgit v1.2.3