Blame src/arbits/output/slbt_ar_output_members.c

47341a
/*******************************************************************/
47341a
/*  slibtool: a skinny libtool implementation, written in C        */
47341a
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
47341a
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
47341a
/*******************************************************************/
47341a
47341a
#include <slibtool/slibtool.h>
47341a
#include <slibtool/slibtool_output.h>
47341a
#include "slibtool_driver_impl.h"
47341a
#include "slibtool_dprintf_impl.h"
47341a
#include "slibtool_errinfo_impl.h"
47341a
#include "slibtool_ar_impl.h"
47341a
47341a
#define SLBT_PRETTY_FLAGS       (SLBT_PRETTY_YAML      \
47341a
	                         | SLBT_PRETTY_POSIX    \
47341a
	                         | SLBT_PRETTY_HEXDATA)
47341a
47341a
47341a
static int slbt_ar_output_members_posix(
47341a
	const struct slbt_driver_ctx *  dctx,
47341a
	const struct slbt_archive_meta * meta,
47341a
	const struct slbt_fd_ctx *       fdctx)
47341a
{
47341a
	struct ar_meta_member_info **   memberp;
47341a
	const char *                    name;
47341a
47341a
	for (memberp=meta->a_memberv; *memberp; memberp++) {
47341a
		switch ((*memberp)->ar_member_attr) {
47341a
			case AR_MEMBER_ATTR_ARMAP:
47341a
			case AR_MEMBER_ATTR_LINKINFO:
47341a
			case AR_MEMBER_ATTR_NAMESTRS:
47341a
				break;
47341a
47341a
			default:
47341a
				name = (*memberp)->ar_file_header.ar_member_name;
47341a
47341a
				if (slbt_dprintf(fdctx->fdout,"%s\n",name) < 0)
47341a
					return SLBT_SYSTEM_ERROR(dctx,0);
47341a
		}
47341a
	}
47341a
47341a
	return 0;
47341a
}
47341a
47341a
static int slbt_ar_output_members_yaml(
47341a
	const struct slbt_driver_ctx *  dctx,
47341a
	const struct slbt_archive_meta * meta,
47341a
	const struct slbt_fd_ctx *       fdctx)
47341a
{
47341a
	struct ar_meta_member_info **   memberp;
47341a
	const char *                    name;
47341a
47341a
	if (slbt_dprintf(fdctx->fdout,"  - Members = {\n") < 0)
47341a
		return SLBT_SYSTEM_ERROR(dctx,0);
47341a
47341a
	for (memberp=meta->a_memberv; *memberp; memberp++) {
47341a
		switch ((*memberp)->ar_member_attr) {
47341a
			case AR_MEMBER_ATTR_ARMAP:
47341a
			case AR_MEMBER_ATTR_LINKINFO:
47341a
			case AR_MEMBER_ATTR_NAMESTRS:
47341a
				break;
47341a
47341a
			default:
47341a
				name = (*memberp)->ar_file_header.ar_member_name;
47341a
47341a
				if (slbt_dprintf(fdctx->fdout,"    - %s\n",name) < 0)
47341a
					return SLBT_SYSTEM_ERROR(dctx,0);
47341a
		}
47341a
	}
47341a
47341a
	if (slbt_dprintf(fdctx->fdout,"  }\n") < 0)
47341a
		return SLBT_SYSTEM_ERROR(dctx,0);
47341a
47341a
	return 0;
47341a
}
47341a
47341a
int slbt_ar_output_members(const struct slbt_archive_meta * meta)
47341a
{
47341a
	const struct slbt_driver_ctx *  dctx;
47341a
	struct slbt_fd_ctx              fdctx;
47341a
47341a
	dctx = (slbt_archive_meta_ictx(meta))->dctx;
47341a
47341a
	if (slbt_get_driver_fdctx(dctx,&fdctx) < 0)
47341a
		return SLBT_NESTED_ERROR(dctx);
47341a
47341a
	if (!meta->a_memberv)
47341a
		return 0;
47341a
47341a
	switch (dctx->cctx->fmtflags & SLBT_PRETTY_FLAGS) {
47341a
		case SLBT_PRETTY_YAML:
47341a
			return slbt_ar_output_members_yaml(
47341a
				dctx,meta,&fdctx);
47341a
47341a
		case SLBT_PRETTY_POSIX:
47341a
			return slbt_ar_output_members_posix(
47341a
				dctx,meta,&fdctx);
47341a
47341a
		default:
47341a
			return slbt_ar_output_members_yaml(
47341a
				dctx,meta,&fdctx);
47341a
	}
47341a
}