1
0

y_ini.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #if defined _INC_y_ini
  2. #endinput
  3. #endif
  4. #define _INC_y_ini
  5. /**
  6. * <library name="y_ini">
  7. * <section>
  8. * Description
  9. * </section>
  10. * Reads the INI and also exports a number of functions to other "classes" for
  11. * easy reading of data files there.
  12. * <section>
  13. * Version
  14. * </section>
  15. * 1.5
  16. * <section>
  17. * Functions
  18. * </section>
  19. * <subsection>
  20. * Stock
  21. * </subsection><ul>
  22. * <symbol name="INI_Load">Loads an INI file using standard features.</symbol>
  23. * <symbol name="INI_ParseFile">Loads a file as an ini and distributes data.</symbol>
  24. * <symbol name="INI_GetEntryName">Gets the name of an INI item.</symbol>
  25. * <symbol name="INI_GetEntryText">Gets the value of an INI item.</symbol>
  26. * <symbol name="INI_Open">Opens an INI for writing.</symbol>
  27. * <symbol name="INI_Close">Closes an INI being written to.</symbol>
  28. * <symbol name="INI_SetTag">Sets a subheading in an INI fo subsequent writes.</symbol>
  29. * <symbol name="INI_WriteString">Writes a string to an INI.</symbol>
  30. * <symbol name="INI_WriteInt">Writes an int to an INI.</symbol>
  31. * <symbol name="INI_WriteFloat">Writes a float to an INI.</symbol>
  32. * <symbol name="INI_WriteHex">Writes a hex to an INI.</symbol>
  33. * <symbol name="INI_WriteBin">Writes a binary to an INI.</symbol>
  34. * <symbol name="INI_WriteBool">Writes a boolean to an INI.</symbol>
  35. * <symbol name="INI_RemoveEntry">Remove an entry from a file.</symbol>
  36. * </ul><subsection>
  37. * Static
  38. * </subsection><ul>
  39. * <symbol name="INI_WriteBuffer">Writes an INI's buffer to the file.</symbol>
  40. * <symbol name="INI_AddToBuffer">Adds a string to an INI buffer.</symbol>
  41. * </ul><subsection>
  42. * Inline
  43. * </subsection><ul>
  44. * <symbol name="INI_Int">Parse an integer INI entry.</symbol>
  45. * <symbol name="INI_Float">Parse a float INI entry.</symbol>
  46. * <symbol name="INI_Hex">Parse a hex INI entry.</symbol>
  47. * <symbol name="INI_Bin">Parse a binary INI entry.</symbol>
  48. * <symbol name="INI_Bool">Parse a binary INI entry.</symbol>
  49. * <symbol name="INI_String">Parse a string INI entry.</symbol>
  50. * </ul><section>
  51. * Definitions
  52. * </section><ul>
  53. * <symbol name="MAX_INI_TAG">Maximum length of an INI tagname.</symbol>
  54. * <symbol name="MAX_INI_ENTRY_NAME">Maximum length of an INI entry name.</symbol>
  55. * <symbol name="MAX_INI_ENTRY_TEXT">Maximum length of an INI's entries' value.</symbol>
  56. * <symbol name="MAX_INI_LINE">Maximum length of a line in a file.</symbol>
  57. * <symbol name="INI_NEW_LINE">String for new lines.</symbol>
  58. * <symbol name="INI_MAX_WRITES">Maximum concurrent files open for writing.</symbol>
  59. * <symbol name="MAX_INI_TAGS">Number of tags the buffer can hold data for at once.</symbol>
  60. * </ul><section>
  61. * Enums
  62. * </section><ul>
  63. * <symbol name="E_INI_WRITE">Storage for entries to be written.</symbol>
  64. * <symbol name="E_INI_TAGS">Data for tags with data.</symbol>
  65. * </ul><section>
  66. * Macros
  67. * </section><ul>
  68. * <symbol name="INI_Parse">Header for ini parsing functions.</symbol>
  69. * </ul><section>
  70. * Tags
  71. * </section><ul>
  72. * <symbol name="INI">Handle to an INI file being written to.</symbol>
  73. * </ul><section>
  74. * Variables
  75. * </section>
  76. * <subsection>
  77. * Static
  78. * </subsection><ul>
  79. * <symbol name="YSI_g_sINIWriteBuffer">Basic data to be written.</symbol>
  80. * <symbol name="YSI_g_sINIWritePos">Next slot to write to.</symbol>
  81. * <symbol name="YSI_g_sINITagPos">Next slot to add a tag to.</symbol>
  82. * <symbol name="YSI_g_sINICurrentTag">Pointer to the tag been writen to.</symbol>
  83. * <symbol name="YSI_g_sINIWriteTag">Data for tags,</symbol>
  84. * <symbol name="YSI_g_sINIWriteFile">Current files been written to.</symbol>
  85. * </ul>
  86. * </library>
  87. *//** *//*
  88. Legal:
  89. Version: MPL 1.1
  90. The contents of this file are subject to the Mozilla Public License Version
  91. 1.1 the "License"; you may not use this file except in compliance with
  92. the License. You may obtain a copy of the License at
  93. http://www.mozilla.org/MPL/
  94. Software distributed under the License is distributed on an "AS IS" basis,
  95. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  96. for the specific language governing rights and limitations under the
  97. License.
  98. The Original Code is the YSI framework.
  99. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  100. Portions created by the Initial Developer are Copyright C 2011
  101. the Initial Developer. All Rights Reserved.
  102. Contributors:
  103. Y_Less
  104. koolk
  105. JoeBullet/Google63
  106. g_aSlice/Slice
  107. Misiur
  108. samphunter
  109. tianmeta
  110. maddinat0r
  111. spacemud
  112. Crayder
  113. Dayvison
  114. Ahmad45123
  115. Zeex
  116. irinel1996
  117. Yiin-
  118. Chaprnks
  119. Konstantinos
  120. Masterchen09
  121. Southclaws
  122. PatchwerkQWER
  123. m0k1
  124. paulommu
  125. udan111
  126. Thanks:
  127. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  128. ZeeX - Very productive conversations.
  129. koolk - IsPlayerinAreaEx code.
  130. TheAlpha - Danish translation.
  131. breadfish - German translation.
  132. Fireburn - Dutch translation.
  133. yom - French translation.
  134. 50p - Polish translation.
  135. Zamaroht - Spanish translation.
  136. Los - Portuguese translation.
  137. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  138. me to strive to better.
  139. Pixels^ - Running XScripters where the idea was born.
  140. Matite - Pestering me to release it and using it.
  141. Very special thanks to:
  142. Thiadmer - PAWN, whose limits continue to amaze me!
  143. Kye/Kalcor - SA:MP.
  144. SA:MP Team past, present and future - SA:MP.
  145. Optional plugins:
  146. Gamer_Z - GPS.
  147. Incognito - Streamer.
  148. Me - sscanf2, fixes2, Whirlpool.
  149. */
  150. #include "..\YSI_Internal\y_compilerdata"
  151. #define MAX_INI_LINE (MAX_INI_ENTRY_NAME + MAX_INI_ENTRY_TEXT + 32)
  152. #if !defined INI_NEW_LINE
  153. #define INI_NEW_LINE "\r\n"
  154. #endif
  155. #if !defined MAX_INI_TAG
  156. #define MAX_INI_TAG (32)
  157. #endif
  158. #if !defined MAX_INI_ENTRY_NAME
  159. #define MAX_INI_ENTRY_NAME (32)
  160. #endif
  161. #if !defined MAX_INI_ENTRY_TEXT
  162. #define MAX_INI_ENTRY_TEXT YSI_MAX_INLINE_STRING
  163. #endif
  164. #if !defined INI_MAX_WRITES
  165. #define INI_MAX_WRITES (4)
  166. #endif
  167. #if !defined INI_BUFFER_SIZE
  168. #define INI_BUFFER_SIZE (128)
  169. #endif
  170. #if !defined MAX_INI_TAGS
  171. #define MAX_INI_TAGS (8)
  172. #endif
  173. #define MAX_INI_STRING FUNCTION_LENGTH
  174. #define Y_INI_WRITE_ARRAY_SIZE ((MAX_INI_ENTRY_TEXT - 1) / 16 * 16)
  175. stock const
  176. INI_NO_TAG[] = "\1"; // NULL
  177. #define INI_NO_FILE (INI:-1)
  178. #include "..\YSI_Internal\y_thirdpartyinclude"
  179. #include "..\YSI_Internal\y_version"
  180. #include "..\YSI_Core\y_utils"
  181. #include "..\YSI_Coding\y_malloc"
  182. #include "..\YSI_Coding\y_inline"
  183. #include "..\YSI_Coding\y_stringhash"
  184. #if defined YSI_TESTS
  185. #define _Y_INI_STATIC
  186. #else
  187. #define _Y_INI_STATIC static
  188. #endif
  189. #if defined YSI_TESTS && defined YSI_MOCK_READER
  190. #include "..\YSI_Internal\y_mock"
  191. #endif
  192. #include "..\YSI_Coding\y_hooks"
  193. forward e_INI_LINE_TYPE:
  194. INI_IdentifyLineType(const str[], &p0s, &p0e, &p1s, &p1e, &p2s, &p2e);
  195. #include "y_ini/reading"
  196. #include "y_ini/writing"
  197. #if defined YSI_TESTS
  198. #include "..\YSI_Core\y_testing"
  199. #include "y_ini/tests"
  200. #endif