#define SILC_PARAM_ALLOC 0x00010000 /* Allocate, bitmask */
#define SILC_PARAM_REPLACE 0x00020000 /* Replace, bitmask */
+/****d* silcutil/SilcCompareValue
+ *
+ * NAME
+ *
+ * typedef enum { ... } SilcCompareValue
+ *
+ * DESCRIPTION
+ *
+ * Values that can be returned by the SilcCompare function. Note that
+ * not all routines may respect all of the return values.
+ *
+ * SOURCE
+ */
+typedef enum {
+ SILC_COMPARE_LESS_THAN_EQUAL_TO = -2, /* Value 1 <= value 2 */
+ SILC_COMPARE_LESS_THAN = -1, /* Value 1 < value 2 */
+ SILC_COMPARE_EQUAL_TO = 0, /* Value 1 == value 2 */
+ SILC_COMPARE_GREATER_THAN = 1, /* Value 1 > value 2 */
+ SILC_COMPARE_GREATER_THAN_EQUAL_TO = 2, /* Value 1 >= value 2 */
+ SILC_COMPARE_STOP = 3, /* Stop comparison */
+} SilcCompareValue;
+/***/
+
+/****f* silcutil/SilcCompare
+ *
+ * SYNOPSIS
+ *
+ * typedef SilcCompareValue (*SilcCompare)(void *value1, void *value2,
+ * void *context);
+ *
+ * DESCRIPTION
+ *
+ * A comparison function used by many routines in SILC Runtime Toolkit.
+ *
+ ***/
+typedef SilcCompareValue (*SilcCompare)(void *value1, void *value2,
+ void *context);
+
/* Macros */
#if (defined(SILC_I486) || defined(SILC_X86_64)) && defined(__GNUC__)
struct foo *prev;
};
-static int compare(void *e1, void *e2, void *context)
+static SilcCompareValue compare(void *e1, void *e2, void *context)
{
struct foo *ee1 = e1, *ee2 = e2;
SILC_LOG_DEBUG(("entry %d, %p, next=%p, prev=%p", ee1->i, ee1, ee1->next,
ee1->prev));
SILC_LOG_DEBUG(("> entry %d, %p, next=%p, prev=%p", ee2->i, ee2, ee2->next,
ee2->prev));
- return ee1->i - ee2->i;
+ if (ee1->i > ee2->i)
+ return SILC_COMPARE_GREATER_THAN;
+ if (ee1->i < ee2->i)
+ return SILC_COMPARE_LESS_THAN;
+ return SILC_COMPARE_EQUAL_TO;
}
int main(int argc, char **argv)
SILC_LOG_DEBUG(("entry %d, %p, next=%p, prev=%p", f->i, f, f->next,
f->prev));
- SILC_LOG_DEBUG(("Sorting"));
+ SILC_LOG_DEBUG(("Sorting"));
silc_list_sort(list, compare, NULL);
SILC_LOG_DEBUG(("Sorted list"));