app-i18n/mozc: Initial commit - add fcitx5 support
[gentoo-zh.git] / app-i18n / mozc / files / mozc-2.23.2815.102-environmental_variables.patch
blob02e522a32e9ed5b5f6ac969f3eea5022c00f959f
1 https://github.com/google/mozc/issues/470
3 --- /src/base/system_util.cc
4 +++ /src/base/system_util.cc
5 @@ -208,28 +208,39 @@
6 dir_ = "/";
7 return;
8 #else // MOZC_USE_PEPPER_FILE_IO
9 + const char *configuration_directory_env;
10 string dir;
12 #ifdef OS_WIN
13 - DCHECK(SUCCEEDED(Singleton<LocalAppDataDirectoryCache>::get()->result()));
14 - dir = Singleton<LocalAppDataDirectoryCache>::get()->path();
15 + configuration_directory_env = ::getenv("MOZC_CONFIGURATION_DIRECTORY");
16 + if (configuration_directory_env) {
17 + dir = configuration_directory_env;
18 + } else {
19 + DCHECK(SUCCEEDED(Singleton<LocalAppDataDirectoryCache>::get()->result()));
20 + dir = Singleton<LocalAppDataDirectoryCache>::get()->path();
21 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
22 - dir = FileUtil::JoinPath(dir, kCompanyNameInEnglish);
23 - FileUtil::CreateDirectory(dir);
24 + dir = FileUtil::JoinPath(dir, kCompanyNameInEnglish);
25 + FileUtil::CreateDirectory(dir);
26 #endif // GOOGLE_JAPANESE_INPUT_BUILD
27 - dir = FileUtil::JoinPath(dir, kProductNameInEnglish);
28 + dir = FileUtil::JoinPath(dir, kProductNameInEnglish);
29 + }
31 #elif defined(OS_MACOSX)
32 - dir = MacUtil::GetApplicationSupportDirectory();
33 + configuration_directory_env = ::getenv("MOZC_CONFIGURATION_DIRECTORY");
34 + if (configuration_directory_env) {
35 + dir = configuration_directory_env;
36 + } else {
37 + dir = MacUtil::GetApplicationSupportDirectory();
38 #ifdef GOOGLE_JAPANESE_INPUT_BUILD
39 - dir = FileUtil::JoinPath(dir, "Google");
40 - // The permission of ~/Library/Application Support/Google seems to be 0755.
41 - // TODO(komatsu): nice to make a wrapper function.
42 - ::mkdir(dir.c_str(), 0755);
43 - dir = FileUtil::JoinPath(dir, "JapaneseInput");
44 + dir = FileUtil::JoinPath(dir, "Google");
45 + // The permission of ~/Library/Application Support/Google seems to be 0755.
46 + // TODO(komatsu): nice to make a wrapper function.
47 + ::mkdir(dir.c_str(), 0755);
48 + dir = FileUtil::JoinPath(dir, "JapaneseInput");
49 #else // GOOGLE_JAPANESE_INPUT_BUILD
50 - dir = FileUtil::JoinPath(dir, "Mozc");
51 + dir = FileUtil::JoinPath(dir, "Mozc");
52 #endif // GOOGLE_JAPANESE_INPUT_BUILD
53 + }
55 #elif defined(OS_ANDROID)
56 // For android, we do nothing here because user profile directory,
57 @@ -237,14 +248,24 @@
58 // is injected from Java layer.
60 #else // !OS_WIN && !OS_MACOSX && !OS_ANDROID
61 - char buf[1024];
62 - struct passwd pw, *ppw;
63 - const uid_t uid = geteuid();
64 - CHECK_EQ(0, getpwuid_r(uid, &pw, buf, sizeof(buf), &ppw))
65 - << "Can't get passwd entry for uid " << uid << ".";
66 - CHECK_LT(0, strlen(pw.pw_dir))
67 - << "Home directory for uid " << uid << " is not set.";
68 - dir = FileUtil::JoinPath(pw.pw_dir, ".mozc");
69 + configuration_directory_env = ::getenv("MOZC_CONFIGURATION_DIRECTORY");
70 + if (configuration_directory_env) {
71 + dir = configuration_directory_env;
72 + } else {
73 + const char *home_env = ::getenv("HOME");
74 + if (home_env) {
75 + dir = FileUtil::JoinPath(home_env, ".mozc");
76 + } else {
77 + char buf[1024];
78 + struct passwd pw, *ppw;
79 + const uid_t uid = geteuid();
80 + CHECK_EQ(0, getpwuid_r(uid, &pw, buf, sizeof(buf), &ppw))
81 + << "Can't get passwd entry for uid " << uid << ".";
82 + CHECK_LT(0, strlen(pw.pw_dir))
83 + << "Home directory for uid " << uid << " is not set.";
84 + dir = FileUtil::JoinPath(pw.pw_dir, ".mozc");
85 + }
86 + }
87 #endif // !OS_WIN && !OS_MACOSX && !OS_ANDROID
89 FileUtil::CreateDirectory(dir);
90 @@ -356,6 +377,10 @@
91 #endif // OS_WIN
93 string SystemUtil::GetServerDirectory() {
94 + const char *server_directory_env = ::getenv("MOZC_SERVER_DIRECTORY");
95 + if (server_directory_env) {
96 + return server_directory_env;
97 + }
98 #ifdef OS_WIN
99 DCHECK(SUCCEEDED(Singleton<ProgramFilesX86Cache>::get()->result()));
100 #if defined(GOOGLE_JAPANESE_INPUT_BUILD)
101 @@ -409,6 +434,10 @@
104 string SystemUtil::GetDocumentDirectory() {
105 + const char *documents_directory_env = ::getenv("MOZC_DOCUMENTS_DIRECTORY");
106 + if (documents_directory_env) {
107 + return documents_directory_env;
109 #if defined(OS_MACOSX)
110 return GetServerDirectory();
111 #elif defined(MOZC_DOCUMENT_DIRECTORY)
112 --- /src/handwriting/zinnia_handwriting.cc
113 +++ /src/handwriting/zinnia_handwriting.cc
114 @@ -31,6 +31,7 @@
116 #include "handwriting/zinnia_handwriting.h"
118 +#include <cstdlib>
119 #include <memory>
120 #include <string>
122 @@ -48,6 +49,10 @@
124 // static
125 string ZinniaHandwriting::GetModelFileName() {
126 + const char *zinnia_model_file_env = ::getenv("MOZC_ZINNIA_MODEL_FILE");
127 + if (zinnia_model_file_env) {
128 + return zinnia_model_file_env;
130 #if defined(MOZC_BUILD)
131 return MOZC_ZINNIA_MODEL_FILE;
132 #else