]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/ppc/filter.c
sim: enable silent rules in common builds
[thirdparty/binutils-gdb.git] / sim / ppc / filter.c
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20
21 #include <stdio.h>
22
23 #include "build-config.h"
24
25 #include <string.h>
26
27 #include "misc.h"
28 #include "filter.h"
29
30 struct _filter {
31 char *flag;
32 filter *next;
33 };
34
35
36 filter *
37 new_filter(const char *filt,
38 filter *filters)
39 {
40 while (strlen(filt) > 0) {
41 filter *new_filter;
42 /* break up the filt list */
43 char *end = strchr(filt, ',');
44 char *next;
45 int len;
46 if (end == NULL) {
47 end = strchr(filt, '\0');
48 next = end;
49 }
50 else {
51 next = end + 1;
52 }
53 len = end - filt;
54 /* add to filter list */
55 new_filter = ZALLOC(filter);
56 new_filter->flag = (char*)zalloc(len + 1);
57 strncpy(new_filter->flag, filt, len);
58 new_filter->next = filters;
59 filters = new_filter;
60 filt = next;
61 }
62 return filters;
63 }
64
65
66 int
67 is_filtered_out(const char *flags,
68 filter *filters)
69 {
70 while (strlen(flags) > 0) {
71 int present;
72 filter *filt = filters;
73 /* break the string up */
74 char *end = strchr(flags, ',');
75 char *next;
76 int len;
77 if (end == NULL) {
78 end = strchr(flags, '\0');
79 next = end;
80 }
81 else {
82 next = end + 1;
83 }
84 len = end - flags;
85 /* check that it is present */
86 present = 0;
87 filt = filters;
88 while (filt != NULL) {
89 if (strncmp(flags, filt->flag, len) == 0
90 && strlen(filt->flag) == len) {
91 present = 1;
92 break;
93 }
94 filt = filt->next;
95 }
96 if (!present)
97 return 1;
98 flags = next;
99 }
100 return 0;
101 }
102
103
104 int
105 it_is(const char *flag,
106 const char *flags)
107 {
108 int flag_len = strlen(flag);
109 while (*flags != '\0') {
110 if (!strncmp(flags, flag, flag_len)
111 && (flags[flag_len] == ',' || flags[flag_len] == '\0'))
112 return 1;
113 while (*flags != ',') {
114 if (*flags == '\0')
115 return 0;
116 flags++;
117 }
118 flags++;
119 }
120 return 0;
121 }
122
123
124 #ifdef MAIN
125 int
126 main(int argc, char **argv)
127 {
128 filter *filters = NULL;
129 int i;
130 if (argc < 2) {
131 printf("Usage: filter <flags> <filter> ...\n");
132 exit (1);
133 }
134 /* load the filter up */
135 for (i = 2; i < argc; i++)
136 filters = new_filter(argv[i], filters);
137 if (is_filtered_out(argv[1], filters))
138 printf("fail\n");
139 else
140 printf("pass\n");
141 return 0;
142 }
143 #endif