Angus Leeming wrote:
> The existing lyx::support::glob() is just a wrapper for the system
> glob(). As such, Path will be used even if the function takes a dir
> param.
>
> My replacement function does take a dir param and does not use chdir:
>
> template <typename StorageT>
> void glob(StorageT & matches,
> std::string const & pattern,
> boost::filesystem::path const & working_dir,
> glob_flags flags);
>
> I'm not yet ready to replace the existing function with this (because I
> have still to ensure that boost::throw_exception() is not called should
> the transformed globbing pattern upset boost::regex). However, I can
> certainly change the function API to take a dir parameter.
Done. See attached patch (committed).
--
Angus
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.949
diff -u -p -r1.949 ChangeLog
--- src/frontends/xforms/ChangeLog 26 Nov 2004 12:31:38 -0000 1.949
+++ src/frontends/xforms/ChangeLog 26 Nov 2004 14:34:46 -0000
@@ -1,5 +1,10 @@
2004-11-26 Angus Leeming <[EMAIL PROTECTED]>
+ * FormFiledialog.C (expand_globs): changes due to the changed
+ lyx::support::glob API.
+
+2004-11-26 Angus Leeming <[EMAIL PROTECTED]>
+
* FileDialog.C:
* FormFiledialog.C: changes due to the changed FileFilterList API.
Index: src/frontends/xforms/FormFiledialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormFiledialog.C,v
retrieving revision 1.58
diff -u -p -r1.58 FormFiledialog.C
--- src/frontends/xforms/FormFiledialog.C 26 Nov 2004 12:31:38 -0000 1.58
+++ src/frontends/xforms/FormFiledialog.C 26 Nov 2004 14:34:47 -0000
@@ -25,7 +25,6 @@
#include "support/globbing.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
-#include "support/path.h"
#include "support/tostr.h"
#include "lyx_forms.h"
@@ -70,7 +69,6 @@ using lyx::support::GetEnvPath;
using lyx::support::LyXReadLink;
using lyx::support::MakeAbsPath;
using lyx::support::OnlyFilename;
-using lyx::support::Path;
using lyx::support::split;
using lyx::support::subst;
using lyx::support::suffixIs;
@@ -99,8 +97,6 @@ namespace {
vector<string> const expand_globs(string const & mask,
string const & directory)
{
- Path p(directory);
-
// Split into individual globs and then call 'glob' on each one.
typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
boost::char_separator<char> const separator(" ");
@@ -109,10 +105,9 @@ vector<string> const expand_globs(string
Tokenizer const tokens(mask, separator);
Tokenizer::const_iterator it = tokens.begin();
Tokenizer::const_iterator const end = tokens.end();
- for (; it != end; ++it) {
- vector<string> const tmp = lyx::support::glob(*it);
- matches.insert(matches.end(), tmp.begin(), tmp.end());
- }
+ for (; it != end; ++it)
+ lyx::support::glob(matches, *it, directory);
+
return matches;
}
@@ -455,7 +450,7 @@ void FileDialog::Private::SetFilters(Fil
ss << ' ';
ss << *it;
}
-
+
mask_ = ss.str();
fl_set_input(file_dlg_form_->PatBox, mask_.c_str());
}
Index: src/support/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.278
diff -u -p -r1.278 ChangeLog
--- src/support/ChangeLog 26 Nov 2004 12:31:39 -0000 1.278
+++ src/support/ChangeLog 26 Nov 2004 14:34:49 -0000
@@ -1,5 +1,12 @@
2004-11-26 Angus Leeming <[EMAIL PROTECTED]>
+ * globbing.[Ch] (glob): change API to:
+ 1. Append matches to the input container.
+ 2. Require a working_dir parameter. The function invokes chdir
+ internally (through use of Path).
+
+2004-11-26 Angus Leeming <[EMAIL PROTECTED]>
+
* filefilterlist.C (convert_brace_glob): moved here from
globbing.[Ch].
Index: src/support/filefilterlist.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filefilterlist.C,v
retrieving revision 1.2
diff -u -p -r1.2 filefilterlist.C
--- src/support/filefilterlist.C 26 Nov 2004 12:31:39 -0000 1.2
+++ src/support/filefilterlist.C 26 Nov 2004 14:34:49 -0000
@@ -74,7 +74,7 @@ string const convert_brace_glob(string c
return pattern;
}
-
+
} // namespace anon
@@ -98,7 +98,7 @@ FileFilterList::Filter::Filter(std::stri
globs_ = vector<string>(tokens.begin(), tokens.end());
}
-
+
FileFilterList::FileFilterList(string const & qt_style_filter)
{
string const filter = qt_style_filter
@@ -171,7 +171,7 @@ string const FileFilterList::as_string()
ss << ' ';
ss << *git;
}
-
+
if (has_description)
ss << ')';
}
Index: src/support/globbing.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/globbing.C,v
retrieving revision 1.10
diff -u -p -r1.10 globbing.C
--- src/support/globbing.C 26 Nov 2004 12:31:39 -0000 1.10
+++ src/support/globbing.C 26 Nov 2004 14:34:49 -0000
@@ -11,6 +11,7 @@
#include <config.h>
#include "support/globbing.h"
+#include "support/path.h"
#include <glob.h>
@@ -21,16 +22,22 @@ using std::vector;
namespace lyx {
namespace support {
-vector<string> const glob(string const & pattern, int flags)
+void glob(vector<string> & matches,
+ string const & pattern,
+ string const & working_dir,
+ int flags)
{
+ Path p(working_dir);
+
glob_t glob_buffer;
glob_buffer.gl_offs = 0;
glob(pattern.c_str(), flags, 0, &glob_buffer);
- vector<string> const matches(glob_buffer.gl_pathv,
- glob_buffer.gl_pathv +
- glob_buffer.gl_pathc);
+
+ matches.insert(matches.end(),
+ glob_buffer.gl_pathv,
+ glob_buffer.gl_pathv + glob_buffer.gl_pathc);
+
globfree(&glob_buffer);
- return matches;
}
} // namespace support
Index: src/support/globbing.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/globbing.h,v
retrieving revision 1.5
diff -u -p -r1.5 globbing.h
--- src/support/globbing.h 26 Nov 2004 12:31:39 -0000 1.5
+++ src/support/globbing.h 26 Nov 2004 14:34:49 -0000
@@ -19,11 +19,16 @@ namespace lyx {
namespace support {
/** A wrapper for the Posix function 'glob'.
+ * \param matches files found to match \c pattern are appended.
* \param pattern the glob to be expanded. Eg "*.[Ch]".
+ * \param working_dir the starting directory from which \c pattern
+ * is to be expanded. Used only if \c pattern is a relative path.
* \param flags flags to be passed to the system function. See 'man glob'.
- * \returns a vector of the files found to match \c pattern.
*/
-std::vector<std::string> const glob(std::string const & pattern, int flags = 0);
+void glob(std::vector<std::string> & matches,
+ std::string const & pattern,
+ std::string const & working_dir,
+ int flags = 0);
} // namespace support
} // namespace lyx