summaryrefslogtreecommitdiffhomepage
path: root/src/output
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-06-27 03:51:35 +0000
committermidipix <writeonce@midipix.org>2018-06-27 07:30:01 -0400
commita82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b (patch)
tree1d0de0094b350cf323b6ea8ee44f571918048789 /src/output
parent6088476d902b8bcbf688ce7cb6055a4c47c2d0b7 (diff)
downloadslibtool-a82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b.tar.bz2
slibtool-a82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b.tar.xz
driver, library interfaces: support alternate fd's for input/output/error/log.
Diffstat (limited to 'src/output')
-rw-r--r--src/output/slbt_output_config.c31
-rw-r--r--src/output/slbt_output_error.c22
-rw-r--r--src/output/slbt_output_exec.c33
-rw-r--r--src/output/slbt_output_features.c15
4 files changed, 63 insertions, 38 deletions
diff --git a/src/output/slbt_output_config.c b/src/output/slbt_output_config.c
index 800c6c3..fc8f5ca 100644
--- a/src/output/slbt_output_config.c
+++ b/src/output/slbt_output_config.c
@@ -9,6 +9,8 @@
#include <stdbool.h>
#include <slibtool/slibtool.h>
+#include "slibtool_driver_impl.h"
+#include "slibtool_dprintf_impl.h"
#include "slibtool_errinfo_impl.h"
#ifndef SLBT_TAB_WIDTH
@@ -20,12 +22,13 @@
#endif
static bool slbt_output_config_line(
+ int fd,
const char * key,
const char * value,
const char * annotation,
int midwidth)
{
- return (fprintf(stdout,"%-*s%-*s%s\n",
+ return (slbt_dprintf(fd,"%-*s%-*s%s\n",
SLBT_KEY_WIDTH, key,
midwidth, value ? value : "",
annotation ? annotation : "") < 0)
@@ -39,11 +42,13 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx)
const char * target;
int len;
int midwidth;
+ int fdout;
cctx = dctx->cctx;
compiler = cctx->cargv[0] ? cctx->cargv[0] : "";
target = cctx->target ? cctx->target : "";
midwidth = strlen(compiler);
+ fdout = slbt_driver_fdout(dctx);
if ((len = strlen(target)) > midwidth)
midwidth = len;
@@ -69,37 +74,35 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx)
midwidth += SLBT_TAB_WIDTH;
midwidth &= (~(SLBT_TAB_WIDTH-1));
- if (slbt_output_config_line("key","value","annotation",midwidth))
+ if (slbt_output_config_line(fdout,"key","value","annotation",midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("---","-----","----------",midwidth))
+ if (slbt_output_config_line(fdout,"---","-----","----------",midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth))
+ if (slbt_output_config_line(fdout,"compiler",cctx->cargv[0],"",midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("target",cctx->target,"",midwidth))
+ if (slbt_output_config_line(fdout,"target",cctx->target,"",midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth))
+ if (slbt_output_config_line(fdout,"host",cctx->host.host,cctx->cfgmeta.host,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
+ if (slbt_output_config_line(fdout,"flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
+ if (slbt_output_config_line(fdout,"ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
+ if (slbt_output_config_line(fdout,"ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
+ if (slbt_output_config_line(fdout,"dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- if (slbt_output_config_line("mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
+ if (slbt_output_config_line(fdout,"mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
return SLBT_SYSTEM_ERROR(dctx);
- return fflush(stdout)
- ? SLBT_SYSTEM_ERROR(dctx)
- : 0;
+ return 0;
}
diff --git a/src/output/slbt_output_error.c b/src/output/slbt_output_error.c
index 49a27b8..0ccabb2 100644
--- a/src/output/slbt_output_error.c
+++ b/src/output/slbt_output_error.c
@@ -10,6 +10,9 @@
#include <unistd.h>
#include <slibtool/slibtool.h>
+#include "slibtool_driver_impl.h"
+#include "slibtool_dprintf_impl.h"
+
static const char aclr_reset[] = "\x1b[0m";
static const char aclr_bold[] = "\x1b[1m";
@@ -56,7 +59,8 @@ static int slbt_output_error_record_plain(
{
const char * errdesc = slbt_output_strerror(erri);
- if (fprintf(stderr,"%s: %s %s(), line %d%s%s.\n",
+ if (slbt_dprintf(slbt_driver_fderr(dctx),
+ "%s: %s %s(), line %d%s%s.\n",
dctx->program,
slbt_output_error_header(erri),
erri->efunction,
@@ -65,7 +69,7 @@ static int slbt_output_error_record_plain(
errdesc) < 0)
return -1;
- return fflush(stderr);
+ return 0;
}
static int slbt_output_error_record_annotated(
@@ -74,8 +78,8 @@ static int slbt_output_error_record_annotated(
{
const char * errdesc = slbt_output_strerror(erri);
- if (fprintf(
- stderr,
+ if (slbt_dprintf(
+ slbt_driver_fderr(dctx),
"%s%s%s:%s %s%s%s %s%s%s()%s, %s%sline %d%s%s%s%s%s.\n",
aclr_bold,aclr_magenta,
@@ -100,20 +104,22 @@ static int slbt_output_error_record_annotated(
aclr_reset) < 0)
return -1;
- return fflush(stderr);
+ return 0;
}
int slbt_output_error_record(
const struct slbt_driver_ctx * dctx,
const struct slbt_error_info * erri)
{
+ int fderr = slbt_driver_fderr(dctx);
+
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
return slbt_output_error_record_plain(dctx,erri);
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
return slbt_output_error_record_annotated(dctx,erri);
- else if (isatty(STDERR_FILENO))
+ else if (isatty(fderr))
return slbt_output_error_record_annotated(dctx,erri);
else
@@ -144,13 +150,15 @@ static int slbt_output_error_vector_annotated(const struct slbt_driver_ctx * dct
int slbt_output_error_vector(const struct slbt_driver_ctx * dctx)
{
+ int fderr = slbt_driver_fderr(dctx);
+
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
return slbt_output_error_vector_plain(dctx);
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
return slbt_output_error_vector_annotated(dctx);
- else if (isatty(STDERR_FILENO))
+ else if (isatty(fderr))
return slbt_output_error_vector_annotated(dctx);
else
diff --git a/src/output/slbt_output_exec.c b/src/output/slbt_output_exec.c
index effa3b7..7d773c2 100644
--- a/src/output/slbt_output_exec.c
+++ b/src/output/slbt_output_exec.c
@@ -7,6 +7,9 @@
#include <unistd.h>
#include <stdio.h>
#include <slibtool/slibtool.h>
+
+#include "slibtool_driver_impl.h"
+#include "slibtool_dprintf_impl.h"
#include "slibtool_errinfo_impl.h"
static const char aclr_null[] = "";
@@ -22,12 +25,16 @@ static int slbt_output_exec_annotated(
const struct slbt_exec_ctx * ectx,
const char * step)
{
+ int fdout;
char ** parg;
const char * aclr_set;
const char * aclr_color;
const char * aclr_unset;
- if (fprintf(stdout,"%s%s%s: %s%s%s%s:%s",
+ fdout = slbt_driver_fdout(dctx);
+
+ if (slbt_dprintf(
+ fdout,"%s%s%s: %s%s%s%s:%s",
aclr_bold,aclr_magenta,
dctx->program,aclr_reset,
aclr_bold,aclr_green,step,aclr_reset) < 0)
@@ -44,7 +51,8 @@ static int slbt_output_exec_annotated(
aclr_unset = aclr_reset;
}
- if (fprintf(stdout," %s%s%s%s",
+ if (slbt_dprintf(
+ fdout," %s%s%s%s",
aclr_set,aclr_color,
*parg,
aclr_unset) < 0)
@@ -52,10 +60,10 @@ static int slbt_output_exec_annotated(
}
- if (fputc('\n',stdout) < 0)
+ if (slbt_dprintf(fdout,"\n") < 0)
return SLBT_SYSTEM_ERROR(dctx);
- return fflush(stdout);
+ return 0;
}
static int slbt_output_exec_plain(
@@ -63,21 +71,22 @@ static int slbt_output_exec_plain(
const struct slbt_exec_ctx * ectx,
const char * step)
{
+ int fdout;
char ** parg;
- if (fprintf(stdout,"%s: %s:",dctx->program,step) < 0)
+ fdout = slbt_driver_fdout(dctx);
+
+ if (slbt_dprintf(fdout,"%s: %s:",dctx->program,step) < 0)
return SLBT_SYSTEM_ERROR(dctx);
for (parg=ectx->argv; *parg; parg++)
- if (fprintf(stdout," %s",*parg) < 0)
+ if (slbt_dprintf(fdout," %s",*parg) < 0)
return SLBT_SYSTEM_ERROR(dctx);
- if (fputc('\n',stdout) < 0)
+ if (slbt_dprintf(fdout,"\n") < 0)
return SLBT_SYSTEM_ERROR(dctx);
- return fflush(stdout)
- ? SLBT_SYSTEM_ERROR(dctx)
- : 0;
+ return 0;
}
int slbt_output_exec(
@@ -85,13 +94,15 @@ int slbt_output_exec(
const struct slbt_exec_ctx * ectx,
const char * step)
{
+ int fdout = slbt_driver_fdout(dctx);
+
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
return slbt_output_exec_plain(dctx,ectx,step);
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
return slbt_output_exec_annotated(dctx,ectx,step);
- else if (isatty(STDOUT_FILENO))
+ else if (isatty(fdout))
return slbt_output_exec_annotated(dctx,ectx,step);
else
diff --git a/src/output/slbt_output_features.c b/src/output/slbt_output_features.c
index b0252fa..577ca5a 100644
--- a/src/output/slbt_output_features.c
+++ b/src/output/slbt_output_features.c
@@ -9,6 +9,8 @@
#include <stdbool.h>
#include <slibtool/slibtool.h>
+#include "slibtool_driver_impl.h"
+#include "slibtool_dprintf_impl.h"
#include "slibtool_errinfo_impl.h"
static const char enable[] = "enable";
@@ -16,25 +18,26 @@ static const char disable[] = "disable";
int slbt_output_features(const struct slbt_driver_ctx * dctx)
{
+ int fdout;
const char * shared_option;
const char * static_option;
+ fdout = slbt_driver_fdout(dctx);
+
shared_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED)
? disable : enable;
static_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC)
? disable : enable;
- if (fprintf(stdout,"host: %s\n",dctx->cctx->host.host) < 0)
+ if (slbt_dprintf(fdout,"host: %s\n",dctx->cctx->host.host) < 0)
return SLBT_SYSTEM_ERROR(dctx);
- if (fprintf(stdout,"%s shared libraries\n",shared_option) < 0)
+ if (slbt_dprintf(fdout,"%s shared libraries\n",shared_option) < 0)
return SLBT_SYSTEM_ERROR(dctx);
- if (fprintf(stdout,"%s static libraries\n",static_option) < 0)
+ if (slbt_dprintf(fdout,"%s static libraries\n",static_option) < 0)
return SLBT_SYSTEM_ERROR(dctx);
- return fflush(stdout)
- ? SLBT_SYSTEM_ERROR(dctx)
- : 0;
+ return 0;
}