mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-19 21:26:26 +01:00
Move member functions from PathScanner to functions in pbd/file_utils.h
This allows us to remove PathScanner source file and keep PathScanner class as header only until it is removed
This commit is contained in:
parent
2334880bc9
commit
e75f227fe3
5 changed files with 165 additions and 193 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 2007 Tim Mayberry
|
||||
Copyright (C) 2007-2014 Tim Mayberry
|
||||
Copyright (C) 1998-2014 Paul Davis
|
||||
|
||||
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
|
||||
|
|
@ -42,8 +43,15 @@
|
|||
/* close(), read(), write() */
|
||||
#ifdef COMPILER_MSVC
|
||||
#include <io.h> // Microsoft's nearest equivalent to <unistd.h>
|
||||
#include <ardourext/misc.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <regex.h>
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#define strtok_r strtok_s
|
||||
#endif
|
||||
|
||||
#include "pbd/compose.h"
|
||||
|
|
@ -51,6 +59,7 @@
|
|||
#include "pbd/debug.h"
|
||||
#include "pbd/error.h"
|
||||
#include "pbd/pathscanner.h"
|
||||
#include "pbd/pathexpand.h"
|
||||
#include "pbd/stl_delete.h"
|
||||
|
||||
#include "i18n.h"
|
||||
|
|
@ -161,6 +170,123 @@ find_file_in_search_path(const Searchpath& search_path,
|
|||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
regexp_filter (const string& str, void *arg)
|
||||
{
|
||||
regex_t* pattern = (regex_t*)arg;
|
||||
return regexec (pattern, str.c_str(), 0, 0, 0) == 0;
|
||||
}
|
||||
|
||||
void
|
||||
find_files_matching_regex (vector<string>& result,
|
||||
const std::string& dirpath,
|
||||
const std::string& regexp,
|
||||
bool match_fullpath, bool return_fullpath,
|
||||
long limit,
|
||||
bool recurse)
|
||||
{
|
||||
int err;
|
||||
char msg[256];
|
||||
regex_t compiled_pattern;
|
||||
|
||||
if ((err = regcomp (&compiled_pattern, regexp.c_str(),
|
||||
REG_EXTENDED|REG_NOSUB))) {
|
||||
|
||||
regerror (err, &compiled_pattern,
|
||||
msg, sizeof (msg));
|
||||
|
||||
error << "Cannot compile soundfile regexp for use ("
|
||||
<< msg
|
||||
<< ")"
|
||||
<< endmsg;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
find_files_matching_filter (result, dirpath,
|
||||
regexp_filter, &compiled_pattern,
|
||||
match_fullpath, return_fullpath,
|
||||
limit, recurse);
|
||||
|
||||
regfree (&compiled_pattern);
|
||||
}
|
||||
|
||||
void
|
||||
find_files_matching_filter (vector<string>& result,
|
||||
const string &dirpath,
|
||||
bool (*filter)(const string &, void *),
|
||||
void *arg,
|
||||
bool match_fullpath, bool return_fullpath,
|
||||
long limit,
|
||||
bool recurse)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *finfo;
|
||||
char *pathcopy = strdup (search_path_expand (dirpath).c_str());
|
||||
char *thisdir;
|
||||
string fullpath;
|
||||
string search_str;
|
||||
long nfound = 0;
|
||||
char *saveptr;
|
||||
|
||||
if ((thisdir = strtok_r (pathcopy, G_SEARCHPATH_SEPARATOR_S, &saveptr)) == 0 ||
|
||||
strlen (thisdir) == 0) {
|
||||
free (pathcopy);
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
if ((dir = opendir (thisdir)) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((finfo = readdir (dir)) != 0) {
|
||||
|
||||
if ((finfo->d_name[0] == '.' && finfo->d_name[1] == '\0') ||
|
||||
(finfo->d_name[0] == '.' && finfo->d_name[1] == '.' && finfo->d_name[2] == '\0')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fullpath = Glib::build_filename (thisdir, finfo->d_name);
|
||||
|
||||
struct stat statbuf;
|
||||
if (stat (fullpath.c_str(), &statbuf) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (statbuf.st_mode & S_IFDIR && recurse) {
|
||||
find_files_matching_filter (result, fullpath, filter, arg, match_fullpath, return_fullpath, limit, recurse);
|
||||
} else {
|
||||
|
||||
if (match_fullpath) {
|
||||
search_str = fullpath;
|
||||
} else {
|
||||
search_str = finfo->d_name;
|
||||
}
|
||||
|
||||
if (!filter(search_str, arg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (return_fullpath) {
|
||||
result.push_back(fullpath);
|
||||
} else {
|
||||
result.push_back(finfo->d_name);
|
||||
}
|
||||
|
||||
nfound++;
|
||||
}
|
||||
}
|
||||
closedir (dir);
|
||||
|
||||
} while ((limit < 0 || (nfound < limit)) && (thisdir = strtok_r (0, G_SEARCHPATH_SEPARATOR_S, &saveptr)));
|
||||
|
||||
free (pathcopy);
|
||||
return;
|
||||
}
|
||||
|
||||
bool
|
||||
copy_file(const std::string & from_path, const std::string & to_path)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue