1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>localemgr.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>localemgr.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * localemgr.cpp - implementation of class LocaleMgr used to interact with</font>
00003 <font class="comment"> * registered locales for a sword installation</font>
00004 <font class="comment"> *</font>
00005 <font class="comment"> * $Id: localemgr_8cpp-source.html,v 1.3 2002/06/20 20:23:09 mgruner Exp $</font>
00006 <font class="comment"> *</font>
00007 <font class="comment"> * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)</font>
00008 <font class="comment"> * CrossWire Bible Society</font>
00009 <font class="comment"> * P. O. Box 2528</font>
00010 <font class="comment"> * Tempe, AZ 85280-2528</font>
00011 <font class="comment"> *</font>
00012 <font class="comment"> * This program is free software; you can redistribute it and/or modify it</font>
00013 <font class="comment"> * under the terms of the GNU General Public License as published by the</font>
00014 <font class="comment"> * Free Software Foundation version 2.</font>
00015 <font class="comment"> *</font>
00016 <font class="comment"> * This program is distributed in the hope that it will be useful, but</font>
00017 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00018 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00019 <font class="comment"> * General Public License for more details.</font>
00020 <font class="comment"> *</font>
00021 <font class="comment"> */</font>
00022
00023 <font class="preprocessor">#include <stdio.h></font>
00024 <font class="preprocessor">#include <stdlib.h></font>
00025 <font class="preprocessor">#include <fcntl.h></font>
00026
00027 <font class="preprocessor">#ifndef __GNUC__</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00029 <font class="preprocessor">#else</font>
00030 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00031 <font class="preprocessor">#include <unixstr.h></font>
00032 <font class="preprocessor">#endif</font>
00033 <font class="preprocessor"></font><font class="preprocessor">#include <sys/stat.h></font>
00034 <font class="preprocessor">#include <dirent.h></font>
00035
00036 <font class="preprocessor">#include <swmgr.h></font>
00037 <font class="preprocessor">#include <utilfuns.h></font>
00038
00039 <font class="preprocessor">#include <localemgr.h></font>
00040 <font class="preprocessor">#include <filemgr.h></font>
00041
00042
<a name="l00043"></a><a class="code" href="class_locale_mgr.html#p0">00043</a> <a class="code" href="class_locale_mgr.html">LocaleMgr</a> <a class="code" href="class_locale_mgr.html#p0">LocaleMgr::systemLocaleMgr</a>;
00044
00045
<a name="l00046"></a><a class="code" href="class_locale_mgr.html#a0">00046</a> <a class="code" href="class_locale_mgr.html#a0">LocaleMgr::LocaleMgr</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *iConfigPath) {
00047 <font class="keywordtype">char</font> *prefixPath = 0;
00048 <font class="keywordtype">char</font> *configPath = 0;
00049 <font class="keywordtype">char</font> configType = 0;
00050 string path;
00051
00052 defaultLocaleName = 0;
00053
00054 <font class="keywordtype">char</font> *lang = getenv (<font class="stringliteral">"LANG"</font>);
00055 <font class="keywordflow">if</font> (lang) {
00056 <font class="keywordflow">if</font> (strlen(lang) > 0)
00057 <a class="code" href="class_locale_mgr.html#a6">setDefaultLocaleName</a>(lang);
00058 <font class="keywordflow">else</font> <a class="code" href="class_locale_mgr.html#a6">setDefaultLocaleName</a>(<font class="stringliteral">"en_us"</font>);
00059 }
00060 <font class="keywordflow">else</font> <a class="code" href="class_locale_mgr.html#a6">setDefaultLocaleName</a>(<font class="stringliteral">"en_us"</font>);
00061
00062 <font class="keywordflow">if</font> (!iConfigPath)
00063 SWMgr::findConfig(&configType, &prefixPath, &configPath);
00064 <font class="keywordflow">else</font> configPath = (<font class="keywordtype">char</font> *)iConfigPath;
00065
00066 <font class="keywordflow">if</font> (prefixPath) {
00067 <font class="keywordflow">switch</font> (configType) {
00068 <font class="keywordflow">case</font> 2:
00069 <font class="keywordtype">int</font> i;
00070 <font class="keywordflow">for</font> (i = strlen(configPath)-1; ((i) && (configPath[i] != <font class="charliteral">'/'</font>) && (configPath[i] != <font class="charliteral">'\\'</font>)); i--);
00071 configPath[i] = 0;
00072 path = configPath;
00073 path += <font class="stringliteral">"/"</font>;
00074 <font class="keywordflow">break</font>;
00075 <font class="keywordflow">default</font>:
00076 path = prefixPath;
00077 <font class="keywordflow">if</font> ((prefixPath[strlen(prefixPath)-1] != <font class="charliteral">'\\'</font>) && (prefixPath[strlen(prefixPath)-1] != <font class="charliteral">'/'</font>))
00078 path += <font class="stringliteral">"/"</font>;
00079
00080 <font class="keywordflow">break</font>;
00081 }
00082 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"locales.d"</font>)) {
00083 path += <font class="stringliteral">"locales.d"</font>;
00084 <a class="code" href="class_locale_mgr.html#a7">loadConfigDir</a>(path.c_str());
00085 }
00086 }
00087
00088 <font class="keywordflow">if</font> (prefixPath)
00089 <font class="keyword">delete</font> [] prefixPath;
00090
00091 <font class="keywordflow">if</font> (configPath)
00092 <font class="keyword">delete</font> [] configPath;
00093 }
00094
00095
<a name="l00096"></a><a class="code" href="class_locale_mgr.html#a1">00096</a> <a class="code" href="class_locale_mgr.html#a1">LocaleMgr::~LocaleMgr</a>() {
00097 <font class="keywordflow">if</font> (defaultLocaleName)
00098 <font class="keyword">delete</font> [] defaultLocaleName;
00099 deleteLocales();
00100 }
00101
00102
<a name="l00103"></a><a class="code" href="class_locale_mgr.html#a7">00103</a> <font class="keywordtype">void</font> <a class="code" href="class_locale_mgr.html#a7">LocaleMgr::loadConfigDir</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath) {
00104 DIR *dir;
00105 <font class="keyword">struct </font>dirent *ent;
00106 string newmodfile;
00107 LocaleMap::iterator it;
00108
00109 <font class="keywordflow">if</font> ((dir = opendir(ipath))) {
00110 rewinddir(dir);
00111 <font class="keywordflow">while</font> ((ent = readdir(dir))) {
00112 <font class="keywordflow">if</font> ((strcmp(ent->d_name, <font class="stringliteral">"."</font>)) && (strcmp(ent->d_name, <font class="stringliteral">".."</font>))) {
00113 newmodfile = ipath;
00114 <font class="keywordflow">if</font> ((ipath[strlen(ipath)-1] != <font class="charliteral">'\\'</font>) && (ipath[strlen(ipath)-1] != <font class="charliteral">'/'</font>))
00115 newmodfile += <font class="stringliteral">"/"</font>;
00116 newmodfile += ent->d_name;
00117 <a class="code" href="class_s_w_locale.html">SWLocale</a> *locale = <font class="keyword">new</font> <a class="code" href="class_s_w_locale.html">SWLocale</a>(newmodfile.c_str());
00118 <font class="keywordflow">if</font> (locale-><a class="code" href="class_s_w_locale.html#a2">getName</a>()) {
00119 it = locales.find(locale-><a class="code" href="class_s_w_locale.html#a2">getName</a>());
00120 <font class="keywordflow">if</font> (it != locales.end()) {
00121 *((*it).second) += *locale;
00122 <font class="keyword">delete</font> locale;
00123 }
00124 <font class="keywordflow">else</font> locales.insert(LocaleMap::value_type(locale-><a class="code" href="class_s_w_locale.html#a2">getName</a>(), locale));
00125 }
00126 <font class="keywordflow">else</font> <font class="keyword">delete</font> locale;
00127 }
00128 }
00129 closedir(dir);
00130 }
00131 }
00132
00133
00134 <font class="keywordtype">void</font> LocaleMgr::deleteLocales() {
00135
00136 LocaleMap::iterator it;
00137
00138 <font class="keywordflow">for</font> (it = locales.begin(); it != locales.end(); it++)
00139 <font class="keyword">delete</font> (*it).second;
00140
00141 locales.erase(locales.begin(), locales.end());
00142 }
00143
00144
<a name="l00145"></a><a class="code" href="class_locale_mgr.html#a2">00145</a> <a class="code" href="class_s_w_locale.html">SWLocale</a> *<a class="code" href="class_locale_mgr.html#a2">LocaleMgr::getLocale</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *name) {
00146 LocaleMap::iterator it;
00147
00148 it = locales.find(name);
00149 <font class="keywordflow">if</font> (it != locales.end())
00150 <font class="keywordflow">return</font> (*it).second;
00151
00152 <font class="keywordflow">return</font> 0;
00153 }
00154
00155
<a name="l00156"></a><a class="code" href="class_locale_mgr.html#a3">00156</a> list <string> <a class="code" href="class_locale_mgr.html#a3">LocaleMgr::getAvailableLocales</a>() {
00157 list <string> retVal;
00158 <font class="keywordflow">for</font> (LocaleMap::iterator it = locales.begin(); it != locales.end(); it++)
00159 retVal.push_back((*it).second->getName());
00160
00161 <font class="keywordflow">return</font> retVal;
00162 }
00163
00164
<a name="l00165"></a><a class="code" href="class_locale_mgr.html#a4">00165</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_locale_mgr.html#a4">LocaleMgr::translate</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *text, <font class="keyword">const</font> <font class="keywordtype">char</font> *localeName) {
00166 <a class="code" href="class_s_w_locale.html">SWLocale</a> *target;
00167 <font class="keywordflow">if</font> (!localeName) {
00168 localeName = <a class="code" href="class_locale_mgr.html#a5">getDefaultLocaleName</a>();
00169 }
00170 target = <a class="code" href="class_locale_mgr.html#a2">getLocale</a>(localeName);
00171 <font class="keywordflow">if</font> (target)
00172 <font class="keywordflow">return</font> target-><a class="code" href="class_s_w_locale.html#a4">translate</a>(text);
00173 <font class="keywordflow">return</font> text;
00174 }
00175
00176
<a name="l00177"></a><a class="code" href="class_locale_mgr.html#a5">00177</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_locale_mgr.html#a5">LocaleMgr::getDefaultLocaleName</a>() {
00178 <font class="keywordflow">return</font> defaultLocaleName;
00179 }
00180
00181
<a name="l00182"></a><a class="code" href="class_locale_mgr.html#a6">00182</a> <font class="keywordtype">void</font> <a class="code" href="class_locale_mgr.html#a6">LocaleMgr::setDefaultLocaleName</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *name) {
00183 stdstr(&defaultLocaleName, name);
00184 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>
|