X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=format.c;h=02edf37aaf15f27154fd1cefbb7c02515f7b3ba2;hp=a3a01ba1ca18b230298f5b349cf8f1737a0d49f6;hb=4603262b4cdb8244379f532782b1579fe5520f5f;hpb=a6c1851843a79d048fb43ec435107a795b8e986e diff --git a/format.c b/format.c index a3a01ba..02edf37 100644 --- a/format.c +++ b/format.c @@ -13,6 +13,7 @@ #include "string.h" #include "error.h" #include "format.h" + enum alignment {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER}; struct num_format { @@ -217,6 +218,15 @@ success: return 1; } +/** + * Parse the given string according to the list of given atoms. + * + * \param fmt The format string. + * \param atoms The array of valid atoms. + * \param result Points to a format_info structure for later use. + * + * \return Standard. + */ int parse_format_string(char *fmt, struct atom *atoms, struct format_info **result) { char *cp, *ap, *ep; @@ -259,11 +269,17 @@ err: } free(info->items); free(info); + *result = NULL; return ret; } /** - * It's OK to pass a \p NULL pointer to this function. + * Free a struct of type \a format_info. + * + * \param info Pointer to the format info to be freed. + * + * It's OK to pass a \p NULL pointer to this function in which case the + * function does nothing. */ void free_format_info(struct format_info *info) { @@ -396,6 +412,14 @@ static char *align_unsigned_int(long long unsigned num, unsigned int width, nnum, postfix, width - (width + len) / 2, ""); } +/** + * Pretty-format the given values according to \a info. + * + * \param info The formating information. + * \param values The contents of the atoms. + * + * \return A string that must be freed by the caller. + */ char *format_items(struct format_info *info, union atom_value *values) { int i; @@ -433,5 +457,7 @@ char *format_items(struct format_info *info, union atom_value *values) buf = adu_strcat(buf, val); free(val); } + if (!buf) + buf = adu_strdup(""); return buf; }