Browse Source

modules: update documentation examples so they compile under ccanlint.

This is everything up to the list module... now it's time for sleep.
Rusty Russell 15 years ago
parent
commit
18636637ee

+ 1 - 1
ccan/array_size/_info

@@ -18,7 +18,7 @@
  *	// We currently use 32 random values.
  *	static unsigned int vals[32];
  *
- *	void init_values(void)
+ *	static void init_values(void)
  *	{
  *		unsigned int i;
  *		for (i = 0; i < ARRAY_SIZE(vals); i++)

+ 3 - 3
ccan/asort/_info

@@ -19,12 +19,12 @@
  *	#include <stdio.h>
  *	#include <string.h>
  *	
- *	static int cmp(const char **a, const char **n, bool *casefold)
+ *	static int cmp(char *const *a, char *const *n, bool *casefold)
  *	{
  *		if (*casefold)
- *			return strcasecmp(*a, *b);
+ *			return strcasecmp(*a, *n);
  *		else
- *			return strcmp(*a, *b);
+ *			return strcmp(*a, *n);
  *	}
  *	
  *	int main(int argc, char *argv[])

+ 5 - 2
ccan/block_pool/_info

@@ -29,12 +29,15 @@
  *      int array[] = {0,1,1,2,3,5,8,13,21,34};
  *      int *array_copy = block_pool_memdup(bp, array, sizeof(array));
  *
+ *	memset(buffer, 0xff, 4096);
+ *	printf("string = %s\n", string);
+ *	printf("array_copy[0] == %i\n", array_copy[0]);
  *      block_pool_free(bp);
  *    return 0;
  * }
  *
- *	Author: Joey Adams
- *	License: BSD
+ * Author: Joey Adams
+ * License: BSD
  */
 int main(int argc, char *argv[])
 {

+ 6 - 6
ccan/btree/_info

@@ -37,7 +37,7 @@
  * };
  * 
  * //Define the ordering function order_by_letter_set
