Blame src/output/amgc_output_pad_symbol.c

2f6d92
/**********************************************************/
2f6d92
/*  apimagic: cparser-based API normalization utility     */
84312f
/*  Copyright (C) 2015--2021  SysDeer Technologies, LLC   */
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(
b8225b
	const struct amgc_driver_ctx *	dctx,
2f6d92
	const char *			symbol,
b8225b
	const struct amgc_layout *	layout)
2f6d92
{
b8225b
	int len      = (int)(strlen(symbol));
b8225b
	int fdout    = amgc_driver_fdout(dctx);
5590ea
	int symwidth = layout->symwidth;
2f6d92
2f6d92
	if (layout->symwidth < 1)
2f6d92
		return -1;
2f6d92
2f6d92
	if (layout->tabwidth == 0)
b8225b
		return amgc_dprintf(
b8225b
			fdout,"%*c",
b8225b
			layout->symwidth-len,' ');
2f6d92
5a349e
	symwidth += layout->tabwidth;
5a349e
	symwidth &= (~(layout->tabwidth-1));
5a349e
2f6d92
	len &= (~(layout->tabwidth-1));
2f6d92
5a349e
	while (len < symwidth) {
b8225b
		if (amgc_dprintf(fdout,"\t") < 0)
2f6d92
			return -1;
b8225b
b8225b
		len += layout->tabwidth;
2f6d92
	}
2f6d92
2f6d92
	return 0;
2f6d92
}