summaryrefslogtreecommitdiff
path: root/src/output/mdso_output_export_symbols.c
blob: 5c8dc666d59425ef3d79b37c22f3dc30c637dcc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/****************************************************************/
/*  mdso: midipix dso scavenger                                 */
/*  Copyright (C) 2015--2017  Z. Gilboa                         */
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
/****************************************************************/

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include <mdso/mdso.h>
#include <mdso/mdso_output.h>
#include "mdso_errinfo_impl.h"

static int pretty_header(const struct mdso_common_ctx * cctx, FILE * fout)
{
	return (cctx->fmtflags & MDSO_PRETTY_YAML)
		? fputs("exports:\n",fout)
		: 0;
}

static int pretty_export_item(const struct mdso_common_ctx * cctx, const char * name, FILE * fout)
{
	if (cctx->fmtflags & MDSO_PRETTY_YAML)
		return fprintf(fout,"- %s\n",name);
	else
		return fprintf(fout,"%s\n",name);
}

int mdso_output_export_symbols(
	const struct mdso_driver_ctx *	dctx,
	const struct mdso_unit_ctx *	uctx,
	FILE *				fout)
{
	const char * const * sym;

	if (!uctx->syms[0])
		return 0;

	if ((pretty_header(dctx->cctx,fout)) < 0)
		return MDSO_FILE_ERROR(dctx);

	for (sym=uctx->syms; *sym; sym++)
		if ((pretty_export_item(dctx->cctx,*sym,fout)) < 0)
			return MDSO_FILE_ERROR(dctx);

	return 0;
}