1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002, 2007, 2008, 2009 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
)
221 it_is (const char *flag
, const char *flags
)
223 int flag_len
= strlen (flag
);
224 while (*flags
!= '\0')
226 if (!strncmp (flags
, flag
, flag_len
)
227 && (flags
[flag_len
] == ',' || flags
[flag_len
] == '\0'))
229 while (*flags
!= ',')
243 filter_next (filter
*set
, char *member
)
247 if (strcmp (set
->member
, member
) > 0)
256 dump_filter (lf
*file
, char *prefix
, filter
*set
, char *suffix
)
259 lf_printf (file
, "%s", prefix
);
260 member
= filter_next (set
, "");
265 lf_printf (file
, "%s", member
);
266 member
= filter_next (set
, member
);
269 lf_printf (file
, ",");
272 lf_printf (file
, "%s", suffix
);
278 main (int argc
, char **argv
)
280 filter
*subset
= NULL
;
281 filter
*superset
= NULL
;
286 printf ("Usage: filter <subset> <filter> ...\n");
290 /* load the filter up */
291 filter_parse (&subset
, argv
[1]);
292 for (i
= 2; i
< argc
; i
++)
293 filter_parse (&superset
, argv
[i
]);
295 /* dump various info */
296 l
= lf_open ("-", "stdout", lf_omit_references
, lf_is_text
, "tmp-filter");
298 if (is_filtered_out (argv
[1], superset
))
299 lf_printf (l
, "excluded\n");
301 lf_printf (l
, "included\n");
305 dump_filter (l
, "{", subset
, " }");
306 if (filter_is_subset (superset
, subset
))
307 lf_printf (l
, " subset of ");
309 lf_printf (l
, " !subset of ");
310 dump_filter (l
, "{", superset
, " }");
315 dump_filter (l
, "{", subset
, " }");
316 if (filter_is_common (subset
, superset
))
317 lf_printf (l
, " intersects ");
319 lf_printf (l
, " !intersects ");
320 dump_filter (l
, "{", superset
, " }");
325 filter
*memb
= subset
;
328 lf_printf (l
, "%s", memb
->member
);
329 if (filter_is_member (superset
, memb
->member
))
330 lf_printf (l
, " in ");
332 lf_printf (l
, " !in ");
333 dump_filter (l
, "{", superset
, " }");
341 filter_add (&add
, superset
);
342 filter_add (&add
, subset
);
343 dump_filter (l
, "{", add
, " }");
344 lf_printf (l
, " = ");
345 dump_filter (l
, "{", subset
, " }");
346 lf_printf (l
, " + ");
347 dump_filter (l
, "{", superset
, " }");
This page took 0.035703 seconds and 4 git commands to generate.