Blame src/output/mdso_output_export_symbols.c

8cfad6
/****************************************************************/
8cfad6
/*  mdso: midipix dso scavenger                                 */
3e816c
/*  Copyright (C) 2015--2016  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>
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(
8cfad6
	const struct mdso_unit_ctx *	uctx,
8cfad6
	const struct mdso_common_ctx *	cctx,
8cfad6
	FILE *				fout)
8cfad6
{
8cfad6
	const char * const * sym;
8cfad6
8cfad6
	if (!uctx->syms[0])
8cfad6
		return 0;
8cfad6
8cfad6
	if ((pretty_header(cctx,fout)) < 0)
8cfad6
		return -1;
8cfad6
8cfad6
	for (sym=uctx->syms; *sym; sym++)
8cfad6
		if ((pretty_export_item(cctx,*sym,fout)) < 0)
8cfad6
			return -1;
8cfad6
8cfad6
	return 0;
8cfad6
}