summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-10-07 13:59:42 +1030
committerRusty Russell <rusty@rustcorp.com.au>2010-10-07 13:59:42 +1030
commit1fe7f55b1efc5deefb20815a03b56c8ef0f6dc53 (patch)
treeea6f2a3efd455cd045310888348078c696329369
parentab4a6fd9a3b417456ccd8f1fb976783683ccaa26 (diff)
compiler, list, noerr, sparse_bsearch, str, str_talloc, stringmap, talloc_link, tdb, tdb2, typesafe_cb: fix examples
Phew, now they call compile!
-rw-r--r--ccan/compiler/compiler.h2
-rw-r--r--ccan/list/list.h54
-rw-r--r--ccan/noerr/_info2
-rw-r--r--ccan/sparse_bsearch/_info2
-rw-r--r--ccan/sparse_bsearch/sparse_bsearch.h2
-rw-r--r--ccan/str/str.h10
-rw-r--r--ccan/str_talloc/str_talloc.h8
-rw-r--r--ccan/stringmap/_info32
-rw-r--r--ccan/talloc_link/_info6
-rw-r--r--ccan/tdb/_info12
-rw-r--r--ccan/tdb2/_info15
-rw-r--r--ccan/typesafe_cb/_info2
12 files changed, 75 insertions, 72 deletions
diff --git a/ccan/compiler/compiler.h b/ccan/compiler/compiler.h
index 7adcc8ca..49088ac7 100644
--- a/ccan/compiler/compiler.h
+++ b/ccan/compiler/compiler.h
@@ -146,7 +146,7 @@
*
* Example:
* // buf param may be freed by this; need return value!
- * static char *WARN_UNUSED_RESULT enlarge(const char *buf, unsigned *size)
+ * static char *WARN_UNUSED_RESULT enlarge(char *buf, unsigned *size)
* {
* return realloc(buf, (*size) *= 2);
* }
diff --git a/ccan/list/list.h b/ccan/list/list.h
index d47e1325..9cb41abd 100644
--- a/ccan/list/list.h
+++ b/ccan/list/list.h
@@ -56,7 +56,7 @@ struct list_head
* {
* struct child *c;
*
- * printf("%s (%u children):\n", p->name, parent->num_children);
+ * printf("%s (%u children):\n", p->name, p->num_children);
* list_check(&p->children, "bad child list");
* list_for_each(&p->children, c, list)
* printf(" -> %s\n", c->name);
@@ -71,10 +71,26 @@ struct list_head *list_check(const struct list_head *h, const char *abortstr);
#endif
/**
+ * LIST_HEAD - define and initalize an empty list_head
+ * @name: the name of the list.
+ *
+ * The LIST_HEAD macro defines a list_head and initializes it to an empty
+ * list. It can be prepended by "static" to define a static list_head.
+ *
+ * Example:
+ * static LIST_HEAD(my_global_list);
+ */
+#define LIST_HEAD(name) \
+ struct list_head name = { { &name.n, &name.n } }
+
+/**
* list_head_init - initialize a list_head
* @h: the list_head to set to the empty list
*
* Example:
+ * ...
+ * struct parent *parent = malloc(sizeof(*parent));
+ *
* list_head_init(&parent->children);
* parent->num_children = 0;
*/
@@ -84,29 +100,14 @@ static inline void list_head_init(struct list_head *h)
}
/**
- * LIST_HEAD - define and initalized empty list_head
- * @name: the name of the list.
- *
- * The LIST_HEAD macro defines a list_head and initializes it to an empty
- * list. It can be prepended by "static" to define a static list_head.
- *
- * Example:
- * // Header:
- * extern struct list_head my_list;
- *
- * // C file:
- * LIST_HEAD(my_list);
- */
-#define LIST_HEAD(name) \
- struct list_head name = { { &name.n, &name.n } }
-
-/**
* list_add - add an entry at the start of a linked list.
* @h: the list_head to add the node to
* @n: the list_node to add to the list.
*
* The list_node does not need to be initialized; it will be overwritten.
* Example:
+ * struct child *child;
+ *
* list_add(&parent->children, &child->list);
* parent->num_children++;
*/
@@ -179,9 +180,11 @@ static inline bool list_empty(const struct list_head *h)
* @member: the list_node member of the type
*
* Example:
- * struct child *c;
* // First list entry is children.next; convert back to child.
- * c = list_entry(parent->children.next, struct child, list);
+ * child = list_entry(parent->children.n.next, struct child, list);
+ *
+ * See Also:
+ * list_top(), list_for_each()
*/
#define list_entry(n, type, member) container_of(n, type, member)
@@ -225,9 +228,8 @@ static inline bool list_empty(const struct list_head *h)
* a for loop, so you can break and continue as normal.
*
* Example:
- * struct child *c;
- * list_for_each(&parent->children, c, list)
- * printf("Name: %s\n", c->name);
+ * list_for_each(&parent->children, child, list)
+ * printf("Name: %s\n", child->name);
*/
#define list_for_each(h, i, member) \
for (i = container_of_var(debug_list(h)->n.next, i, member); \
@@ -246,9 +248,9 @@ static inline bool list_empty(const struct list_head *h)
* @nxt is used to hold the next element, so you can delete @i from the list.
*
* Example:
- * struct child *c, *n;
- * list_for_each_safe(&parent->children, c, n, list) {
- * list_del(&c->list);
+ * struct child *next;
+ * list_for_each_safe(&parent->children, child, next, list) {
+ * list_del(&child->list);
* parent->num_children--;
* }
*/
diff --git a/ccan/noerr/_info b/ccan/noerr/_info
index 9f852957..c5d8768f 100644
--- a/ccan/noerr/_info
+++ b/ccan/noerr/_info
@@ -19,7 +19,7 @@
* #include <errno.h>
* #include <ccan/noerr/noerr.h>
*
- * bool write_string_to_file(const char *file, const char *string)
+ * static bool write_string_to_file(const char *file, const char *string)
* {
* int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
* if (fd < 0)
diff --git a/ccan/sparse_bsearch/_info b/ccan/sparse_bsearch/_info
index 7d7164f0..b0bcb2f0 100644
--- a/ccan/sparse_bsearch/_info
+++ b/ccan/sparse_bsearch/_info
@@ -26,7 +26,7 @@
* static unsigned int values[] = { 1, 7, 11, 1235, 99999 };
*
* // Return true if this value is in set, and remove it.
- * bool remove_from_values(unsigned int val)
+ * static bool remove_from_values(unsigned int val)
* {
* unsigned int *p;
* // We use 5 here, but ccan/array_size.h is better!
diff --git a/ccan/sparse_bsearch/sparse_bsearch.h b/ccan/sparse_bsearch/sparse_bsearch.h
index 5317dbf8..731f9a4f 100644
--- a/ccan/sparse_bsearch/sparse_bsearch.h
+++ b/ccan/sparse_bsearch/sparse_bsearch.h
@@ -27,7 +27,7 @@
* static unsigned int values[] = { 1, 7, 11, 1235, 99999 };
*
* // Return true if this value is in set, and remove it.
- * bool remove_from_values(unsigned int val)
+ * static bool remove_from_values(unsigned int val)
* {
* unsigned int *p;
* p = sparse_bsearch(&val, values, 5, val_cmp, val_valid);
diff --git a/ccan/str/str.h b/ccan/str/str.h
index 70fe26c7..8cfd7f29 100644
--- a/ccan/str/str.h
+++ b/ccan/str/str.h
@@ -11,7 +11,7 @@
* This macro is arguably more readable than "!strcmp(a, b)".
*
* Example:
- * if (streq(str, ""))
+ * if (streq(somestring, ""))
* printf("String is empty!\n");
*/
#define streq(a,b) (strcmp((a),(b)) == 0)
@@ -22,8 +22,8 @@
* @prefix: prefix to look for at start of str
*
* Example:
- * if (strstarts(str, "foo"))
- * printf("String %s begins with 'foo'!\n", str);
+ * if (strstarts(somestring, "foo"))
+ * printf("String %s begins with 'foo'!\n", somestring);
*/
#define strstarts(str,prefix) (strncmp((str),(prefix),strlen(prefix)) == 0)
@@ -33,8 +33,8 @@
* @postfix: postfix to look for at end of str
*
* Example:
- * if (strends(str, "foo"))
- * printf("String %s end with 'foo'!\n", str);
+ * if (strends(somestring, "foo"))
+ * printf("String %s end with 'foo'!\n", somestring);
*/
static inline bool strends(const char *str, const char *postfix)
{
diff --git a/ccan/str_talloc/str_talloc.h b/ccan/str_talloc/str_talloc.h
index 9828cd85..50cea2dc 100644
--- a/ccan/str_talloc/str_talloc.h
+++ b/ccan/str_talloc/str_talloc.h
@@ -20,7 +20,10 @@
* @nump to find the array length.
*
* Example:
- * unsigned int count_long_lines(const char *text)
+ * #include <ccan/talloc/talloc.h>
+ * #include <ccan/str_talloc/str_talloc.h>
+ * ...
+ * static unsigned int count_long_lines(const char *string)
* {
* char **lines;
* unsigned int i, long_lines = 0;
@@ -49,10 +52,9 @@ char **strsplit(const void *ctx, const char *string, const char *delims,
*
* Example:
* // Append the string "--EOL" to each line.
- * char *append_to_all_lines(const char *string)
+ * static char *append_to_all_lines(const char *string)
* {
* char **lines, *ret;
- * unsigned int i, num, newnum;
*
* lines = strsplit(NULL, string, "\n", NULL);
* ret = strjoin(NULL, lines, "-- EOL\n");
diff --git a/ccan/stringmap/_info b/ccan/stringmap/_info
index 5ad40cac..b5e78755 100644
--- a/ccan/stringmap/_info
+++ b/ccan/stringmap/_info
@@ -12,22 +12,22 @@
*
* Example:
*
- * #include <ccan/stringmap/stringmap.h>
+ * #include <ccan/stringmap/stringmap.h>
*
- * static const char *get_string(void) {
- * static char buffer[4096];
- * char *tail;
- * if (!fgets(buffer, sizeof(buffer), stdin))
- * return NULL;
- * tail = strchr(buffer, 0);
- * if (tail>buffer && tail[-1]=='\n')
- * *--tail = 0;
- * if (!*buffer)
- * return NULL;
- * return buffer;
- * }
+ * static const char *get_string(void) {
+ * static char buffer[4096];
+ * char *tail;
+ * if (!fgets(buffer, sizeof(buffer), stdin))
+ * return NULL;
+ * tail = strchr(buffer, 0);
+ * if (tail>buffer && tail[-1]=='\n')
+ * *--tail = 0;
+ * if (!*buffer)
+ * return NULL;
+ * return buffer;
+ * }
*
- * int main(void) {
+ * int main(void) {
* stringmap(int) map = stringmap_new(NULL);
* const char *string;
*
@@ -49,8 +49,8 @@
* return 0;
* }
*
- * Authors: Joey Adams, Anders Magnusson
- * License: BSD
+ * Authors: Joey Adams, Anders Magnusson
+ * License: BSD
*/
int main(int argc, char *argv[])
{
diff --git a/ccan/talloc_link/_info b/ccan/talloc_link/_info
index 8758e073..dd25c201 100644
--- a/ccan/talloc_link/_info
+++ b/ccan/talloc_link/_info
@@ -29,7 +29,7 @@
* static struct upcache *cache;
* static unsigned int cache_hits = 0;
* #define CACHE_SIZE 4
- * void init_upcase(void)
+ * static void init_upcase(void)
* {
* cache = talloc_zero_array(NULL, struct upcache, CACHE_SIZE);
* }
@@ -70,7 +70,7 @@
* }
*
* // If you want to keep the result, talloc_link it.
- * const char *get_upcase(const char *str)
+ * static const char *get_upcase(const char *str)
* {
* struct upcache *uc = lookup_upcase(str);
* if (!uc)
@@ -80,7 +80,7 @@
* return uc->upstr;
* }
*
- * void exit_upcase(void)
+ * static void exit_upcase(void)
* {
* talloc_free(cache);
* printf("Cache hits: %u\n", cache_hits);
diff --git a/ccan/tdb/_info b/ccan/tdb/_info
index 8c1e5dc4..10d02b96 100644
--- a/ccan/tdb/_info
+++ b/ccan/tdb/_info
@@ -14,10 +14,10 @@
* #include <err.h>
* #include <stdio.h>
*
- * static void usage(void)
+ * static void usage(const char *argv0)
* {
* errx(1, "Usage: %s fetch <dbfile> <key>\n"
- * "OR %s store <dbfile> <key> <data>");
+ * "OR %s store <dbfile> <key> <data>", argv0, argv0);
* }
*
* int main(int argc, char *argv[])
@@ -26,7 +26,7 @@
* TDB_DATA key, value;
*
* if (argc < 4)
- * usage();
+ * usage(argv[0]);
*
* tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
* 0600);
@@ -38,7 +38,7 @@
*
* if (streq(argv[1], "fetch")) {
* if (argc != 4)
- * usage();
+ * usage(argv[0]);
* value = tdb_fetch(tdb, key);
* if (!value.dptr)
* errx(1, "fetch %s: %s",
@@ -47,14 +47,14 @@
* free(value.dptr);
* } else if (streq(argv[1], "store")) {
* if (argc != 5)
- * usage();
+ * usage(argv[0]);
* value.dptr = (void *)argv[4];
* value.dsize = strlen(argv[4]);
* if (tdb_store(tdb, key, value, 0) != 0)
* errx(1, "store %s: %s",
* argv[3], tdb_errorstr(tdb));
* } else
- * usage();
+ * usage(argv[0]);
*
* return 0;
* }
diff --git a/ccan/tdb2/_info b/ccan/tdb2/_info
index 66d3cb8b..35e32b72 100644
--- a/ccan/tdb2/_info
+++ b/ccan/tdb2/_info
@@ -14,10 +14,10 @@
* #include <err.h>
* #include <stdio.h>
*
- * static void usage(void)
+ * static void usage(const char *argv0)
* {
* errx(1, "Usage: %s fetch <dbfile> <key>\n"
- * "OR %s store <dbfile> <key> <data>");
+ * "OR %s store <dbfile> <key> <data>", argv0, argv0);
* }
*
* int main(int argc, char *argv[])
@@ -26,10 +26,9 @@
* TDB_DATA key, value;
*
* if (argc < 4)
- * usage();
+ * usage(argv[0]);
*
- * tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
- * 0600);
+ * tdb = tdb_open(argv[2], TDB_DEFAULT, O_CREAT|O_RDWR,0600, NULL);
* if (!tdb)
* err(1, "Opening %s", argv[2]);
*
@@ -38,7 +37,7 @@
*
* if (streq(argv[1], "fetch")) {
* if (argc != 4)
- * usage();
+ * usage(argv[0]);
* value = tdb_fetch(tdb, key);
* if (!value.dptr)
* errx(1, "fetch %s: %s",
@@ -47,14 +46,14 @@
* free(value.dptr);
* } else if (streq(argv[1], "store")) {
* if (argc != 5)
- * usage();
+ * usage(argv[0]);
* value.dptr = (void *)argv[4];
* value.dsize = strlen(argv[4]);
* if (tdb_store(tdb, key, value, 0) != 0)
* errx(1, "store %s: %s",
* argv[3], tdb_errorstr(tdb));
* } else
- * usage();
+ * usage(argv[0]);
*
* return 0;
* }
diff --git a/ccan/typesafe_cb/_info b/ccan/typesafe_cb/_info
index 2d8f6848..fea27116 100644
--- a/ccan/typesafe_cb/_info
+++ b/ccan/typesafe_cb/_info
@@ -87,7 +87,7 @@
*
* // Define several silly callbacks. Note they don't use void *!
* #define DEF_CALLBACK(name, op) \
- * static int name(int val, const int *arg)\
+ * static int name(int val, int *arg) \
* { \
* printf("%s", #op); \
* return val op *arg; \