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