/src/CMake/Utilities/cmllpkgc/llpkgc.c
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. |
2 | | See accompanying file LICENSE.rst for details. */ |
3 | | |
4 | | #include <string.h> |
5 | | |
6 | | #include "llpkgc.h" |
7 | | |
8 | 101k | static int field_equal(const char* name, size_t length, const char* field) { |
9 | 101k | size_t i; |
10 | 101k | if(strlen(field) != length) |
11 | 88.8k | return 0; |
12 | 60.4k | for(i = 0; i < length; i++) { |
13 | 53.6k | unsigned char c = (unsigned char) name[i]; |
14 | 53.6k | if(c >= 'A' && c <= 'Z') |
15 | 13.2k | c += 'a' - 'A'; |
16 | 53.6k | if(c != (unsigned char) field[i]) |
17 | 5.68k | return 0; |
18 | 53.6k | } |
19 | 6.84k | return 1; |
20 | 12.5k | } |
21 | | |
22 | 12.2k | llpkgc_value_kind_t llpkgc_classify_field(const char* name, size_t length) { |
23 | 12.2k | static const char* const fragments[] = { |
24 | 12.2k | "cflags", |
25 | 12.2k | "cflags.private", |
26 | 12.2k | "cflags.shared", |
27 | 12.2k | "libs", |
28 | 12.2k | "libs.private", |
29 | 12.2k | "libs.shared", |
30 | 12.2k | }; |
31 | 12.2k | static const char* const dependencies[] = { |
32 | 12.2k | "conflicts", |
33 | 12.2k | "provides", |
34 | 12.2k | "requires", |
35 | 12.2k | "requires.private", |
36 | 12.2k | "requires.internal", |
37 | 12.2k | "requires.shared", |
38 | 12.2k | }; |
39 | 12.2k | size_t i; |
40 | 69.5k | for(i = 0; i < sizeof(fragments) / sizeof(*fragments); i++) |
41 | 61.2k | if(field_equal(name, length, fragments[i])) |
42 | 3.89k | return LLPKGC_VALUE_FRAGMENTS; |
43 | 45.5k | for(i = 0; i < sizeof(dependencies) / sizeof(*dependencies); i++) |
44 | 40.1k | if(field_equal(name, length, dependencies[i])) |
45 | 2.94k | return LLPKGC_VALUE_DEPENDENCIES; |
46 | 5.37k | return LLPKGC_VALUE_LITERAL; |
47 | 8.31k | } |
48 | | |
49 | 0 | const char* llpkgc_dep_comparator_name(llpkgc_dep_comparator_t comparator) { |
50 | 0 | switch(comparator) { |
51 | 0 | case LLPKGC_DEP_LESS_THAN: |
52 | 0 | return "<"; |
53 | 0 | case LLPKGC_DEP_LESS_THAN_EQUAL: |
54 | 0 | return "<="; |
55 | 0 | case LLPKGC_DEP_EQUAL: |
56 | 0 | return "="; |
57 | 0 | case LLPKGC_DEP_NOT_EQUAL: |
58 | 0 | return "!="; |
59 | 0 | case LLPKGC_DEP_GREATER_THAN: |
60 | 0 | return ">"; |
61 | 0 | case LLPKGC_DEP_GREATER_THAN_EQUAL: |
62 | 0 | return ">="; |
63 | 0 | default: |
64 | 0 | return ""; |
65 | 0 | } |
66 | 0 | } |