aboutsummaryrefslogtreecommitdiff
path: root/src/lookup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lookup.c')
-rw-r--r--src/lookup.c252
1 files changed, 126 insertions, 126 deletions
diff --git a/src/lookup.c b/src/lookup.c
index 7cb95df..8c0df3f 100644
--- a/src/lookup.c
+++ b/src/lookup.c
@@ -1,4 +1,4 @@
1/* grecs - Gray's Extensible Configuration System 1/* argot - Gray's Extensible Configuration System
2 Copyright (C) 2007-2016 Sergey Poznyakoff 2 Copyright (C) 2007-2016 Sergey Poznyakoff
3 3
4 Grecs is free software; you can redistribute it and/or modify it 4 Grecs is free software; you can redistribute it and/or modify it
@@ -20,16 +20,16 @@
20#include <string.h> 20#include <string.h>
21#include <errno.h> 21#include <errno.h>
22#include <ctype.h> 22#include <ctype.h>
23#include "grecs.h" 23#include "argot.h"
24#include "wordsplit.h" 24#include "wordsplit.h"
25#include <fnmatch.h> 25#include <fnmatch.h>
26#include <stdlib.h> 26#include <stdlib.h>
27 27
28static int 28static int
29_grecs_list_eq(struct grecs_value *a, struct grecs_value *b) 29_argot_list_eq(struct argot_value *a, struct argot_value *b)
30{ 30{
31 struct grecs_list_entry *aent, *bent; 31 struct argot_list_entry *aent, *bent;
32 if (grecs_list_size(a->v.list) != grecs_list_size(b->v.list)) 32 if (argot_list_size(a->v.list) != argot_list_size(b->v.list))
33 return 0; 33 return 0;
34 34
35 for (aent = a->v.list->head, bent = b->v.list->head;; 35 for (aent = a->v.list->head, bent = b->v.list->head;;
@@ -38,7 +38,7 @@ _grecs_list_eq(struct grecs_value *a, struct grecs_value *b)
38 return bent == NULL; 38 return bent == NULL;
39 if (!bent) 39 if (!bent)
40 return 0; 40 return 0;
41 if (!grecs_value_eq(aent->data, bent->data)) 41 if (!argot_value_eq(aent->data, bent->data))
42 return 0; 42 return 0;
43 } 43 }
44 /*notreached*/ 44 /*notreached*/
@@ -46,7 +46,7 @@ _grecs_list_eq(struct grecs_value *a, struct grecs_value *b)
46} 46}
47 47
48static int 48static int
49_grecs_array_eq(struct grecs_value *a, struct grecs_value *b) 49_argot_array_eq(struct argot_value *a, struct argot_value *b)
50{ 50{
51 size_t i; 51 size_t i;
52 52
@@ -54,39 +54,39 @@ _grecs_array_eq(struct grecs_value *a, struct grecs_value *b)
54 return 0; 54 return 0;
55 55
56 for (i = 0; i < a->v.arg.c; i++) 56 for (i = 0; i < a->v.arg.c; i++)
57 if (!grecs_value_eq(a->v.arg.v[i], b->v.arg.v[i])) 57 if (!argot_value_eq(a->v.arg.v[i], b->v.arg.v[i]))
58 return 0; 58 return 0;
59 return 1; 59 return 1;
60} 60}
61 61
62/* Return 1 if configuration value A equals B */ 62/* Return 1 if configuration value A equals B */
63int 63int
64grecs_value_eq(struct grecs_value *a, struct grecs_value *b) 64argot_value_eq(struct argot_value *a, struct argot_value *b)
65{ 65{
66 if (a == 0 || b == 0) 66 if (a == 0 || b == 0)
67 return a == b; 67 return a == b;
68 if (a->type != b->type) 68 if (a->type != b->type)
69 return 0; 69 return 0;
70 switch (a->type) { 70 switch (a->type) {
71 case GRECS_TYPE_STRING: 71 case ARGOT_TYPE_STRING:
72 if (a->v.string == NULL) 72 if (a->v.string == NULL)
73 return b->v.string == NULL; 73 return b->v.string == NULL;
74 return strcmp(a->v.string, b->v.string) == 0; 74 return strcmp(a->v.string, b->v.string) == 0;
75 75
76 case GRECS_TYPE_LIST: 76 case ARGOT_TYPE_LIST:
77 return _grecs_list_eq(a, b); 77 return _argot_list_eq(a, b);
78 78
79 case GRECS_TYPE_ARRAY: 79 case ARGOT_TYPE_ARRAY:
80 return _grecs_array_eq(a, b); 80 return _argot_array_eq(a, b);
81 } 81 }
82 return 0; 82 return 0;
83} 83}
84 84
85static int 85static int
86_grecs_list_match(struct grecs_value *pat, struct grecs_value *b, int flags) 86_argot_list_match(struct argot_value *pat, struct argot_value *b, int flags)
87{ 87{
88 struct grecs_list_entry *aent, *bent; 88 struct argot_list_entry *aent, *bent;
89 if (grecs_list_size(pat->v.list) != grecs_list_size(b->v.list)) 89 if (argot_list_size(pat->v.list) != argot_list_size(b->v.list))
90 return 0; 90 return 0;
91 91
92 for (aent = pat->v.list->head, bent = b->v.list->head;; 92 for (aent = pat->v.list->head, bent = b->v.list->head;;
@@ -95,7 +95,7 @@ _grecs_list_match(struct grecs_value *pat, struct grecs_value *b, int flags)
95 return bent == NULL; 95 return bent == NULL;
96 if (!bent) 96 if (!bent)
97 return 0; 97 return 0;
98 if (!grecs_value_match(aent->data, bent->data, flags)) 98 if (!argot_value_match(aent->data, bent->data, flags))
99 return 0; 99 return 0;
100 } 100 }
101 /*notreached*/ 101 /*notreached*/
@@ -103,7 +103,7 @@ _grecs_list_match(struct grecs_value *pat, struct grecs_value *b, int flags)
103} 103}
104 104
105static int 105static int
106_grecs_array_match(struct grecs_value *pat, struct grecs_value *b, int flags) 106_argot_array_match(struct argot_value *pat, struct argot_value *b, int flags)
107{ 107{
108 size_t i; 108 size_t i;
109 109
@@ -111,61 +111,61 @@ _grecs_array_match(struct grecs_value *pat, struct grecs_value *b, int flags)
111 return 0; 111 return 0;
112 112
113 for (i = 0; i < pat->v.arg.c; i++) 113 for (i = 0; i < pat->v.arg.c; i++)
114 if (!grecs_value_match(pat->v.arg.v[i], b->v.arg.v[i], flags)) 114 if (!argot_value_match(pat->v.arg.v[i], b->v.arg.v[i], flags))
115 return 0; 115 return 0;
116 return 1; 116 return 1;
117} 117}
118 118
119int 119int
120grecs_value_match(struct grecs_value *pat, struct grecs_value *b, int flags) 120argot_value_match(struct argot_value *pat, struct argot_value *b, int flags)
121{ 121{
122 if (pat == 0 || b == 0) 122 if (pat == 0 || b == 0)
123 return pat == b; 123 return pat == b;
124 if (pat->type != b->type) { 124 if (pat->type != b->type) {
125 if (pat->type != GRECS_TYPE_STRING) 125 if (pat->type != ARGOT_TYPE_STRING)
126 return 0; 126 return 0;
127 switch (b->type) { 127 switch (b->type) {
128 case GRECS_TYPE_LIST: 128 case ARGOT_TYPE_LIST:
129 b = grecs_list_index(b->v.list, 0); 129 b = argot_list_index(b->v.list, 0);
130 break; 130 break;
131 131
132 case GRECS_TYPE_ARRAY: 132 case ARGOT_TYPE_ARRAY:
133 b = b->v.arg.v[0]; 133 b = b->v.arg.v[0];
134 } 134 }
135 } 135 }
136 136
137 switch (pat->type) { 137 switch (pat->type) {
138 case GRECS_TYPE_STRING: 138 case ARGOT_TYPE_STRING:
139 if (pat->v.string == NULL) 139 if (pat->v.string == NULL)
140 return b->v.string == NULL; 140 return b->v.string == NULL;
141 return fnmatch(pat->v.string, b->v.string, flags) == 0; 141 return fnmatch(pat->v.string, b->v.string, flags) == 0;
142 142
143 case GRECS_TYPE_LIST: 143 case ARGOT_TYPE_LIST:
144 return _grecs_list_match(pat, b, flags); 144 return _argot_list_match(pat, b, flags);
145 145
146 case GRECS_TYPE_ARRAY: 146 case ARGOT_TYPE_ARRAY:
147 return _grecs_array_match(pat, b, flags); 147 return _argot_array_match(pat, b, flags);
148 } 148 }
149 return 0; 149 return 0;
150} 150}
151 151
152 152
153struct grecs_match_buf { 153struct argot_match_buf {
154 int argc; /* number of path components */ 154 int argc; /* number of path components */
155 char **argv; /* array of path components */ 155 char **argv; /* array of path components */
156 int argi; /* Index of the current component */ 156 int argi; /* Index of the current component */
157 struct grecs_value **labelv; /* Component labels */ 157 struct argot_value **labelv; /* Component labels */
158 struct grecs_node *root; /* Root node */ 158 struct argot_node *root; /* Root node */
159 struct grecs_node *node; /* Last found node */ 159 struct argot_node *node; /* Last found node */
160}; 160};
161 161
162#define ISWC(c,w) ((c)[0] == (w) && (c)[1] == 0) 162#define ISWC(c,w) ((c)[0] == (w) && (c)[1] == 0)
163 163
164grecs_match_buf_t 164argot_match_buf_t
165grecs_match_buf_create(int argc, char **argv, struct grecs_value **labelv) 165argot_match_buf_create(int argc, char **argv, struct argot_value **labelv)
166{ 166{
167 int i; 167 int i;
168 struct grecs_match_buf *buf = grecs_zalloc(sizeof(*buf)); 168 struct argot_match_buf *buf = argot_zalloc(sizeof(*buf));
169