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