- * btree_search_implement
+ * static btree_search_implement
  * (
  * 	order_by_letter_set,
  * 	struct word *,
@@ -50,7 +50,7 @@
  * char *chomp(char *str);
  * char *make_letter_set(char *str);
  * 
- * void insert_word(struct btree *btree, struct word *word)
+ * static void insert_word(struct btree *btree, struct word *word)
  * {
  * 	btree_iterator iter;
  * 	
@@ -61,7 +61,7 @@
  * 	btree_insert_at(iter, word);
  * }
  * 
- * void print_anagrams(struct btree *btree, char *line)
+ * static void print_anagrams(struct btree *btree, char *line)
  * {
  * 	btree_iterator iter, end;
  * 	struct word key = {
@@ -86,7 +86,7 @@
  * 	}
  * }
  * 
- * int destroy_word(struct word *word, void *ctx)
+ * static int destroy_word(struct word *word, void *ctx)
  * {
  * 	(void) ctx;
  * 	
@@ -97,7 +97,7 @@
  * 	return 1;
  * }
  * 
- * struct btree *read_dictionary(const char *filename)
+ * static struct btree *read_dictionary(const char *filename)
  * {
  * 	FILE *f;
  * 	char line[256];
@@ -129,7 +129,7 @@
  * 	
  * 	return btree;
  * 
- * fail:
+ *   fail:
  * 	btree_delete(btree);
  * 	fprintf(stderr, "%s: %s\n", filename, strerror(errno));
  * 	return NULL;

+ 1 - 1
ccan/build_assert/_info

@@ -26,7 +26,7 @@
  *		int x;
  *	};
  *
- *	char *foo_string(struct foo *foo)
+ *	static char *foo_string(struct foo *foo)
  *	{
  *		// This trick requires that the string be first in the structure
  *		BUILD_ASSERT(offsetof(struct foo, string) == 0);

+ 3 - 1
ccan/build_assert/build_assert.h

@@ -9,7 +9,9 @@
  * by the compiler.  This can only be used within a function.
  *
  * Example:
- *	char *foo_to_char(struct foo *foo)
+ *	#include <stddef.h>
+ *	...
+ *	static char *foo_to_char(struct foo *foo)
  *	{
  *		// This code needs string to be at start of foo.
  *		BUILD_ASSERT(offsetof(struct foo, string) == 0);

+ 1 - 1
ccan/ccan_tokenizer/_info

@@ -14,7 +14,7 @@
  * #include <ccan/grab_file/grab_file.h>
  * #include <err.h>
  *
- * void token_list_stats(const struct token_list *tl) {
+ * static void token_list_stats(const struct token_list *tl) {
  * 	size_t comment=0, white=0, stray=0, code=0, total=0;
  * 	size_t count = 0;
  * 	const struct token *i;

+ 1 - 1
ccan/charset/_info

@@ -32,7 +32,7 @@
  *		if (!file)
  *			err(1, "Could not read file %s", argv[1]);
  *
- *		valid = utf8_validate(file, len));
+ *		valid = utf8_validate(file, len);
  *		printf("File contents are %s UTF-8\n", valid ? "valid" : "invalid");
  *
  *		talloc_free(file);

+ 3 - 3
ccan/compiler/_info

@@ -6,7 +6,7 @@
  * compiler - macros for common compiler extensions
  *
  * Abstracts away some compiler hints.  Currently these include:
- * - UNLIKELY_FUNCTION_ATTRIBUTE
+ * - COLD_ATTRIBUTE
  *	For functions not called in fast paths (aka. cold functions)
  * - PRINTF_ATTRIBUTE
  *	For functions which take printf-style parameters.
@@ -23,13 +23,13 @@
  * Author: Rusty Russell <rusty@rustcorp.com.au>
  *
  * Example:
- *	#include <ccan/compiler/attributs.h>
+ *	#include <ccan/compiler/compiler.h>
  *	#include <stdio.h>
  *	#include <stdarg.h>
  *
  *	// Example of a (slow-path) logging function.
  *	static int log_threshold = 2;
- *	static void UNLIKELY_FUNCTION_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
+ *	static void COLD_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
  *		logger(int level, const char *fmt, ...)
  *	{
  *		va_list ap;

+ 17 - 20
ccan/compiler/compiler.h

@@ -10,10 +10,10 @@
  * It is usually used on logging or error routines.
  *
  * Example:
- *	void COLD_ATTRIBUTE moan(const char *reason)
- *	{
- *		fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
- *	}
+ * static void COLD_ATTRIBUTE moan(const char *reason)
+ * {
+ *	fprintf(stderr, "Error: %s (%s)\n", reason, strerror(errno));
+ * }
  */
 #define COLD_ATTRIBUTE __attribute__((cold))
 #else
@@ -23,13 +23,14 @@
 #if HAVE_ATTRIBUTE_PRINTF
 /**
  * PRINTF_ATTRIBUTE - a function takes printf-style arguments
- * nfmt: the 1-based number of the function's format argument.
- * narg: the 1-based number of the function's first variable argument.
+ * @nfmt: the 1-based number of the function's format argument.
+ * @narg: the 1-based number of the function's first variable argument.
  *
  * This allows the compiler to check your parameters as it does for printf().
  *
  * Example:
- *	void PRINTF_ATTRIBUTE(2,3) my_printf(char *prefix, char *format, ...);
+ * void PRINTF_ATTRIBUTE(2,3) my_printf(const char *prefix,
+ *					const char *fmt, ...);
  */
 #define PRINTF_ATTRIBUTE(nfmt, narg) \
 	__attribute__((format(__printf__, nfmt, narg)))
@@ -58,18 +59,14 @@
  * the compiler that if it is unused it need not emit it into the source code.
  *
  * Example:
- *	// With some config options, this is unnecessary.
- *	static UNNEEDED_ATTRIBUTE int counter;
- *	...
- *		#ifdef DEBUG
- *		counter++;
- *		#endif
- *	...
- *	// With some config options, this is unnecessary.
- *	static UNNEEDED_ATTRIBUTE int add_to_counter(int add)
- *	{
- *		counter += add;
- *	}
+ * // With some preprocessor options, this is unnecessary.
+ * static UNNEEDED_ATTRIBUTE int counter;
+ *
+ * // With some preprocessor options, this is unnecessary.
+ * static UNNEEDED_ATTRIBUTE void add_to_counter(int add)
+ * {
+ *	counter += add;
+ * }
  */
 #define UNNEEDED_ATTRIBUTE __attribute__((unused))
 
@@ -117,7 +114,7 @@
  *	const char *greek_name(enum greek greek);
  *
  *	// Inline version.
- *	static inline _greek_name(enum greek greek)
+ *	static inline char *_greek_name(enum greek greek)
  *	{
  *		switch (greek) {
  *		case ALPHA: return "alpha";

+ 6 - 1
ccan/container_of/_info

@@ -26,13 +26,18 @@
  *		struct timer timer;
  *	};
  *
+ *	static void register_timer(struct timer *timer)
+ *	{
+ *		//...
+ *	}
+ *
  *	static void my_timer_callback(struct timer *timer)
  *	{
  *		struct info *info = container_of(timer, struct info, timer);
  *		printf("my_stuff is %u\n", info->my_stuff);
  *	}
  *
- *	int main()
+ *	int main(void)
  *	{
  *		struct info info = { .my_stuff = 1 };
  *

+ 7 - 10
ccan/container_of/container_of.h

@@ -15,13 +15,16 @@
  * subtraction to return the pointer to the enclosing type.
  *
  * Example:
- *	struct info
- *	{
+ *	struct foo {
+ *		int fielda, fieldb;
+ *		// ...
+ *	};
+ *	struct info {
  *		int some_other_field;
  *		struct foo my_foo;
  *	};
  *
- *	struct info *foo_to_info(struct foo *foop)
+ *	static struct info *foo_to_info(struct foo *foo)
  *	{
  *		return container_of(foo, struct info, my_foo);
  *	}
@@ -42,13 +45,7 @@
  * subtraction to return the pointer to the enclosing type.
  *
  * Example:
- *	struct info
- *	{
- *		int some_other_field;
- *		struct foo my_foo;
- *	};
- *
- *	struct info *foo_to_info(struct foo *foop)
+ *	static struct info *foo_to_i(struct foo *foo)
  *	{
  *		struct info *i = container_of_var(foo, i, my_foo);
  *		return i;

+ 2 - 2
ccan/crc/_info

@@ -11,7 +11,7 @@
  * detect a single error burst of up to 32 bits.
  *
  * Example:
- *	#include <ccan/crc.h>
+ *	#include <ccan/crc/crc.h>
  *	#include <stdio.h>
  *	#include <stdlib.h>
  *
@@ -22,7 +22,7 @@
  *				"Prints 32 bit CRC of the string\n", argv[0]);
  *			exit(1);
  *		}
- *		printf("0x%08x\n", crc32c(argv[1], strlen(argv[1])));
+ *		printf("0x%08x\n", crc32c(0, argv[1], strlen(argv[1])));
  *		exit(0);
  *	}
  *

+ 5 - 3
ccan/crc/crc.h

@@ -29,11 +29,13 @@
  * as 0 the first time, and the current crc result from then on.
  *
  * Example:
+ *	#include <sys/uio.h>
+ *	...
  *	// Check that iovec has the crc we expect (Castagnoli version)
- *	bool check_crc(uint32_t expected, const struct iovec *iov, int iovcnt)
+ *	static bool check_crc(uint32_t expected, const struct iovec *iov, int l)
  *	{
  *		uint32_t crc = 0;
- *		while (iovcnt >= 0) {
+ *		while (l >= 0) {
  *			crc = crc32c(crc, iov->iov_base, iov->iov_len);
  *			iov++;
  *		}
@@ -52,7 +54,7 @@ uint32_t crc32c(uint32_t start_crc, const void *buf, size_t size);
  *
  * Example:
  *	// This dumb code only handles Castagnoli, so assert that here.
- *	void check_user_crc_table(const uint32_t *usertab)
+ *	static void check_user_crc_table(const uint32_t *usertab)
  *	{
  *		const uint32_t *ctab = crc32c_table();
  *		if (!ctab || memcmp(ctab, usertab, 1024) != 0)

+ 4 - 4
ccan/crcsync/_info

@@ -30,7 +30,7 @@
  *		size_t len, used, blocksize;
  *		char *file;
  *		struct crc_context *ctx;
- *		uint32_t *crcs;
+ *		uint64_t *crcs;
  *		long res, i;
  *	
  *		if (argc < 3 || (blocksize = atoi(argv[1])) == 0)
@@ -44,10 +44,10 @@
  *		if (argc == 3) {
  *			// Short form prints CRCs of file for use in long form.
  *			used = (len + blocksize - 1) / blocksize;
- *			crcs = malloc(used * sizeof(uint32_t));
+ *			crcs = malloc(used * sizeof(crcs[0]));
  *			crc_of_blocks(file, len, blocksize, 32, crcs);
  *			for (i = 0; i < used; i++)
- *				printf("%i ", crcs[i]);
+ *				printf("%llu ", (long long)crcs[i]);
  *			printf("\n");
  *			return 0;
  *		}
@@ -56,7 +56,7 @@
  *		for (i = 0; i < argc-3; i++)
  *			crcs[i] = atoi(argv[3+i]);
  *	
- *		ctx = crc_context_new(blocksize, 32, crcs, argc-3);
+ *		ctx = crc_context_new(blocksize, 32, crcs, argc-3, 0);
  *		for (used = 0; used < len; ) {
  *			used += crc_read_block(ctx, &res, file+used, len-used);
  *			print_result(res);

+ 1 - 0
ccan/endian/_info

@@ -29,6 +29,7 @@
  *		if (argc != 2)
  *			errx(1, "Usage: %s <value>", argv[0]);
  *
+ *		value = atoi(argv[1]);
  *		printf("native:        %08x\n", value);
  *		printf("little-endian: %08x\n", cpu_to_le32(value));
  *		printf("big-endian:    %08x\n", cpu_to_be32(value));

+ 5 - 2
ccan/grab_file/grab_file.h

@@ -14,8 +14,11 @@
  * byte after the end of the content will always be NUL.
  *
  * Example:
+ *	#include <ccan/str_talloc/str_talloc.h>
+ *	#include <ccan/talloc/talloc.h>
+ *	...
  *	// Return all of standard input, as lines.
- *	char **read_as_lines(void)
+ *	static char **read_stdin_as_lines(void)
  *	{
  *		char **lines, *all;
  *
@@ -42,7 +45,7 @@ void *grab_fd(const void *ctx, int fd, size_t *size);
  *
  * Example:
  *	// Return all of a given file, as lines.
- *	char **read_as_lines(const char *filename)
+ *	static char **read_file_as_lines(const char *filename)
  *	{
  *		char **lines, *all;
  *

+ 2 - 1
ccan/idtree/_info

@@ -30,7 +30,8 @@
  *			       argv[i], idtree_add(idtree, argv[i], -1));
  *		}
  *		for (i = 0; i < argc; i++) {
- *			printf("id %i -> '%s'\n", i, idtree_lookup(idtree, i));
+ *			printf("id %i -> '%s'\n",
+ *			       i, (char *)idtree_lookup(idtree, i));
  *		}
  *		return 0;
  *	}

+ 10 - 16
ccan/idtree/idtree.h

@@ -9,14 +9,14 @@
  * Allocate an empty id tree.  You can free it with talloc_free().
  *
  * Example:
- *	#include <err.h>
- *
  *	static struct idtree *ids;
  *
- *	...
+ *	static void init(void)
+ *	{
  *		ids = idtree_new(NULL);
  *		if (!ids)
  *			err(1, "Failed to allocate idtree");
+ *	}
  */
 struct idtree *idtree_new(void *mem_ctx);
 
@@ -31,14 +31,14 @@ struct idtree *idtree_new(void *mem_ctx);
  * Example:
  *	struct foo {
  *		unsigned int id;
- *		...
+ *		// ...
  *	};
  *
  *	// Create a new foo, assigning an id.
- *	struct foo *new_foo(void)
+ *	static struct foo *new_foo(void)
  *	{
  *		int id;
- *		foo = malloc(sizeof(*foo));
+ *		struct foo *foo = malloc(sizeof(*foo));
  *		if (!foo)
  *			return NULL;
  *
@@ -62,17 +62,13 @@ int idtree_add(struct idtree *idtree, const void *ptr, int limit);
  *
  * Example:
  *	static int last_id = -1;
- *	struct foo {
- *		unsigned int id;
- *		...
- *	};
  *
  *	// Create a new foo, assigning a consecutive id.
  *	// This maximizes the time before ids roll.
- *	struct foo *new_foo(void)
+ *	static struct foo *new_foo_inc_id(void)
  *	{
  *		int id;
- *		foo = malloc(sizeof(*foo));
+ *		struct foo *foo = malloc(sizeof(*foo));
  *		if (!foo)
  *			return NULL;
  *
@@ -102,7 +98,7 @@ int idtree_add_above(struct idtree *idtree, const void *ptr,
  *
  * Example:
  *	// Look up a foo for a given ID.
- *	struct foo *find_foo(unsigned int id)
+ *	static struct foo *find_foo(unsigned int id)
  *	{
  *		return idtree_lookup(ids, id);
  *	}
@@ -117,10 +113,8 @@ void *idtree_lookup(const struct idtree *idtree, int id);
  * Returns false if the id was not in the tree.
  *
  * Example:
- *	#include <assert.h>
- *
  *	// Look up a foo for a given ID.
- *	void *free_foo(struct foo *foo)
+ *	static void free_foo(struct foo *foo)
  *	{
  *		bool exists = idtree_remove(ids, foo->id);
  *		assert(exists);

+ 1 - 1
ccan/ilog/_info

@@ -22,7 +22,7 @@
  *    printf("ILOG_32(0x%08X)=%i\n",0,ILOG_32(0));
  *    for(i=1;i<=STATIC_ILOG_32(USHRT_MAX);i++){
  *      uint32_t v;
- *      v=(uint32_t)1U<<i-1;
+ *      v=(uint32_t)1U<<(i-1);
  *      //Here we know v is non-zero, so we can use ILOGNZ_32().
  *      printf("ILOG_32(0x%08X)=%i\n",v,ILOGNZ_32(v));
  *    }

+ 2 - 2
ccan/likely/likely.h

@@ -23,7 +23,7 @@
  *	// Returns false if we overflow.
  *	static inline bool inc_int(unsigned int *val)
  *	{
- *		*(val)++;
+ *		(*val)++;
  *		if (likely(*val))
  *			return true;
  *		return false;
@@ -45,7 +45,7 @@
  *	// Prints a warning if we overflow.
  *	static inline void inc_int(unsigned int *val)
  *	{
- *		*(val)++;
+ *		(*val)++;
  *		if (unlikely(*val == 0))
  *			fprintf(stderr, "Overflow!");
  *	}