From 355ad9110508db0c9c089879ae51a4f635b4d9aa Mon Sep 17 00:00:00 2001
From: Amar Takhar <verm@aegisub.org>
Date: Tue, 8 Feb 2011 04:22:52 +0000
Subject: [PATCH]  * Instead of ~ use getenv("HOME") to get the users home
 directory.  * Fix Locale() to return P_LOCALE  * Change data and doc values
 to P_DATA and P_DOC.

Originally committed to SVN as r5322.
---
 aegisub/libaegisub/Makefile      |  2 +-
 aegisub/libaegisub/unix/path.cpp | 31 ++++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/aegisub/libaegisub/Makefile b/aegisub/libaegisub/Makefile
index daf685903..b7b85465a 100644
--- a/aegisub/libaegisub/Makefile
+++ b/aegisub/libaegisub/Makefile
@@ -17,7 +17,7 @@ LDFLAGS += -L../universalchardet -luniversalchardet
 endif
 
 common/charset_conv.o: CXXFLAGS += $(CFLAGS_ICONV)
-unix/path.o: CXXFLAGS += -DDIR_DATA=\"$(P_DATA)\" -DDIR_DOC=\"$(P_DOC)\"
+unix/path.o: CXXFLAGS += -DP_DATA=\"$(P_DATA)\" -DP_DOC=\"$(P_DOC)\" -DP_LOCALE=\"$(P_LOCALE)\"
 
 SRC = \
 	common/charset.cpp \
diff --git a/aegisub/libaegisub/unix/path.cpp b/aegisub/libaegisub/unix/path.cpp
index 9e76ee08a..f863717ea 100644
--- a/aegisub/libaegisub/unix/path.cpp
+++ b/aegisub/libaegisub/unix/path.cpp
@@ -22,6 +22,9 @@
 #include "config.h"
 
 #ifndef LAGI_PRE
+#include <stdio.h>
+#include <stdlib.h>
+
 #include <string>
 #endif
 
@@ -30,26 +33,40 @@
 
 namespace agi {
 
+
+const std::string home() {
+	char *ehome;
+	ehome = getenv("HOME");
+	if (ehome == NULL) {
+		//XXX: explode here.
+	}
+	std::string home(ehome);
+	free(ehome);
+	return home;
+}
+
+
 const std::string Path::Data() {
-	return DIR_DATA;
+	return P_DATA;
 }
 
 const std::string Path::Doc() {
-	return DIR_DOC;
+	return P_DOC;
 }
 
 const std::string Path::User() {
-	return "~/";
+	return home();
 }
 
 const std::string Path::Locale() {
-	std::string tmp("~/.aegisub-");
-	return tmp.append(AEGISUB_VERSION_DATA);
+	return P_LOCALE;
 }
 
 const std::string Path::Config() {
-	std::string tmp("~/.aegisub-");
-	return tmp.append(AEGISUB_VERSION_DATA);
+	std::string tmp(home());
+	tmp.append("/.aegisub-");
+	tmp.append(AEGISUB_VERSION_DATA);
+	return tmp.append("/");
 }
 
 const std::string Path::Temp() {
-- 
GitLab