]> git.ozlabs.org Git - ccan/commitdiff
modules: update documentation examples so they compile under ccanlint.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Oct 2010 17:01:55 +0000 (03:31 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Oct 2010 17:01:55 +0000 (03:31 +1030)
This is everything up to the list module... now it's time for sleep.

21 files changed:
ccan/array_size/_info
ccan/asort/_info
ccan/block_pool/_info
ccan/btree/_info
ccan/build_assert/_info
ccan/build_assert/build_assert.h
ccan/ccan_tokenizer/_info
ccan/charset/_info
ccan/compiler/_info
ccan/compiler/compiler.h
ccan/container_of/_info
ccan/container_of/container_of.h
ccan/crc/_info
ccan/crc/crc.h
ccan/crcsync/_info
ccan/endian/_info
ccan/grab_file/grab_file.h
ccan/idtree/_info
ccan/idtree/idtree.h
ccan/ilog/_info
ccan/likely/likely.h

index cbe332ad9aee64d05a3c0a7014b545f3033f32fc..1722ba2933f1906479f6da5263eb8bf0b7930c48 100644 (file)
@@ -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++)
index e848ff1a974d73660200694cf33279448270a490..c5b2a0bb23706f50b6646b8310ee21eeed4a8893 100644 (file)
  *     #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[])
index 53afc7bd8826e5a3474392548c1af31458b8559f..245ed1a900166b8a621048bde969824cd6256761 100644 (file)
  *      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[])
 {
index 46877229b9e015944d9b6cf56d289ad4a78165a0..5d72c490f0de31d9c0f7b1208bc5519974d14eb9 100644 (file)
@@ -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];
  *     
  *     return btree;
  * 
- * fail:
+ *   fail:
  *     btree_delete(btree);
  *     fprintf(stderr, "%s: %s\n", filename, strerror(errno));
  *     return NULL;
index cf939d794ce95ddd7829fd00b0ba9db48d2653c8..16a4a94c8f292c27665120023f503cfd33c61974 100644 (file)
@@ -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);
index 4b0d75e4bf29ade83fe741440d56532e3c8ffdfe..c6ee362f2299933160a552484434f911c713a290 100644 (file)
@@ -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);
index 8c3c9df2d9792a5656256d81282a4198a8b04b9b..754b3cf680f4cc412b3d1adf36112ba557cf8fbc 100644 (file)
@@ -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;
index 4319ecb33022181109d5b7e613eccb4d24e801d9..a7086ba12e99cd36e2c35cb9e06e43ebdb209b16 100644 (file)
@@ -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);
index ea4fe702857155cedf9825501955199b1c656da8..06645b1d8c9d8e26ea2d554553351f53795e8bd7 100644 (file)
@@ -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.
  * 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;
index be229670fd127a5f89e9e9bc6b14e4a7cc48ddce..242ef84d133ddb65ea378bdfcc6585a7f46d7bd8 100644 (file)
  * 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
 #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)))
  * 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))
 
  *     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";
index 2b9da338a70a9abd0bf97594929c2a08a9dee66c..8580526a40040913736b449d458fe1dd35580efb 100644 (file)
  *             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 };
  *
index ec66f106f2aeb0144b17455973607b873ae88731..de3f4505162a5416f477d5624e0049da6d2abeec 100644 (file)
  * 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);
  *     }
  * 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;
index c505a2b63987f1643c3fd7c5cb3b95a8ff949d14..7812f212d445a1683dd042c632091209d64f3682 100644 (file)
@@ -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);
  *     }
  *
index d3184cb1a7b606fdb9c9e8bf9327321633e4dda8..6338000e23d937e5628f7a8191ceaf8d2e38a17c 100644 (file)
  * 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)
index 3a98951c428c01739e35a2e2f365d0f977774997..79368c1d60b3dd091d4a1bd256e04fd7d5f83456 100644 (file)
@@ -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)
  *             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);
index 52e919365017f675bdd80f1f6530cda0209e6bb9..400f7745569a2f0ba2c78a26ac410631c93e4c41 100644 (file)
@@ -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));
index 5f7e37c6de004a634d04441dcdb031b197581cfd..b2bd31ada26108d0c5a179b07c744bcdc26f692e 100644 (file)
  * 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;
  *
index 058b32b48a2d49033b745c268a5ee0cf52036be5..c0db3632e2c62731b4aed090473c3ef21b6c7cee 100644 (file)
@@ -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;
  *     }
index cc84a3a9a7e9b61069625c0d55616618fe66dab4..3835d7f522b38582f7e592dda2e76dd99e792874 100644 (file)
@@ -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);
index 2b4aeb2edded654b395bf9c6302e005b2d6944fd..59e556656a6e30064db022aad78ba79cd5453efa 100644 (file)
@@ -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));
  *    }
index 62a203727507f359dcfa46ef4209629dfa79a848..eed1f209f7535c6d1d13f7e8abb1a580f10c267c 100644 (file)
@@ -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!");
  *     }