1 /* The IGEN simulator generator for GDB, the GNU Debugger.
3 Copyright 2002 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 2 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, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
49 filter_parse (filter
**filters
, const char *filt
)
51 while (strlen (filt
) > 0)
55 /* break out a member of the filter list */
56 const char *flag
= filt
;
57 unsigned /*size_t */ len
;
58 filt
= strchr (filt
, ',');
61 filt
= strchr (flag
, '\0');
69 /* find an insertion point - sorted order */
71 while (*last
!= NULL
&& strncmp (flag
, (*last
)->member
, len
) > 0)
72 last
= &(*last
)->next
;
74 && strncmp (flag
, (*last
)->member
, len
) == 0
75 && strlen ((*last
)->member
) == len
)
76 continue; /* duplicate */
77 /* create an entry for that member */
78 new_filter
= ZALLOC (filter
);
79 new_filter
->member
= NZALLOC (char, len
+ 1);
80 strncpy (new_filter
->member
, flag
, len
);
82 new_filter
->next
= *last
;
89 filter_add (filter
**set
, filter
*add
)
95 cmp
= 1; /* set->member > add->member */
97 cmp
= strcmp ((*set
)->member
, add
->member
);
101 filter
*new = ZALLOC (filter
);
102 new->member
= NZALLOC (char, strlen (add
->member
) + 1);
103 strcpy (new->member
, add
->member
);
115 /* not reached insertion point */
123 filter_is_subset (filter
*superset
, filter
*subset
)
130 if (superset
== NULL
)
131 return 0; /* subset isn't finished */
132 cmp
= strcmp (subset
->member
, superset
->member
);
134 return 0; /* not found */
136 subset
= subset
->next
; /* found */
138 superset
= superset
->next
; /* later in list? */
144 filter_is_common (filter
*l
, filter
*r
)
153 cmp
= strcmp (l
->member
, r
->member
);
157 return 1; /* common member */
165 filter_is_member (filter
*filt
, const char *flag
)
170 if (strcmp (flag
, filt
->member
) == 0)
180 is_filtered_out (filter
*filters
, const char *flags
)
182 while (strlen (flags
) > 0)
185 filter
*filt
= filters
;
186 /* break the string up */
187 char *end
= strchr (flags
, ',');
189 unsigned /*size_t */ len
;
192 end
= strchr (flags
, '\0');
200 /* check that it is present */
205 if (strncmp (flags
, filt
->member
, len
) == 0
206 && strlen (filt
->member
) == len
)
223 it_is (const char *flag
, const char *flags
)
225 int flag_len
= strlen (flag
);
226 while (*flags
!= '\0')
228 if (!strncmp (flags
, flag
, flag_len
)
229 && (flags
[flag_len
] == ',' || flags
[flag_len
] == '\0'))
231 while (*flags
!= ',')
245 filter_next (filter
*set
, char *member
)
249 if (strcmp (set
->member
, member
) > 0)
258 dump_filter (lf
*file
, char *prefix
, filter
*set
, char *suffix
)
261 lf_printf (file
, "%s", prefix
);
262 member
= filter_next (set
, "");
267 lf_printf (file
, "%s", member
);
268 member
= filter_next (set
, member
);
271 lf_printf (file
, ",");
274 lf_printf (file
, "%s", suffix
);
280 main (int argc
, char **argv
)
282 filter
*subset
= NULL
;
283 filter
*superset
= NULL
;
288 printf ("Usage: filter <subset> <filter> ...\n");
292 /* load the filter up */
293 filter_parse (&subset
, argv
[1]);
294 for (i
= 2; i
< argc
; i
++)
295 filter_parse (&superset
, argv
[i
]);
297 /* dump various info */
298 l
= lf_open ("-", "stdout", lf_omit_references
, lf_is_text
, "tmp-filter");
300 if (is_filtered_out (argv
[1], superset
))
301 lf_printf (l
, "excluded\n");
303 lf_printf (l
, "included\n");
307 dump_filter (l
, "{", subset
, " }");
308 if (filter_is_subset (superset
, subset
))
309 lf_printf (l
, " subset of ");
311 lf_printf (l
, " !subset of ");
312 dump_filter (l
, "{", superset
, " }");
317 dump_filter (l
, "{", subset
, " }");
318 if (filter_is_common (subset
, superset
))
319 lf_printf (l
, " intersects ");
321 lf_printf (l
, " !intersects ");
322 dump_filter (l
, "{", superset
, " }");
327 filter
*memb
= subset
;
330 lf_printf (l
, "%s", memb
->member
);
331 if (filter_is_member (superset
, memb
->member
))
332 lf_printf (l
, " in ");
334 lf_printf (l
, " !in ");
335 dump_filter (l
, "{", superset
, " }");
343 filter_add (&add
, superset
);
344 filter_add (&add
, subset
);
345 dump_filter (l
, "{", add
, " }");
346 lf_printf (l
, " = ");
347 dump_filter (l
, "{", subset
, " }");
348 lf_printf (l
, " + ");
349 dump_filter (l
, "{", superset
, " }");
This page took 0.035569 seconds and 4 git commands to generate.