summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-04-15 14:41:38 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-04-15 14:41:38 +0000
commit5565078136e72c6c098fc4b4b688f6c1af58d069 (patch)
treedb7aa276be3e7b08480eda6bc1e1e5aee40c8af4
parent1d1de9b669a141954a252a1d0173ddc6348cba9c (diff)
remove a bunch of explicit uses of '/' as a directory separator; use Glib::build_filename() to construct more paths rather than doing it "by hand"; fixup small logic mistake (which had no actual consequences) in export track marker dialog
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6909 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/ardour_ui.cc15
-rw-r--r--gtk2_ardour/editor_audio_import.cc5
-rw-r--r--gtk2_ardour/editor_region_list.cc2
-rw-r--r--gtk2_ardour/export_range_markers_dialog.cc12
-rw-r--r--gtk2_ardour/imageframe_socket_handler.cc7
-rw-r--r--gtk2_ardour/new_session_dialog.cc8
-rw-r--r--gtk2_ardour/opts.cc2
-rw-r--r--libs/ardour/audiofilesource.cc35
-rw-r--r--libs/ardour/audiosource.cc2
-rw-r--r--libs/ardour/import.cc5
-rw-r--r--libs/ardour/named_selection.cc2
-rw-r--r--libs/ardour/plugin_manager.cc4
-rw-r--r--libs/ardour/redirect.cc2
-rw-r--r--libs/ardour/session.cc25
-rw-r--r--libs/ardour/session_state.cc37
15 files changed, 62 insertions, 101 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc
index a12783ac94..979dc1237c 100644
--- a/gtk2_ardour/ardour_ui.cc
+++ b/gtk2_ardour/ardour_ui.cc
@@ -1039,7 +1039,7 @@ ARDOUR_UI::redisplay_recent_sessions ()
/* remove any trailing / */
- if (fullpath[fullpath.length()-1] == '/') {
+ if (fullpath[fullpath.length()-1] == G_DIR_SEPARATOR) {
fullpath = fullpath.substr (0, fullpath.length()-1);
}
@@ -2204,11 +2204,8 @@ ARDOUR_UI::load_cmdline_session (const Glib::ustring& session_name, const Glib::
if (Glib::file_test (session_path, Glib::FILE_TEST_IS_DIR)) {
Glib::ustring predicted_session_file;
-
- predicted_session_file = session_path;
- predicted_session_file += '/';
- predicted_session_file += session_name;
- predicted_session_file += Session::statefile_suffix();
+
+ predicted_session_file = Glib::build_filename (session_path, session_name + Session::statefile_suffix());
if (Glib::file_test (predicted_session_file, Glib::FILE_TEST_EXISTS)) {
existing_session = true;
@@ -2497,9 +2494,9 @@ ARDOUR_UI::get_session_parameters (bool backend_audio_is_running, bool should_be
convert what they typed into a path & a name
*/
- if (session_name[0] == '/' ||
- (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == '/') ||
- (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == '/')) {
+ if (Glib::path_is_absolute (session_name) ||
+ (session_name.length() > 2 && session_name[0] == '.' && session_name[1] == G_DIR_SEPARATOR) ||
+ (session_name.length() > 3 && session_name[0] == '.' && session_name[1] == '.' && session_name[2] == G_DIR_SEPARATOR)) {
session_path = Glib::path_get_dirname (session_name);
session_name = Glib::path_get_basename (session_name);
diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc
index 3f9192828e..4f1a63b42e 100644
--- a/gtk2_ardour/editor_audio_import.cc
+++ b/gtk2_ardour/editor_audio_import.cc
@@ -534,10 +534,7 @@ Editor::embed_sndfiles (vector<Glib::ustring> paths, bool multifile,
/* lets see if we can link it into the session */
- linked_path = session->sound_dir();
- linked_path += '/';
- linked_path += Glib::path_get_basename (path);
-
+ linked_path = Glib::build_filename (session->sound_dir(), Glib::path_get_basename (path));
path_to_use = path;
if (link (path.c_str(), linked_path.c_str()) == 0) {
diff --git a/gtk2_ardour/editor_region_list.cc b/gtk2_ardour/editor_region_list.cc
index 0e14391895..d56bf4844e 100644
--- a/gtk2_ardour/editor_region_list.cc
+++ b/gtk2_ardour/editor_region_list.cc
@@ -149,7 +149,7 @@ Editor::add_audio_region_to_region_display (boost::shared_ptr<AudioRegion> regio
}
row[region_list_columns.color_] = c;
- if (region->source()->name()[0] == '/') { // external file
+ if (Glib::path_is_absolute (region->source()->name())) { // external file
/* XXX there was old code here to try to show an abbreviated version
of the path name for whole file regions.
diff --git a/gtk2_ardour/export_range_markers_dialog.cc b/gtk2_ardour/export_range_markers_dialog.cc
index 50b8098d60..5a04b25f86 100644
--- a/gtk2_ardour/export_range_markers_dialog.cc
+++ b/gtk2_ardour/export_range_markers_dialog.cc
@@ -110,22 +110,16 @@ ExportRangeMarkersDialog::process_range_markers_export(Locations::LocationList&
string
ExportRangeMarkersDialog::get_target_filepath(string path, string filename, string postfix)
{
- string target_path = path;
- if ((target_path.find_last_of ('/')) != string::npos) {
- target_path += '/';
- }
-
- string target_filepath = target_path + filename + postfix;
+ string target_filepath = Glib::build_filename (path, filename + postfix);
struct stat statbuf;
- for(int counter=1; (stat (target_filepath.c_str(), &statbuf) == 0); counter++){
+ for (int counter=1; Glib::file_test (target_filepath, Glib::FILE_TEST_EXISTS); counter++) {
// while file exists
ostringstream scounter;
scounter.flush();
scounter << counter;
- target_filepath =
- target_path + filename + "_" + scounter.str() + postfix;
+ target_filepath = Glib::build_filename (path, filename + "_" + scounter.str() + postfix);
}
return target_filepath;
diff --git a/gtk2_ardour/imageframe_socket_handler.cc b/gtk2_ardour/imageframe_socket_handler.cc
index 9279a177ee..363094990d 100644
--- a/gtk2_ardour/imageframe_socket_handler.cc
+++ b/gtk2_ardour/imageframe_socket_handler.cc
@@ -1616,12 +1616,7 @@ ImageFrameSocketHandler::handle_session_name_request(const char* msg)
std::string sessionName = currentSession->name() ;
std::string sessionPath = currentSession->path() ;
- if(sessionPath[sessionPath.length() -1] != '/')
- {
- sessionPath.append("/") ;
- }
-
- sessionPath.append(sessionName) ;
+ sessionPath = Glib::build_filename (sessionPath, sessionName);
std::ostringstream msgBuf ;
msgBuf << ardourvis::RETURN_DATA << ardourvis::SESSION_NAME ;
diff --git a/gtk2_ardour/new_session_dialog.cc b/gtk2_ardour/new_session_dialog.cc
index d7f7539185..98ff6a2586 100644
--- a/gtk2_ardour/new_session_dialog.cc
+++ b/gtk2_ardour/new_session_dialog.cc
@@ -618,8 +618,8 @@ NewSessionDialog::set_session_folder(const Glib::ustring& dir)
std::string
NewSessionDialog::session_name() const
{
- std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
- std::string::size_type position = str.find_last_of ('/');
+ std::string str = Glib::filename_from_utf8 (m_open_filechooser->get_filename());
+ std::string::size_type position = str.find_last_of (G_DIR_SEPARATOR);
str = str.substr (position+1);
position = str.find_last_of ('.');
str = str.substr (0, position);
@@ -1073,9 +1073,9 @@ NewSessionDialog::reset_recent()
std::vector<const gchar*> item;
std::string fullpath = *(*i);
- /* remove any trailing / */
+ /* remove any trailing separator */
- if (fullpath[fullpath.length()-1] == '/') {
+ if (fullpath[fullpath.length()-1] == G_DIR_SEPARATOR) {
fullpath = fullpath.substr (0, fullpath.length()-1);
}
diff --git a/gtk2_ardour/opts.cc b/gtk2_ardour/opts.cc
index a6c90495a4..8183bd265f 100644
--- a/gtk2_ardour/opts.cc
+++ b/gtk2_ardour/opts.cc
@@ -73,7 +73,7 @@ int
ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
{
const char *optstring = "U:hSbvVnOdc:C:m:N:k:p:";
- const char *execname = strrchr (argv[0], '/');
+ const char *execname = strrchr (argv[0], G_DIR_SEPARATOR);
if (getenv ("ARDOUR_SAE")) {
menus_file = "ardour-sae.menus";
diff --git a/libs/ardour/audiofilesource.cc b/libs/ardour/audiofilesource.cc
index b612974789..9141456e22 100644
--- a/libs/ardour/audiofilesource.cc
+++ b/libs/ardour/audiofilesource.cc
@@ -406,12 +406,14 @@ AudioFileSource::move_to_trash (const ustring& trash_dir_name)
cerr << "from " << _path << " dead dir looks like " << newpath << endl;
- newpath += '/';
- newpath += trash_dir_name;
- newpath += '/';
- newpath += Glib::path_get_basename (_path);
+ vector<string> p;
+ p.push_back (newpath);
+ p.push_back (trash_dir_name);
+ p.push_back (Glib::path_get_basename (_path));
- if (access (newpath.c_str(), F_OK) == 0) {
+ newpath = Glib::build_filename (p);
+
+ if (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS)) {
/* the new path already exists, try versioning */
@@ -422,7 +424,7 @@ AudioFileSource::move_to_trash (const ustring& trash_dir_name)
snprintf (buf, sizeof (buf), "%s.%d", newpath.c_str(), version);
newpath_v = buf;
- while (access (newpath_v.c_str(), F_OK) == 0 && version < 999) {
+ while (Glib::file_test (newpath_v, Glib::FILE_TEST_EXISTS) && version < 999) {
snprintf (buf, sizeof (buf), "%s.%d", newpath.c_str(), ++version);
newpath_v = buf;
}
@@ -442,7 +444,7 @@ AudioFileSource::move_to_trash (const ustring& trash_dir_name)
}
if (::rename (_path.c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename audio file source from %1 to %2 (%3)"),
+ error << string_compose (_("cannot 1 rename audio file source from %1 to %2 (%3)"),
_path, newpath, strerror (errno))
<< endmsg;
return -1;
@@ -477,7 +479,7 @@ AudioFileSource::find (ustring pathstr, bool must_exist, bool embedded,
isnew = false;
- if (pathstr[0] != '/') {
+ if (!Glib::path_is_absolute (pathstr)) {
/* non-absolute pathname: find pathstr in search path */
@@ -497,12 +499,7 @@ AudioFileSource::find (ustring pathstr, bool must_exist, bool embedded,
for (vector<ustring>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
- fullpath = *i;
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += pathstr;
+ fullpath = Glib::build_filename (*i, pathstr);
/* i (paul) made a nasty design error by using ':' as a special character in
Ardour 0.99 .. this hack tries to make things sort of work.
@@ -526,13 +523,7 @@ AudioFileSource::find (ustring pathstr, bool must_exist, bool embedded,
*/
ustring shorter = pathstr.substr (0, pos);
- fullpath = *i;
-
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += shorter;
+ fullpath = Glib::build_filename (*i, shorter);
if (Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
chan = atoi (pathstr.substr (pos+1));
@@ -686,7 +677,7 @@ AudioFileSource::set_name (ustring newname, bool destructive)
}
if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename audio file %1 to %2"), _name, newpath) << endmsg;
+ error << string_compose (_("cannot 2 rename audio file %1 to %2"), _name, newpath) << endmsg;
return -1;
}
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index 5bd9712762..fbac57dc7c 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -175,7 +175,7 @@ AudioSource::rename_peakfile (ustring newpath)
if (access (oldpath.c_str(), F_OK) == 0) {
if (rename (oldpath.c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename peakfile for %1 from %2 to %3 (%4)"), _name, oldpath, newpath, strerror (errno)) << endmsg;
+ error << string_compose (_("cannot 3 rename peakfile for %1 from %2 to %3 (%4)"), _name, oldpath, newpath, strerror (errno)) << endmsg;
return -1;
}
}
diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc
index 496c43fca2..08e0c537c4 100644
--- a/libs/ardour/import.cc
+++ b/libs/ardour/import.cc
@@ -153,9 +153,8 @@ get_paths_for_new_sources (const bool allow_replacing, const string& import_file
std::string filepath;
- filepath = session_dir;
- filepath += '/';
- filepath += get_non_existent_filename (allow_replacing, session_dir, basename, n, channels);
+ filepath = Glib::build_filename (session_dir,
+ get_non_existent_filename (allow_replacing, session_dir, basename, n, channels));
new_paths.push_back (filepath);
}
diff --git a/libs/ardour/named_selection.cc b/libs/ardour/named_selection.cc
index fbb4b748df..922cd798aa 100644
--- a/libs/ardour/named_selection.cc
+++ b/libs/ardour/named_selection.cc
@@ -42,7 +42,7 @@ NamedSelection::NamedSelection (string n, PlaylistList& l)
string new_name;
/* rename playlists to reflect our ownership */
-
+
new_name = name;
new_name += '/';
new_name += (*i)->name();
diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc
index f45ef27b36..78d69d10c6 100644
--- a/libs/ardour/plugin_manager.cc
+++ b/libs/ardour/plugin_manager.cc
@@ -166,7 +166,7 @@ PluginManager::ladspa_refresh ()
/* allow LADSPA_PATH to augment, not override standard locations */
/* Only add standard locations to ladspa_path if it doesn't
- * already contain them. Check for trailing '/'s too.
+ * already contain them. Check for trailing dir separators too.
*/
int i;
@@ -177,7 +177,7 @@ PluginManager::ladspa_refresh ()
case ':' :
case '\0':
continue;
- case '/' :
+ case G_DIR_SEPARATOR:
if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
continue;
diff --git a/libs/ardour/redirect.cc b/libs/ardour/redirect.cc
index 6cfd2e97c6..6995632c3f 100644
--- a/libs/ardour/redirect.cc
+++ b/libs/ardour/redirect.cc
@@ -344,7 +344,7 @@ Redirect::load_automation (string path)
{
string fullpath;
- if (path[0] == '/') { // legacy
+ if (Glib::path_is_absolute (path)) { // legacy
fullpath = path;
} else {
fullpath = Glib::build_filename(_session.automation_dir(), path);
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index cf84d794c4..be5b5270c8 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -156,17 +156,14 @@ Session::find_session (string str, string& path, string& snapshot, bool& isnew)
if (S_ISDIR (statbuf.st_mode)) {
- string::size_type slash = str.find_last_of ('/');
+ string::size_type slash = str.find_last_of (G_DIR_SEPARATOR);
if (slash == string::npos) {
/* a subdirectory of cwd, so statefile should be ... */
string tmp;
- tmp = str;
- tmp += '/';
- tmp += str;
- tmp += _statefile_suffix;
+ tmp = Glib::build_filename (str, str + _statefile_suffix);
/* is it there ? */
@@ -193,7 +190,7 @@ Session::find_session (string str, string& path, string& snapshot, bool& isnew)
} else if (S_ISREG (statbuf.st_mode)) {
- string::size_type slash = str.find_last_of ('/');
+ string::size_type slash = str.find_last_of (G_DIR_SEPARATOR);
string::size_type suffix;
/* remove the suffix */
@@ -251,7 +248,7 @@ Session::find_session (string str, string& path, string& snapshot, bool& isnew)
as "dirname" does.
*/
- string::size_type slash = str.find_last_of ('/');
+ string::size_type slash = str.find_last_of (G_DIR_SEPARATOR);
if (slash == string::npos) {
@@ -3208,7 +3205,7 @@ Session::change_audio_path_by_name (string path, string oldname, string newname,
string::size_type slash;
string::size_type dash;
- if ((slash = path.find_last_of ('/')) == string::npos) {
+ if ((slash = path.find_last_of (G_DIR_SEPARATOR)) == string::npos) {
return "";
}
@@ -3245,7 +3242,7 @@ Session::change_audio_path_by_name (string path, string oldname, string newname,
/* find last slash */
- if ((slash = path.find_last_of ('/')) == string::npos) {
+ if ((slash = path.find_last_of (G_DIR_SEPARATOR)) == string::npos) {
return "";
}
@@ -3341,8 +3338,7 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool
} else {
- spath += '/';
- spath += legalized;
+ spath = Glib::build_filename (spath, legalized);
if (nchan < 2) {
snprintf (buf, sizeof(buf), "%s-%u.wav", spath.c_str(), cnt);
@@ -3383,14 +3379,13 @@ Session::audio_path_from_name (string name, uint32_t nchan, uint32_t chan, bool
string foo = buf;
spath = discover_best_sound_dir ();
- spath += '/';
- string::size_type pos = foo.find_last_of ('/');
+ string::size_type pos = foo.find_last_of (G_DIR_SEPARATOR);
if (pos == string::npos) {
- spath += foo;
+ spath = Glib::build_filename (spath, foo);
} else {
- spath += foo.substr (pos + 1);
+ spath = Glib::build_filename (spath, foo.substr (pos + 1));
}
return spath;
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index ded4dc426d..781c8e1312 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -114,8 +114,8 @@ Session::first_stage_init (string fullpath, string snapshot_name)
_path = string(buf);
- if (_path[_path.length()-1] != '/') {
- _path += '/';
+ if (_path[_path.length()-1] != G_DIR_SEPARATOR) {
+ _path += G_DIR_SEPARATOR;
}
if (Glib::file_test (_path, Glib::FILE_TEST_EXISTS) && ::access (_path.c_str(), W_OK)) {
@@ -1779,7 +1779,7 @@ Session::ensure_sound_dir (string path, string& result)
/* callers expect this to be terminated ... */
- result += '/';
+ result += G_DIR_SEPARATOR;
return 0;
}
@@ -2043,7 +2043,7 @@ Session::sound_dir (bool with_path) const
string old_withpath;
old_nopath += old_sound_dir_name;
- old_nopath += '/';
+ old_nopath += G_DIR_SEPARATOR;
old_withpath = _path;
old_withpath += old_sound_dir_name;
@@ -2120,7 +2120,7 @@ Session::suffixed_search_path (string suffix, bool data)
for (vector<string>::iterator i = split_path.begin(); i != split_path.end(); ++i) {
path += *i;
path += suffix;
- path += '/';
+ path += G_DIR_SEPARATOR;
if (distance (i, split_path.end()) != 1) {
path += ':';
@@ -2230,7 +2230,7 @@ remove_end(string* state)
string statename(*state);
string::size_type start,end;
- if ((start = statename.find_last_of ('/')) != string::npos) {
+ if ((start = statename.find_last_of (G_DIR_SEPARATOR)) != string::npos) {
statename = statename.substr (start+1);
}
@@ -2502,7 +2502,7 @@ Session::get_template_list (list<string> &template_names)
string fullpath = *(*i);
int start, end;
- start = fullpath.find_last_of ('/') + 1;
+ start = fullpath.find_last_of (G_DIR_SEPARATOR) + 1;
if ((end = fullpath.find_last_of ('.')) <0) {
end = fullpath.length();
}
@@ -2641,7 +2641,7 @@ Session::find_all_sources (string path, set<string>& result)
continue;
}
- if (prop->value()[0] == '/') {
+ if (Glib::path_is_absolute (prop->value())) {
/* external file, ignore */
continue;
}
@@ -2654,7 +2654,6 @@ Session::find_all_sources (string path, set<string>& result)
std::string name;
if (AudioFileSource::find (prop->value(), true, false, is_new, chan, path, name)) {
- cerr << "Got " << path << " from XML source with prop = " << prop->value() << endl;
result.insert (path);
}
}
@@ -2674,7 +2673,7 @@ Session::find_all_sources_across_snapshots (set<string>& result, bool exclude_th
ripped = _path;
- if (ripped[ripped.length()-1] == '/') {
+ if (ripped[ripped.length()-1] == G_DIR_SEPARATOR) {
ripped = ripped.substr (0, ripped.length() - 1);
}
@@ -2844,8 +2843,6 @@ Session::cleanup_sources (Session::cleanup_report& rep)
realpath(spath.c_str(), tmppath1);
realpath((*i).c_str(), tmppath2);
- cerr << "comparing " << tmppath1 << " and " << tmppath2 << endl;
-
if (strcmp(tmppath1, tmppath2) == 0) {
used = true;
break;
@@ -2891,18 +2888,16 @@ Session::cleanup_sources (Session::cleanup_report& rep)
newpath = Glib::path_get_dirname (newpath); // "session-dir"
}
- newpath += '/';
- newpath += dead_sound_dir_name;
+ newpath = Glib::build_filename (newpath, dead_sound_dir_name);
if (g_mkdir_with_parents (newpath.c_str(), 0755) < 0) {
error << string_compose(_("Session: cannot create session peakfile folder \"%1\" (%2)"), newpath, strerror (errno)) << endmsg;
return -1;
}
-
- newpath += '/';
- newpath += Glib::path_get_basename ((*x));
+
+ newpath = Glib::build_filename (newpath, Glib::path_get_basename ((*x)));
- if (access (newpath.c_str(), F_OK) == 0) {
+ if (Glib::file_test (newpath, Glib::FILE_TEST_EXISTS)) {
/* the new path already exists, try versioning */
@@ -2933,7 +2928,7 @@ Session::cleanup_sources (Session::cleanup_report& rep)
}
if (::rename ((*x).c_str(), newpath.c_str()) != 0) {
- error << string_compose (_("cannot rename audio file source from %1 to %2 (%3)"),
+ error << string_compose (_("cannot 4 rename audio file source from %1 to %2 (%3)"),
(*x), newpath, strerror (errno))
<< endmsg;
goto out;
@@ -3007,9 +3002,7 @@ Session::cleanup_trash_sources (Session::cleanup_report& rep)
string fullpath;
- fullpath = dead_sound_dir;
- fullpath += '/';
- fullpath += dentry->d_name;
+ fullpath = Glib::build_filename (dead_sound_dir, dentry->d_name);
if (stat (fullpath.c_str(), &statbuf)) {
continue;