blob: 1f6465b6c8c46cf93421369c15e63cc2f42c386c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* stringmap - Macros for mapping strings to things
*
* stringmap provides a generic string map via macros. It also supports byte
* strings with null characters.
*
* Features which are sorely lacking in this version of stringmap are deletion and traversal.
*
* Example:
*
* #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;
* }
*
* int main(void) {
* stringmap(int) map = stringmap_new(NULL);
* const char *string;
*
* while ((string = get_string()) != NULL) {
* int *count = stringmap_lookup(map, string);
*
* if (!count) {
* printf("\"%s\" is new\n", string);
* count = stringmap_enter(map, string);
* }
*
* (*count) ++;
*
* printf("\"%s\" has been entered %d times\n", string, *count);
* }
*
* stringmap_free(map);
*
* return 0;
* }
*
* Authors: Joey Adams, Anders Magnusson
* License: BSD (3 clause)
* Version: 0.2
* Ccanlint:
* // We actually depend (indirectly) on the LGPL talloc
* license_depends_compat FAIL
*/
int main(int argc, char *argv[])
{
/* Expect exactly one argument */
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
printf("ccan/block_pool\n");
return 0;
}
return 1;
}
|