Blame src/output/mdso_output_export_symbols.c

8cfad6
/****************************************************************/
8cfad6
/*  mdso: midipix dso scavenger                                 */
78ab3c
/*  Copyright (C) 2015--2017  Z. Gilboa                         */
8cfad6
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
8cfad6
/****************************************************************/
8cfad6
8cfad6
#include <stdint.h>
8cfad6
#include <stdlib.h>
8cfad6
#include <stdio.h>
8cfad6
#include <string.h>
8cfad6
#include <errno.h>
8cfad6
8cfad6
#include <mdso/mdso.h>
8cfad6
#include <mdso/mdso_output.h>
63e310
#include "mdso_errinfo_impl.h"
8cfad6
8cfad6
static int pretty_header(const struct mdso_common_ctx * cctx, FILE * fout)
8cfad6
{
8cfad6
	return (cctx->fmtflags & MDSO_PRETTY_YAML)
8cfad6
		? fputs("exports:\n",fout)
8cfad6
		: 0;
8cfad6
}
8cfad6
8cfad6
static int pretty_export_item(const struct mdso_common_ctx * cctx, const char * name, FILE * fout)
8cfad6
{
8cfad6
	if (cctx->fmtflags & MDSO_PRETTY_YAML)
8cfad6
		return fprintf(fout,"- %s\n",name);
8cfad6
	else
8cfad6
		return fprintf(fout,"%s\n",name);
8cfad6
}
8cfad6
8cfad6
int mdso_output_export_symbols(
63e310
	const struct mdso_driver_ctx *	dctx,
8cfad6
	const struct mdso_unit_ctx *	uctx,
8cfad6
	FILE *				fout)
8cfad6
{
8cfad6
	const char * const * sym;
8cfad6
8cfad6
	if (!uctx->syms[0])
8cfad6
		return 0;
8cfad6
63e310
	if ((pretty_header(dctx->cctx,fout)) < 0)
63e310
		return MDSO_FILE_ERROR(dctx);
8cfad6
8cfad6
	for (sym=uctx->syms; *sym; sym++)
63e310
		if ((pretty_export_item(dctx->cctx,*sym,fout)) < 0)
63e310
			return MDSO_FILE_ERROR(dctx);
8cfad6
8cfad6
	return 0;
8cfad6
}