Blame src/output/amgc_output_pad_symbol.c

2f6d92
/**********************************************************/
2f6d92
/*  apimagic: cparser-based API normalization utility     */
2f6d92
/*  Copyright (C) 2015--2016  Z. Gilboa                   */
2f6d92
/*  Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */
2f6d92
/**********************************************************/
2f6d92
2f6d92
#include <stdio.h>
2f6d92
#include <string.h>
2f6d92
2f6d92
#include <apimagic/apimagic.h>
5590ea
#include "apimagic_driver_impl.h"
2f6d92
2f6d92
int  amgc_output_pad_symbol(
2f6d92
	const char *			symbol,
2f6d92
	const struct amgc_layout *	layout,
2f6d92
	FILE *				fout)
2f6d92
{
2f6d92
	int len = (int)(strlen(symbol));
5590ea
	int symwidth = layout->symwidth;
2f6d92
2f6d92
	if (layout->symwidth < 1)
2f6d92
		return -1;
2f6d92
2f6d92
	if (layout->tabwidth == 0)
2f6d92
		return fprintf(fout,"%*c",layout->symwidth-len,' ');
2f6d92
5a349e
	symwidth += layout->tabwidth;
5a349e
	symwidth &= (~(layout->tabwidth-1));
5a349e
2f6d92
	len &= (~(layout->tabwidth-1));
2f6d92
5a349e
	while (len < symwidth) {
2f6d92
		if (fputc('\t',fout) < 0)
2f6d92
			return -1;
2f6d92
		else
2f6d92
			len += layout->tabwidth;
2f6d92
	}
2f6d92
2f6d92
	return 0;
2f6d92
}