summaryrefslogtreecommitdiffhomepage
path: root/src/output/amgc_output_pad_symbol.c
blob: 6a475ee83af9f734fa7ead050fcfb6fa526c0996 (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
/**********************************************************/
/*  apimagic: cparser-based API normalization utility     */
/*  Copyright (C) 2015--2016  Z. Gilboa                   */
/*  Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */
/**********************************************************/

#include <stdio.h>
#include <string.h>

#include <apimagic/apimagic.h>
#include "apimagic_driver_impl.h"

int  amgc_output_pad_symbol(
	const char *			symbol,
	const struct amgc_layout *	layout,
	FILE *				fout)
{
	int len = (int)(strlen(symbol));
	int symwidth = layout->symwidth;

	if (layout->symwidth < 1)
		return -1;

	if (layout->tabwidth) {
		symwidth += layout->tabwidth;
		symwidth &= (~(layout->tabwidth-1));
	} else {
		symwidth += AMGC_TAB_WIDTH;
		symwidth &= (~(AMGC_TAB_WIDTH-1));
	}

	if (layout->tabwidth == 0)
		return fprintf(fout,"%*c",layout->symwidth-len,' ');

	len &= (~(layout->tabwidth-1));

	while (len < layout->symwidth) {
		if (fputc('\t',fout) < 0)
			return -1;
		else
			len += layout->tabwidth;
	}

	return 0;
}