Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. /* dumpConfig.sqf, v0.95
  2. *
  3. * Copyright (c) 2009, shreds-of-sanity@gmx.net
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23.  
  24. private ["_fn_writeToReport","_fn_dumpConfig","_fn_dumpArray","_fn_dumpText","_fn_dumpNumber","_fn_writeClassProlog","_fn_writeClassEpilog","_fn_writeArrayProlog","_fn_writeArrayEpilog","_fn_increaseIndent","_fn_decreaseIndent","_fn_duplicateSpecialChars","_tab","_indentLevel","_indent"];
  25.  
  26. #define USE_TABS
  27. #define TAB_WIDTH 2
  28.  
  29. #define OUTPUT_FUNCTION _fn_writeToReport
  30.  
  31. #define ASCII_TAB 9
  32. #define ASCII_DBLQUOTE 34
  33. #define ASCII_PERCENT 37
  34.  
  35. #define SPECIAL_CHARS [ASCII_DBLQUOTE,ASCII_PERCENT]
  36.  
  37. //////////////////////////////////////////////////////////////////////////////
  38.  
  39. _fn_writeToReport =
  40. {
  41. private["_i","_array","_stringArray"];
  42. _i = 0;
  43. _stringArray = toArray _this;
  44. if ((count _stringArray) > 1000) then
  45. {
  46. _array = [];
  47. {
  48. _array set [count _array,_x];
  49. _i = _i + 1;
  50. if (_i > 1000) then
  51. {
  52. diag_log (text (toString _array));
  53. diag_log "XXX TO REMOVE XXX";
  54. _i = 0;
  55. _array = [];
  56. };
  57. } forEach _stringArray;
  58. if ((count _array) > 0) then
  59. {
  60. diag_log (text (toString _array));
  61. };
  62. }
  63. else
  64. {
  65. diag_log (text _this);
  66. };
  67. };
  68. _fn_dumpConfig =
  69. {
  70. switch (true) do
  71. {
  72. case isClass _this:
  73. {
  74. //to found buggy model
  75. //if ( getText (_this >> "model") == "bmp" ) then
  76. //if (getText(configFile >> "CfgVehicles" >> (configName _this) >> "model") == "bmp") then
  77. //{
  78. // "found" call OUTPUT_FUNCTION;
  79. //};
  80. _this call _fn_writeClassProlog;
  81. for "_i" from 0 to (count _this - 1) do
  82. {
  83. (_this select _i) call _fn_dumpConfig;// recursion
  84. };
  85. call _fn_writeClassEpilog;
  86. };
  87. case isArray _this:
  88. {
  89. private "_s";
  90. _s = _this call _fn_writeArrayProlog;
  91. _s = _s + ([getArray _this] call _fn_dumpArray);
  92. _s = _s + "};";
  93. _s call OUTPUT_FUNCTION;
  94.  
  95. };
  96. case isNumber _this:
  97. {
  98. _this call _fn_dumpNumber;
  99. };
  100. case isText _this:
  101. {
  102. _this call _fn_dumpText;
  103. };
  104. default
  105. {
  106. hintC "ERROR: Unknown type:\n" + str _this; sleep 1;
  107. halt;
  108. };
  109. };
  110. };
  111. _fn_dumpArray =
  112. {
  113. private ["_delimiter","_count","_element","_s","_array"];
  114. _delimiter = ",";
  115. _array = _this select 0;
  116. _count = count _array - 1;
  117. _s = "";
  118.  
  119. for "_i" from 0 to _count do
  120. {
  121. _element = _array select _i;
  122. if (_i == _count) then {_delimiter = "";};// no delimiter after last element
  123.  
  124. switch (typeName _element) do
  125. {
  126. case "ARRAY":
  127. {
  128. _s = _s + "{";
  129. _newString = [_element] call _fn_dumpArray;// recursion
  130. _s = _s + _newString + "}" + _delimiter;
  131. };
  132. case "SCALAR":
  133. {
  134. _s = _s + str(_element) + _delimiter;//_indent +
  135. };
  136. case "STRING":
  137. {
  138. _newString = _element call _fn_duplicateSpecialChars;
  139. _s = _s + """" + _newString + """" + _delimiter;//_indent +
  140. };
  141. };
  142. };
  143. _s;
  144. };
  145. _fn_dumpText =
  146. {
  147. private "_s";
  148. _s = getText _this call _fn_duplicateSpecialChars;
  149. _s = _indent + configName _this + " = """ + _s + """;";
  150. _s call OUTPUT_FUNCTION;
  151. };
  152. _fn_dumpNumber =
  153. {
  154. private "_s";
  155. _s = str getNumber _this;
  156. _s = _indent + configName _this + " = " + _s + ";";
  157. _s call OUTPUT_FUNCTION;
  158. };
  159.  
  160. //////////////////////////////////////////////////////////////////////////////
  161.  
  162. _fn_writeClassProlog =
  163. {
  164. private "_s";
  165. _s = configName inheritsFrom _this;
  166. if (_s != "") then {_s = ": " + _s;};
  167.  
  168. _s = _indent + "class " + configName _this + _s;
  169. _s call OUTPUT_FUNCTION;
  170.  
  171. _s = _indent + "{";
  172. _s call OUTPUT_FUNCTION;
  173.  
  174. call _fn_increaseIndent;
  175. };
  176. _fn_writeClassEpilog =
  177. {
  178. private "_s";
  179. call _fn_decreaseIndent;
  180.  
  181. _s = _indent + "};";
  182. _s call OUTPUT_FUNCTION;
  183. };
  184. _fn_writeArrayProlog =
  185. {
  186. private "_s";
  187. _s = _indent + configName _this + "[] = {";
  188. _s;
  189. };
  190. _fn_writeArrayEpilog =
  191. {
  192. call _fn_writeClassEpilog;
  193. };
  194. _fn_increaseIndent =
  195. {
  196. _indentLevel = _indentLevel + 1;
  197. _indent = "";
  198. for "_i" from 1 to _indentLevel do {_indent = _indent + _tab;};
  199. };
  200. _fn_decreaseIndent =
  201. {
  202. _indentLevel = _indentLevel - 1;
  203. _indent = "";
  204. for "_i" from 1 to _indentLevel do {_indent = _indent + _tab;};
  205. };
  206. _fn_duplicateSpecialChars =
  207. {
  208. private "_t";
  209. _t = [];
  210. {
  211. _t set [count _t,_x];
  212. if (_x in SPECIAL_CHARS) then
  213. {
  214. _t set [count _t,_x];
  215. };
  216. } forEach toArray _this;
  217. toString _t;// return value
  218. };
  219.  
  220. //////////////////////////////////////////////////////////////////////////////
  221.  
  222. #ifdef USE_TABS
  223. _tab = toString [ASCII_TAB];
  224. #else
  225. _tab = " ";
  226. for "_i" from 2 to TAB_WIDTH do {_tab = _tab + " ";};
  227. #endif
  228.  
  229. _indentLevel = 0;
  230. _indent = "";
  231.  
  232. hint "Working...";
  233.  
  234. startLoadingScreen [""];
  235. _this call _fn_dumpConfig;
  236. endLoadingScreen;
  237.  
  238. hintC "All done.";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement