Assorted typo fixes in comments.
[adu.git] / adu.h
diff --git a/adu.h b/adu.h
index 775af7faef3c85bfc3890e87426b044f161a552b..adba2c6ac5264452fa532d39604e3458f47b3341 100644 (file)
--- a/adu.h
+++ b/adu.h
@@ -1,14 +1,14 @@
 /*
- * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file para.h global paraslash definitions */
+/** \file adu.h \brief Global definitions. */
 
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <sys/wait.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h> /* time(), localtime() */
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <ctype.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <sys/un.h> /* needed by create_pf_socket */
+#include <inttypes.h>
 #include <string.h>
 #include <assert.h>
 #include <osl.h>
 #include "gcc-compat.h"
-
-/** compute the minimum of \a a and \a b */
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-/** compute the maximum of \a a and \a b */
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-/** compute the absolute value of \a a */
-#define ABS(a) ((a) > 0 ? (a) : -(a))
+#include "portable_io.h"
 
 /** debug loglevel, gets really noisy */
 #define DEBUG 1
 #define EMERG_LOG(...)
 #endif
 /** \endcond */
-__printf_2_3 void __log(int, const char*, ...);
+
+/** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
+#define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
+
+/** The columns of the directory table. */
+enum dir_table_columns {
+       /** The name of the directory. */
+       DT_NAME,
+       /** The dir count number. */
+       DT_NUM,
+       /** The number of the parent directory. */
+       DT_PARENT_NUM,
+       /** The number of bytes of all regular files. */
+       DT_BYTES,
+       /** The number of all regular files. */
+       DT_FILES,
+       /** Number of columns in this table. */
+       NUM_DT_COLUMNS
+};
+
+extern struct osl_table *dir_table;
+
+/** The adu command line options. */
+extern struct gengetopt_args_info conf;
+
+/** Computed database dir. */
+extern char *database_dir;
+
+/**
+ * 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;
+
+/**
+ * Compare two osl objects pointing to unsigned integers of 64 bit size.
+ *
+ * \param obj1 Pointer to the first integer.
+ * \param obj2 Pointer to the second integer.
+ *
+ * \return The values required for an osl compare function.
+ *
+ * \sa osl_compare_func, osl_hash_compare().
+ */
+_static_inline_ int uint64_compare(const struct osl_object *obj1,
+               const struct osl_object *obj2)
+{
+       uint64_t d1 = read_u64((const char *)obj1->data);
+       uint64_t d2 = read_u64((const char *)obj2->data);
+
+       if (d1 < d2)
+               return 1;
+       if (d1 > d2)
+               return -1;
+       return 0;
+}
 
 /**
- * Write a log message to a dynamically allocated string.
+ * Compare the size of two directories
  *
- * \param fmt Usual format string.
- * \param p Result pointer.
+ * \param obj1 Pointer to the first object.
+ * \param obj2 Pointer to the second object.
  *
- * \sa printf(3). */
-#define VSPRINTF(fmt, p) \
-{ \
-       int n; \
-       size_t size = 100; \
-       p = adu_malloc(size); \
-       while (1) { \
-               va_list ap; \
-               /* Try to print in the allocated space. */ \
-               va_start(ap, fmt); \
-               n = vsnprintf(p, size, fmt, ap); \
-               va_end(ap); \
-               /* If that worked, return the string. */ \
-               if (n > -1 && n < size) \
-                       break; \
-               /* Else try again with more space. */ \
-               if (n > -1) /* glibc 2.1 */ \
-                       size = n + 1; /* precisely what is needed */ \
-               else /* glibc 2.0 */ \
-                       size *= 2; /* twice the old size */ \
-               p = adu_realloc(p, size); \
-       } \
+ * This function first compares the size values as usual integers. If they compare as
+ * equal, the address of \a obj1 and \a obj2 are compared. So this compare function
+ * returns zero if and only if \a obj1 and \a obj2 point to the same memory area.
+ */
+_static_inline_ int size_compare(const struct osl_object *obj1, const struct osl_object *obj2)
+{
+       uint64_t d1 = *(uint64_t *)obj1->data;
+       uint64_t d2 = *(uint64_t *)obj2->data;
+       int ret = NUM_COMPARE(d2, d1);
+
+       if (ret)
+               return ret;
+       //INFO_LOG("addresses: %p, %p\n", obj1->data, obj2->data);
+       return NUM_COMPARE(obj2->data, obj1->data);
 }
+
+/* adu.c */
+__printf_2_3 void __log(int, const char*, ...);
+int open_dir_table(int create);
+void check_signals(void);
+/* create.c */
+int com_create(void);
+
+/* interactive.c */
+void print_interactive_help(void);
+int com_interactive(void);