OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [ppc/] [filter.c] - Diff between revs 157 and 223

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 157 Rev 223
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    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
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#include <stdio.h>
#include <stdio.h>
 
 
#include "config.h"
#include "config.h"
 
 
#ifdef HAVE_STRING_H
#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
#else
#else
#ifdef HAVE_STRINGS_H
#ifdef HAVE_STRINGS_H
#include <strings.h>
#include <strings.h>
#endif
#endif
#endif
#endif
 
 
#include "misc.h"
#include "misc.h"
#include "filter.h"
#include "filter.h"
 
 
struct _filter {
struct _filter {
  char *flag;
  char *flag;
  filter *next;
  filter *next;
};
};
 
 
 
 
filter *
filter *
new_filter(const char *filt,
new_filter(const char *filt,
           filter *filters)
           filter *filters)
{
{
  while (strlen(filt) > 0) {
  while (strlen(filt) > 0) {
    filter *new_filter;
    filter *new_filter;
    /* break up the filt list */
    /* break up the filt list */
    char *end = strchr(filt, ',');
    char *end = strchr(filt, ',');
    char *next;
    char *next;
    int len;
    int len;
    if (end == NULL) {
    if (end == NULL) {
      end = strchr(filt, '\0');
      end = strchr(filt, '\0');
      next = end;
      next = end;
    }
    }
    else {
    else {
      next = end + 1;
      next = end + 1;
    }
    }
    len = end - filt;
    len = end - filt;
    /* add to filter list */
    /* add to filter list */
    new_filter = ZALLOC(filter);
    new_filter = ZALLOC(filter);
    new_filter->flag = (char*)zalloc(len + 1);
    new_filter->flag = (char*)zalloc(len + 1);
    strncpy(new_filter->flag, filt, len);
    strncpy(new_filter->flag, filt, len);
    new_filter->next = filters;
    new_filter->next = filters;
    filters = new_filter;
    filters = new_filter;
    filt = next;
    filt = next;
  }
  }
  return filters;
  return filters;
}
}
 
 
 
 
int
int
is_filtered_out(const char *flags,
is_filtered_out(const char *flags,
                filter *filters)
                filter *filters)
{
{
  while (strlen(flags) > 0) {
  while (strlen(flags) > 0) {
    int present;
    int present;
    filter *filt = filters;
    filter *filt = filters;
    /* break the string up */
    /* break the string up */
    char *end = strchr(flags, ',');
    char *end = strchr(flags, ',');
    char *next;
    char *next;
    int len;
    int len;
    if (end == NULL) {
    if (end == NULL) {
      end = strchr(flags, '\0');
      end = strchr(flags, '\0');
      next = end;
      next = end;
    }
    }
    else {
    else {
      next = end + 1;
      next = end + 1;
    }
    }
    len = end - flags;
    len = end - flags;
    /* check that it is present */
    /* check that it is present */
    present = 0;
    present = 0;
    filt = filters;
    filt = filters;
    while (filt != NULL) {
    while (filt != NULL) {
      if (strncmp(flags, filt->flag, len) == 0
      if (strncmp(flags, filt->flag, len) == 0
          && strlen(filt->flag) == len) {
          && strlen(filt->flag) == len) {
        present = 1;
        present = 1;
        break;
        break;
      }
      }
      filt = filt->next;
      filt = filt->next;
    }
    }
    if (!present)
    if (!present)
      return 1;
      return 1;
    flags = next;
    flags = next;
  }
  }
  return 0;
  return 0;
}
}
 
 
 
 
int
int
it_is(const char *flag,
it_is(const char *flag,
      const char *flags)
      const char *flags)
{
{
  int flag_len = strlen(flag);
  int flag_len = strlen(flag);
  while (*flags != '\0') {
  while (*flags != '\0') {
    if (!strncmp(flags, flag, flag_len)
    if (!strncmp(flags, flag, flag_len)
        && (flags[flag_len] == ',' || flags[flag_len] == '\0'))
        && (flags[flag_len] == ',' || flags[flag_len] == '\0'))
      return 1;
      return 1;
    while (*flags != ',') {
    while (*flags != ',') {
      if (*flags == '\0')
      if (*flags == '\0')
        return 0;
        return 0;
      flags++;
      flags++;
    }
    }
    flags++;
    flags++;
  }
  }
  return 0;
  return 0;
}
}
 
 
 
 
#ifdef MAIN
#ifdef MAIN
int
int
main(int argc, char **argv)
main(int argc, char **argv)
{
{
  filter *filters = NULL;
  filter *filters = NULL;
  int i;
  int i;
  if (argc < 2) {
  if (argc < 2) {
    printf("Usage: filter <flags> <filter> ...\n");
    printf("Usage: filter <flags> <filter> ...\n");
    exit (1);
    exit (1);
  }
  }
  /* load the filter up */
  /* load the filter up */
  for (i = 2; i < argc; i++)
  for (i = 2; i < argc; i++)
    filters = new_filter(argv[i], filters);
    filters = new_filter(argv[i], filters);
  if (is_filtered_out(argv[1], filters))
  if (is_filtered_out(argv[1], filters))
    printf("fail\n");
    printf("fail\n");
  else
  else
    printf("pass\n");
    printf("pass\n");
  return 0;
  return 0;
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.