1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002-2018 Free Software Foundation, Inc.
5 Contributed by Andrew Cagney.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
47 filter_parse (filter
**filters
, const char *filt
)
49 while (strlen (filt
) > 0)
53 /* break out a member of the filter list */
54 const char *flag
= filt
;
55 unsigned /*size_t */ len
;
56 filt
= strchr (filt
, ',');
59 filt
= strchr (flag
, '\0');
67 /* find an insertion point - sorted order */
69 while (*last
!= NULL
&& strncmp (flag
, (*last
)->member
, len
) > 0)
70 last
= &(*last
)->next
;
72 && strncmp (flag
, (*last
)->member
, len
) == 0
73 && strlen ((*last
)->member
) == len
)
74 continue; /* duplicate */
75 /* create an entry for that member */
76 new_filter
= ZALLOC (filter
);
77 new_filter
->member
= NZALLOC (char, len
+ 1);
78 strncpy (new_filter
->member
, flag
, len
);
80 new_filter
->next
= *last
;
87 filter_add (filter
**set
, filter
*add
)
93 cmp
= 1; /* set->member > add->member */
95 cmp
= strcmp ((*set
)->member
, add
->member
);
99 filter
*new = ZALLOC (filter
);
100 new->member
= NZALLOC (char, strlen (add
->member
) + 1);
101 strcpy (new->member
, add
->member
);
113 /* not reached insertion point */
121 filter_is_subset (filter
*superset
, filter
*subset
)
128 if (superset
== NULL
)
129 return 0; /* subset isn't finished */
130 cmp
= strcmp (subset
->member
, superset
->member
);
132 return 0; /* not found */
134 subset
= subset
->next
; /* found */
136 superset
= superset
->next
; /* later in list? */
142 filter_is_common (filter
*l
, filter
*r
)
151 cmp
= strcmp (l
->member
, r
->member
);
155 return 1; /* common member */
163 filter_is_member (filter
*filt
, const char *flag
)
168 if (strcmp (flag
, filt
->member
) == 0)
178 is_filtered_out (filter
*filters
, const char *flags
)
180 while (strlen (flags
) > 0)
183 filter
*filt
= filters
;
184 /* break the string up */
185 char *end
= strchr (flags
, ',');
187 unsigned /*size_t */ len
;
190 end
= strchr (flags
, '\0');
198 /* check that it is present */
203 if (strncmp (flags
, filt
->member
, len
) == 0
204 && strlen (filt
->member
) == len
)
220 filter_next (filter
*set
, char *member
)
224 if (strcmp (set
->member
, member
) > 0)
233 dump_filter (lf
*file
, char *prefix
, filter
*set
, char *suffix
)
236 lf_printf (file
, "%s", prefix
);
237 member
= filter_next (set
, "");
242 lf_printf (file
, "%s", member
);
243 member
= filter_next (set
, member
);
246 lf_printf (file
, ",");
249 lf_printf (file
, "%s", suffix
);
255 main (int argc
, char **argv
)
257 filter
*subset
= NULL
;
258 filter
*superset
= NULL
;
263 printf ("Usage: filter <subset> <filter> ...\n");
267 /* load the filter up */
268 filter_parse (&subset
, argv
[1]);
269 for (i
= 2; i
< argc
; i
++)
270 filter_parse (&superset
, argv
[i
]);
272 /* dump various info */
273 l
= lf_open ("-", "stdout", lf_omit_references
, lf_is_text
, "tmp-filter");
277 dump_filter (l
, "{", subset
, " }");
278 if (filter_is_subset (superset
, subset
))
279 lf_printf (l
, " subset of ");
281 lf_printf (l
, " !subset of ");
282 dump_filter (l
, "{", superset
, " }");
287 dump_filter (l
, "{", subset
, " }");
288 if (filter_is_common (subset
, superset
))
289 lf_printf (l
, " intersects ");
291 lf_printf (l
, " !intersects ");
292 dump_filter (l
, "{", superset
, " }");
297 filter
*memb
= subset
;
300 lf_printf (l
, "%s", memb
->member
);
301 if (filter_is_member (superset
, memb
->member
))
302 lf_printf (l
, " in ");
304 lf_printf (l
, " !in ");
305 dump_filter (l
, "{", superset
, " }");
313 filter_add (&add
, superset
);
314 filter_add (&add
, subset
);
315 dump_filter (l
, "{", add
, " }");
316 lf_printf (l
, " = ");
317 dump_filter (l
, "{", subset
, " }");
318 lf_printf (l
, " + ");
319 dump_filter (l
, "{", superset
, " }");