Redfoxmoon / cross / slibtool

Forked from cross/slibtool 10 months ago
Clone

Blame src/output/slbt_output_exec.c

6f991b
/*******************************************************************/
6f991b
/*  slibtool: a skinny libtool implementation, written in C        */
bb281c
/*  Copyright (C) 2016--2021  SysDeer Technologies, LLC            */
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>
a82cc2
a82cc2
#include "slibtool_driver_impl.h"
a82cc2
#include "slibtool_dprintf_impl.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
{
a82cc2
	int          fdout;
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
a82cc2
	fdout = slbt_driver_fdout(dctx);
a82cc2
a82cc2
	if (slbt_dprintf(
a82cc2
			fdout,"%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)
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
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
a82cc2
		if (slbt_dprintf(
a82cc2
				fdout," %s%s%s%s",
Kylie McClain e20148
				aclr_set,aclr_color,
Kylie McClain e20148
				*parg,
Kylie McClain e20148
				aclr_unset) < 0)
6beda1
			return SLBT_SYSTEM_ERROR(dctx,0);
Kylie McClain e20148
Kylie McClain e20148
	}
Kylie McClain e20148
a82cc2
	if (slbt_dprintf(fdout,"\n") < 0)
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
Kylie McClain e20148
a82cc2
	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
{
a82cc2
	int	fdout;
6f991b
	char ** parg;
6f991b
a82cc2
	fdout = slbt_driver_fdout(dctx);
a82cc2
a82cc2
	if (slbt_dprintf(fdout,"%s: %s:",dctx->program,step) < 0)
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
6f991b
6f991b
	for (parg=ectx->argv; *parg; parg++)
a82cc2
		if (slbt_dprintf(fdout," %s",*parg) < 0)
6beda1
			return SLBT_SYSTEM_ERROR(dctx,0);
6f991b
a82cc2
	if (slbt_dprintf(fdout,"\n") < 0)
6beda1
		return SLBT_SYSTEM_ERROR(dctx,0);
6f991b
a82cc2
	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
{
a82cc2
	int fdout = slbt_driver_fdout(dctx);
a82cc2
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
a82cc2
	else if (isatty(fdout))
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
}