Add more source code documentation.
[adu.git] / format.h
index 2b8b7f20e5999c8b27a44a2c9c8c4640ca3ae81b..4446f49c7c7908477dfd6fb546291e0102eadaaf 100644 (file)
--- a/format.h
+++ b/format.h
@@ -1,20 +1,68 @@
-/* format.h */
-enum atom_type {AT_STRING, AT_ID, AT_COUNT, AT_SIZE};
-/*
- * STRING: %(foo:a:w)
- * (U)INT: %(foo:a:w:u)
+/** \file format.h 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 */
-int parse_format_string(char *fmt, struct atom *atoms, struct format_info **result);
+/**
+ * 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);