|
|
5d46be |
/*******************************************************************/
|
|
|
5d46be |
/* slibtool: a skinny libtool implementation, written in C */
|
|
|
5d46be |
/* Copyright (C) 2016--2024 SysDeer Technologies, LLC */
|
|
|
5d46be |
/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
|
|
|
5d46be |
/*******************************************************************/
|
|
|
5d46be |
|
|
|
5d46be |
#include <slibtool/slibtool.h>
|
|
|
5d46be |
#include <slibtool/slibtool_output.h>
|
|
|
5d46be |
#include "slibtool_driver_impl.h"
|
|
|
5d46be |
#include "slibtool_dprintf_impl.h"
|
|
|
5d46be |
#include "slibtool_errinfo_impl.h"
|
|
|
5d46be |
#include "slibtool_ar_impl.h"
|
|
|
5d46be |
|
|
|
5d46be |
#define SLBT_PRETTY_FLAGS (SLBT_PRETTY_YAML \
|
|
|
5d46be |
| SLBT_PRETTY_POSIX \
|
|
|
5d46be |
| SLBT_PRETTY_HEXDATA)
|
|
|
5d46be |
|
|
|
7ffcb5 |
static int slbt_ar_output_arname_impl(
|
|
|
7ffcb5 |
const struct slbt_driver_ctx * dctx,
|
|
|
7ffcb5 |
const struct slbt_archive_ctx * actx,
|
|
|
7ffcb5 |
const struct slbt_fd_ctx * fdctx,
|
|
|
7ffcb5 |
const char * fmt)
|
|
|
7ffcb5 |
{
|
|
|
7ffcb5 |
const char * path;
|
|
|
7ffcb5 |
const char mema[] = "<memory_object>";
|
|
|
7ffcb5 |
|
|
|
7ffcb5 |
path = actx->path && *actx->path ? *actx->path : mema;
|
|
|
7ffcb5 |
|
|
|
7ffcb5 |
if (slbt_dprintf(fdctx->fdout,fmt,path) < 0)
|
|
|
7ffcb5 |
return SLBT_SYSTEM_ERROR(dctx,0);
|
|
|
7ffcb5 |
|
|
|
7ffcb5 |
return 0;
|
|
|
7ffcb5 |
}
|
|
|
5d46be |
|
|
|
5d46be |
static int slbt_ar_output_arname_posix(
|
|
|
5d46be |
const struct slbt_driver_ctx * dctx,
|
|
|
5d46be |
const struct slbt_archive_ctx * actx,
|
|
|
5d46be |
const struct slbt_fd_ctx * fdctx)
|
|
|
5d46be |
{
|
|
|
7ffcb5 |
if (slbt_ar_output_arname_impl(
|
|
|
7ffcb5 |
dctx,actx,fdctx,
|
|
|
7ffcb5 |
"%s:\n") < 0)
|
|
|
7ffcb5 |
return SLBT_NESTED_ERROR(dctx);
|
|
|
5d46be |
|
|
|
5d46be |
return 0;
|
|
|
5d46be |
}
|
|
|
5d46be |
|
|
|
5d46be |
static int slbt_ar_output_arname_yaml(
|
|
|
5d46be |
const struct slbt_driver_ctx * dctx,
|
|
|
5d46be |
const struct slbt_archive_ctx * actx,
|
|
|
5d46be |
const struct slbt_fd_ctx * fdctx)
|
|
|
5d46be |
{
|
|
|
7ffcb5 |
if (slbt_ar_output_arname_impl(
|
|
|
7ffcb5 |
dctx,actx,fdctx,
|
|
|
e7c28b |
"Archive:\n"
|
|
|
39866c |
" - Meta:\n"
|
|
|
7ffcb5 |
" - [ name: %s ]\n\n") < 0)
|
|
|
7ffcb5 |
return SLBT_NESTED_ERROR(dctx);
|
|
|
5d46be |
|
|
|
5d46be |
return 0;
|
|
|
5d46be |
}
|
|
|
5d46be |
|
|
|
5d46be |
int slbt_ar_output_arname(const struct slbt_archive_ctx * actx)
|
|
|
5d46be |
{
|
|
|
5d46be |
const struct slbt_driver_ctx * dctx;
|
|
|
5d46be |
struct slbt_fd_ctx fdctx;
|
|
|
5d46be |
|
|
|
5d46be |
dctx = (slbt_get_archive_ictx(actx))->dctx;
|
|
|
5d46be |
|
|
|
5d46be |
if (slbt_get_driver_fdctx(dctx,&fdctx) < 0)
|
|
|
5d46be |
return SLBT_NESTED_ERROR(dctx);
|
|
|
5d46be |
|
|
|
5d46be |
switch (dctx->cctx->fmtflags & SLBT_PRETTY_FLAGS) {
|
|
|
5d46be |
case SLBT_PRETTY_YAML:
|
|
|
5d46be |
return slbt_ar_output_arname_yaml(
|
|
|
5d46be |
dctx,actx,&fdctx);
|
|
|
5d46be |
|
|
|
5d46be |
case SLBT_PRETTY_POSIX:
|
|
|
5d46be |
return slbt_ar_output_arname_posix(
|
|
|
5d46be |
dctx,actx,&fdctx);
|
|
|
5d46be |
|
|
|
5d46be |
default:
|
|
|
5d46be |
return slbt_ar_output_arname_yaml(
|
|
|
5d46be |
dctx,actx,&fdctx);
|
|
|
5d46be |
}
|
|
|
5d46be |
}
|