diff options
-rw-r--r-- | include/apimagic/apimagic.h | 8 | ||||
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | src/output/amgc_output_pad_symbol.c | 35 |
3 files changed, 44 insertions, 0 deletions
diff --git a/include/apimagic/apimagic.h b/include/apimagic/apimagic.h index d7a61ac..ac78b57 100644 --- a/include/apimagic/apimagic.h +++ b/include/apimagic/apimagic.h @@ -116,6 +116,13 @@ struct amgc_unit_ctx { int nerrors; }; +struct amgc_layout { + const char * header; + const char * footer; + int symwidth; + int tabwidth; +}; + /* driver api */ amgc_api int amgc_get_driver_ctx (const char ** argv, const char ** envp, uint32_t flags, struct amgc_driver_ctx **); amgc_api int amgc_create_driver_ctx (const struct amgc_common_ctx *, struct amgc_driver_ctx **); @@ -131,6 +138,7 @@ amgc_api int amgc_unmap_input (struct amgc_input *); amgc_api int amgc_lang_std_from_string (const char * std); /* utility api */ +amgc_api int amgc_output_pad_symbol (const char *, const struct amgc_layout *, FILE *); /* low-level api */ amgc_api int amgc_init_unit_meta (const struct amgc_unit_ctx *, struct amgc_unit_meta *); diff --git a/project/common.mk b/project/common.mk index d54a0f2..318de8b 100644 --- a/project/common.mk +++ b/project/common.mk @@ -6,6 +6,7 @@ COMMON_SRCS = \ src/logic/amgc_init_unit_meta.c \ src/logic/amgc_map_input.c \ src/logic/amgc_unit_entities.c \ + src/output/amgc_output_pad_symbol.c \ src/skin/amgc_skin_default.c \ APP_SRCS = \ diff --git a/src/output/amgc_output_pad_symbol.c b/src/output/amgc_output_pad_symbol.c new file mode 100644 index 0000000..ea10204 --- /dev/null +++ b/src/output/amgc_output_pad_symbol.c @@ -0,0 +1,35 @@ +/**********************************************************/ +/* 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> + +int amgc_output_pad_symbol( + const char * symbol, + const struct amgc_layout * layout, + FILE * fout) +{ + int len = (int)(strlen(symbol)); + + if (layout->symwidth < 1) + return -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; +} |