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
5590ea
	if (layout->tabwidth) {
5590ea
		symwidth += layout->tabwidth;
5590ea
		symwidth &= (~(layout->tabwidth-1));
5590ea
	} else {
5590ea
		symwidth += AMGC_TAB_WIDTH;
5590ea
		symwidth &= (~(AMGC_TAB_WIDTH-1));
5590ea
	}
5590ea
2f6d92
	if (layout->tabwidth == 0)
2f6d92
		return fprintf(fout,"%*c",layout->symwidth-len,' ');
2f6d92
2f6d92
	len &= (~(layout->tabwidth-1));
2f6d92
2f6d92
	while (len < layout->symwidth) {
2f6d92
		if (fputc('\t',fout) < 0)
2f6d92
			return -1;
2f6d92
		else
2f6d92
			len += layout->tabwidth;
2f6d92
	}
2f6d92
2f6d92
	return 0;
2f6d92
}