+/** \file adu.c The main functions used by all modes of operation. */
#include "adu.h"
#include <dirent.h> /* readdir() */
#include <pwd.h>
* The log function.
*
* \param ll Loglevel.
- * \param fml Usual format string.
+ * \param fmt Usual format string.
*
* All XXX_LOG() macros use this function.
*/
NUM_UT_COLUMNS
};
+/** Flags for the user hash table. */
enum uid_info_flags {
/** Whether this slot of the hash table is used. */
UI_FL_SLOT_USED = 1,
UI_FL_ADMISSIBLE = 2,
};
+/** Information about one admissible user. */
struct user_info {
+ /** User ID. */
uint32_t uid;
+ /** \sa enum uid_info_flags. */
uint32_t flags;
+ /** The user name. */
char *pw_name;
+ /** The user table of this user.*/
struct osl_table *table;
+ /** Total number of files owned by this user. */
uint64_t files;
+ /** Total number of bytes owned by this user. */
uint64_t bytes;
+ /** Total number of directories that contain at least one file */
uint64_t dirs;
+ /** The description of the user table. */
struct osl_table_description *desc;
};
+/**
+ * Describes one range of admissible user IDs.
+ *
+ * adu converts the admissible user ids given at the command line
+ * into an array of such structs.
+ */
struct uid_range {
+ /** Lowest admissible user ID. */
uint32_t low;
+ /** Greatest admissible user ID. */
uint32_t high;
};
extern uint32_t num_uids;
extern struct osl_table *dir_table;
+
+/** The adu command line options. */
extern struct gengetopt_args_info conf;
+
+/**
+ * The select command line options.
+ *
+ * Either given at the command line, or via the \a set command
+ * in interactive mode.
+ */
extern struct select_args_info select_conf;
/* adu.c */
#include "string.h"
#include "error.h"
#include "format.h"
+
enum alignment {ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER};
struct num_format {
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;
}
/**
- * 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)
{
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;
-/* 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);
#include "error.h"
#include "cmdline.h"
+/**
+ * Describes one valid command for interactive mode.
+ *
+ * When invoked in interactive mode, adu reads commands from stdin. There's a
+ * static array of all such commands.
+ */
struct interactive_command {
+ /** The name of the command. */
const char *name;
+ /** Pointer to The function that is being executed. */
int (*handler)(char *);
+ /** Help text. */
const char *desc;
};
* Convert a string to a 64-bit signed integer value.
*
* \param str The string to be converted.
- * \param value Result pointer.
+ * \param result Result pointer.
*
* \return Standard.
*