Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
Source at commit ebb0d2708b542ee20929375d9a22d37d86b100a5 created 10 years 1 month ago. By Werner Almesberger, ircstat/README: change date format from MMYY to YYMM | |
---|---|
1 | /* |
2 | * id.h - Registry of unique and alphabetically sorted identifiers |
3 | * |
4 | * Written 2010 by Werner Almesberger |
5 | * Copyright 2010 Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | #ifndef ID_H |
14 | #define ID_H |
15 | |
16 | #include <sys/types.h> |
17 | |
18 | #include "jrb.h" |
19 | |
20 | |
21 | /* |
22 | * The role of key and value in jrb nodes: |
23 | * |
24 | * - the key points to a "struct id". This "struct id" is unique for the |
25 | * identifier in question and its location can be used to check for equality |
26 | * with a simple pointer comparison. |
27 | * |
28 | * A caller to find_id may therefore be interested in a pointer to the key, |
29 | * even if the content of the key is known. |
30 | * |
31 | * - for the value, we have to distinguish between packages and versions: |
32 | * |
33 | * - package: pointer to the first package definition. If there are multiple |
34 | * packages with the same name, the rest is linked via pkg->more. |
35 | * |
36 | * The value can be NULL if a reference to the package has been |
37 | * encountered, but |
38 | * |
39 | * - the package definition has not been parsed yet, |
40 | * - no corresponding package definition exist (which would be an error), |
41 | * - the reference is an item listed in Provides: (this will change once |
42 | * we handle Provides: properly) |
43 | * |
44 | * - version: the value is not used |
45 | */ |
46 | |
47 | |
48 | struct id; |
49 | |
50 | struct tree { |
51 | int (*comp)(const void *a, const void *b); |
52 | struct jrb *root; |
53 | }; |
54 | |
55 | struct id { |
56 | struct jrb *jrb; |
57 | const char *s; |
58 | size_t len; |
59 | }; |
60 | |
61 | |
62 | /* |
63 | * Helper macro for printing identifiers. |
64 | * Use with "... %.*s ..." |
65 | */ |
66 | |
67 | #define ID2PF(id) (int) (id)->len, (id)->s |
68 | |
69 | |
70 | int comp_id(const void *a, const void *b); |
71 | int comp_versions(const struct id *va, const struct id *vb); |
72 | |
73 | struct tree *make_tree(int (*comp)(const void *a, const void *b)); |
74 | struct jrb *make_id(struct tree *tree, const char *s, size_t len); |
75 | const struct jrb *find_id(const struct tree *tree, const char *s, size_t len); |
76 | |
77 | #endif /* !ID_H */ |
78 |
Branches:
master