ferret 0.9.6 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. data/MIT-LICENSE +1 -1
  2. data/README +12 -24
  3. data/Rakefile +38 -54
  4. data/TODO +14 -17
  5. data/ext/analysis.c +982 -823
  6. data/ext/analysis.h +133 -76
  7. data/ext/array.c +96 -58
  8. data/ext/array.h +40 -13
  9. data/ext/bitvector.c +476 -118
  10. data/ext/bitvector.h +264 -22
  11. data/ext/compound_io.c +217 -229
  12. data/ext/defines.h +49 -0
  13. data/ext/document.c +107 -317
  14. data/ext/document.h +31 -65
  15. data/ext/except.c +81 -36
  16. data/ext/except.h +117 -55
  17. data/ext/extconf.rb +2 -9
  18. data/ext/ferret.c +211 -104
  19. data/ext/ferret.h +22 -11
  20. data/ext/filter.c +97 -82
  21. data/ext/fs_store.c +348 -367
  22. data/ext/global.c +226 -188
  23. data/ext/global.h +44 -26
  24. data/ext/hash.c +474 -391
  25. data/ext/hash.h +441 -68
  26. data/ext/hashset.c +124 -96
  27. data/ext/hashset.h +169 -20
  28. data/ext/helper.c +56 -5
  29. data/ext/helper.h +7 -0
  30. data/ext/inc/lang.h +29 -49
  31. data/ext/inc/threading.h +31 -0
  32. data/ext/ind.c +288 -278
  33. data/ext/ind.h +68 -0
  34. data/ext/index.c +5688 -0
  35. data/ext/index.h +663 -616
  36. data/ext/lang.h +29 -49
  37. data/ext/libstemmer.c +3 -3
  38. data/ext/mem_pool.c +84 -0
  39. data/ext/mem_pool.h +35 -0
  40. data/ext/posh.c +1006 -0
  41. data/ext/posh.h +1007 -0
  42. data/ext/priorityqueue.c +117 -194
  43. data/ext/priorityqueue.h +135 -39
  44. data/ext/q_boolean.c +1305 -1108
  45. data/ext/q_const_score.c +106 -93
  46. data/ext/q_filtered_query.c +138 -135
  47. data/ext/q_fuzzy.c +206 -242
  48. data/ext/q_match_all.c +94 -80
  49. data/ext/q_multi_term.c +663 -0
  50. data/ext/q_parser.c +667 -593
  51. data/ext/q_phrase.c +992 -555
  52. data/ext/q_prefix.c +72 -61
  53. data/ext/q_range.c +235 -210
  54. data/ext/q_span.c +1480 -1166
  55. data/ext/q_term.c +273 -246
  56. data/ext/q_wildcard.c +127 -114
  57. data/ext/r_analysis.c +1720 -711
  58. data/ext/r_index.c +3049 -0
  59. data/ext/r_qparser.c +433 -146
  60. data/ext/r_search.c +2934 -1993
  61. data/ext/r_store.c +372 -143
  62. data/ext/r_utils.c +941 -0
  63. data/ext/ram_store.c +330 -326
  64. data/ext/search.c +1291 -668
  65. data/ext/search.h +403 -702
  66. data/ext/similarity.c +91 -113
  67. data/ext/similarity.h +45 -30
  68. data/ext/sort.c +721 -484
  69. data/ext/stopwords.c +361 -273
  70. data/ext/store.c +556 -58
  71. data/ext/store.h +706 -126
  72. data/ext/tags +3578 -2780
  73. data/ext/term_vectors.c +352 -0
  74. data/ext/threading.h +31 -0
  75. data/ext/win32.h +54 -0
  76. data/lib/ferret.rb +5 -17
  77. data/lib/ferret/document.rb +130 -2
  78. data/lib/ferret/index.rb +577 -26
  79. data/lib/ferret/number_tools.rb +157 -0
  80. data/lib/ferret_version.rb +3 -0
  81. data/test/test_helper.rb +5 -13
  82. data/test/unit/analysis/tc_analyzer.rb +513 -1
  83. data/test/unit/analysis/{ctc_tokenstream.rb → tc_token_stream.rb} +23 -0
  84. data/test/unit/index/tc_index.rb +183 -240
  85. data/test/unit/index/tc_index_reader.rb +312 -479
  86. data/test/unit/index/tc_index_writer.rb +397 -13
  87. data/test/unit/index/th_doc.rb +269 -206
  88. data/test/unit/query_parser/tc_query_parser.rb +40 -33
  89. data/test/unit/search/tc_filter.rb +59 -71
  90. data/test/unit/search/tc_fuzzy_query.rb +24 -16
  91. data/test/unit/search/tc_index_searcher.rb +23 -201
  92. data/test/unit/search/tc_multi_searcher.rb +78 -226
  93. data/test/unit/search/tc_search_and_sort.rb +93 -81
  94. data/test/unit/search/tc_sort.rb +23 -23
  95. data/test/unit/search/tc_sort_field.rb +7 -7
  96. data/test/unit/search/tc_spans.rb +51 -47
  97. data/test/unit/search/tm_searcher.rb +339 -0
  98. data/test/unit/store/tc_fs_store.rb +1 -1
  99. data/test/unit/store/tm_store_lock.rb +3 -3
  100. data/test/unit/tc_document.rb +81 -0
  101. data/test/unit/ts_analysis.rb +1 -1
  102. data/test/unit/ts_utils.rb +1 -1
  103. data/test/unit/utils/tc_bit_vector.rb +288 -0
  104. data/test/unit/utils/tc_number_tools.rb +117 -0
  105. data/test/unit/utils/tc_priority_queue.rb +106 -0
  106. metadata +140 -301
  107. data/CHANGELOG +0 -9
  108. data/ext/dummy.exe +0 -0
  109. data/ext/field.c +0 -408
  110. data/ext/frtio.h +0 -13
  111. data/ext/inc/except.h +0 -90
  112. data/ext/index_io.c +0 -382
  113. data/ext/index_rw.c +0 -2658
  114. data/ext/lang.c +0 -41
  115. data/ext/nix_io.c +0 -134
  116. data/ext/q_multi_phrase.c +0 -380
  117. data/ext/r_doc.c +0 -582
  118. data/ext/r_index_io.c +0 -1021
  119. data/ext/r_term.c +0 -219
  120. data/ext/term.c +0 -820
  121. data/ext/termdocs.c +0 -611
  122. data/ext/vector.c +0 -637
  123. data/ext/w32_io.c +0 -150
  124. data/lib/ferret/analysis.rb +0 -11
  125. data/lib/ferret/analysis/analyzers.rb +0 -112
  126. data/lib/ferret/analysis/standard_tokenizer.rb +0 -71
  127. data/lib/ferret/analysis/token.rb +0 -100
  128. data/lib/ferret/analysis/token_filters.rb +0 -86
  129. data/lib/ferret/analysis/token_stream.rb +0 -26
  130. data/lib/ferret/analysis/tokenizers.rb +0 -112
  131. data/lib/ferret/analysis/word_list_loader.rb +0 -27
  132. data/lib/ferret/document/document.rb +0 -152
  133. data/lib/ferret/document/field.rb +0 -312
  134. data/lib/ferret/index/compound_file_io.rb +0 -338
  135. data/lib/ferret/index/document_writer.rb +0 -289
  136. data/lib/ferret/index/field_infos.rb +0 -279
  137. data/lib/ferret/index/fields_io.rb +0 -181
  138. data/lib/ferret/index/index.rb +0 -675
  139. data/lib/ferret/index/index_file_names.rb +0 -33
  140. data/lib/ferret/index/index_reader.rb +0 -503
  141. data/lib/ferret/index/index_writer.rb +0 -534
  142. data/lib/ferret/index/multi_reader.rb +0 -377
  143. data/lib/ferret/index/multiple_term_doc_pos_enum.rb +0 -98
  144. data/lib/ferret/index/segment_infos.rb +0 -130
  145. data/lib/ferret/index/segment_merge_info.rb +0 -49
  146. data/lib/ferret/index/segment_merge_queue.rb +0 -16
  147. data/lib/ferret/index/segment_merger.rb +0 -358
  148. data/lib/ferret/index/segment_reader.rb +0 -412
  149. data/lib/ferret/index/segment_term_enum.rb +0 -169
  150. data/lib/ferret/index/segment_term_vector.rb +0 -58
  151. data/lib/ferret/index/term.rb +0 -53
  152. data/lib/ferret/index/term_buffer.rb +0 -83
  153. data/lib/ferret/index/term_doc_enum.rb +0 -291
  154. data/lib/ferret/index/term_enum.rb +0 -52
  155. data/lib/ferret/index/term_info.rb +0 -37
  156. data/lib/ferret/index/term_infos_io.rb +0 -321
  157. data/lib/ferret/index/term_vector_offset_info.rb +0 -20
  158. data/lib/ferret/index/term_vectors_io.rb +0 -553
  159. data/lib/ferret/query_parser.rb +0 -312
  160. data/lib/ferret/query_parser/query_parser.tab.rb +0 -928
  161. data/lib/ferret/search.rb +0 -50
  162. data/lib/ferret/search/boolean_clause.rb +0 -100
  163. data/lib/ferret/search/boolean_query.rb +0 -299
  164. data/lib/ferret/search/boolean_scorer.rb +0 -294
  165. data/lib/ferret/search/caching_wrapper_filter.rb +0 -40
  166. data/lib/ferret/search/conjunction_scorer.rb +0 -99
  167. data/lib/ferret/search/disjunction_sum_scorer.rb +0 -205
  168. data/lib/ferret/search/exact_phrase_scorer.rb +0 -32
  169. data/lib/ferret/search/explanation.rb +0 -41
  170. data/lib/ferret/search/field_cache.rb +0 -215
  171. data/lib/ferret/search/field_doc.rb +0 -31
  172. data/lib/ferret/search/field_sorted_hit_queue.rb +0 -184
  173. data/lib/ferret/search/filter.rb +0 -11
  174. data/lib/ferret/search/filtered_query.rb +0 -130
  175. data/lib/ferret/search/filtered_term_enum.rb +0 -79
  176. data/lib/ferret/search/fuzzy_query.rb +0 -154
  177. data/lib/ferret/search/fuzzy_term_enum.rb +0 -247
  178. data/lib/ferret/search/hit_collector.rb +0 -34
  179. data/lib/ferret/search/hit_queue.rb +0 -11
  180. data/lib/ferret/search/index_searcher.rb +0 -200
  181. data/lib/ferret/search/match_all_query.rb +0 -104
  182. data/lib/ferret/search/multi_phrase_query.rb +0 -216
  183. data/lib/ferret/search/multi_searcher.rb +0 -261
  184. data/lib/ferret/search/multi_term_query.rb +0 -65
  185. data/lib/ferret/search/non_matching_scorer.rb +0 -22
  186. data/lib/ferret/search/phrase_positions.rb +0 -55
  187. data/lib/ferret/search/phrase_query.rb +0 -214
  188. data/lib/ferret/search/phrase_scorer.rb +0 -152
  189. data/lib/ferret/search/prefix_query.rb +0 -54
  190. data/lib/ferret/search/query.rb +0 -140
  191. data/lib/ferret/search/query_filter.rb +0 -51
  192. data/lib/ferret/search/range_filter.rb +0 -103
  193. data/lib/ferret/search/range_query.rb +0 -139
  194. data/lib/ferret/search/req_excl_scorer.rb +0 -125
  195. data/lib/ferret/search/req_opt_sum_scorer.rb +0 -70
  196. data/lib/ferret/search/score_doc.rb +0 -38
  197. data/lib/ferret/search/score_doc_comparator.rb +0 -114
  198. data/lib/ferret/search/scorer.rb +0 -91
  199. data/lib/ferret/search/similarity.rb +0 -278
  200. data/lib/ferret/search/sloppy_phrase_scorer.rb +0 -47
  201. data/lib/ferret/search/sort.rb +0 -112
  202. data/lib/ferret/search/sort_comparator.rb +0 -60
  203. data/lib/ferret/search/sort_field.rb +0 -91
  204. data/lib/ferret/search/spans.rb +0 -12
  205. data/lib/ferret/search/spans/near_spans_enum.rb +0 -304
  206. data/lib/ferret/search/spans/span_first_query.rb +0 -79
  207. data/lib/ferret/search/spans/span_near_query.rb +0 -108
  208. data/lib/ferret/search/spans/span_not_query.rb +0 -130
  209. data/lib/ferret/search/spans/span_or_query.rb +0 -176
  210. data/lib/ferret/search/spans/span_query.rb +0 -25
  211. data/lib/ferret/search/spans/span_scorer.rb +0 -74
  212. data/lib/ferret/search/spans/span_term_query.rb +0 -105
  213. data/lib/ferret/search/spans/span_weight.rb +0 -84
  214. data/lib/ferret/search/spans/spans_enum.rb +0 -44
  215. data/lib/ferret/search/term_query.rb +0 -128
  216. data/lib/ferret/search/term_scorer.rb +0 -183
  217. data/lib/ferret/search/top_docs.rb +0 -36
  218. data/lib/ferret/search/top_field_docs.rb +0 -17
  219. data/lib/ferret/search/weight.rb +0 -54
  220. data/lib/ferret/search/wildcard_query.rb +0 -26
  221. data/lib/ferret/search/wildcard_term_enum.rb +0 -61
  222. data/lib/ferret/stemmers.rb +0 -1
  223. data/lib/ferret/stemmers/porter_stemmer.rb +0 -218
  224. data/lib/ferret/store.rb +0 -5
  225. data/lib/ferret/store/buffered_index_io.rb +0 -190
  226. data/lib/ferret/store/directory.rb +0 -141
  227. data/lib/ferret/store/fs_store.rb +0 -381
  228. data/lib/ferret/store/index_io.rb +0 -245
  229. data/lib/ferret/store/ram_store.rb +0 -286
  230. data/lib/ferret/utils.rb +0 -8
  231. data/lib/ferret/utils/bit_vector.rb +0 -123
  232. data/lib/ferret/utils/date_tools.rb +0 -138
  233. data/lib/ferret/utils/number_tools.rb +0 -91
  234. data/lib/ferret/utils/parameter.rb +0 -41
  235. data/lib/ferret/utils/priority_queue.rb +0 -120
  236. data/lib/ferret/utils/string_helper.rb +0 -47
  237. data/lib/ferret/utils/thread_local.rb +0 -28
  238. data/lib/ferret/utils/weak_key_hash.rb +0 -60
  239. data/lib/rferret.rb +0 -37
  240. data/rake_utils/code_statistics.rb +0 -106
  241. data/test/benchmark/tb_ram_store.rb +0 -76
  242. data/test/benchmark/tb_rw_vint.rb +0 -26
  243. data/test/functional/thread_safety_index_test.rb +0 -81
  244. data/test/functional/thread_safety_test.rb +0 -137
  245. data/test/longrunning/tc_numbertools.rb +0 -60
  246. data/test/longrunning/tm_store.rb +0 -19
  247. data/test/unit/analysis/ctc_analyzer.rb +0 -532
  248. data/test/unit/analysis/data/wordfile +0 -6
  249. data/test/unit/analysis/rtc_letter_tokenizer.rb +0 -20
  250. data/test/unit/analysis/rtc_lower_case_filter.rb +0 -20
  251. data/test/unit/analysis/rtc_lower_case_tokenizer.rb +0 -27
  252. data/test/unit/analysis/rtc_per_field_analyzer_wrapper.rb +0 -39
  253. data/test/unit/analysis/rtc_porter_stem_filter.rb +0 -16
  254. data/test/unit/analysis/rtc_standard_analyzer.rb +0 -20
  255. data/test/unit/analysis/rtc_standard_tokenizer.rb +0 -20
  256. data/test/unit/analysis/rtc_stop_analyzer.rb +0 -20
  257. data/test/unit/analysis/rtc_stop_filter.rb +0 -14
  258. data/test/unit/analysis/rtc_white_space_analyzer.rb +0 -21
  259. data/test/unit/analysis/rtc_white_space_tokenizer.rb +0 -20
  260. data/test/unit/analysis/rtc_word_list_loader.rb +0 -32
  261. data/test/unit/analysis/tc_token.rb +0 -25
  262. data/test/unit/document/rtc_field.rb +0 -28
  263. data/test/unit/document/tc_document.rb +0 -47
  264. data/test/unit/document/tc_field.rb +0 -98
  265. data/test/unit/index/rtc_compound_file_io.rb +0 -107
  266. data/test/unit/index/rtc_field_infos.rb +0 -127
  267. data/test/unit/index/rtc_fields_io.rb +0 -167
  268. data/test/unit/index/rtc_multiple_term_doc_pos_enum.rb +0 -83
  269. data/test/unit/index/rtc_segment_infos.rb +0 -74
  270. data/test/unit/index/rtc_segment_term_docs.rb +0 -17
  271. data/test/unit/index/rtc_segment_term_enum.rb +0 -60
  272. data/test/unit/index/rtc_segment_term_vector.rb +0 -71
  273. data/test/unit/index/rtc_term_buffer.rb +0 -57
  274. data/test/unit/index/rtc_term_info.rb +0 -19
  275. data/test/unit/index/rtc_term_infos_io.rb +0 -192
  276. data/test/unit/index/rtc_term_vectors_io.rb +0 -108
  277. data/test/unit/index/tc_term.rb +0 -27
  278. data/test/unit/index/tc_term_voi.rb +0 -18
  279. data/test/unit/search/rtc_similarity.rb +0 -37
  280. data/test/unit/search/rtc_sort_field.rb +0 -14
  281. data/test/unit/search/tc_multi_searcher2.rb +0 -126
  282. data/test/unit/store/rtc_fs_store.rb +0 -62
  283. data/test/unit/store/rtc_ram_store.rb +0 -15
  284. data/test/unit/store/rtm_store.rb +0 -150
  285. data/test/unit/store/rtm_store_lock.rb +0 -2
  286. data/test/unit/ts_document.rb +0 -2
  287. data/test/unit/utils/rtc_bit_vector.rb +0 -73
  288. data/test/unit/utils/rtc_date_tools.rb +0 -50
  289. data/test/unit/utils/rtc_number_tools.rb +0 -59
  290. data/test/unit/utils/rtc_parameter.rb +0 -40
  291. data/test/unit/utils/rtc_priority_queue.rb +0 -62
  292. data/test/unit/utils/rtc_string_helper.rb +0 -21
  293. data/test/unit/utils/rtc_thread.rb +0 -61
  294. data/test/unit/utils/rtc_weak_key_hash.rb +0 -25
  295. data/test/utils/number_to_spoken.rb +0 -132
