#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
-#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include <glibmm/miscutils.h>
#ifdef HAVE_WORDEXP
#include <wordexp.h>
}
errno = 0;
- long int version = strtol (name.c_str()+delim+1, (char **)NULL, 10);
+ int32_t version = strtol (name.c_str()+delim+1, (char **)NULL, 10);
if (isnumber == 0 || errno != 0) {
// last_element is not a number, or is too large
} else {
char buf[32];
- snprintf (buf, sizeof(buf), "%ld", version+1);
+ snprintf (buf, sizeof(buf), "%d", version+1);
newname = name.substr (0, delim+1);
newname += buf;
/* remove any leading path */
- if ((pos = path.find_last_of ('/')) != string::npos) {
+ if ((pos = path.find_last_of (G_DIR_SEPARATOR)) != string::npos) {
path = path.substr(pos+1);
}
EditMode
string_to_edit_mode (string str)
{
- if (str == _("Splice Edit")) {
+ if (str == _("Splice")) {
return Splice;
- } else if (str == _("Slide Edit")) {
+ } else if (str == _("Slide")) {
return Slide;
- } else if (str == _("Lock Edit")) {
+ } else if (str == _("Lock")) {
return Lock;
}
fatal << string_compose (_("programming error: unknown edit mode string \"%1\""), str) << endmsg;
{
switch (mode) {
case Slide:
- return _("Slide Edit");
+ return _("Slide");
case Lock:
- return _("Lock Edit");
+ return _("Lock");
default:
case Splice:
- return _("Splice Edit");
+ return _("Splice");
}
}
return ".wav";
}
+bool
+matching_unsuffixed_filename_exists_in (const string& dir, const string& path)
+{
+ string bws = basename_nosuffix (path);
+ struct dirent* dentry;
+ struct stat statbuf;
+ DIR* dead;
+ bool ret = false;
+
+ if ((dead = ::opendir (dir.c_str())) == 0) {
+ error << string_compose (_("cannot open directory %1 (%2)"), dir, strerror (errno)) << endl;
+ return false;
+ }
+
+ while ((dentry = ::readdir (dead)) != 0) {
+
+ /* avoid '.' and '..' */
+
+ if ((dentry->d_name[0] == '.' && dentry->d_name[1] == '\0') ||
+ (dentry->d_name[2] == '\0' && dentry->d_name[0] == '.' && dentry->d_name[1] == '.')) {
+ continue;
+ }
+
+ string fullpath = Glib::build_filename (dir, dentry->d_name);
+
+ if (::stat (fullpath.c_str(), &statbuf)) {
+ continue;
+ }
+
+ if (!S_ISREG (statbuf.st_mode)) {
+ continue;
+ }
+
+ string bws2 = basename_nosuffix (dentry->d_name);
+
+ if (bws2 == bws) {
+ ret = true;
+ break;
+ }
+ }
+
+ ::closedir (dead);
+ return ret;
+}
+
extern "C" {
void c_stacktrace() { stacktrace (cerr); }
}