firasuke / cross / slibtool

Forked from cross/slibtool 3 months ago
Clone

Blame src/output/slbt_output_exec.c

6f991b
/*******************************************************************/
6f991b
/*  slibtool: a skinny libtool implementation, written in C        */
6f991b
/*  Copyright (C) 2016  Z. Gilboa                                  */
6f991b
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
6f991b
/*******************************************************************/
6f991b
Kylie McClain e20148
#include <unistd.h>
6f991b
#include <stdio.h>
6f991b
#include <slibtool/slibtool.h>
6f991b
Kylie McClain e20148
const char aclr_null[]    = "";
Kylie McClain e20148
const char aclr_reset[]   = "\e[0m";
Kylie McClain e20148
const char aclr_bold[]    = "\e[1m";
Kylie McClain e20148
Kylie McClain e20148
const char aclr_green[]   = "\e[32m";
Kylie McClain e20148
const char aclr_blue[]    = "\e[34m";
Kylie McClain e20148
const char aclr_magenta[] = "\e[35m";
Kylie McClain e20148
Kylie McClain e20148
static int slbt_output_exec_annotated(
6f991b
	const struct slbt_driver_ctx *	dctx,
fab986
	const struct slbt_exec_ctx *	ectx,
fab986
	const char *			step)
6f991b
{
Kylie McClain e20148
	char **      parg;
Kylie McClain e20148
	const char * aclr_set;
Kylie McClain e20148
	const char * aclr_color;
Kylie McClain e20148
	const char * aclr_unset;
Kylie McClain e20148
Kylie McClain e20148
	if (fprintf(stdout,"%s%s%s: %s%s%s%s:%s",
Kylie McClain e20148
			aclr_bold,aclr_magenta,
Kylie McClain e20148
			dctx->program,aclr_reset,
Kylie McClain e20148
			aclr_bold,aclr_green,step,aclr_reset) < 0)
Kylie McClain e20148
		return -1;
Kylie McClain e20148
Kylie McClain e20148
	for (parg=ectx->argv; *parg; parg++) {
df07fb
		if ((parg == ectx->lout[0]) || (parg == ectx->mout[0])) {
Kylie McClain e20148
			aclr_set      = aclr_bold;
Kylie McClain e20148
			aclr_color    = aclr_blue;
Kylie McClain e20148
			aclr_unset    = aclr_null;
Kylie McClain e20148
		} else {
Kylie McClain e20148
			aclr_set      = aclr_null;
Kylie McClain e20148
			aclr_color    = aclr_null;
Kylie McClain e20148
			aclr_unset    = aclr_reset;
Kylie McClain e20148
		}
Kylie McClain e20148
Kylie McClain e20148
		if (fprintf(stdout," %s%s%s%s",
Kylie McClain e20148
				aclr_set,aclr_color,
Kylie McClain e20148
				*parg,
Kylie McClain e20148
				aclr_unset) < 0)
Kylie McClain e20148
			return -1;
Kylie McClain e20148
Kylie McClain e20148
	}
Kylie McClain e20148
Kylie McClain e20148
	if (fputc('\n',stdout) < 0)
Kylie McClain e20148
		return -1;
Kylie McClain e20148
Kylie McClain e20148
	return 0;
Kylie McClain e20148
}
Kylie McClain e20148
Kylie McClain e20148
static int slbt_output_exec_plain(
Kylie McClain e20148
	const struct slbt_driver_ctx *	dctx,
Kylie McClain e20148
	const struct slbt_exec_ctx *	ectx,
Kylie McClain e20148
	const char *		step)
Kylie McClain e20148
{
6f991b
	char ** parg;
6f991b
fab986
	if (fprintf(stdout,"%s: %s:",dctx->program,step) < 0)
6f991b
		return -1;
6f991b
6f991b
	for (parg=ectx->argv; *parg; parg++)
6f991b
		if (fprintf(stdout," %s",*parg) < 0)
6f991b
			return -1;
6f991b
6f991b
	if (fputc('\n',stdout) < 0)
6f991b
		return -1;
6f991b
6f991b
	return 0;
6f991b
}
fab986
Kylie McClain e20148
int slbt_output_exec(
Kylie McClain e20148
	const struct slbt_driver_ctx *	dctx,
Kylie McClain e20148
	const struct slbt_exec_ctx *	ectx,
Kylie McClain e20148
	const char *			step)
Kylie McClain e20148
{
Kylie McClain e20148
	if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
Kylie McClain e20148
		return slbt_output_exec_plain(dctx,ectx,step);
Kylie McClain e20148
Kylie McClain e20148
	else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
Kylie McClain e20148
		return slbt_output_exec_annotated(dctx,ectx,step);
Kylie McClain e20148
Kylie McClain e20148
	else if (isatty(STDOUT_FILENO))
Kylie McClain e20148
		return slbt_output_exec_annotated(dctx,ectx,step);
Kylie McClain e20148
Kylie McClain e20148
	else
Kylie McClain e20148
		return slbt_output_exec_plain(dctx,ectx,step);
Kylie McClain e20148
}
Kylie McClain e20148
fab986
int slbt_output_compile(
fab986
	const struct slbt_driver_ctx *	dctx,
fab986
	const struct slbt_exec_ctx *	ectx)
fab986
{
fab986
	return slbt_output_exec(dctx,ectx,"compile");
fab986
}
ba3523
045b88
int slbt_output_execute(
045b88
	const struct slbt_driver_ctx *	dctx,
045b88
	const struct slbt_exec_ctx *	ectx)
045b88
{
045b88
	return slbt_output_exec(dctx,ectx,"execute");
045b88
}
045b88
ca15b9
int slbt_output_install(
ca15b9
	const struct slbt_driver_ctx *	dctx,
ca15b9
	const struct slbt_exec_ctx *	ectx)
ca15b9
{
ca15b9
	return slbt_output_exec(dctx,ectx,"install");
ca15b9
}
ca15b9
ba3523
int slbt_output_link(
ba3523
	const struct slbt_driver_ctx *	dctx,
ba3523
	const struct slbt_exec_ctx *	ectx)
ba3523
{
ba3523
	return slbt_output_exec(dctx,ectx,"link");
ba3523
}