aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-08-20 03:43:41 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-08-20 03:43:41 +0200
commitf302ee1cb7b6247bd213fa07ef7643a1bd161b9b (patch)
tree0a26d6722eb1e1730c108f7ff786ab799fd809fe
parentRemove all directories. (diff)
downloadmusic-file-organizer-f302ee1cb7b6247bd213fa07ef7643a1bd161b9b.tar.xz
music-file-organizer-f302ee1cb7b6247bd213fa07ef7643a1bd161b9b.zip
Support variable targets.
-rw-r--r--organizemusic.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/organizemusic.cpp b/organizemusic.cpp
index bd4a433..081f989 100644
--- a/organizemusic.cpp
+++ b/organizemusic.cpp
@@ -27,7 +27,7 @@ using namespace std;
#define CYAN "\x1b[36m"
#define RESET "\x1b[0m"
-static string base_destination = "/home/zx2c4/Music/";
+static string base_destination;
static Transliterator *transliterator;
void process_file(const char *filename, ino_t inode);
@@ -208,6 +208,7 @@ void process_path(const char *path)
int main(int argc, char *argv[])
{
+ size_t len;
UErrorCode status = U_ZERO_ERROR;
transliterator = Transliterator::createInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:^ASCII:] Remove; [\\:;*?\"<>|\\\\] Remove", UTRANS_FORWARD, status);
if (!transliterator || status != U_ZERO_ERROR) {
@@ -215,6 +216,20 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ if (char *base = getenv("MUSICDIR")) {
+ base_destination = base;
+ if (base_destination[base_destination.length() - 1] != '/')
+ base_destination.append("/");
+ } else if (char *home = getenv("HOME")) {
+ len = strlen(home);
+ if (home[len - 1] == '/')
+ home[len - 1] = '\0';
+ base_destination = string(home) + "/Music/";
+ } else {
+ cerr << RED << "Fatal: Could not determine the music directory. Try setting the MUSICDIR or HOME environment variable." << RESET << endl;
+ return EXIT_FAILURE;
+ }
+
for (int i = 1; i < argc; ++i) {
size_t len = strlen(argv[i]);
if (argv[i][len - 1] == '/')