]> git.ozlabs.org Git - ccan/blobdiff - ccan/htable/_info
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / htable / _info
index 8dabe46a50ed6aab36f3b59538934e0724fb8bca..ea11beb44003520ff137b27afc8fdae85551cae9 100644 (file)
@@ -1,3 +1,4 @@
+#include "config.h"
 #include <string.h>
 #include <stdio.h>
 
  *     // Wrapper for rehash function pointer.
  *     static size_t rehash(const void *e, void *unused)
  *     {
+ *             (void)unused;
  *             return hash_string(((struct name_to_digit *)e)->name);
  *     }
  *
  *     // Comparison function.
- *     static bool streq(const void *e, void *string)
+ *     static bool nameeq(const void *e, void *string)
  *     {
  *             return strcmp(((struct name_to_digit *)e)->name, string) == 0;
  *     }
  *     // We let them add their own aliases, eg. --alias=v=5
  *     static void add_alias(struct htable *ht, const char *alias)
  *     {
- *             char *eq;
+ *             char *eq, *name;
  *             struct name_to_digit *n;
  *
  *             n = malloc(sizeof(*n));
- *             n->name = strdup(alias);
+ *             n->name = name = strdup(alias);
  *
- *             eq = strchr(n->name, '=');
+ *             eq = strchr(name, '=');
  *             if (!eq || ((n->val = atoi(eq+1)) == 0 && !strcmp(eq+1, "0")))
  *                     errx(1, "Usage: --alias=<name>=<value>");
  *             *eq = '\0';
@@ -62,8 +64,8 @@
  *
  *     int main(int argc, char *argv[])
  *     {
- *             struct htable *ht;
- *             unsigned int i;
+ *             struct htable ht;
+ *             int i;
  *             unsigned long val;
  *
  *             if (argc < 2)
  *                          argv[0]);
  *
  *             // Create and populate hash table.
- *             ht = htable_new(rehash, NULL);
- *             for (i = 0; i < sizeof(map)/sizeof(map[0]); i++)
- *                     htable_add(ht, hash_string(map[i].name), &map[i]);
+ *             htable_init(&ht, rehash, NULL);
+ *             for (i = 0; i < (int)(sizeof(map)/sizeof(map[0])); i++)
+ *                     htable_add(&ht, hash_string(map[i].name), &map[i]);
  *
  *             // Add any aliases to the hash table.
  *             for (i = 1; i < argc; i++) {
  *                     if (!strncmp(argv[i], "--alias=", strlen("--alias=")))
- *                             add_alias(ht, argv[i] + strlen("--alias="));
+ *                             add_alias(&ht, argv[i] + strlen("--alias="));
  *                     else
  *                             break;
  *             }
@@ -86,8 +88,8 @@
  *             // Find the other args in the hash table.
  *             for (val = 0; i < argc; i++) {
  *                     struct name_to_digit *n;
- *                     n = htable_get(ht, hash_string(argv[i]),
- *                                    streq, argv[i]);
+ *                     n = htable_get(&ht, hash_string(argv[i]),
+ *                                    nameeq, argv[i]);
  *                     if (!n)
  *                             errx(1, "Invalid digit name %s", argv[i]);
  *                     // Append it to the value we are building up.
  *             return 0;
  *     }
  *
- * License: GPLv2 (or later)
+ * License: LGPL (v2.1 or any later version)
  * Author: Rusty Russell <rusty@rustcorp.com.au>
  */
 int main(int argc, char *argv[])
@@ -108,6 +110,7 @@ int main(int argc, char *argv[])
 
        if (strcmp(argv[1], "depends") == 0) {
                printf("ccan/compiler\n");
+               printf("ccan/str\n");
                return 0;
        }