]> git.ozlabs.org Git - ccan/blob - ccan/stringmap/_info
Added module stringmap
[ccan] / ccan / stringmap / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * stringmap - Macros for mapping strings to things
7  *
8  * stringmap provides a generic string map via macros.
9  *
10  * Features which are sorely lacking in this version of stringmap are deletion and traversal.
11  *
12  * Example:
13  *
14  * #include <ccan/stringmap/stringmap.h>                                                                                                                                        
15  *
16  * static const char *get_string(void) {                                                                                                                                        
17  *      static char buffer[4096];                                                                                                                                               
18  *      char *tail;                                                                                                                                                             
19  *      if (!fgets(buffer, sizeof(buffer), stdin))                                                                                                                              
20  *              return NULL;                                                                                                                                                    
21  *      tail = strchr(buffer, 0);                                                                                                                                               
22  *      if (tail>buffer && tail[-1]=='\n')                                                                                                                                      
23  *              *--tail = 0;                                                                                                                                                    
24  *      if (!*buffer)                                                                                                                                                           
25  *              return NULL;                                                                                                                                                    
26  *      return buffer;                                                                                                                                                          
27  * }                                                                                                                                                                            
28  *
29  * int main(void) {                                                                                                                                                             
30  *      stringmap(int) map = stringmap_new(NULL);
31  *      const char *string;
32  *
33  *      while ((string = get_string()) != NULL) {
34  *              int *count = stringmap_lookup(map, string);
35  *
36  *              if (!count) {
37  *                      printf("\"%s\" is new\n", string);
38  *                      count = stringmap_enter(map, string);
39  *              }
40  *
41  *              (*count) ++;
42  *
43  *              printf("\"%s\" has been entered %d times\n", string, *count);
44  *      }
45  *
46  *      stringmap_free(map);
47  *
48  *    return 0;
49  * }
50  *
51  *      Authors: Joey Adams, Anders Magnusson
52  *      License: BSD
53  */
54 int main(int argc, char *argv[])
55 {
56         /* Expect exactly one argument */
57         if (argc != 2)
58                 return 1;
59
60         if (strcmp(argv[1], "depends") == 0) {
61                 printf("ccan/block_pool\n");
62                 return 0;
63         }
64
65         return 1;
66 }