data/ext/posh.h ADDED
@@ -0,0 +1,1007 @@
1
+ /**
2
+ @file posh.h
3
+ @author Brian Hook
4
+ @version 1.3.001
5
+
6
+ Header file for POSH, the Portable Open Source Harness project.
7
+
8
+ NOTE: Unlike most header files, this one is designed to be included
9
+ multiple times, which is why it does not have the @#ifndef/@#define
10
+ preamble.
11
+
12
+ POSH relies on environment specified preprocessor symbols in order
13
+ to infer as much as possible about the target OS/architecture and
14
+ the host compiler capabilities.
15
+
16
+ NOTE: POSH is simple and focused. It attempts to provide basic
17
+ functionality and information, but it does NOT attempt to emulate
18
+ missing functionality. I am also not willing to make POSH dirty
19
+ and hackish to support truly ancient and/or outmoded and/or bizarre
20
+ technologies such as non-ANSI compilers, systems with non-IEEE
21
+ floating point formats, segmented 16-bit operating systems, etc.
22
+
23
+ Please refer to the accompanying HTML documentation or visit
24
+ http://www.poshlib.org for more information on how to use POSH.
25
+
26
+ LICENSE:
27
+
28
+ Copyright (c) 2004, Brian Hook
29
+ All rights reserved.
30
+
31
+ Redistribution and use in source and binary forms, with or without
32
+ modification, are permitted provided that the following conditions are
33
+ met:
34
+
35
+ * Redistributions of source code must retain the above copyright
36
+ notice, this list of conditions and the following disclaimer.
37
+
38
+ * Redistributions in binary form must reproduce the above
39
+ copyright notice, this list of conditions and the following
40
+ disclaimer in the documentation and/or other materials provided
41
+ with the distribution.
42
+
43
+ * The names of this package'ss contributors contributors may not
44
+ be used to endorse or promote products derived from this
45
+ software without specific prior written permission.
46
+
47
+
48
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
+
60
+ REVISION:
61
+
62
+ I've been lax about revision histories, so this starts at, um, 1.3.001.
63
+ Sorry for any inconveniences.
64
+
65
+ 1.3.001 - 2/23/2006 - Incorporated fix for bug reported by Bill Cary,
66
+ where I was not detecting Visual Studio
67
+ compilation on x86-64 systems. Added check for
68
+ _M_X64 which should fix that.
69
+
70
+ */
71
+ /*
72
+ I have yet to find an authoritative reference on preprocessor
73
+ symbols, but so far this is what I've gleaned:
74
+
75
+ GNU GCC/G++:
76
+ - __GNUC__: GNU C version
77
+ - __GNUG__: GNU C++ compiler
78
+ - __sun__ : on Sun platforms
79
+ - __svr4__: on Solaris and other SysV R4 platforms
80
+ - __mips__: on MIPS processor platforms
81
+ - __sparc_v9__: on Sparc 64-bit CPUs
82
+ - __sparcv9: 64-bit Solaris
83
+ - __MIPSEL__: mips processor, compiled for little endian
84
+ - __MIPSEB__: mips processor, compiled for big endian
85
+ - _R5900: MIPS/Sony/Toshiba R5900 (PS2)
86
+ - mc68000: 68K
87
+ - m68000: 68K
88
+ - m68k: 68K
89
+ - __palmos__: PalmOS
90
+
91
+ Intel C/C++ Compiler:
92
+ - __ECC : compiler version, IA64 only
93
+ - __EDG__
94
+ - __ELF__
95
+ - __GXX_ABI_VERSION
96
+ - __i386 : IA-32 only
97
+ - __i386__ : IA-32 only
98
+ - i386 : IA-32 only
99
+ - __ia64 : IA-64 only
100
+ - __ia64__ : IA-64 only
101
+ - ia64 : IA-64 only
102
+ - __ICC : IA-32 only
103
+ - __INTEL_COMPILER : IA-32 or IA-64, newer versions only
104
+
105
+ Apple's C/C++ Compiler for OS X:
106
+ - __APPLE_CC__
107
+ - __APPLE__
108
+ - __BIG_ENDIAN__
109
+ - __APPLE__
110
+ - __ppc__
111
+ - __MACH__
112
+
113
+ DJGPP:
114
+ - __MSDOS__
115
+ - __unix__
116
+ - __unix
117
+ - __GNUC__
118
+ - __GO32
119
+ - DJGPP
120
+ - __i386, __i386, i386
121
+
122
+ Cray's C compiler:
123
+ - _ADDR64: if 64-bit pointers
124
+ - _UNICOS:
125
+ - __unix:
126
+
127
+ SGI's CC compiler predefines the following (and more) with -ansi:
128
+ - __sgi
129
+ - __unix
130
+ - __host_mips
131
+ - _SYSTYPE_SVR4
132
+ - __mips
133
+ - _MIPSEB
134
+ - anyone know if there is a predefined symbol for the compiler?!
135
+
136
+ MinGW:
137
+ - as GnuC but also defines _WIN32, __WIN32, WIN32, _X86_, __i386, __i386__, and several others
138
+ - __MINGW32__
139
+
140
+ Cygwin:
141
+ - as Gnu C, but also
142
+ - __unix__
143
+ - __CYGWIN32__
144
+
145
+ Microsoft Visual Studio predefines the following:
146
+ - _MSC_VER
147
+ - _WIN32: on Win32
148
+ - _M_IX6 (on x86 systems)
149
+ - _M_X64: on x86-64 systems
150
+ - _M_ALPHA (on DEC AXP systems)
151
+ - _SH3: WinCE, Hitachi SH-3
152
+ - _MIPS: WinCE, MIPS
153
+ - _ARM: WinCE, ARM
154
+
155
+ Sun's C Compiler:
156
+ - sun and _sun
157
+ - unix and _unix
158
+ - sparc and _sparc (SPARC systems only)
159
+ - i386 and _i386 (x86 systems only)
160
+ - __SVR4 (Solaris only)
161
+ - __sparcv9: 64-bit solaris
162
+ - __SUNPRO_C
163
+ - _LP64: defined in 64-bit LP64 mode, but only if <sys/types.h> is included
164
+
165
+ Borland C/C++ predefines the following:
166
+ - __BORLANDC__:
167
+
168
+ DEC/Compaq C/C++ on Alpha:
169
+ - __alpha
170
+ - __arch64__
171
+ - __unix__ (on Tru64 Unix)
172
+ - __osf__
173
+ - __DECC
174
+ - __DECCXX (C++ compilation)
175
+ - __DECC_VER
176
+ - __DECCXX_VER
177
+
178
+ IBM's AIX compiler:
179
+ - __64BIT__ if 64-bit mode
180
+ - _AIX
181
+ - __IBMC__: C compiler version
182
+ - __IBMCPP__: C++ compiler version
183
+ - _LONG_LONG: compiler allows long long
184
+
185
+ Watcom:
186
+ - __WATCOMC__
187
+ - __DOS__ : if targeting DOS
188
+ - __386__ : if 32-bit support
189
+ - __WIN32__ : if targetin 32-bit Windows
190
+
191
+ HP-UX C/C++ Compiler:
192
+ - __hpux
193
+ - __unix
194
+ - __hppa (on PA-RISC)
195
+ - __LP64__: if compiled in 64-bit mode
196
+
197
+ Metrowerks:
198
+ - __MWERKS__
199
+ - __powerpc__
200
+ - _powerc
201
+ - __MC68K__
202
+ - macintosh when compiling for MacOS
203
+ - __INTEL__ for x86 targets
204
+ - __POWERPC__
205
+
206
+ */
207
+
208
+ /*
209
+ ** ----------------------------------------------------------------------------
210
+ ** Include <limits.h> optionally
211
+ ** ----------------------------------------------------------------------------
212
+ */
213
+ #ifdef POSH_USE_LIMITS_H
214
+ # include <limits.h>
215
+ #endif
216
+
217
+ /*
218
+ ** ----------------------------------------------------------------------------
219
+ ** Determine compilation environment
220
+ ** ----------------------------------------------------------------------------
221
+ */
222
+ #if defined __ECC || defined __ICC || defined __INTEL_COMPILER
223
+ # define POSH_COMPILER_STRING "Intel C/C++"
224
+ # define POSH_COMPILER_INTEL 1
225
+ #endif
226
+
227
+ #if ( defined __host_mips || defined __sgi ) && !defined __GNUC__
228
+ # define POSH_COMPILER_STRING "MIPSpro C/C++"
229
+ # define POSH_COMPILER_MIPSPRO 1
230
+ #endif
231
+
232
+ #if defined __hpux && !defined __GNUC__
233
+ # define POSH_COMPILER_STRING "HP-UX CC"
234
+ # define POSH_COMPILER_HPCC 1
235
+ #endif
236
+
237
+ #if defined __GNUC__
238
+ # define POSH_COMPILER_STRING "Gnu GCC"
239
+ # define POSH_COMPILER_GCC 1
240
+ #endif
241
+
242
+ #if defined __APPLE_CC__
243
+ /* we don't define the compiler string here, let it be GNU */
244
+ # define POSH_COMPILER_APPLECC 1
245
+ #endif
246
+
247
+ #if defined __IBMC__ || defined __IBMCPP__
248
+ # define POSH_COMPILER_STRING "IBM C/C++"
249
+ # define POSH_COMPILER_IBM 1
250
+ #endif
251
+
252
+ #if defined _MSC_VER
253
+ # define POSH_COMPILER_STRING "Microsoft Visual C++"
254
+ # define POSH_COMPILER_MSVC 1
255
+ #endif
256
+
257
+ #if defined __SUNPRO_C
258
+ # define POSH_COMPILER_STRING "Sun Pro"
259
+ # define POSH_COMPILER_SUN 1
260
+ #endif
261
+
262
+ #if defined __BORLANDC__
263
+ # define POSH_COMPILER_STRING "Borland C/C++"
264
+ # define POSH_COMPILER_BORLAND 1
265
+ #endif
266
+
267
+ #if defined __MWERKS__
268
+ # define POSH_COMPILER_STRING "MetroWerks CodeWarrior"
269
+ # define POSH_COMPILER_METROWERKS 1
270
+ #endif
271
+
272
+ #if defined __DECC || defined __DECCXX
273
+ # define POSH_COMPILER_STRING "Compaq/DEC C/C++"
274
+ # define POSH_COMPILER_DEC 1
275
+ #endif
276
+
277
+ #if defined __WATCOMC__
278
+ # define POSH_COMPILER_STRING "Watcom C/C++"
279
+ # define POSH_COMPILER_WATCOM 1
280
+ #endif
281
+
282
+ #if !defined POSH_COMPILER_STRING
283
+ # define POSH_COMPILER_STRING "Unknown compiler"
284
+ #endif
285
+
286
+ /*
287
+ ** ----------------------------------------------------------------------------
288
+ ** Determine target operating system
289
+ ** ----------------------------------------------------------------------------
290
+ */
291
+ #if defined linux || defined __linux__
292
+ # define POSH_OS_LINUX 1
293
+ # define POSH_OS_STRING "Linux"
294
+ #endif
295
+
296
+ #if defined __CYGWIN32__
297
+ # define POSH_OS_CYGWIN32 1
298
+ # define POSH_OS_STRING "Cygwin"
299
+ #endif
300
+
301
+ #if defined GEKKO
302
+ # define POSH_OS_GAMECUBE
303
+ # define __powerpc__
304
+ # define POSH_OS_STRING "GameCube"
305
+ #endif
306
+
307
+ #if defined __MINGW32__
308
+ # define POSH_OS_MINGW 1
309
+ # define POSH_OS_STRING "MinGW"
310
+ #endif
311
+
312
+ #if defined GO32 && defined DJGPP && defined __MSDOS__
313
+ # define POSH_OS_GO32 1
314
+ # define POSH_OS_STRING "GO32/MS-DOS"
315
+ #endif
316
+
317
+ /* NOTE: make sure you use /bt=DOS if compiling for 32-bit DOS,
318
+ otherwise Watcom assumes host=target */
319
+ #if defined __WATCOMC__ && defined __386__ && defined __DOS__
320
+ # define POSH_OS_DOS32 1
321
+ # define POSH_OS_STRING "DOS/32-bit"
322
+ #endif
323
+
324
+ #if defined _UNICOS
325
+ # define POSH_OS_UNICOS 1
326
+ # define POSH_OS_STRING "UNICOS"
327
+ #endif
328
+
329
+ #if ( defined __MWERKS__ && defined __powerc && !defined macintosh ) || defined __APPLE_CC__ || defined macosx
330
+ # define POSH_OS_OSX 1
331
+ # define POSH_OS_STRING "MacOS X"
332
+ #endif
333
+
334
+ #if defined __sun__ || defined sun || defined __sun || defined __solaris__
335
+ # if defined __SVR4 || defined __svr4__ || defined __solaris__
336
+ # define POSH_OS_STRING "Solaris"
337
+ # define POSH_OS_SOLARIS 1
338
+ # endif
339
+ # if !defined POSH_OS_STRING
340
+ # define POSH_OS_STRING "SunOS"
341
+ # define POSH_OS_SUNOS 1
342
+ # endif
343
+ #endif
344
+
345
+ #if defined __sgi__ || defined sgi || defined __sgi
346
+ # define POSH_OS_IRIX 1
347
+ # define POSH_OS_STRING "Irix"
348
+ #endif
349
+
350
+ #if defined __hpux__ || defined __hpux
351
+ # define POSH_OS_HPUX 1
352
+ # define POSH_OS_STRING "HP-UX"
353
+ #endif
354
+
355
+ #if defined _AIX
356
+ # define POSH_OS_AIX 1
357
+ # define POSH_OS_STRING "AIX"
358
+ #endif
359
+
360
+ #if ( defined __alpha && defined __osf__ )
361
+ # define POSH_OS_TRU64 1
362
+ # define POSH_OS_STRING "Tru64"
363
+ #endif
364
+
365
+ #if defined __BEOS__ || defined __beos__
366
+ # define POSH_OS_BEOS 1
367
+ # define POSH_OS_STRING "BeOS"
368
+ #endif
369
+
370
+ #if defined amiga || defined amigados || defined AMIGA || defined _AMIGA
371
+ # define POSH_OS_AMIGA 1
372
+ # define POSH_OS_STRING "Amiga"
373
+ #endif
374
+
375
+ #if defined __unix__
376
+ # define POSH_OS_UNIX 1
377
+ # if !defined POSH_OS_STRING
378
+ # define POSH_OS_STRING "Unix-like(generic)"
379
+ # endif
380
+ #endif
381
+
382
+ #if defined _WIN32_WCE
383
+ # define POSH_OS_WINCE 1
384
+ # define POSH_OS_STRING "Windows CE"
385
+ #endif
386
+
387
+ #if defined _XBOX
388
+ # define POSH_OS_XBOX 1
389
+ # define POSH_OS_STRING "XBOX"
390
+ #endif
391
+
392
+ #if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__
393
+ # define POSH_OS_WIN32 1
394
+ # if !defined POSH_OS_XBOX
395
+ # if defined _WIN64
396
+ # define POSH_OS_WIN64 1
397
+ # define POSH_OS_STRING "Win64"
398
+ # else
399
+ # if !defined POSH_OS_STRING
400
+ # define POSH_OS_STRING "Win32"
401
+ # endif
402
+ # endif
403
+ # endif
404
+ #endif
405
+
406
+ #if defined __palmos__
407
+ # define POSH_OS_PALM 1
408
+ # define POSH_OS_STRING "PalmOS"
409
+ #endif
410
+
411
+ #if defined THINK_C || defined macintosh
412
+ # define POSH_OS_MACOS 1
413
+ # define POSH_OS_STRING "MacOS"
414
+ #endif
415
+
416
+ /*
417
+ ** -----------------------------------------------------------------------------
418
+ ** Determine target CPU
419
+ ** -----------------------------------------------------------------------------
420
+ */
421
+
422
+ #if defined GEKKO
423
+ # define POSH_CPU_PPC750 1
424
+ # define POSH_CPU_STRING "IBM PowerPC 750 (NGC)"
425
+ #endif
426
+
427
+ #if defined mc68000 || defined m68k || defined __MC68K__ || defined m68000
428
+ # define POSH_CPU_68K 1
429
+ # define POSH_CPU_STRING "MC68000"
430
+ #endif
431
+
432
+ #if defined __PPC__ || defined __POWERPC__ || defined powerpc || defined _POWER || defined __ppc__ || defined __powerpc__
433
+ # define POSH_CPU_PPC 1
434
+ # if !defined POSH_CPU_STRING
435
+ # if defined __powerpc64__
436
+ # define POSH_CPU_STRING "PowerPC64"
437
+ # else
438
+ # define POSH_CPU_STRING "PowerPC"
439
+ # endif
440
+ # endif
441
+ #endif
442
+
443
+ #if defined _CRAYT3E || defined _CRAYMPP
444
+ # define POSH_CPU_CRAYT3E 1 /* target processor is a DEC Alpha 21164 used in a Cray T3E*/
445
+ # define POSH_CPU_STRING "Cray T3E (Alpha 21164)"
446
+ #endif
447
+
448
+ #if defined CRAY || defined _CRAY && !defined _CRAYT3E
449
+ # error Non-AXP Cray systems not supported
450
+ #endif
451
+
452
+ #if defined _SH3
453
+ # define POSH_CPU_SH3 1
454
+ # define POSH_CPU_STRING "Hitachi SH-3"
455
+ #endif
456
+
457
+ #if defined __sh4__ || defined __SH4__
458
+ # define POSH_CPU_SH3 1
459
+ # define POSH_CPU_SH4 1
460
+ # define POSH_CPU_STRING "Hitachi SH-4"
461
+ #endif
462
+
463
+ #if defined __sparc__ || defined __sparc
464
+ # if defined __arch64__ || defined __sparcv9 || defined __sparc_v9__
465
+ # define POSH_CPU_SPARC64 1
466
+ # define POSH_CPU_STRING "Sparc/64"
467
+ # else
468
+ # define POSH_CPU_STRING "Sparc/32"
469
+ # endif
470
+ # define POSH_CPU_SPARC 1
471
+ #endif
472
+
473
+ #if defined ARM || defined __arm__ || defined _ARM
474
+ # define POSH_CPU_STRONGARM 1
475
+ # define POSH_CPU_STRING "ARM"
476
+ #endif
477
+
478
+ #if defined mips || defined __mips__ || defined __MIPS__ || defined _MIPS
479
+ # define POSH_CPU_MIPS 1
480
+ # if defined _R5900
481
+ # define POSH_CPU_STRING "MIPS R5900 (PS2)"
482
+ # else
483
+ # define POSH_CPU_STRING "MIPS"
484
+ # endif
485
+ #endif
486
+
487
+ #if defined __ia64 || defined _M_IA64 || defined __ia64__
488
+ # define POSH_CPU_IA64 1
489
+ # define POSH_CPU_STRING "IA64"
490
+ #endif
491
+
492
+ #if defined __X86__ || defined __i386__ || defined i386 || defined _M_IX86 || defined __386__ || defined __x86_64__ || defined _M_X64
493
+ # define POSH_CPU_X86 1
494
+ # if defined __x86_64__ || defined _M_X64
495
+ # define POSH_CPU_X86_64 1
496
+ # endif
497
+ # if defined POSH_CPU_X86_64
498
+ # define POSH_CPU_STRING "AMD x86-64"
499
+ # else
500
+ # define POSH_CPU_STRING "Intel 386+"
501
+ # endif
502
+ #endif
503
+
504
+ #if defined __alpha || defined alpha || defined _M_ALPHA || defined __alpha__
505
+ # define POSH_CPU_AXP 1
506
+ # define POSH_CPU_STRING "AXP"
507
+ #endif
508
+
509
+ #if defined __hppa || defined hppa
510
+ # define POSH_CPU_HPPA 1
511
+ # define POSH_CPU_STRING "PA-RISC"
512
+ #endif
513
+
514
+ #if !defined POSH_CPU_STRING
515
+ # error POSH cannot determine target CPU
516
+ # define POSH_CPU_STRING "Unknown" /* this is here for Doxygen's benefit */
517
+ #endif
518
+
519
+ /*
520
+ ** -----------------------------------------------------------------------------
521
+ ** Attempt to autodetect building for embedded on Sony PS2
522
+ ** -----------------------------------------------------------------------------
523
+ */
524
+ #if !defined POSH_OS_STRING
525
+ # if !defined FORCE_DOXYGEN
526
+ # define POSH_OS_EMBEDDED 1
527
+ # endif
528
+ # if defined _R5900
529
+ # define POSH_OS_STRING "Sony PS2(embedded)"
530
+ # else
531
+ # define POSH_OS_STRING "Embedded/Unknown"
532
+ # endif
533
+ #endif
534
+
535
+ /*
536
+ ** ---------------------------------------------------------------------------
537
+ ** Handle cdecl, stdcall, fastcall, etc.
538
+ ** ---------------------------------------------------------------------------
539
+ */
540
+ #if defined POSH_CPU_X86 && !defined POSH_CPU_X86_64
541
+ # if defined __GNUC__
542
+ # define POSH_CDECL __attribute__((cdecl))
543
+ # define POSH_STDCALL __attribute__((stdcall))
544
+ # define POSH_FASTCALL __attribute__((fastcall))
545
+ # elif ( defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__ || defined __MWERKS__ )
546
+ # define POSH_CDECL __cdecl
547
+ # define POSH_STDCALL __stdcall
548
+ # define POSH_FASTCALL __fastcall
549
+ # endif
550
+ #else
551
+ # define POSH_CDECL
552
+ # define POSH_STDCALL
553
+ # define POSH_FASTCALL
554
+ #endif
555
+
556
+ /*
557
+ ** ---------------------------------------------------------------------------
558
+ ** Define POSH_IMPORTEXPORT signature based on POSH_DLL and POSH_BUILDING_LIB
559
+ ** ---------------------------------------------------------------------------
560
+ */
561
+
562
+ /*
563
+ ** We undefine this so that multiple inclusions will work
564
+ */
565
+ #if defined POSH_IMPORTEXPORT
566
+ # undef POSH_IMPORTEXPORT
567
+ #endif
568
+
569
+ #if defined POSH_DLL
570
+ # if defined POSH_OS_WIN32
571
+ # if defined _MSC_VER
572
+ # if ( _MSC_VER >= 800 )
573
+ # if defined POSH_BUILDING_LIB
574
+ # define POSH_IMPORTEXPORT __declspec( dllexport )
575
+ # else
576
+ # define POSH_IMPORTEXPORT __declspec( dllimport )
577
+ # endif
578
+ # else
579
+ # if defined POSH_BUILDING_LIB
580
+ # define POSH_IMPORTEXPORT __export
581
+ # else
582
+ # define POSH_IMPORTEXPORT
583
+ # endif
584
+ # endif
585
+ # endif /* defined _MSC_VER */
586
+ # if defined __BORLANDC__
587
+ # if ( __BORLANDC__ >= 0x500 )
588
+ # if defined POSH_BUILDING_LIB
589
+ # define POSH_IMPORTEXPORT __declspec( dllexport )
590
+ # else
591
+ # define POSH_IMPORTEXPORT __declspec( dllimport )
592
+ # endif
593
+ # else
594
+ # if defined POSH_BUILDING_LIB
595
+ # define POSH_IMPORTEXPORT __export
596
+ # else
597
+ # define POSH_IMPORTEXPORT
598
+ # endif
599
+ # endif
600
+ # endif /* defined __BORLANDC__ */
601
+ /* for all other compilers, we're just making a blanket assumption */
602
+ # if defined __GNUC__ || defined __WATCOMC__ || defined __MWERKS__
603
+ # if defined POSH_BUILDING_LIB
604
+ # define POSH_IMPORTEXPORT __declspec( dllexport )
605
+ # else
606
+ # define POSH_IMPORTEXPORT __declspec( dllimport )
607
+ # endif
608
+ # endif /* all other compilers */
609
+ # if !defined POSH_IMPORTEXPORT
610
+ # error Building DLLs not supported on this compiler (poshlib@poshlib.org if you know how)
611
+ # endif
612
+ # endif /* defined POSH_OS_WIN32 */
613
+ #endif
614
+
615
+ /* On pretty much everything else, we can thankfully just ignore this */
616
+ #if !defined POSH_IMPORTEXPORT
617
+ # define POSH_IMPORTEXPORT
618
+ #endif
619
+
620
+ #if defined FORCE_DOXYGEN
621
+ # define POSH_DLL
622
+ # define POSH_BUILDING_LIB
623
+ # undef POSH_DLL
624
+ # undef POSH_BUILDING_LIB
625
+ #endif
626
+
627
+ /*
628
+ ** ----------------------------------------------------------------------------
629
+ ** (Re)define POSH_PUBLIC_API export signature
630
+ ** ----------------------------------------------------------------------------
631
+ */
632
+ #ifdef POSH_PUBLIC_API
633
+ # undef POSH_PUBLIC_API
634
+ #endif
635
+
636
+ #if ( ( defined _MSC_VER ) && ( _MSC_VER < 800 ) ) || ( defined __BORLANDC__ && ( __BORLANDC__ < 0x500 ) )
637
+ # define POSH_PUBLIC_API(rtype) extern rtype POSH_IMPORTEXPORT
638
+ #else
639
+ # define POSH_PUBLIC_API(rtype) extern POSH_IMPORTEXPORT rtype
640
+ #endif
641
+
642
+ /*
643
+ ** ----------------------------------------------------------------------------
644
+ ** Try to infer endianess. Basically we just go through the CPUs we know are
645
+ ** little endian, and assume anything that isn't one of those is big endian.
646
+ ** As a sanity check, we also do this with operating systems we know are
647
+ ** little endian, such as Windows. Some processors are bi-endian, such as
648
+ ** the MIPS series, so we have to be careful about those.
649
+ ** ----------------------------------------------------------------------------
650
+ */
651
+ #if defined POSH_CPU_X86 || defined POSH_CPU_AXP || defined POSH_CPU_STRONGARM || defined POSH_OS_WIN32 || defined POSH_OS_WINCE || defined __MIPSEL__
652
+ # define POSH_ENDIAN_STRING "little"
653
+ # define POSH_LITTLE_ENDIAN 1
654
+ #else
655
+ # define POSH_ENDIAN_STRING "big"
656
+ # define POSH_BIG_ENDIAN 1
657
+ #endif
658
+
659
+ #if defined FORCE_DOXYGEN
660
+ # define POSH_LITTLE_ENDIAN
661
+ #endif
662
+
663
+ /*
664
+ ** ----------------------------------------------------------------------------
665
+ ** Cross-platform compile time assertion macro
666
+ ** ----------------------------------------------------------------------------
667
+ */
668
+ #define POSH_COMPILE_TIME_ASSERT(name, x) typedef int _POSH_dummy_ ## name[(x) ? 1 : -1 ]
669
+
670
+ /*
671
+ ** ----------------------------------------------------------------------------
672
+ ** 64-bit Integer
673
+ **
674
+ ** We don't require 64-bit support, nor do we emulate its functionality, we
675
+ ** simply export it if it's available. Since we can't count on <limits.h>
676
+ ** for 64-bit support, we ignore the POSH_USE_LIMITS_H directive.
677
+ ** ----------------------------------------------------------------------------
678
+ */
679
+ #if defined ( __LP64__ ) || defined ( __powerpc64__ ) || defined POSH_CPU_SPARC64
680
+ # define POSH_64BIT_INTEGER 1
681
+ typedef long posh_i64_t;
682
+ typedef unsigned long posh_u64_t;
683
+ # define POSH_I64( x ) ((posh_i64_t)x)
684
+ # define POSH_U64( x ) ((posh_u64_t)x)
685
+ # define POSH_I64_PRINTF_PREFIX "l"
686
+ #elif defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ || ( defined __alpha && defined __DECC )
687
+ # define POSH_64BIT_INTEGER 1
688
+ typedef __int64 posh_i64_t;
689
+ typedef unsigned __int64 posh_u64_t;
690
+ # define POSH_I64( x ) ((posh_i64_t)x)
691
+ # define POSH_U64( x ) ((posh_u64_t)x)
692
+ # define POSH_I64_PRINTF_PREFIX "I64"
693
+ #elif defined __GNUC__ || defined __MWERKS__ || defined __SUNPRO_C || defined __SUNPRO_CC || defined __APPLE_CC__ || defined POSH_OS_IRIX || defined _LONG_LONG || defined _CRAYC
694
+ # define POSH_64BIT_INTEGER 1
695
+ typedef long long posh_i64_t;
696
+ typedef unsigned long long posh_u64_t;
697
+ # define POSH_U64( x ) ((posh_u64_t)(x##LL))
698
+ # define POSH_I64( x ) ((posh_i64_t)(x##LL))
699
+ # define POSH_I64_PRINTF_PREFIX "ll"
700
+ #endif
701
+
702
+ /* hack */
703
+ #ifdef __MINGW32__
704
+ #undef POSH_I64
705
+ #undef POSH_U64
706
+ #undef POSH_I64_PRINTF_PREFIX
707
+ #define POSH_I64( x ) ((posh_i64_t)x)
708
+ #define POSH_U64( x ) ((posh_u64_t)x)
709
+ #define POSH_I64_PRINTF_PREFIX "I64"
710
+ #endif
711
+
712
+ #ifdef FORCE_DOXYGEN
713
+ typedef long long posh_i64_t;
714
+ typedef unsigned long posh_u64_t;
715
+ # define POSH_64BIT_INTEGER
716
+ # define POSH_I64_PRINTF_PREFIX
717
+ # define POSH_I64(x)
718
+ # define POSH_U64(x)
719
+ #endif
720
+
721
+ /** Minimum value for a 64-bit signed integer */
722
+ #define POSH_I64_MIN POSH_I64(0x8000000000000000)
723
+ /** Maximum value for a 64-bit signed integer */
724
+ #define POSH_I64_MAX POSH_I64(0x7FFFFFFFFFFFFFFF)
725
+ /** Minimum value for a 64-bit unsigned integer */
726
+ #define POSH_U64_MIN POSH_U64(0)
727
+ /** Maximum value for a 64-bit unsigned integer */
728
+ #define POSH_U64_MAX POSH_U64(0xFFFFFFFFFFFFFFFF)
729
+
730
+ /* ----------------------------------------------------------------------------
731
+ ** Basic Sized Types
732
+ **
733
+ ** These types are expected to be EXACTLY sized so you can use them for
734
+ ** serialization.
735
+ ** ----------------------------------------------------------------------------
736
+ */
737
+ #define POSH_FALSE 0
738
+ #define POSH_TRUE 1
739
+
740
+ typedef int posh_bool_t;
741
+ typedef unsigned char posh_byte_t;
742
+
743
+ /* NOTE: These assume that CHAR_BIT is 8!! */
744
+ typedef unsigned char posh_u8_t;
745
+ typedef signed char posh_i8_t;
746
+
747
+ #if defined POSH_USE_LIMITS_H
748
+ # if CHAR_BITS > 8
749
+ # error This machine uses 9-bit characters. This is a warning, you can comment this out now.
750
+ # endif /* CHAR_BITS > 8 */
751
+
752
+ /* 16-bit */
753
+ # if ( USHRT_MAX == 65535 )
754
+ typedef unsigned short posh_u16_t;
755
+ typedef short posh_i16_t;
756
+ # else
757
+ /* Yes, in theory there could still be a 16-bit character type and shorts are
758
+ 32-bits in size...if you find such an architecture, let me know =P */
759
+ # error No 16-bit type found
760
+ # endif
761
+
762
+ /* 32-bit */
763
+ # if ( INT_MAX == 2147483647 )
764
+ typedef unsigned posh_u32_t;
765
+ typedef int posh_i32_t;
766
+ # elif ( LONG_MAX == 2147483647 )
767
+ typedef unsigned long posh_u32_t;
768
+ typedef long posh_i32_t;
769
+ # else
770
+ error No 32-bit type found
771
+ # endif
772
+
773
+ #else /* POSH_USE_LIMITS_H */
774
+
775
+ typedef unsigned short posh_u16_t;
776
+ typedef short posh_i16_t;
777
+
778
+ # if !defined POSH_OS_PALM
779
+ typedef unsigned posh_u32_t;
780
+ typedef int posh_i32_t;
781
+ # else
782
+ typedef unsigned long posh_u32_t;
783
+ typedef long posh_i32_t;
784
+ # endif
785
+ #endif
786
+
787
+ /** Minimum value for a byte */
788
+ #define POSH_BYTE_MIN 0
789
+ /** Maximum value for an 8-bit unsigned value */
790
+ #define POSH_BYTE_MAX 255
791
+ /** Minimum value for a byte */
792
+ #define POSH_I16_MIN ( ( posh_i16_t ) 0x8000 )
793
+ /** Maximum value for a 16-bit signed value */
794
+ #define POSH_I16_MAX ( ( posh_i16_t ) 0x7FFF )
795
+ /** Minimum value for a 16-bit unsigned value */
796
+ #define POSH_U16_MIN 0
797
+ /** Maximum value for a 16-bit unsigned value */
798
+ #define POSH_U16_MAX ( ( posh_u16_t ) 0xFFFF )
799
+ /** Minimum value for a 32-bit signed value */
800
+ #define POSH_I32_MIN ( ( posh_i32_t ) 0x80000000 )
801
+ /** Maximum value for a 32-bit signed value */
802
+ #define POSH_I32_MAX ( ( posh_i32_t ) 0x7FFFFFFF )
803
+ /** Minimum value for a 32-bit unsigned value */
804
+ #define POSH_U32_MIN 0
805
+ /** Maximum value for a 32-bit unsigned value */
806
+ #define POSH_U32_MAX ( ( posh_u32_t ) 0xFFFFFFFF )
807
+
808
+ /*
809
+ ** ----------------------------------------------------------------------------
810
+ ** Sanity checks on expected sizes
811
+ ** ----------------------------------------------------------------------------
812
+ */
813
+ #if !defined FORCE_DOXYGEN
814
+
815
+ POSH_COMPILE_TIME_ASSERT(posh_byte_t, sizeof(posh_byte_t) == 1);
816
+ POSH_COMPILE_TIME_ASSERT(posh_u8_t, sizeof(posh_u8_t) == 1);
817
+ POSH_COMPILE_TIME_ASSERT(posh_i8_t, sizeof(posh_i8_t) == 1);
818
+ POSH_COMPILE_TIME_ASSERT(posh_u16_t, sizeof(posh_u16_t) == 2);
819
+ POSH_COMPILE_TIME_ASSERT(posh_i16_t, sizeof(posh_i16_t) == 2);
820
+ POSH_COMPILE_TIME_ASSERT(posh_u32_t, sizeof(posh_u32_t) == 4);
821
+ POSH_COMPILE_TIME_ASSERT(posh_i32_t, sizeof(posh_i32_t) == 4);
822
+
823
+ #if !defined POSH_NO_FLOAT
824
+ POSH_COMPILE_TIME_ASSERT(posh_testfloat_t, sizeof(float)==4 );
825
+ POSH_COMPILE_TIME_ASSERT(posh_testdouble_t, sizeof(double)==8);
826
+ #endif
827
+
828
+ #if defined POSH_64BIT_INTEGER
829
+ POSH_COMPILE_TIME_ASSERT(posh_u64_t, sizeof(posh_u64_t) == 8);
830
+ POSH_COMPILE_TIME_ASSERT(posh_i64_t, sizeof(posh_i64_t) == 8);
831
+ #endif
832
+
833
+ #endif
834
+
835
+ /*
836
+ ** ----------------------------------------------------------------------------
837
+ ** 64-bit pointer support
838
+ ** ----------------------------------------------------------------------------
839
+ */
840
+ #if defined POSH_CPU_AXP && ( defined POSH_OS_TRU64 || defined POSH_OS_LINUX )
841
+ # define POSH_64BIT_POINTER 1
842
+ #endif
843
+
844
+ #if defined POSH_CPU_X86_64 && defined POSH_OS_LINUX
845
+ # define POSH_64BIT_POINTER 1
846
+ #endif
847
+
848
+ #if defined POSH_CPU_SPARC64 || defined POSH_OS_WIN64 || defined __64BIT__ || defined __LP64 || defined _LP64 || defined __LP64__ || defined _ADDR64 || defined _CRAYC
849
+ # define POSH_64BIT_POINTER 1
850
+ #endif
851
+
852
+ #if defined POSH_64BIT_POINTER
853
+ POSH_COMPILE_TIME_ASSERT( posh_64bit_pointer, sizeof( void * ) == 8 );
854
+ #elif !defined FORCE_DOXYGEN
855
+ /* if this assertion is hit then you're on a system that either has 64-bit
856
+ addressing and we didn't catch it, or you're on a system with 16-bit
857
+ pointers. In the latter case, POSH doesn't actually care, we're just
858
+ triggering this assertion to make sure you're aware of the situation,
859
+ so feel free to delete it.
860
+
861
+ If this assertion is triggered on a known 32 or 64-bit platform,
862
+ please let us know (poshlib@poshlib.org) */
863
+ POSH_COMPILE_TIME_ASSERT( posh_32bit_pointer, sizeof( void * ) == 4 );
864
+ #endif
865
+
866
+ #if defined FORCE_DOXYGEN
867
+ # define POSH_64BIT_POINTER
868
+ #endif
869
+
870
+ /*
871
+ ** ----------------------------------------------------------------------------
872
+ ** POSH Utility Functions
873
+ **
874
+ ** These are optional POSH utility functions that are not required if you don't
875
+ ** need anything except static checking of your host and target environment.
876
+ **
877
+ ** These functions are NOT wrapped with POSH_PUBLIC_API because I didn't want
878
+ ** to enforce their export if your own library is only using them internally.
879
+ ** ----------------------------------------------------------------------------
880
+ */
881
+ #ifdef __cplusplus
882
+ extern "C" {
883
+ #endif
884
+
885
+ const char *POSH_GetArchString( void );
886
+
887
+ #if !defined POSH_NO_FLOAT
888
+
889
+ posh_u32_t POSH_LittleFloatBits( float f );
890
+ posh_u32_t POSH_BigFloatBits( float f );
891
+ float POSH_FloatFromLittleBits( posh_u32_t bits );
892
+ float POSH_FloatFromBigBits( posh_u32_t bits );
893
+
894
+ void POSH_DoubleBits( double d, posh_byte_t dst[ 8 ] );
895
+ double POSH_DoubleFromBits( const posh_byte_t src[ 8 ] );
896
+
897
+ /* unimplemented
898
+ float *POSH_WriteFloatToLittle( void *dst, float f );
899
+ float *POSH_WriteFloatToBig( void *dst, float f );
900
+ float POSH_ReadFloatFromLittle( const void *src );
901
+ float POSH_ReadFloatFromBig( const void *src );
902
+
903
+ double *POSH_WriteDoubleToLittle( void *dst, double d );
904
+ double *POSH_WriteDoubleToBig( void *dst, double d );
905
+ double POSH_ReadDoubleFromLittle( const void *src );
906
+ double POSH_ReadDoubleFromBig( const void *src );
907
+ */
908
+ #endif /* !defined POSH_NO_FLOAT */
909
+
910
+ #if defined FORCE_DOXYGEN
911
+ # define POSH_NO_FLOAT
912
+ # undef POSH_NO_FLOAT
913
+ #endif
914
+
915
+ extern posh_u16_t POSH_SwapU16( posh_u16_t u );
916
+ extern posh_i16_t POSH_SwapI16( posh_i16_t u );
917
+ extern posh_u32_t POSH_SwapU32( posh_u32_t u );
918
+ extern posh_i32_t POSH_SwapI32( posh_i32_t u );
919
+
920
+ #if defined POSH_64BIT_INTEGER
921
+
922
+ extern posh_u64_t POSH_SwapU64( posh_u64_t u );
923
+ extern posh_i64_t POSH_SwapI64( posh_i64_t u );
924
+
925
+ #endif /*POSH_64BIT_INTEGER */
926
+
927
+ extern posh_u16_t *POSH_WriteU16ToLittle( void *dst, posh_u16_t value );
928
+ extern posh_i16_t *POSH_WriteI16ToLittle( void *dst, posh_i16_t value );
929
+ extern posh_u32_t *POSH_WriteU32ToLittle( void *dst, posh_u32_t value );
930
+ extern posh_i32_t *POSH_WriteI32ToLittle( void *dst, posh_i32_t value );
931
+
932
+ extern posh_u16_t *POSH_WriteU16ToBig( void *dst, posh_u16_t value );
933
+ extern posh_i16_t *POSH_WriteI16ToBig( void *dst, posh_i16_t value );
934
+ extern posh_u32_t *POSH_WriteU32ToBig( void *dst, posh_u32_t value );
935
+ extern posh_i32_t *POSH_WriteI32ToBig( void *dst, posh_i32_t value );
936
+
937
+ extern posh_u16_t POSH_ReadU16FromLittle( const void *src );
938
+ extern posh_i16_t POSH_ReadI16FromLittle( const void *src );
939
+ extern posh_u32_t POSH_ReadU32FromLittle( const void *src );
940
+ extern posh_i32_t POSH_ReadI32FromLittle( const void *src );
941
+
942
+ extern posh_u16_t POSH_ReadU16FromBig( const void *src );
943
+ extern posh_i16_t POSH_ReadI16FromBig( const void *src );
944
+ extern posh_u32_t POSH_ReadU32FromBig( const void *src );
945
+ extern posh_i32_t POSH_ReadI32FromBig( const void *src );
946
+
947
+ #if defined POSH_64BIT_INTEGER
948
+ extern posh_u64_t *POSH_WriteU64ToLittle( void *dst, posh_u64_t value );
949
+ extern posh_i64_t *POSH_WriteI64ToLittle( void *dst, posh_i64_t value );
950
+ extern posh_u64_t *POSH_WriteU64ToBig( void *dst, posh_u64_t value );
951
+ extern posh_i64_t *POSH_WriteI64ToBig( void *dst, posh_i64_t value );
952
+
953
+ extern posh_u64_t POSH_ReadU64FromLittle( const void *src );
954
+ extern posh_i64_t POSH_ReadI64FromLittle( const void *src );
955
+ extern posh_u64_t POSH_ReadU64FromBig( const void *src );
956
+ extern posh_i64_t POSH_ReadI64FromBig( const void *src );
957
+ #endif /* POSH_64BIT_INTEGER */
958
+
959
+ #if defined POSH_LITTLE_ENDIAN
960
+
961
+ # define POSH_LittleU16(x) (x)
962
+ # define POSH_LittleU32(x) (x)
963
+ # define POSH_LittleI16(x) (x)
964
+ # define POSH_LittleI32(x) (x)
965
+ # if defined POSH_64BIT_INTEGER
966
+ # define POSH_LittleU64(x) (x)
967
+ # define POSH_LittleI64(x) (x)
968
+ # endif /* defined POSH_64BIT_INTEGER */
969
+
970
+ # define POSH_BigU16(x) POSH_SwapU16(x)
971
+ # define POSH_BigU32(x) POSH_SwapU32(x)
972
+ # define POSH_BigI16(x) POSH_SwapI16(x)
973
+ # define POSH_BigI32(x) POSH_SwapI32(x)
974
+ # if defined POSH_64BIT_INTEGER
975
+ # define POSH_BigU64(x) POSH_SwapU64(x)
976
+ # define POSH_BigI64(x) POSH_SwapI64(x)
977
+ # endif /* defined POSH_64BIT_INTEGER */
978
+
979
+ #else
980
+
981
+ # define POSH_BigU16(x) (x)
982
+ # define POSH_BigU32(x) (x)
983
+ # define POSH_BigI16(x) (x)
984
+ # define POSH_BigI32(x) (x)
985
+
986
+ # if defined POSH_64BIT_INTEGER
987
+ # define POSH_BigU64(x) (x)
988
+ # define POSH_BigI64(x) (x)
989
+ # endif /* POSH_64BIT_INTEGER */
990
+
991
+ # define POSH_LittleU16(x) POSH_SwapU16(x)
992
+ # define POSH_LittleU32(x) POSH_SwapU32(x)
993
+ # define POSH_LittleI16(x) POSH_SwapI16(x)
994
+ # define POSH_LittleI32(x) POSH_SwapI32(x)
995
+
996
+ # if defined POSH_64BIT_INTEGER
997
+ # define POSH_LittleU64(x) POSH_SwapU64(x)
998
+ # define POSH_LittleI64(x) POSH_SwapI64(x)
999
+ # endif /* POSH_64BIT_INTEGER */
1000
+
1001
+ #endif
1002
+
1003
+ #ifdef __cplusplus
1004
+ }
1005
+ #endif
1006
+
1007
+