orbea / cross / slibtool

Forked from cross/slibtool 3 years 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>
522163
#include "slibtool_errinfo_impl.h"
6f991b
8ea8fc
static const char aclr_null[]    = "";
8ea8fc
static const char aclr_reset[]   = "\x1b[0m";
8ea8fc
static const char aclr_bold[]    = "\x1b[1m";
Kylie McClain e20148
8ea8fc
static const char aclr_green[]   = "\x1b[32m";
8ea8fc
static const char aclr_blue[]    = "\x1b[34m";
8ea8fc
static const char aclr_magenta[] = "\x1b[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)
522163
		return SLBT_SYSTEM_ERROR(dctx);
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)
522163
			return SLBT_SYSTEM_ERROR(dctx);
Kylie McClain e20148
Kylie McClain e20148
	}
Kylie McClain e20148
Kylie McClain e20148
	if (fputc('\n',stdout) < 0)
522163
		return SLBT_SYSTEM_ERROR(dctx);
Kylie McClain e20148
26127d
	return fflush(stdout);
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)
522163
		return SLBT_SYSTEM_ERROR(dctx);
6f991b
6f991b
	for (parg=ectx->argv; *parg; parg++)
6f991b
		if (fprintf(stdout," %s",*parg) < 0)
522163
			return SLBT_SYSTEM_ERROR(dctx);
6f991b
6f991b
	if (fputc('\n',stdout) < 0)
522163
		return SLBT_SYSTEM_ERROR(dctx);
6f991b
522163
	return fflush(stdout)
522163
		? SLBT_SYSTEM_ERROR(dctx)
522163
		: 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
}
0fb20a
0fb20a
int slbt_output_uninstall(
0fb20a
	const struct slbt_driver_ctx *	dctx,
0fb20a
	const struct slbt_exec_ctx *	ectx)
0fb20a
{
0fb20a
	return slbt_output_exec(dctx,ectx,"uninstall");
0fb20a
}