Blame src/arbits/output/slbt_ar_output_symbols.c

d9285e
/*******************************************************************/
d9285e
/*  slibtool: a skinny libtool implementation, written in C        */
d9285e
/*  Copyright (C) 2016--2024  SysDeer Technologies, LLC            */
d9285e
/*  Released under the Standard MIT License; see COPYING.SLIBTOOL. */
d9285e
/*******************************************************************/
d9285e
d9285e
#include <time.h>
d9285e
#include <locale.h>
76c5e9
#include <regex.h>
d9285e
#include <inttypes.h>
d9285e
#include <slibtool/slibtool.h>
d9285e
#include <slibtool/slibtool_output.h>
d9285e
#include "slibtool_driver_impl.h"
d9285e
#include "slibtool_dprintf_impl.h"
d9285e
#include "slibtool_errinfo_impl.h"
d9285e
#include "slibtool_ar_impl.h"
d9285e
d9285e
#define SLBT_PRETTY_FLAGS       (SLBT_PRETTY_YAML      \
d9285e
	                         | SLBT_PRETTY_POSIX    \
d9285e
	                         | SLBT_PRETTY_HEXDATA)
d9285e
3fa3e3
static int slbt_au_output_symbols_posix(
d9285e
	const struct slbt_driver_ctx *  dctx,
d9285e
	struct slbt_archive_meta_impl * mctx,
d9285e
	const struct slbt_fd_ctx *      fdctx)
d9285e
{
d9285e
	int             fdout;
df2627
	bool            fsort;
9feb47
	bool            fcoff;
76c5e9
	const char *    regex;
d9285e
	const char **   symv;
df2627
	const char **   symstrv;
76c5e9
	regex_t         regctx;
5ade20
	regmatch_t      pmatch[2] = {{0,0},{0,0}};
d9285e
d9285e
	fdout = fdctx->fdout;
874b59
	fsort = !(dctx->cctx->fmtflags & SLBT_OUTPUT_ARCHIVE_NOSORT);
9feb47
	fcoff = (mctx->ofmtattr == AR_OBJECT_ATTR_COFF);
df2627
df2627
	if (fsort && !mctx->mapstrv)
df2627
		if (slbt_update_mapstrv(dctx,mctx) < 0)
df2627
			return SLBT_NESTED_ERROR(dctx);
d9285e
76c5e9
	if ((regex = dctx->cctx->regex))
76c5e9
		if (regcomp(&regctx,regex,REG_NEWLINE))
76c5e9
			return SLBT_CUSTOM_ERROR(
76c5e9
				dctx,
76c5e9
				SLBT_ERR_FLOW_ERROR);
76c5e9
df2627
	symstrv = fsort ? mctx->mapstrv : mctx->symstrv;
df2627
df2627
	for (symv=symstrv; *symv; symv++)
9feb47
		if (!fcoff || strncmp(*symv,"__imp_",6))
9feb47
			if (!regex || !regexec(&regctx,*symv,1,pmatch,0))
9feb47
				if (slbt_dprintf(fdout,"%s\n",*symv) < 0)
9feb47
					return SLBT_SYSTEM_ERROR(dctx,0);
76c5e9
76c5e9
	if (regex)
76c5e9
		regfree(&regctx);
d9285e
d9285e
	return 0;
d9285e
}
d9285e
3fa3e3
static int slbt_au_output_symbols_yaml(
d9285e
	const struct slbt_driver_ctx *  dctx,
d9285e
	struct slbt_archive_meta_impl * mctx,
d9285e
	const struct slbt_fd_ctx *      fdctx)
d9285e
{
d9285e
	(void)dctx;
d9285e
	(void)mctx;
d9285e
	(void)fdctx;
d9285e
d9285e
	return 0;
d9285e
}
d9285e
3fa3e3
int slbt_au_output_symbols(const struct slbt_archive_meta * meta)
d9285e
{
d9285e
	struct slbt_archive_meta_impl * mctx;
d9285e
	const struct slbt_driver_ctx *  dctx;
d9285e
	struct slbt_fd_ctx              fdctx;
d9285e
d9285e
	mctx = slbt_archive_meta_ictx(meta);
d9285e
	dctx = (slbt_archive_meta_ictx(meta))->dctx;
d9285e
d9285e
	if (slbt_get_driver_fdctx(dctx,&fdctx) < 0)
d9285e
		return SLBT_NESTED_ERROR(dctx);
d9285e
d9285e
	if (!meta->a_memberv)
d9285e
		return 0;
d9285e
d9285e
	switch (dctx->cctx->fmtflags & SLBT_PRETTY_FLAGS) {
d9285e
		case SLBT_PRETTY_YAML:
3fa3e3
			return slbt_au_output_symbols_yaml(
d9285e
				dctx,mctx,&fdctx);
d9285e
d9285e
		case SLBT_PRETTY_POSIX:
3fa3e3
			return slbt_au_output_symbols_posix(
d9285e
				dctx,mctx,&fdctx);
d9285e
d9285e
		default:
3fa3e3
			return slbt_au_output_symbols_yaml(
d9285e
				dctx,mctx,&fdctx);
d9285e
	}
d9285e
}