2 * Copyright (C) 2015-2020 "IoT.bzh"
3 * Author: José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
26 void process(FILE *in, FILE *out)
29 char buffer[1024], *str;
30 const struct globset_handler *gh;
33 set = globset_create();
34 while (fgets(buffer, sizeof buffer, in)) {
35 str = strchr(buffer,'\n');
40 rc = globset_add(set, &buffer[1], NULL, NULL);
41 fprintf(out, "add [%s]: %d, %m\n", &buffer[1], rc);
44 rc = globset_del(set, &buffer[1], NULL);
45 fprintf(out, "del [%s]: %d, %m\n", &buffer[1], rc);
48 gh = globset_search(set, &buffer[1]);
49 fprintf(out, "search [%s]: %s%s\n", &buffer[1], gh ? "found " : "NOT FOUND", gh ? gh->pattern : "");
52 gh = globset_match(set, buffer);
53 fprintf(out, "match [%s]: %s%s\n", buffer, gh ? "found by " : "NOT FOUND", gh ? gh->pattern : "");
60 int compare(FILE *f1, FILE *f2)
63 char b1[1024], b2[1024];
68 s1 = fgets(b1, sizeof b1, f1);
69 s2 = fgets(b2, sizeof b2, f2);
70 if (s1 == NULL || s2 == NULL) {
72 fprintf(stderr, "Length of outputs differ\n");
78 fprintf(stderr, "Line %d differ\n\t%s\t%s", l, s1, s2);
84 int main(int ac, char **av)
91 in = fopen(av[1], "r");
93 fprintf(stderr, "Can't open file %s: %m\n", av[1]);
99 setvbuf(stdout, NULL, _IOLBF, 0);
101 ref = fopen(av[2], "r");
103 fprintf(stderr, "Can't open file %s: %m\n", av[2]);
108 fprintf(stderr, "Can't create temporary file: %m\n");
117 if (compare(out, ref))