Root/qpkg/id.h

Source at commit 3f820dc41d82c78d972efe3c69f139f209a742f9 created 9 years 16 days ago.
By Werner Almesberger, cad/test2/README: added more results and cleaned up the text
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
48struct id;
49
50struct tree {
51    int (*comp)(const void *a, const void *b);
52    struct jrb *root;
53};
54
55struct 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
70int comp_id(const void *a, const void *b);
71int comp_versions(const struct id *va, const struct id *vb);
72
73struct tree *make_tree(int (*comp)(const void *a, const void *b));
74struct jrb *make_id(struct tree *tree, const char *s, size_t len);
75const struct jrb *find_id(const struct tree *tree, const char *s, size_t len);
76
77#endif /* !ID_H */
78

Archive Download this file

Branches:
master



interactive