Ejemplo n.º 1
0
filter_type extract_filter(const stringlist &args, const std::string &filter_command, const std::string &short_filter_command)
{
    auto start_filter = locate_command(args, filter_command, short_filter_command);
    if (start_filter != std::end(args))
    {
        auto start_filter_args = start_filter + 1;
        auto end_filter = std::find_if(start_filter_args, std::end(args), [](const std::string &arg){return arg.substr(0,1) == arg_short_command_prefix;});
        return filter_type(start_filter_args, end_filter);
    }
    return filter_type();
}
Ejemplo n.º 2
0
typename default_filter_factory< CharT >::filter_type
default_filter_factory< CharT >::on_custom_relation(string_type const& name, string_type const& rel, string_type const& arg)
{
    typedef log::aux::char_constants< char_type > constants;
    if (rel == constants::begins_with_keyword())
        return filter_type(log::filters::attr< string_type >(name).begins_with(arg));
    else if (rel == constants::ends_with_keyword())
        return filter_type(log::filters::attr< string_type >(name).ends_with(arg));
    else if (rel == constants::contains_keyword())
        return filter_type(log::filters::attr< string_type >(name).contains(arg));
    else if (rel == constants::matches_keyword())
    {
        typedef xpressive::basic_regex< typename string_type::const_iterator > regex_t;
        regex_t rex = regex_t::compile(arg, regex_t::ECMAScript | regex_t::optimize);
        return filter_type(log::filters::attr< string_type >(name, std::nothrow).matches(rex));
    }
    else
    {
        BOOST_LOG_THROW_DESCR(parse_error, "The custom attribute relation is not supported");
    }
}
FilterExpanderLabel* FilterFactory::WidgetForFilter(Filter::Ptr const& filter)
{
  std::string filter_type(filter->renderer_name);
  LOG_DEBUG(logger) << "building filter of type, " << filter_type;

  FilterExpanderLabel* widget = nullptr;
  if (filter_type == renderer_type_check_options)
  {
    widget = new FilterGenre(2, NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_check_options_compact)
  {
    widget = new FilterGenre(3, NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_ratings)
  {
    widget = new FilterRatingsWidget(NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_multirange)
  {
    widget = new FilterMultiRangeWidget(NUX_TRACKER_LOCATION);
  }
  else if (filter_type == renderer_type_radio_options)
  {
    widget = new FilterGenre(2, NUX_TRACKER_LOCATION);
  }
  else
  {
    LOG_WARNING(logger) << "Do not understand filter of type \""
                        << filter_type
                        << "\"";
  }

  if (widget)
    widget->SetFilter(filter);

  return widget;
}
Ejemplo n.º 4
0
/**
 * filter on name and type
 * @param opts
 * @param currpath
 * @param num_glob_call
 */
void filter_results(struct opt_info * opts, char *currpath,
        int *num_glob_call) {
    glob_t gbuf;
    int typematches = 1;
    memset(&gbuf, 0, sizeof ( gbuf));
    if (((*num_glob_call) == 0) && glob(opts->name_arg, 0, NULL, &gbuf) == 0) {
        for (size_t i = 0; i < gbuf.gl_pathc; i++) {
            if (opts->type_flag) { /* looking for type? */
                struct stat pstat;
                /* make sure you can open the file */
                if (stat(gbuf.gl_pathv[i], &pstat) < 0) {
                    report_err("stat", gbuf.gl_pathv[i]);
                    continue;
                }
                typematches = filter_type(opts->type_arg, pstat.st_mode);
            }
            if (typematches) {
                printf("%s/%s\n", currpath, gbuf.gl_pathv[i]);
            }
        }
    }
    (*num_glob_call)++;
}
Ejemplo n.º 5
0
/** Filtering conversion shim function for implicitly adapting
 *  <code>float</code> floating points as format arguments.
 */
inline stlsoft::basic_shim_string<ff_char_t, 32> filter_type(float value, float const*, ff_char_t const volatile*)
{
    double value2 = value;

    return filter_type(value2, &value2, static_cast<ff_char_t const volatile*>(0));
}
Ejemplo n.º 6
0
static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, const char* dir, const char* sub)
{
	DIR* d;

	d = opendir(dir);
	if (!d) {
		/* LCOV_EXCL_START */
		msg_error("Error opening directory '%s'. %s.\n", dir, strerror(errno));
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}

	while (1) {
		char path_next[PATH_MAX];
		char sub_next[PATH_MAX];
		char out[PATH_MAX];
		struct snapraid_filter* reason = 0;
		struct stat st;
		const char* name;
		struct dirent* dd;

		/* clear errno to detect erroneous conditions */
		errno = 0;
		dd = readdir(d);
		if (dd == 0 && errno != 0) {
			/* LCOV_EXCL_START */
			msg_error("Error reading directory '%s'. %s.\n", dir, strerror(errno));
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}
		if (dd == 0) {
			break; /* finished */
		}

		/* skip "." and ".." files */
		name = dd->d_name;
		if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
			continue;

		pathprint(path_next, sizeof(path_next), "%s%s", dir, name);
		pathprint(sub_next, sizeof(sub_next), "%s%s", sub, name);

		/* exclude hidden files even before calling lstat() */
		if (disk != 0 && filter_hidden(state->filter_hidden, dd) != 0) {
			msg_verbose("Excluding hidden '%s'\n", path_next);
			continue;
		}

		/* exclude content files even before calling lstat() */
		if (disk != 0 && filter_content(&state->contentlist, path_next) != 0) {
			msg_verbose("Excluding content '%s'\n", path_next);
			continue;
		}

#if HAVE_STRUCT_DIRENT_D_STAT
		/* convert dirent to lstat result */
		dirent_lstat(dd, &st);

		/* if the st_mode field is missing, takes care to fill it using normal lstat() */
		/* at now this can happen only in Windows (with HAVE_STRUCT_DIRENT_D_STAT defined), */
		/* because we use a directory reading method that doesn't read info about ReparsePoint. */
		/* Note that here we cannot call here lstat_sync(), because we don't know what kind */
		/* of file is it, and lstat_sync() doesn't always work */
		if (st.st_mode == 0) {
			if (lstat(path_next, &st) != 0) {
				/* LCOV_EXCL_START */
				msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
				exit(EXIT_FAILURE);
				/* LCOV_EXCL_STOP */
			}
		}
#else
		/* get lstat info about the file */
		if (lstat(path_next, &st) != 0) {
			/* LCOV_EXCL_START */
			msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno));
			exit(EXIT_FAILURE);
			/* LCOV_EXCL_STOP */
		}
#endif

		if (S_ISREG(st.st_mode)) {
			if (disk == 0 || filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0) {
				search_file(state, path_next, st.st_size, st.st_mtime, STAT_NSEC(&st));
			} else {
				msg_verbose("Excluding link '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
			}
		} else if (S_ISDIR(st.st_mode)) {
			if (disk == 0 || filter_dir(&state->filterlist, &reason, disk->name, sub_next) == 0) {
				pathslash(path_next, sizeof(path_next));
				pathslash(sub_next, sizeof(sub_next));
				search_dir(state, disk, path_next, sub_next);
			} else {
				msg_verbose("Excluding directory '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out)));
			}
		}
	}

	if (closedir(d) != 0) {
		/* LCOV_EXCL_START */
		msg_error("Error closing directory '%s'. %s.\n", dir, strerror(errno));
		exit(EXIT_FAILURE);
		/* LCOV_EXCL_STOP */
	}
}
    inline std::string filter_type(extrasuperhero const& hero, extrasuperhero const*, char const volatile* p)
    {
        superhero const& regular_hero = hero;

        return filter_type(regular_hero, &regular_hero, p);
    }
Ejemplo n.º 8
0
/**
 *
 * \brief Handle the file.
 *
 * \param file_name is the filename which has to be checked against the find options.
 * \param file_info file information of file_name which has to be checked against the find options.
 * \param params is the program argument vector.
 *
 * \return int represents the exit status of do_file.
 * \retval EXIT_SUCCESS successful exit status.
 * \retval EXIT_FAILURE failing exit status.
 */
static int do_file(const char* file_name, StatType* file_info, const char* const* params)
{

    int i = 1;
    boolean printed_print = FALSE; /* flag for: already printed */
    boolean printed_ls = FALSE; /* flag for: already printed in ls mode*/
    boolean to_print_ls = FALSE; /* flag for: must be printed in ls mode*/
    boolean matched = FALSE; /* flag for: line meets filter criteria */
    boolean filter = FALSE; /* flag for: result of filter */
    boolean filtered = FALSE; /* flag for: at least one filter has been applied */
    boolean path_given = FALSE; /* flag for: first commandline parameter is a file/dir */
    char test_char = '\0';

    /*check if first command line parameter is an option or a file/dir*/
    test_char = *params[1];
    path_given = ('-' == test_char) ? FALSE : TRUE;
    matched = path_given;

    /* loop all command line parameters */
    while (NULL != params[i])
    {
        /* could be later optimzed by remembering for each params[i] element, if it
         * is matched for the i-th parameter, store for each filter in an bool filter_array[argc]
         * if strcmp matched for the filter e.g for type cmp_filter_type[arg]
         */
        /* apply filters */
        if (strcmp(params[i], PARAM_STR_TYPE) == 0)
        {
            filter = filter_type(i, params, file_info);
            matched = matched && filter;
            filtered = TRUE;
            ++i;
            continue;
        }

        if (strcmp(params[i], PARAM_STR_USER) == 0)
        {
            filter = filter_user(i, params, file_info);
            matched = matched && filter;
            filtered = TRUE;
            ++i;
            continue;
        }

        if (strcmp(params[i], PARAM_STR_NOUSER) == 0)
        {
            filter = filter_nouser(file_info);
            matched = matched && filter;
            filtered = TRUE;
            ++i;
            continue;
        }

        if (strcmp(params[i], PARAM_STR_NAME) == 0)
        {
            filter = filter_name(file_name, i, params);
            matched = matched && filter;
            filtered = TRUE;
            ++i;
            continue;
        }

        if (strcmp(params[i], PARAM_STR_PATH) == 0)
        {
            filter = filter_path(file_name, i, params);
            matched = matched && filter;
            filtered = TRUE;
            ++i;
            continue;
        }

        /* apply actions */
        if (strcmp(params[i], PARAM_STR_LS) == 0)
        {
            if (filtered && matched)
            {
                print_detail_ls(file_name, file_info);
                printed_ls = TRUE;
            }
            else
            {
                /* special case -ls defined before filter parameters */
                to_print_ls = TRUE;
            }
        }
        if (strcmp(params[i], PARAM_STR_PRINT) == 0)
        {
            if (filtered && matched)
            {
                print_detail_print(file_name);
                printed_print = TRUE;
            }
        }

        ++i;
    }

    /* special cases */
    /* no -print action or no filter parameter on command line */
    if ((matched && !printed_print && !printed_ls) || (!filtered))
    {
        if (to_print_ls)
        {
            print_detail_ls(file_name, file_info);
        }
        else
        {
            print_detail_print(file_name);
        }
    }

    return EXIT_SUCCESS;
}