X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=format.h;h=b5ca1af78b6ae8b37fcc330446daf45f0b1b9f3b;hp=4929bff1c29246389addba390a9ccb9d75e3d73d;hb=ca20c17a6742464bcf861fe856a4caddf2bfeab2;hpb=4c71ff7f9b6afe7c15331a1cc9e134c2db65cd73 diff --git a/format.h b/format.h index 4929bff..b5ca1af 100644 --- a/format.h +++ b/format.h @@ -1,20 +1,74 @@ -/* format.h */ -enum atom_type {AT_STRING, AT_ID, AT_COUNT, AT_SIZE}; /* - * STRING: %(foo:a:w) - * (U)INT: %(foo:a:w:u) + * Copyright (C) 2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file format.h \brief Exported symbols from \p format.c. */ + +/** The possible types of format string directives (aka atoms). */ +enum atom_type { + /** String, supports alignment and width. */ + AT_STRING, + /** Used for user IDs, supports alignment and width. */ + AT_ID, + /** + * Used for number of files/directories, supports alignment, + * width, unit. + */ + AT_COUNT, + /** + * Used for number of bytes. Like \p AT_COUNT, but the unit is + * treated differently: By default, 1024 is used as the base, + * and low numbers get a "b" (bytes) appended which does not make + * sense for counters. + */ + AT_SIZE +}; + +/** + * One format string directive. + * + * Each application must define its own set of valid atoms as an array + * of struct atom. The \ref parse_format_string() function takes a format + * string and the array of valid atoms and returns an opaque pointer to + * a struct \a format_info. + * + * At a later time the application may pass the \a format_info pointer + * together with the current value for each atom to \a format_items() which + * returns these values, formated according to the format string which has + * been passed to parse_format_string() previously. + * + * Usually, the application will call parse_format_string() only once, but + * format_items() many times. */ struct atom { + /** The name of the directive. */ const char const *name; + /** Its type. */ enum atom_type type; }; +/** + * The current value of one atom. + * + * An array of this type, whose entries must match the array of valid atoms, + * may be passed to format_items() to obtain a formated string. + */ union atom_value { + /** Used for atoms of type string. */ char *string_value; + /** Used for atoms not of type string. */ long long unsigned num_value; }; -struct format_info; /* opaque */ -struct format_info *parse_format_string(char *fmt, struct atom *atoms); +/** + * The details of this structure are only relevant to the functions in \p + * format.c. + */ +struct format_info; + +int parse_format_string(char *fmt, struct atom *atoms, + struct format_info **result); char *format_items(struct format_info *info, union atom_value *values); void free_format_info(struct format_info *info);