X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=format.c;h=8b96830291dd044399bbd7ebdcecb471674a62eb;hp=bcdbff9ff425df1783975cf8ac62a64ab28fa40e;hb=560d397a66ba141f18e13557feae78ca94a25f98;hpb=6dc3d02ae5959a4ec5f3de4765d7440a580ff3e1 diff --git a/format.c b/format.c index bcdbff9..8b96830 100644 --- a/format.c +++ b/format.c @@ -1,10 +1,10 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file format.c Functions for pretty-printing numbers and strings. */ +/** \file format.c \brief Functions for pretty-printing numbers and strings. */ #include /* readdir() */ #include "adu.h" @@ -13,6 +13,8 @@ #include "string.h" #include "error.h" #include "format.h" + +/** The three different alignment types. */ enum alignment {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER}; struct num_format { @@ -217,6 +219,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; @@ -264,7 +275,12 @@ err: } /** - * 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) { @@ -397,6 +413,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; @@ -425,14 +449,14 @@ char *format_items(struct format_info *info, union atom_value *values) align = af->sf.align; val = align_string(values[idx].string_value, fi->width, align); } else { - char unit; align = af->nf.align; - unit = af->nf.unit; val = align_unsigned_int(values[idx].num_value, fi->width, &af->nf, type); } buf = adu_strcat(buf, val); free(val); } + if (!buf) + buf = adu_strdup(""); return buf; }