From 5a338c3927e05f489122191201feaebb62ca8441 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 26 Nov 2004 14:37:40 +0000 Subject: [PATCH] Change glob() API to accept a dir parameter. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9313 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/xforms/ChangeLog | 5 +++++ src/frontends/xforms/FormFiledialog.C | 13 ++++--------- src/support/ChangeLog | 7 +++++++ src/support/filefilterlist.C | 6 +++--- src/support/globbing.C | 17 ++++++++++++----- src/support/globbing.h | 9 +++++++-- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 0eb91a053f..bcdd25cc54 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2004-11-26 Angus Leeming + + * FormFiledialog.C (expand_globs): changes due to the changed + lyx::support::glob API. + 2004-11-26 Angus Leeming * FileDialog.C: diff --git a/src/frontends/xforms/FormFiledialog.C b/src/frontends/xforms/FormFiledialog.C index b0fbdb4850..1c8aec4024 100644 --- a/src/frontends/xforms/FormFiledialog.C +++ b/src/frontends/xforms/FormFiledialog.C @@ -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 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 > Tokenizer; boost::char_separator const separator(" "); @@ -109,10 +105,9 @@ vector const expand_globs(string const & mask, Tokenizer const tokens(mask, separator); Tokenizer::const_iterator it = tokens.begin(); Tokenizer::const_iterator const end = tokens.end(); - for (; it != end; ++it) { - vector 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(FileFilterList const & filters) ss << ' '; ss << *it; } - + mask_ = ss.str(); fl_set_input(file_dlg_form_->PatBox, mask_.c_str()); } diff --git a/src/support/ChangeLog b/src/support/ChangeLog index a63249d18f..f854d807b6 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,10 @@ +2004-11-26 Angus Leeming + + * 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 * filefilterlist.C (convert_brace_glob): moved here from diff --git a/src/support/filefilterlist.C b/src/support/filefilterlist.C index 109a045e02..9c53eb3f6f 100644 --- a/src/support/filefilterlist.C +++ b/src/support/filefilterlist.C @@ -74,7 +74,7 @@ string const convert_brace_glob(string const & glob) return pattern; } - + } // namespace anon @@ -98,7 +98,7 @@ FileFilterList::Filter::Filter(std::string const & description, globs_ = vector(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() const ss << ' '; ss << *git; } - + if (has_description) ss << ')'; } diff --git a/src/support/globbing.C b/src/support/globbing.C index 0000f34e3a..dbc6b0ab4e 100644 --- a/src/support/globbing.C +++ b/src/support/globbing.C @@ -11,6 +11,7 @@ #include #include "support/globbing.h" +#include "support/path.h" #include @@ -21,16 +22,22 @@ using std::vector; namespace lyx { namespace support { -vector const glob(string const & pattern, int flags) +void glob(vector & 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 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 diff --git a/src/support/globbing.h b/src/support/globbing.h index e4c53c808b..d495a9670c 100644 --- a/src/support/globbing.h +++ b/src/support/globbing.h @@ -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 const glob(std::string const & pattern, int flags = 0); +void glob(std::vector & matches, + std::string const & pattern, + std::string const & working_dir, + int flags = 0); } // namespace support } // namespace lyx