3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
7 * The contents of this file are subject to the terms of either the GNU Lesser
8 * General Public License Version 2.1 only ("LGPL") or the Common Development and
9 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
10 * file except in compliance with the License. You can obtain a copy of the CDDL at
11 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
12 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
13 * specific language governing permissions and limitations under the License. When
14 * distributing the software, include this License Header Notice in each file and
15 * include the full text of the License in the License file as well as the
18 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
20 * For Covered Software in this distribution, this License shall be governed by the
21 * laws of the State of California (excluding conflict-of-law provisions).
22 * Any litigation relating to this License shall be subject to the jurisdiction of
23 * the Federal Courts of the Northern District of California and the state courts
24 * of the State of California, with venue lying in Santa Clara County, California.
28 * If you wish your version of this file to be governed by only the CDDL or only
29 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
30 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
31 * license." If you don't indicate a single choice of license, a recipient has the
32 * option to distribute your version of this file under either the CDDL or the LGPL
33 * Version 2.1, or to extend the choice of license to its licensees as provided
34 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
35 * Version 2 license, then the option applies only if the new code is made subject
36 * to such option by the copyright holder.
39 #ifndef ___SUN_SLM_PORTABILITY_H___
40 #define ___SUN_SLM_PORTABILITY_H___
55 #endif //ifdef HAVE_UNISTD_H
57 #ifndef HOST_OS_GNUC_2
58 #if defined(DEBUG) && !defined(NDEBUG)
59 #define DEBUG_print(fmt, ...) fprintf(stderr, fmt, ...)
61 #define DEBUG_print(fmt, ...) (int(0))
63 #else // HOST_OS_GNUC_2
64 #if defined(DEBUG) && !defined(NDEBUG)
65 #define DEBUG_print(fmt, a ...) fprintf(stderr, fmt, a ...)
67 #define DEBUG_print(fmt, a ...) (int(0))
69 #endif // !HOST_OS_GNUC_2
72 inline double log2(double x) { return log(x) / M_LN2; }
75 #if defined(sun) // Solaris/HP-UX 's iconv is const char**
76 typedef const char* TIConvSrcPtr;
78 typedef char* TIConvSrcPtr;
81 union TDoubleAnatomy {
83 TDoubleAnatomy(double d) : m_value(d){
86 int getExp(void) const
87 { return anony.m_exp - 0x3FF; }
89 double getValue(void) const
93 { anony.m_exp = 0x3FF; }
98 #ifndef WORDS_BIGENDIAN
99 unsigned m_other2 : 32;
100 unsigned m_other1 : 20;
106 unsigned m_other1 : 20;
107 unsigned m_other2 : 32;
112 struct TLongExpFloat {
114 TLongExpFloat(const TLongExpFloat& b) : m_base(b.m_base), m_exp(b.m_exp) { }
116 TLongExpFloat(int exp = 0, double base = 0.0) : m_base(base), m_exp(exp) { }
118 TLongExpFloat(double d);
121 operator*(const TLongExpFloat& b) const;
124 operator/(const TLongExpFloat& b) const;
127 operator<(const TLongExpFloat& b) const;
130 operator<=(const TLongExpFloat& b) const;
133 operator==(const TLongExpFloat& b) const;
136 operator=(const TLongExpFloat& b);
139 toString(std::string& str) const;
141 void toString(char* buf) const
142 { if (buf) sprintf(buf, "%10lf*2^%d", m_base, m_exp); }
144 double log2() const { return ::log2(m_base) + m_exp; }
152 * UCS4 wide character type, system dependent
153 * Multibytes string in this program is UTF-8 only
155 typedef unsigned int TWCHAR;
157 #if !defined(WORDS_BIGENDIAN)
158 #define TWCHAR_ICONV_NAME "UCS-4LE"
160 #define TWCHAR_ICONV_NAME "UCS-4BE"
163 typedef TWCHAR TSIMWordId;
165 const TSIMWordId SIM_ID_NOT_WORD = (0x0);
166 const TSIMWordId SIM_ID_UNKNOWN_CN = (2);
167 const TSIMWordId SIM_ID_SEN_TOKEN = (10);
168 const TSIMWordId SIM_ID_DIGIT = (20);
169 const TSIMWordId SIM_ID_SIMBOL = (21);
170 const TSIMWordId SIM_ID_DUMMY_WORD = (69);
171 const TSIMWordId SIM_ID_NONWORD = (69);
172 const TSIMWordId SIM_ID_ALLWORD = (69);
173 const TSIMWordId SIM_ID_REALWORD_START = (70);
174 const TSIMWordId SIM_ID_CNWORD_START = (100);
176 const TWCHAR WCH_NULL = 0;
177 const TWCHAR WCH_RETURN = '\n';
178 const TWCHAR WCH_TAB = '\t';
179 const TWCHAR WCH_SPACE = ' ';
180 const TWCHAR WCH_LESSTHAN = '<';
181 const TWCHAR WCH_GREATERTHAN = '>';
183 const TWCHAR WCH_DOUBLESPACE = 0x3000;
184 const TWCHAR WCH_JUHAO = 0x3002;
185 const TWCHAR WCH_WENHAO = 0xFF1F;
186 const TWCHAR WCH_TANHAO = 0xFF01;
187 const TWCHAR WCH_FENHAO = 0xFF1B;
188 const TWCHAR WCH_MAOHAO = 0xFF1A;
189 const TWCHAR WCH_DOUHAO = 0xFF0C;
190 const TWCHAR WCH_ZUOKUOHAO = 0x201C;
191 const TWCHAR WCH_YOUKUOHAO = 0x201D;
192 const TWCHAR WCH_SHENGLUEHAO = 0x2026;
195 size_t MBSTOWCS(TWCHAR *pwcs, const char* s, size_t n);
197 size_t WCSTOMBS(char* s, const TWCHAR* pwcs, size_t n);
199 EXPORTED size_t WCSLEN(const TWCHAR* ws);
202 #ifdef HOST_OS_GNUC_2
203 struct string_char_traits<TWCHAR>
204 #else // !HOST_OS_GNUC_2
206 struct char_traits<TWCHAR>
207 #endif // HOST_OS_GNUC_2
209 typedef TWCHAR char_type;
210 typedef unsigned int int_type;
211 #ifndef HOST_OS_GNUC_2
212 typedef streamoff off_type;
213 typedef wstreampos pos_type;
214 typedef mbstate_t state_type;
215 #endif // !HOST_OS_GNUC_2
217 static void assign(char_type& __c1, const char_type& __c2)
220 static bool eq(const char_type& __c1, const char_type& __c2)
221 { return __c1 == __c2; }
223 static bool lt(const char_type& __c1, const char_type& __c2)
224 { return __c1 < __c2; }
226 static int compare(const char_type* __s1, const char_type* __s2,
228 for (size_t i = 0; i < __n; ++i) {
231 else if (*__s1++ == *__s2++)
239 static size_t length(const char_type* __s)
240 { return WCSLEN(__s); }
242 static char_type*copy(char_type* __s1, const char_type* __s2,
244 return static_cast<char_type*>(memcpy(__s1, __s2, __n *
248 static char_type*move(char_type* __s1, const char_type* __s2,
250 return static_cast<char_type*>(memmove(__s1, __s2, __n *
254 #ifndef HOST_OS_GNUC_2
255 static const char_type*find(const char_type* __s,
257 const char_type& __a) {
265 static char_type to_char_type(const int_type& __c) { return char_type(__c); }
267 static int_type to_int_type(const char_type& __c) { return int_type(__c); }
269 static bool eq_int_type(const int_type& __c1, const int_type& __c2)
270 { return __c1 == __c2; }
272 static int_type eof() { return static_cast<int_type>(WEOF); }
274 static int_type not_eof(const int_type& __c)
275 { return eq_int_type(__c, eof()) ? 0 : __c; }
277 static char_type*assign(char_type* __s, size_t __n,
279 for (char_type *p = __s; __n--; )
283 #else // HOST_OS_GNUC_2
284 static bool ne(const char_type& __c1, const char_type& __c2)
285 { return __c1 != __c2; }
287 static char_type eos()
290 static bool is_del(char_type a)
291 { return a == WCH_SPACE; }
293 static char_type* set(char_type* __s, char_type __a, size_t __n){
294 for (char_type *p = __s; __n--; )
298 #endif // !HOST_OS_GNUC_2
302 #ifndef HOST_OS_GNUC_2
303 typedef std::basic_string<TWCHAR> wstring;
304 #else // HOST_OS_GNUC_2
305 class wstring : public std::basic_string<TWCHAR>
308 inline wstring() : std::basic_string<TWCHAR>((TWCHAR) 0) {}
309 inline wstring(const TWCHAR* c) : std::basic_string<TWCHAR>(c) {}
310 inline wstring(const TWCHAR* c, size_t n) : std::basic_string<TWCHAR>(c,
312 inline void push_back(TWCHAR c) { this->append(1, c); }
313 inline void clear(void) { this->resize(0); }
314 inline const TWCHAR* c_str(void) const {
315 static TWCHAR null_s = 0;
316 if (this->length() == 0) return &null_s;
317 *(const_cast<TWCHAR*>(this->data()) + this->length()) = 0;
321 #endif // !HOST_OS_GNUC_2
324 template <class Iterator>
325 inline long distance(Iterator pos1, Iterator pos2){
327 distance(pos1, pos2, d);
332 #if !defined (HAVE_STRNDUP)
333 extern "C" char *strndup(const char *s, size_t n);
334 #endif //HAVE_STRNDUP