dof2.inc 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. #if defined _dof2_included
  2. #endinput
  3. #endif
  4. #define _dof2_included
  5. #include <a_samp>
  6. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7. /*
  8. * This is a new version of the INI script Double-O-Files.
  9. * However, it's has completely been rewritten and has now a much better performance.
  10. * There is also the support for sections in the INI file. (But there is no support for comments.)
  11. * Double-O-Files 2 is compatible with DUDB, DINI, Double-O-Files and possibly y_ini since it
  12. * can handle sections and entry of the format "key = value", not only "key=value".
  13. * The number of spaces between the equal sign and key and value can actually be arbitrary.
  14. * I've added some comments below. You may see that I've mentioned the big-O-notation,
  15. * 'n' always Entries.Count.
  16. * Double-O-Files 2 should also be useful for Russian letter because I'm using
  17. * the functions fgetchar and fputchar to write and read the files.
  18. *
  19. * There is another new feature which has been inspired by ZCMD and y_ini:
  20. * The OnParseFile callbacks. To learn more about it, read the description in
  21. * the SA-MP forums if you haven't already.
  22. * THE END
  23. */
  24. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  25. /*
  26. native DOF2_SetFile(file[]);
  27. native DOF2_LoadFile();
  28. native DOF2_SaveFile();
  29. native DOF2_ParseFile(file[],extraid,bool:callback=true);
  30. native DOF2_ReparseFile(file[],extraid,bool:callback=true);
  31. native DOF2_WriteFile();
  32. native DOF2_PrintFile(comment[]="");
  33. native DOF2_GetString(file[],key[],tag[]="");
  34. native DOF2_GetStringEx(file[],key[],result[],size,tag[]="");
  35. native Float:DOF2_GetFloat(file[],key[]);
  36. native DOF2_GetInt(file[],key[],tag[]="");
  37. native DOF2_GetHex(file[],key[],tag[]="");
  38. native DOF2_GetBin(file[],key[],tag[]="");
  39. native bool:DOF2_GetBool(file[],key[],tag[]="");
  40. native DOF2_SetString(file[],key[],value[],tag[]="");
  41. native DOF2_SetFloat(file[],key[],Float:value);
  42. native DOF2_SetInt(file[],key[],value,tag[]="");
  43. native DOF2_SetHex(file[],key[],value,tag[]="");
  44. native DOF2_SetBin(file[],key[],value,tag[]="");
  45. native DOF2_SetBool(file[],key[],bool:value,tag[]="");
  46. native DOF2_IsSet(file[],key[],tag[]="");
  47. native DOF2_Unset(file[],key[],tag[]="");
  48. native DOF2_FileExists(file[]);
  49. native DOF2_RemoveFile(file[]);
  50. native DOF2_CreateFile(file[],password[]="");
  51. native DOF2_RenameFile(oldfile[],newfile[]);
  52. native DOF2_RenameKey(file[],oldkey[],newkey[],tag[]="");
  53. native DOF2_CopyFile(filetocopy[],newfile[]);
  54. native DOF2_CheckLogin(file[],password[]);
  55. native DOF2_File(user[]);
  56. native DOF2_ParseInt();
  57. native DOF2_ParseFloat();
  58. native DOF2_ParseBool();
  59. native DOF2_ParseBin();
  60. native DOF2_ParseHex();
  61. native DOF2_SetUTF8(bool:set);
  62. native bool:DOF2_GetUTF8();
  63. native DOF2_GetFile();
  64. native DOF2_MakeBackup(file[]);
  65. native DOF2_RemoveSection (file [], tag []);
  66. native DOF2_SectionExists (file [], tag []);
  67. native DOF2_SortSection (file [], tag [], bool: ignorecase = true, bool: ascending = true);
  68. native DOF2_SortAllSections (file [], bool: ignorecase = true, bool: ascending = true);
  69. native DOF2_SetCaseSensitivity (bool: set);
  70. native DOF2_GetCaseSensitivity ();
  71. */
  72. #define DOF2_TagExists DOF2_SectionExists
  73. #define DOF2_RemoveTag DOF2_RemoveSection
  74. // OnParseFile <Tag><Key>(extraid, value [])
  75. // OnParseFile <><Key>(extraid, value [])
  76. // OnDefaultParseFile (extraid, value [], key [], tag [], file [])
  77. // The arguments of your OnParseFile functions may have arbitrary names but must be an integer followed by a string.
  78. // Function must return a value.
  79. #define OnParseFile<%0><%1>(%2) \
  80. forward _OnParseFile_%0_%1 (extraid, value []); \
  81. public _OnParseFile_%0_%1 (extraid, value []) \
  82. return __OnParseFile_%0_%1 (extraid, (value [0] == '\1' && value [1] == '\0') ? ("") : value); \
  83. stock __OnParseFile_%0_%1 (%2)
  84. // Also here: The argument names may be arbitrary but must be an integer followed by 4 strings.
  85. // Function must return a value.
  86. #define OnDefaultParseFile(%0) \
  87. forward _OnDefaultParseFile (extraid, value [], key [], tag [], file []); \
  88. public _OnDefaultParseFile (extraid, value [], key [], tag [], file []) \
  89. return __OnDefaultParseFile (extraid, (value [0] == '\1' && value [1] == '\0') ? ("") : value, key, (tag [0] == '\1' && tag [1] == '\0') ? ("") : tag, file); \
  90. stock __OnDefaultParseFile (%0)
  91. #define DOF2_ParseBool() \
  92. (strval (value) || (value [0] && !strcmp (value, "true", true)))
  93. #define DOF2_ParseInt() \
  94. (strval (value))
  95. #define DOF2_ParseFloat() \
  96. (floatstr (value))
  97. #define DOF2_ParseBin() \
  98. (DOF2_strbin (value))
  99. #define DOF2_ParseHex() \
  100. (DOF2_strhex (value))
  101. #define DOF2_LoadFile() \
  102. DOF2_ParseFile (CurrentFile, -1, false)
  103. #define DOF2_SaveFile \
  104. DOF2_WriteFile
  105. #define DOF2_FileExists \
  106. fexist
  107. #define Sections. \
  108. Sections_
  109. #define Entries. \
  110. Entries_
  111. #define DOF2:: \
  112. DOF2_
  113. #if !defined private
  114. #define private static stock
  115. #endif
  116. #pragma dynamic 65536
  117. /*
  118. #define MAX_SECTION_TAG (32)
  119. #define MAX_LINE_SIZE (128)
  120. #define MAX_SECTIONS (32)
  121. #define MAX_ENTRIES (256)
  122. #define MAX_FILE_SIZE (64)
  123. #define USER_FILE_PATH "Users/%s.ini"
  124. */
  125. // The maximum length of the name of a tag.
  126. #if !defined MAX_SECTION_TAG
  127. #define MAX_SECTION_TAG (32)
  128. #endif
  129. // The maximum length of a line (including key and value).
  130. #if !defined MAX_LINE_SIZE
  131. #define MAX_LINE_SIZE (128)
  132. #endif
  133. // The maximum number of sections which can be handled. Be careful: MUST NOT be higher than 255.
  134. #if !defined MAX_SECTIONS
  135. #define MAX_SECTIONS (32)
  136. #endif
  137. // The maximum number of entries which can be loaded into the cache.
  138. #if !defined MAX_ENTRIES
  139. #define MAX_ENTRIES (256)
  140. #endif
  141. // The maximum length of the name of a file.
  142. #if !defined MAX_FILE_SIZE
  143. #define MAX_FILE_SIZE (64)
  144. #endif
  145. /*
  146. If PACK_CONTENT == true tag names and lines (key + value) will get stored in cache as packed strings.
  147. The result is less memory usage. However, you won't be able to use special characters like russian or chinese ones.
  148. */
  149. #if !defined PACK_CONTENT
  150. #define PACK_CONTENT (false)
  151. #endif
  152. #define INVALID_ENTRY (-1)
  153. #define INVALID_SECTION (-1)
  154. // Do you want to emulate DUDB?
  155. #if !defined DUDB_CONVERT && 0 // Change to 1 to enable.
  156. #define DUDB_CONVERT
  157. #endif
  158. #if !defined USER_FILE_PATH
  159. #if defined DUDB_CONVERT
  160. #define USER_FILE_PATH "%s.dudb.sav"
  161. #else
  162. #define USER_FILE_PATH "%s.ini"
  163. #endif
  164. #endif
  165. #if !defined USER_PW_HASH_KEY
  166. #if defined DUDB_CONVERT
  167. #define USER_PW_HASH_KEY "password_hash"
  168. #else
  169. #define USER_PW_HASH_KEY "password"
  170. #endif
  171. #endif
  172. // Do you want to emulate DINI?
  173. #if !defined DINI_CONVERT && 0 // Change to 1 to enable.
  174. #define DINI_CONVERT
  175. #endif
  176. /*
  177. #if MAX_SECTIONS >= 256
  178. #error MAX_SECTIONS must not be greater than 255.
  179. #endif
  180. */
  181. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  182. private
  183. bool: UseUTF8 = PACK_CONTENT,
  184. bool: CaseSensitive = false,
  185. CurrentFile [MAX_FILE_SIZE],
  186. bool: FileChanged,
  187. Sections.FirstEntry [MAX_SECTIONS] = {INVALID_ENTRY, ...},
  188. Sections.LastEntry [MAX_SECTIONS] = {INVALID_ENTRY, ...},
  189. Sections.Count,
  190. #if PACK_CONTENT == true
  191. Sections.Tag [MAX_SECTIONS][MAX_SECTION_TAG char],
  192. Entries.Line [MAX_ENTRIES][MAX_LINE_SIZE char],
  193. Entries.Tag [MAX_ENTRIES][MAX_SECTION_TAG char],
  194. #else
  195. Sections.Tag [MAX_SECTIONS][MAX_SECTION_TAG],
  196. Entries.Line [MAX_ENTRIES][MAX_LINE_SIZE],
  197. Entries.Tag [MAX_ENTRIES][MAX_SECTION_TAG],
  198. #endif
  199. #if MAX_SECTIONS >= 256
  200. Entries.Section [MAX_ENTRIES],
  201. #else
  202. Entries.Section [MAX_ENTRIES char],
  203. #endif
  204. Entries.NextEntry [MAX_ENTRIES] = {INVALID_ENTRY, ...},
  205. Entries.PreviousEntry [MAX_ENTRIES] = {INVALID_ENTRY, ...},
  206. Entries.Count,
  207. SortedEntryList [MAX_ENTRIES][2]; // Index 0: Hashcode, Index 1: EntryID
  208. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  209. stock DOF2::Exit ()
  210. DOF2::WriteFile ();
  211. stock DOF2::SetUTF8 (bool: set)
  212. UseUTF8 = set;
  213. stock bool: DOF2::GetUTF8 ()
  214. return UseUTF8;
  215. stock bool: DOF2::SetCaseSensitivity (bool: set)
  216. CaseSensitive = set;
  217. stock bool: DOF2::GetCaseSensitivity ()
  218. return CaseSensitive;
  219. stock DOF2::SetFile (file [])
  220. DOF2::strcpy (CurrentFile, file);
  221. stock DOF2::GetFile ()
  222. return CurrentFile;
  223. stock DOF2::CreateFile (file [], password [] = "")
  224. {
  225. if (!DOF2::FileExists (file))
  226. {
  227. new File: f = fopen (file, io_append);
  228. if (fclose (f))
  229. {
  230. if (password [0])
  231. return DOF2::SetInt (file, USER_PW_HASH_KEY, DOF2::num_hash (password));
  232. return 1;
  233. }
  234. }
  235. return 0;
  236. }
  237. stock DOF2::RenameFile (oldfile [], newfile [])
  238. {
  239. if (!DOF2::FileExists (newfile))
  240. {
  241. // If 'CurrentFile' is 'oldfile', write it if it has been changed.
  242. if (CurrentFile [0] && !strcmp (CurrentFile, oldfile) && FileChanged)
  243. DOF2::WriteFile ();
  244. else if (!DOF2::ParseFile (oldfile, -1, false)) // Otherwise parse 'oldfile'.
  245. return 0;
  246. DOF2::SetFile (newfile);
  247. if (DOF2::WriteFile ())
  248. return fremove (oldfile);
  249. }
  250. return 0;
  251. }
  252. stock DOF2::CopyFile (filetocopy [], newfile [])
  253. {
  254. if (!DOF2::FileExists (newfile))
  255. {
  256. if (CurrentFile [0] && !strcmp (CurrentFile, filetocopy) && FileChanged)
  257. DOF2::WriteFile ();
  258. else if(!DOF2::ParseFile (filetocopy, -1, false))
  259. return 0;
  260. DOF2::SetFile (newfile);
  261. return DOF2::WriteFile ();
  262. }
  263. return 0;
  264. }
  265. stock DOF2::RemoveFile (file [])
  266. {
  267. if (file [0])
  268. {
  269. if (CurrentFile [0] && !strcmp (CurrentFile, file))
  270. CurrentFile [0] = '\0';
  271. return fremove (file);
  272. }
  273. return 0;
  274. }
  275. stock DOF2::MakeBackup (file [])
  276. {
  277. new
  278. year,
  279. month,
  280. day,
  281. hour,
  282. minute,
  283. second,
  284. backupfile [MAX_FILE_SIZE];
  285. getdate (year, month, day);
  286. gettime (hour, minute, second);
  287. format (backupfile, sizeof (backupfile), "%s.%02d_%02d_%02d.%02d_%02d_%02d_%02d.bak", CurrentFile, month, day, year, hour, minute, second, GetTickCount ());
  288. return DOF2::CopyFile (CurrentFile, backupfile);
  289. }
  290. stock bool: DOF2::SectionExists (file [], tag [])
  291. {
  292. if (file [0]) // You can't remove the empty Sections.
  293. {
  294. if (!tag [0])
  295. return true; // Emptry section always exists. In every file.
  296. if (!CurrentFile [0] || strcmp (CurrentFile, file)) // No file in buffer or the file you want to read from is not the file in the buffer.
  297. if (!DOF2::ParseFile (file, -1, false))
  298. return false;
  299. #if PACK_CONTENT == true
  300. new buf [MAX_SECTION_TAG];
  301. #endif
  302. for (new i = 1; i < Sections.Count; ++i)
  303. {
  304. #if PACK_CONTENT == true
  305. strunpack (buf, Sections.Tag [i]);
  306. if (!strcmp (buf, tag, !CaseSensitive))
  307. return true;
  308. #else
  309. if (!strcmp (Sections.Tag [i], tag, !CaseSensitive))
  310. return true;
  311. #endif
  312. }
  313. }
  314. return false;
  315. }
  316. stock DOF2::RemoveSection (file [], tag [])
  317. {
  318. // Removes tag 'tag' with all it's entries.
  319. if (file [0] && tag [0]) // You can't remove the empty Sections.
  320. {
  321. if (!CurrentFile [0] || strcmp (CurrentFile, file)) // No file in buffer or the file you want to read from is not the file in the buffer.
  322. if (!DOF2::ParseFile (file, -1, false))
  323. return 0;
  324. new
  325. #if PACK_CONTENT == true
  326. line [MAX_LINE_SIZE],
  327. #endif
  328. buf [MAX_SECTION_TAG],
  329. section = INVALID_SECTION,
  330. entry,
  331. key [MAX_LINE_SIZE];
  332. for (new i = 1; i < Sections.Count; ++i)
  333. {
  334. #if PACK_CONTENT == true
  335. strunpack (buf, Sections.Tag [i]);
  336. if (!strcmp (buf, tag, !CaseSensitive))
  337. {
  338. section = i;
  339. break;
  340. }
  341. #else
  342. if (!strcmp (Sections.Tag [i], tag, !CaseSensitive))
  343. {
  344. section = i;
  345. break;
  346. }
  347. #endif
  348. }
  349. if (section != INVALID_SECTION)
  350. {
  351. entry = Sections.FirstEntry [section];
  352. while (entry != INVALID_ENTRY)
  353. {
  354. // Remove all entries under the current Sections.
  355. #if PACK_CONTENT == true
  356. strunpack (line, Entries.Line [entry]);
  357. DOF2::ParseLine (line, key, buf);
  358. #else
  359. DOF2::ParseLine (Entries.Line [entry], key, buf);
  360. #endif
  361. DOF2::Unset (file, key, tag);
  362. entry = Entries.NextEntry [entry];
  363. }
  364. // Move the last tag to the position of the current tag. Creates a little mess.
  365. --Sections.Count;
  366. Sections.Tag [section] = Sections.Tag [Sections.Count];
  367. Sections.FirstEntry [section] = Sections.FirstEntry [Sections.Count];
  368. Sections.LastEntry [section] = Sections.LastEntry [Sections.Count];
  369. // Adjust the tag IDs of the entries.
  370. entry = Sections.FirstEntry [section];
  371. while (entry != INVALID_ENTRY)
  372. {
  373. #if MAX_SECTIONS >= 256
  374. Entries.Section [entry] = section;
  375. #else
  376. Entries.Section {entry} = section;
  377. #endif
  378. entry = Entries.NextEntry [entry];
  379. }
  380. FileChanged = true;
  381. return 1;
  382. }
  383. }
  384. return 0;
  385. }
  386. private DOF2::SearchEntry (key [], tag [], keybuf [], valbuf [], &pos, keybufsize = sizeof (keybuf), valbufsize = sizeof (valbuf))
  387. {
  388. if (key [0] && Entries.Count)
  389. {
  390. new
  391. entry = INVALID_ENTRY,
  392. l,
  393. m,
  394. r,
  395. h,
  396. #if PACK_CONTENT == true
  397. line [MAX_LINE_SIZE],
  398. buf [MAX_SECTION_TAG],
  399. #endif
  400. i;
  401. h = DOF2::HashKey (key);
  402. l = 0;
  403. r = Entries.Count - 1;
  404. /*
  405. * Binary search in a sorted list of entries in O(log n) time. This algorithm makes for example with 256 elements a maximum of ~8 steps until the entry is found if it exists.
  406. * A sequential search would take up to 256 steps. That was the case in the first Double-O-Files script.
  407. */
  408. while (l <= r)
  409. {
  410. if ((r - l) < 2)
  411. {
  412. if (h == SortedEntryList [l][0])
  413. {
  414. m = l;
  415. entry = SortedEntryList [l][1];
  416. }
  417. else if (r > l && h == SortedEntryList [r][0])
  418. {
  419. m = r;
  420. entry = SortedEntryList [r][1];
  421. }
  422. break;
  423. }
  424. else
  425. {
  426. m = l + (r - l) / 2;
  427. if (h == SortedEntryList [m][0])
  428. {
  429. entry = SortedEntryList [m][1];
  430. break;
  431. }
  432. else if (h > SortedEntryList [m][0])
  433. l = m + 1;
  434. else
  435. r = m - 1;
  436. }
  437. }
  438. // Candidate found?
  439. if (entry != INVALID_ENTRY)
  440. {
  441. // Check if it's the entry we want.
  442. #if PACK_CONTENT == true
  443. strunpack (line, Entries.Line [entry]);
  444. DOF2::ParseLine (line, keybuf, valbuf, keybufsize, valbufsize);
  445. strunpack (buf, Entries.Tag [entry]);
  446. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !buf [0]) || (tag [0] && buf [0] && !strcmp (tag, buf, !CaseSensitive))))
  447. #else
  448. DOF2::ParseLine (Entries.Line [entry], keybuf, valbuf, keybufsize, valbufsize);
  449. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !Entries.Tag [entry][0]) || (tag [0] && Entries.Tag [entry][0] && !strcmp (tag, Entries.Tag [entry], !CaseSensitive))))
  450. #endif
  451. return (pos = m, entry);
  452. else
  453. {
  454. // If not, look left and right in the list for entries with the same hash code. This can be collisions or entries with the same key from another section.
  455. for (i = m - 1; i >= 0 && h == SortedEntryList [i][0]; --i)
  456. {
  457. entry = SortedEntryList [i][1];
  458. #if PACK_CONTENT == true
  459. strunpack (line, Entries.Line [entry]);
  460. DOF2::ParseLine (line, keybuf, valbuf, keybufsize, valbufsize);
  461. strunpack (buf, Entries.Tag [entry]);
  462. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !buf [0]) || (tag [0] && buf [0] && !strcmp (tag, buf, !CaseSensitive))))
  463. #else
  464. DOF2::ParseLine (Entries.Line [entry], keybuf, valbuf, keybufsize, valbufsize);
  465. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !Entries.Tag [entry][0]) || (tag [0] && Entries.Tag [entry][0] && !strcmp (tag, Entries.Tag [entry], !CaseSensitive))))
  466. #endif
  467. return (pos = i, entry);
  468. }
  469. for (i = m + 1; i < Entries.Count && h == SortedEntryList [i][0]; ++i)
  470. {
  471. entry = SortedEntryList [i][1];
  472. #if PACK_CONTENT == true
  473. strunpack (line, Entries.Line [entry]);
  474. DOF2::ParseLine (line, keybuf, valbuf, keybufsize, valbufsize);
  475. strunpack (buf, Entries.Tag [entry]);
  476. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !buf [0]) || (tag [0] && buf [0] && !strcmp (tag, buf, !CaseSensitive))))
  477. #else
  478. DOF2::ParseLine (Entries.Line [entry], keybuf, valbuf, keybufsize, valbufsize);
  479. if (!strcmp (keybuf, key, !CaseSensitive) && ((!tag [0] && !Entries.Tag [entry][0]) || (tag [0] && Entries.Tag [entry][0] && !strcmp (tag, Entries.Tag [entry], !CaseSensitive))))
  480. #endif
  481. return (pos = i, entry);
  482. }
  483. }
  484. }
  485. }
  486. keybuf [0] = valbuf [0] = '\0';
  487. return INVALID_ENTRY;
  488. }
  489. stock DOF2::SetString (file [], key [], value [], tag [] = "")
  490. {
  491. if (file [0] && key [0])
  492. {
  493. new
  494. entry,
  495. pos,
  496. section = INVALID_SECTION,
  497. keybuf [MAX_LINE_SIZE],
  498. valbuf [MAX_LINE_SIZE],
  499. #if PACK_CONTENT == true
  500. buf [MAX_SECTION_TAG],
  501. line [MAX_LINE_SIZE],
  502. #endif
  503. i;
  504. if (!CurrentFile [0] || strcmp (CurrentFile, file)) // No file in buffer or the file you want to read from is not the file in the buffer.
  505. if (!DOF2::ParseFile (file, -1, false))
  506. return 0;
  507. entry = DOF2::SearchEntry (key, tag, keybuf, valbuf, pos);
  508. // If the entry has been found, just change it's content.
  509. if (entry != INVALID_ENTRY)
  510. {
  511. FileChanged = true;
  512. #if PACK_CONTENT == true
  513. format (line, sizeof (line), "%s = %s", key, value [0] ? value : ("(null)"));
  514. return strpack (Entries.Line [entry], line);
  515. #else
  516. format (Entries.Line [entry], sizeof (Entries.Line []), "%s = %s", key, value [0] ? value : ("(null)"));
  517. return 1;
  518. #endif
  519. }
  520. if (Entries.Count >= MAX_ENTRIES)
  521. return 0;
  522. // Search for the section where the entry belongs.
  523. if (!tag [0])
  524. section = 0;
  525. else
  526. {
  527. for (i = 1; i < Sections.Count; ++i)
  528. {
  529. #if PACK_CONTENT == true
  530. strunpack (buf, Sections.Tag [i]);
  531. if (buf [0] && !strcmp (tag, buf, !CaseSensitive))
  532. {
  533. section = i;
  534. break;
  535. }
  536. #else
  537. if (Sections.Tag [i][0] && !strcmp (tag, Sections.Tag [i], !CaseSensitive))
  538. {
  539. section = i;
  540. break;
  541. }
  542. #endif
  543. }
  544. }
  545. // Section we want does not exist, create new one if possible.
  546. if (section == INVALID_SECTION)
  547. {
  548. if (Sections.Count >= MAX_SECTIONS)
  549. return 0;
  550. section = Sections.Count++;
  551. #if PACK_CONTENT == true
  552. strpack (Sections.Tag [section], tag);
  553. #else
  554. DOF2::strcpy (Sections.Tag [section], tag);
  555. #endif
  556. Sections.FirstEntry [section] = Sections.LastEntry [section] = INVALID_ENTRY;
  557. }
  558. // Add the entry to the section. Section's content is defined by a linear two way list.
  559. #if PACK_CONTENT == true
  560. format (line, sizeof (line), "%s = %s", key, value [0] ? value : ("(null)"));
  561. strpack (Entries.Line [Entries.Count], line);
  562. #else
  563. format (Entries.Line [Entries.Count], sizeof (Entries.Line []), "%s = %s", key, value [0] ? value : ("(null)"));
  564. #endif
  565. Entries.Tag [Entries.Count] = Sections.Tag [section];
  566. #if MAX_SECTIONS >= 256
  567. Entries.Section [Entries.Count] = section;
  568. #else
  569. Entries.Section {Entries.Count} = section;
  570. #endif
  571. Entries.NextEntry [Entries.Count] = INVALID_ENTRY;
  572. // Add entry to sorted list of entries and move to right correct position in O(n) time.
  573. SortedEntryList [Entries.Count][0] = DOF2::HashKey (key);
  574. SortedEntryList [Entries.Count][1] = Entries.Count;
  575. i = Entries.Count - 1;
  576. while (i >= 0 && SortedEntryList [i][0] > SortedEntryList [i + 1][0])
  577. {
  578. DOF2::SwapSortedEntries (SortedEntryList [i], SortedEntryList [i + 1]);
  579. --i;
  580. }
  581. if (Sections.LastEntry [section] == INVALID_ENTRY) // No entry in this section.
  582. {
  583. Sections.FirstEntry [section] = Sections.LastEntry [section] = Entries.Count;
  584. Entries.PreviousEntry [Entries.Count] = INVALID_ENTRY;
  585. }
  586. else
  587. {
  588. Entries.NextEntry [Sections.LastEntry [section]] = Entries.Count;
  589. Entries.PreviousEntry [Entries.Count] = Sections.LastEntry [section];
  590. Sections.LastEntry [section] = Entries.Count;
  591. }
  592. ++Entries.Count;
  593. FileChanged = true;
  594. }
  595. return 1;
  596. }
  597. stock DOF2::GetString (file [], key [], tag [] = "")
  598. {
  599. new buf [MAX_LINE_SIZE];
  600. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  601. return buf;
  602. }
  603. stock DOF2::GetStringEx (file [], key [], result [], size, tag [] = "")
  604. {
  605. if (file [0] && key [0])
  606. {
  607. new
  608. pos,
  609. keybuf [MAX_LINE_SIZE];
  610. if (!CurrentFile [0] || strcmp (CurrentFile, file))
  611. {
  612. if (!DOF2::ParseFile (file, -1, false))
  613. {
  614. result [0] = '\0';
  615. return 0;
  616. }
  617. }
  618. // Find entry and assign the result with it's value.
  619. return (DOF2::SearchEntry (key, tag, keybuf, result, pos, sizeof (keybuf), size) != INVALID_ENTRY);
  620. }
  621. return 0;
  622. }
  623. stock DOF2::Unset (file [], key [], tag [] = "")
  624. {
  625. if (file [0] && key [0])
  626. {
  627. new
  628. entry,
  629. pos,
  630. keybuf [MAX_LINE_SIZE],
  631. valbuf [MAX_LINE_SIZE];
  632. if (!CurrentFile [0] || strcmp (CurrentFile, file))
  633. if (!DOF2::ParseFile (file, -1, false))
  634. return 0;
  635. if ((entry = DOF2::SearchEntry (key, tag, keybuf, valbuf, pos)) != INVALID_ENTRY)
  636. {
  637. // Remove entry from it's section.
  638. #if MAX_SECTIONS >= 256
  639. if (Sections.FirstEntry [Entries.Section [entry]] == entry) // Is the entry the first entry in the section? Make it's next entry the first entry.
  640. #else
  641. if (Sections.FirstEntry [Entries.Section {entry}] == entry)
  642. #endif
  643. {
  644. #if MAX_SECTIONS >= 256
  645. Sections.FirstEntry [Entries.Section [entry]] = Entries.NextEntry [entry];
  646. #else
  647. Sections.FirstEntry [Entries.Section {entry}] = Entries.NextEntry [entry];
  648. #endif
  649. if (Entries.NextEntry [entry] != INVALID_ENTRY)
  650. Entries.PreviousEntry [Entries.NextEntry [entry]] = INVALID_ENTRY;
  651. }
  652. else
  653. {
  654. Entries.NextEntry [Entries.PreviousEntry [entry]] = Entries.NextEntry [entry];
  655. if (Entries.NextEntry [entry] != INVALID_ENTRY)
  656. Entries.PreviousEntry [Entries.NextEntry [entry]] = Entries.PreviousEntry [entry];
  657. }
  658. #if MAX_SECTIONS >= 256
  659. if (Sections.LastEntry [Entries.Section [entry]] == entry)
  660. #else
  661. if (Sections.LastEntry [Entries.Section {entry}] == entry)
  662. #endif
  663. {
  664. #if MAX_SECTIONS >= 256
  665. Sections.LastEntry [Entries.Section [entry]] = Entries.PreviousEntry [entry];
  666. #else
  667. Sections.LastEntry [Entries.Section {entry}] = Entries.PreviousEntry [entry];
  668. #endif
  669. if (Entries.PreviousEntry [entry] != INVALID_ENTRY)
  670. Entries.NextEntry [Entries.PreviousEntry [entry]] = INVALID_ENTRY;
  671. }
  672. else
  673. {
  674. Entries.PreviousEntry [Entries.NextEntry [entry]] = Entries.PreviousEntry [entry];
  675. if (Entries.PreviousEntry [entry] != INVALID_ENTRY)
  676. Entries.NextEntry [Entries.PreviousEntry [entry]] = Entries.NextEntry [entry];
  677. }
  678. // Move the entry to the end of the sorted list and decrement Entries.Count to forget about the unset Entries.
  679. while (pos < (Entries.Count - 1))
  680. {
  681. DOF2::SwapSortedEntries (SortedEntryList [pos], SortedEntryList [pos + 1]);
  682. ++pos;
  683. }
  684. --Entries.Count;
  685. FileChanged = true;
  686. return 1;
  687. }
  688. }
  689. return 0;
  690. }
  691. stock DOF2::RenameKey (file [], oldkey [], newkey [], tag [] = "")
  692. {
  693. if (file [0] && oldkey [0])
  694. {
  695. new
  696. entry,
  697. pos,
  698. #if PACK_CONTENT == true
  699. line [MAX_LINE_SIZE],
  700. #endif
  701. keybuf [MAX_LINE_SIZE],
  702. valbuf [MAX_LINE_SIZE];
  703. if (!CurrentFile [0] || strcmp (CurrentFile, file))
  704. if (!DOF2::ParseFile (file, -1, false))
  705. return 0;
  706. if ((entry = DOF2::SearchEntry (oldkey, tag, keybuf, valbuf, pos)) != INVALID_ENTRY)
  707. {
  708. // Change content of Entries.
  709. #if PACK_CONTENT == true
  710. format (line, sizeof (line), "%s = %s", newkey, valbuf [0] ? valbuf : ("(null)"));
  711. strpack (Entries.Line [entry], line);
  712. #else
  713. format (Entries.Line [entry], sizeof (Entries.Line []), "%s = %s", newkey, valbuf [0] ? valbuf : ("(null)"));
  714. #endif
  715. // Because the hashcode has been changed, the entry has to move in the list.
  716. SortedEntryList [pos][0] = DOF2::HashKey (newkey);
  717. if (pos < (MAX_ENTRIES - 1) && SortedEntryList [pos][0] > SortedEntryList [pos + 1][0])
  718. {
  719. // Hash value of key is greater than the hash value of it's right neighbor, move to the right by swapping the 2 entries.
  720. while (pos < (MAX_ENTRIES - 1) && SortedEntryList [pos][0] > SortedEntryList [pos + 1][0])
  721. {
  722. DOF2::SwapSortedEntries (SortedEntryList [pos], SortedEntryList [pos + 1]);
  723. ++pos;
  724. }
  725. }
  726. else if (pos > 0 && SortedEntryList [pos][0] < SortedEntryList [pos + 1][0])
  727. {
  728. // Hash value of key is smaller than the hash value of it' left neighbor, move to the left by swapping the 2 entries.
  729. while (pos > 0 && SortedEntryList [pos][0] < SortedEntryList [pos - 1][0])
  730. {
  731. DOF2::SwapSortedEntries (SortedEntryList [pos], SortedEntryList [pos - 1]);
  732. --pos;
  733. }
  734. }
  735. FileChanged = true;
  736. return 1;
  737. }
  738. }
  739. return 0;
  740. }
  741. stock bool: DOF2::IsSet (file [], key [], tag [] = "")
  742. {
  743. new
  744. pos,
  745. keybuf [MAX_LINE_SIZE],
  746. valbuf [MAX_LINE_SIZE];
  747. if (!CurrentFile [0] || strcmp (CurrentFile, file))
  748. if (!DOF2::ParseFile (file, -1, false))
  749. return false;
  750. // Try to find the Entries.
  751. return (DOF2::SearchEntry (key, tag, keybuf, valbuf, pos) != INVALID_ENTRY);
  752. }
  753. stock DOF2::SetInt (file [], key [], value, tag [] = "")
  754. {
  755. new buf [16];
  756. format (buf, sizeof (buf), "%d", value);
  757. return DOF2::SetString (file, key, buf, tag);
  758. }
  759. stock DOF2::GetInt (file [], key [], tag [] = "")
  760. {
  761. new buf [16];
  762. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  763. return strval (buf);
  764. }
  765. stock DOF2::SetHex (file [], key [], value, tag [] = "")
  766. {
  767. new buf [16];
  768. DOF2::hexstr (value, buf);
  769. return DOF2::SetString (file, key, buf, tag);
  770. }
  771. stock DOF2::GetHex (file [], key [], tag [] = "")
  772. {
  773. new buf [16];
  774. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  775. return DOF2::strhex (buf);
  776. }
  777. stock DOF2::SetBin (file [], key [], value, tag [] = "")
  778. {
  779. new buf [35];
  780. DOF2::binstr (value, buf);
  781. return DOF2::SetString (file, key, buf, tag);
  782. }
  783. stock DOF2::GetBin (file [], key [], tag [] = "")
  784. {
  785. new buf [35];
  786. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  787. return DOF2::strbin (buf);
  788. }
  789. stock DOF2::SetFloat (file [], key [], Float: value, tag [] = "")
  790. {
  791. new buf [32];
  792. format (buf, sizeof (buf), "%.8f", value);
  793. return DOF2::SetString (file, key, buf, tag);
  794. }
  795. stock Float: DOF2::GetFloat (file [], key [], tag [] = "")
  796. {
  797. new buf [32];
  798. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  799. return floatstr (buf);
  800. }
  801. stock bool: DOF2::GetBool (file [], key [], tag [] = "")
  802. {
  803. new buf [16];
  804. DOF2::GetStringEx (file, key, buf, sizeof (buf), tag);
  805. return (strval (buf) || (buf [0] && !strcmp (buf, "true", true)));
  806. }
  807. stock DOF2::SetBool (file [], key [], bool: value, tag [] = "")
  808. return DOF2::SetString (file, key, value ? ("true") : ("false"), tag);
  809. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  810. stock DOF2::PrintFile (comment [] = "")
  811. {
  812. if (CurrentFile [0])
  813. {
  814. new
  815. bool: firstline = true,
  816. entry,
  817. #if PACK_CONTENT == true
  818. buf [MAX_LINE_SIZE],
  819. #endif
  820. entries,
  821. i;
  822. printf ("[DOF] Current file: %s", CurrentFile);
  823. for ( ; i < Sections.Count; ++i)
  824. {
  825. if (i)
  826. {
  827. if (!firstline)
  828. print (" ");
  829. else
  830. firstline = false;
  831. #if PACK_CONTENT == true
  832. strunpack (buf, Sections.Tag [i]);
  833. printf ("[%s]", buf);
  834. #else
  835. printf ("[%s]", Sections.Tag [i]);
  836. #endif
  837. }
  838. entry = Sections.FirstEntry [i];
  839. while (entry != INVALID_ENTRY)
  840. {
  841. #if PACK_CONTENT == true
  842. strunpack (buf, Entries.Line [entry]);
  843. print (buf);
  844. #else
  845. print (Entries.Line [entry]);
  846. #endif
  847. entry = Entries.NextEntry [entry];
  848. firstline = false;
  849. ++entries;
  850. }
  851. }
  852. printf ("* %d sections, %d entries", i, entries);
  853. if (comment [0])
  854. printf ("* Comment: %s", comment);
  855. return 1;
  856. }
  857. return 0;
  858. }
  859. stock DOF2::WriteFile ()
  860. {
  861. if (CurrentFile [0])
  862. {
  863. new
  864. File: f = fopen (CurrentFile, io_write),
  865. bool: firstline = true,
  866. entry;
  867. if (f)
  868. {
  869. for (new i; i < Sections.Count; ++i)
  870. {
  871. if (Sections.FirstEntry [i] != INVALID_ENTRY) // Do not write when empty.
  872. {
  873. if (i)
  874. {
  875. if (!firstline)
  876. {
  877. fputchar (f, '\r', UseUTF8);
  878. fputchar (f, '\n', UseUTF8);
  879. }
  880. else
  881. firstline = false;
  882. fputchar (f, '[', UseUTF8);
  883. fwritechars (f, Sections.Tag [i]);
  884. fputchar (f, ']', UseUTF8);
  885. fputchar (f, '\r', UseUTF8);
  886. fputchar (f, '\n', UseUTF8);
  887. }
  888. entry = Sections.FirstEntry [i];
  889. while (entry != INVALID_ENTRY)
  890. {
  891. fwritechars (f, Entries.Line [entry]);
  892. fputchar (f, '\r', UseUTF8);
  893. fputchar (f, '\n', UseUTF8);
  894. entry = Entries.NextEntry [entry];
  895. firstline = false;
  896. }
  897. }
  898. }
  899. FileChanged = false;
  900. return fclose (f);
  901. }
  902. }
  903. return 0;
  904. }
  905. stock DOF2::ParseFile (file [], extraid = -1, bool: callback = false)
  906. {
  907. if (file [0] && DOF2::FileExists (file))
  908. {
  909. /*
  910. Write the file in the buffer when:
  911. - There is actually a file in the buffer
  912. - The file in the buffer is not the file you want to parse and this file has been changed.
  913. - Or the current file is the file you want to and has been changed.
  914. */
  915. //if (CurrentFile [0] && ((strcmp (CurrentFile, file) && FileChanged) || FileChanged))
  916. if (CurrentFile [0] && FileChanged) // Equal to the query above but shorter.
  917. DOF2::WriteFile ();
  918. new
  919. File: f = fopen (file, io_readwrite),
  920. buf [MAX_LINE_SIZE],
  921. #if PACK_CONTENT == true
  922. line [MAX_LINE_SIZE char],
  923. tag [MAX_SECTION_TAG],
  924. #else
  925. line [MAX_LINE_SIZE],
  926. #endif
  927. key [MAX_LINE_SIZE],
  928. value [MAX_LINE_SIZE],
  929. c,
  930. pos;
  931. if (f)
  932. {
  933. FileChanged = false;
  934. DOF2::SetFile (file);
  935. Sections.Count = 1;
  936. Entries.Count = 0;
  937. Sections.FirstEntry [0] = Sections.LastEntry [0] = INVALID_ENTRY;
  938. for (new i, size = flength (f); i < size; ++i)
  939. {
  940. c = fgetchar (f, 0, UseUTF8);
  941. if (pos == MAX_LINE_SIZE - 1 || c == '\n' || c == '\r')
  942. c = '\0';
  943. #if PACK_CONTENT == true
  944. line {pos++} = c;
  945. #else
  946. line [pos++] = c;
  947. #endif
  948. if (c == '\0')
  949. {
  950. // A new section found. Add the section to the list of sections.
  951. #if PACK_CONTENT == true
  952. if (line {0} == '[')
  953. #else
  954. if (line [0] == '[')
  955. #endif
  956. {
  957. if (Sections.Count < MAX_SECTIONS)
  958. {
  959. pos = 1;
  960. #if PACK_CONTENT == true
  961. while (line {pos} && line {pos} != ']' && (pos - 1) < MAX_SECTION_TAG)
  962. {
  963. Sections.Tag [Sections.Count]{pos - 1} = line {pos};
  964. ++pos;
  965. }
  966. Sections.Tag [Sections.Count]{pos - 1} = '\0';
  967. #else
  968. while (line [pos] && line [pos] != ']' && (pos - 1) < MAX_SECTION_TAG)
  969. {
  970. Sections.Tag [Sections.Count][pos - 1] = line [pos];
  971. ++pos;
  972. }
  973. Sections.Tag [Sections.Count][pos - 1] = '\0';
  974. #endif
  975. Sections.FirstEntry [Sections.Count] = Sections.LastEntry [Sections.Count] = INVALID_ENTRY;
  976. ++Sections.Count;
  977. }
  978. }
  979. else
  980. {
  981. #if PACK_CONTENT == true
  982. if (line {0})
  983. #else
  984. if (line [0])
  985. #endif
  986. {
  987. #if PACK_CONTENT == true
  988. strunpack (buf, line);
  989. DOF2::ParseLine (buf, key, value);
  990. strunpack (tag, Sections.Tag [Sections.Count - 1]);
  991. // Call a specific function for a specific entry - ZCMD-style!
  992. if (callback)
  993. {
  994. format (buf, sizeof (buf), "_OnParseFile_%s_%s", tag, key);
  995. if (!CallRemoteFunction (buf, "is", extraid, value))
  996. CallRemoteFunction ("_OnDefaultParseFile", "issss", extraid, value [0] ? value : ("\1"), key, Sections.Tag [Sections.Count - 1][0] ? Sections.Tag [Sections.Count - 1] : ("\1"), file);
  997. }
  998. #else
  999. DOF2::ParseLine (line, key, value);
  1000. // Call a specific function for a specific entry - ZCMD-style!
  1001. if (callback)
  1002. {
  1003. format (buf, sizeof (buf), "_OnParseFile_%s_%s", Sections.Tag [Sections.Count - 1], key);
  1004. if (!CallRemoteFunction (buf, "is", extraid, value))
  1005. CallRemoteFunction ("_OnDefaultParseFile", "issss", extraid, value [0] ? value : ("\1"), key, Sections.Tag [Sections.Count - 1][0] ? Sections.Tag [Sections.Count - 1] : ("\1"), file);
  1006. }
  1007. #endif
  1008. // Add entry to it's section and to the list which will be sorted.
  1009. Entries.Line [Entries.Count] = line;
  1010. Entries.Tag [Entries.Count] = Sections.Tag [Sections.Count - 1];
  1011. #if MAX_SECTIONS >= 256
  1012. Entries.Section [Entries.Count] = Sections.Count - 1;
  1013. #else
  1014. Entries.Section {Entries.Count} = Sections.Count - 1;
  1015. #endif
  1016. Entries.NextEntry [Entries.Count] = INVALID_ENTRY;
  1017. SortedEntryList [Entries.Count][0] = DOF2::HashKey (key);
  1018. SortedEntryList [Entries.Count][1] = Entries.Count;
  1019. if (Sections.LastEntry [Sections.Count - 1] == INVALID_ENTRY)
  1020. {
  1021. Sections.FirstEntry [Sections.Count - 1] = Sections.LastEntry [Sections.Count - 1] = Entries.Count;
  1022. Entries.PreviousEntry [Entries.Count] = INVALID_ENTRY;
  1023. }
  1024. else
  1025. {
  1026. Entries.NextEntry [Sections.LastEntry [Sections.Count - 1]] = Entries.Count;
  1027. Entries.PreviousEntry [Entries.Count] = Sections.LastEntry [Sections.Count - 1];
  1028. Sections.LastEntry [Sections.Count - 1] = Entries.Count;
  1029. }
  1030. ++Entries.Count;
  1031. }
  1032. }
  1033. pos = 0;
  1034. }
  1035. }
  1036. /*
  1037. * Sort list of entries by it's hashcodes in O(n * log n) time.
  1038. * (Worst case is actually O(n * n), however, this QuickSort implementation chooses a randomized pivot
  1039. * to minimize the chance for the worst case.)
  1040. */
  1041. DOF2::SortEntries (SortedEntryList, 0, Entries.Count - 1, true);
  1042. return fclose (f);
  1043. }
  1044. }
  1045. return 0;
  1046. }
  1047. // Rather useless.
  1048. stock DOF2::ReparseFile (file [], extraid, bool: callback = true)
  1049. {
  1050. if (file [0] && CurrentFile [0] && !strcmp (file, CurrentFile))
  1051. {
  1052. CurrentFile [0] = '\0';
  1053. return DOF2::ParseFile (file, extraid, callback);
  1054. }
  1055. return 0;
  1056. }
  1057. private DOF2::ParseLine (line [], key [], value [], keysize = sizeof (key), valuesize = sizeof (value))
  1058. {
  1059. new
  1060. pos,
  1061. readpos;
  1062. if ((pos = charfind (line, '=')) != -1)
  1063. {
  1064. // Read key and value.
  1065. readpos = pos - 1;
  1066. while (readpos >= 0 && line [readpos] == ' ')
  1067. --readpos;
  1068. if (readpos >= 0 && keysize > (readpos + 1))
  1069. {
  1070. key [readpos + 1] = '\0';
  1071. while (readpos >= 0)
  1072. {
  1073. key [readpos] = line [readpos];
  1074. --readpos;
  1075. }
  1076. }
  1077. else
  1078. return 0;
  1079. readpos = pos + 1;
  1080. ++pos;
  1081. while (line [readpos] == ' ')
  1082. {
  1083. ++pos;
  1084. ++readpos;
  1085. }
  1086. if (line [readpos])
  1087. {
  1088. while (readpos >= 0 && line [readpos] && valuesize > (readpos - pos + 1))
  1089. {
  1090. value [readpos - pos] = line [readpos];
  1091. ++readpos;
  1092. }
  1093. value [readpos - pos] = '\0';
  1094. }
  1095. else
  1096. {
  1097. key [0] = value [0] = '\0';
  1098. return 0;
  1099. }
  1100. if (!strcmp (value, "(null)", true))
  1101. value [0] = '\0';
  1102. return 1;
  1103. }
  1104. key [0] = value [0] = '\0';
  1105. return 0;
  1106. }
  1107. stock DOF2::File (user [])
  1108. {
  1109. new newfile [MAX_FILE_SIZE];
  1110. format (newfile, sizeof (newfile), USER_FILE_PATH, DOF2::udb_encode (user));
  1111. return newfile;
  1112. }
  1113. stock bool: DOF2::CheckLogin (file [], password [])
  1114. return (file [0] && password [0] && DOF2::num_hash (password) == DOF2::GetInt (file, USER_PW_HASH_KEY));
  1115. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1116. stock DOF2::binstr (value, dest [], size = sizeof (dest))
  1117. {
  1118. new buf [32 + 3] = "0b";
  1119. for (new i = 0; i < 32; ++i)
  1120. buf [i + 2] = '0' + ((value >>> (31 - i)) & 1);
  1121. DOF2::strcpy (dest, buf, size);
  1122. }
  1123. //format (dest, size, "0b%b", value);
  1124. stock DOF2::hexstr (value, dest [], size = sizeof (dest))
  1125. {
  1126. static const characters [] =
  1127. {
  1128. '0', '1', '2', '3',
  1129. '4', '5', '6', '7',
  1130. '8', '9', 'A', 'B',
  1131. 'C', 'D', 'E', 'F'
  1132. };
  1133. new buf [8 + 3] = "0x";
  1134. for (new i = 0; i < 8; ++i)
  1135. buf [2 + i] = characters [(value >>> ((7 - i) << 2)) & 0x0F];
  1136. DOF2::strcpy (dest, buf, size);
  1137. }
  1138. //format (dest, size, "0x%x", value);
  1139. stock DOF2::strhex (string [])
  1140. {
  1141. new
  1142. i,
  1143. value;
  1144. if (string [0] == '0' && (string [1] == 'x' || string [1] == 'X'))
  1145. i = 2;
  1146. while (string [i])
  1147. {
  1148. value <<= 4;
  1149. switch (string [i])
  1150. {
  1151. case '0' .. '9':
  1152. value |= string [i] - '0';
  1153. case 'A' .. 'F':
  1154. value |= string [i] - 'A' + 10;
  1155. case 'a' .. 'f':
  1156. value |= string [i] - 'a' + 10;
  1157. default:
  1158. return 0;
  1159. }
  1160. ++i;
  1161. }
  1162. return value;
  1163. }
  1164. stock DOF2::strbin (string [])
  1165. {
  1166. new
  1167. i,
  1168. value;
  1169. if (string [0] == '0' && (string [1] == 'b' || string [1] == 'B'))
  1170. i = 2;
  1171. while (string [i])
  1172. {
  1173. if (string [i] != '1' && string [i] != '0')
  1174. return 0;
  1175. value <<= 1;
  1176. value |= (string [i] - '0');
  1177. ++i;
  1178. }
  1179. return value;
  1180. }
  1181. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1182. private charfind (string [], c)
  1183. {
  1184. for (new i, len = strlen (string); i < len; ++i)
  1185. if (string [i] == c)
  1186. return i;
  1187. return -1;
  1188. }
  1189. private fwritechars (File: handle, c [])
  1190. {
  1191. new pos;
  1192. #if PACK_CONTENT == true
  1193. while (c {pos})
  1194. fputchar (handle, c {pos++}, UseUTF8);
  1195. #else
  1196. while (c [pos])
  1197. fputchar (handle, c [pos++], UseUTF8);
  1198. #endif
  1199. }
  1200. private DOF2::SortEntries (entries [][2], l, r, bool: randomize = true)
  1201. {
  1202. if (r > l)
  1203. {
  1204. if (randomize)
  1205. {
  1206. new k = l + (random (65535) % (r - l + 1));
  1207. DOF2::SwapSortedEntries (entries [k], entries [r]);
  1208. }
  1209. new
  1210. i = l - 1,
  1211. j = r,
  1212. pivot = entries [r][0];
  1213. while (i < j)
  1214. {
  1215. do
  1216. ++i;
  1217. while (entries [i][0] <= pivot && i < r);
  1218. do
  1219. --j;
  1220. while (entries [j][0] >= pivot && j > l);
  1221. if (i < j)
  1222. DOF2::SwapSortedEntries (entries [i], entries [j]);
  1223. }
  1224. DOF2::SwapSortedEntries (entries [i], entries [r]);
  1225. DOF2::SortEntries (entries, l, i - 1, randomize);
  1226. DOF2::SortEntries (entries, i + 1, r, randomize);
  1227. }
  1228. }
  1229. private DOF2::SwapSortedEntries (a [2], b [2])
  1230. {
  1231. new c [2];
  1232. c [0] = a [0];
  1233. c [1] = a [1];
  1234. a [0] = b [0];
  1235. a [1] = b [1];
  1236. b [0] = c [0];
  1237. b [1] = c [1];
  1238. }
  1239. stock DOF2::SortAllSections (file [], bool: ignorecase = true, bool: ascending = true)
  1240. {
  1241. if (file [0])
  1242. {
  1243. if (!CurrentFile [0] || strcmp (CurrentFile, file)) // No file in buffer or the file you want to read from is not the file in the buffer.
  1244. if (!DOF2::ParseFile (file, -1, false))
  1245. return 0;
  1246. new
  1247. entries [MAX_ENTRIES],
  1248. keys [MAX_ENTRIES][MAX_LINE_SIZE],
  1249. key [MAX_LINE_SIZE],
  1250. value [MAX_LINE_SIZE],
  1251. #if PACK_CONTENT == true
  1252. line [MAX_LINE_SIZE],
  1253. #endif
  1254. entry,
  1255. i;
  1256. for (new section = 0; section < Sections.Count; ++section)
  1257. {
  1258. i = 0;
  1259. entry = Sections.FirstEntry [section];
  1260. while (entry != INVALID_ENTRY)
  1261. {
  1262. #if PACK_CONTENT == true
  1263. strunpack (line, Entries.Line [entry]);
  1264. DOF2::ParseLine (line, key, value);
  1265. #else
  1266. DOF2::ParseLine (Entries.Line [entry], key, value);
  1267. #endif
  1268. keys [i][0] = '\0';
  1269. strcat (keys [i], key);
  1270. entries [i] = entry;
  1271. entry = Entries.NextEntry [entry];
  1272. ++i;
  1273. }
  1274. if (i > 0)
  1275. DOF2::SortSection_Internal (section, entries, keys, 0, i - 1, ignorecase, ascending);
  1276. }
  1277. return 1;
  1278. }
  1279. return 0;
  1280. }
  1281. stock DOF2::SortSection (file [], tag [], bool: ignorecase = true, bool: ascending = true)
  1282. {
  1283. if (file [0])
  1284. {
  1285. if (!CurrentFile [0] || strcmp (CurrentFile, file)) // No file in buffer or the file you want to read from is not the file in the buffer.
  1286. if (!DOF2::ParseFile (file, -1, false))
  1287. return 0;
  1288. new
  1289. section = INVALID_SECTION,
  1290. entries [MAX_ENTRIES],
  1291. keys [MAX_ENTRIES][MAX_LINE_SIZE],
  1292. key [MAX_LINE_SIZE],
  1293. buf [MAX_LINE_SIZE],
  1294. #if PACK_CONTENT == true
  1295. line [MAX_LINE_SIZE],
  1296. #endif
  1297. entry,
  1298. i;
  1299. if (!tag [0])
  1300. section = 0;
  1301. else
  1302. {
  1303. for (i = 1; i < Sections.Count; ++i)
  1304. {
  1305. #if PACK_CONTENT == true
  1306. strunpack (buf, Sections.Tag [i]);
  1307. if (buf [0] && !strcmp (tag, buf, !CaseSensitive))
  1308. {
  1309. section = i;
  1310. break;
  1311. }
  1312. #else
  1313. if (Sections.Tag [i][0] && !strcmp (tag, Sections.Tag [i], !CaseSensitive))
  1314. {
  1315. section = i;
  1316. break;
  1317. }
  1318. #endif
  1319. }
  1320. }
  1321. if (section != INVALID_SECTION)
  1322. {
  1323. i = 0;
  1324. entry = Sections.FirstEntry [section];
  1325. while (entry != INVALID_ENTRY)
  1326. {
  1327. #if PACK_CONTENT == true
  1328. strunpack (line, Entries.Line [entry]);
  1329. DOF2::ParseLine (line, key, buf);
  1330. #else
  1331. DOF2::ParseLine (Entries.Line [entry], key, buf);
  1332. #endif
  1333. keys [i][0] = '\0';
  1334. strcat (keys [i], key);
  1335. entries [i] = entry;
  1336. entry = Entries.NextEntry [entry];
  1337. ++i;
  1338. }
  1339. if (i > 0)
  1340. {
  1341. DOF2::SortSection_Internal (section, entries, keys, 0, i - 1, ignorecase, ascending);
  1342. return 1;
  1343. }
  1344. }
  1345. }
  1346. return 0;
  1347. }
  1348. private DOF2::SortSection_Internal (section, entries [], keys [][], l, r, bool: ignorecase = true, bool: ascending = true)
  1349. {
  1350. // Entries must be stored into an array...
  1351. if (0 <= section < Sections.Count && r > l)
  1352. {
  1353. new
  1354. i = l - 1,
  1355. j = r,
  1356. buf [MAX_LINE_SIZE];
  1357. static
  1358. pivot [MAX_LINE_SIZE]; // Must be static, otherwise too much memory usage during recursion ==> Script will crash!
  1359. pivot [0] = '\0';
  1360. strcat (pivot, keys [r]);
  1361. while (i < j)
  1362. {
  1363. if (ascending)
  1364. {
  1365. do
  1366. ++i;
  1367. while (strcmp (keys [i], pivot, ignorecase) <= 0 && i < r);
  1368. do
  1369. --j;
  1370. while (strcmp (keys [j], pivot, ignorecase) >= 0 && j > l);
  1371. }
  1372. else
  1373. {
  1374. do
  1375. ++i;
  1376. while (strcmp (keys [i], pivot, ignorecase) >= 0 && i < r);
  1377. do
  1378. --j;
  1379. while (strcmp (keys [j], pivot, ignorecase) <= 0 && j > l);
  1380. }
  1381. if (i < j)
  1382. {
  1383. DOF2::SwapEntries (section, entries [i], entries [j]);
  1384. DOF2::strcpy (buf, keys [i]);
  1385. DOF2::strcpy (keys [i], keys [j], MAX_LINE_SIZE);
  1386. DOF2::strcpy (keys [j], buf, MAX_LINE_SIZE);
  1387. entries [i] ^= entries [j];
  1388. entries [j] ^= entries [i];
  1389. entries [i] ^= entries [j];
  1390. }
  1391. }
  1392. if (i != r)
  1393. {
  1394. DOF2::SwapEntries (section, entries [i], entries [r]);
  1395. DOF2::strcpy (buf, keys [i]);
  1396. DOF2::strcpy (keys [i], keys [r], MAX_LINE_SIZE);
  1397. DOF2::strcpy (keys [r], buf, MAX_LINE_SIZE);
  1398. entries [i] ^= entries [r];
  1399. entries [r] ^= entries [i];
  1400. entries [i] ^= entries [r];
  1401. }
  1402. DOF2::SortSection_Internal (section, entries, keys, l, i - 1, ignorecase, ascending);
  1403. DOF2::SortSection_Internal (section, entries, keys, i + 1, r, ignorecase, ascending);
  1404. }
  1405. }
  1406. private DOF2::SwapEntries (section, entry1, entry2)
  1407. {
  1408. // This swaps two entries in the entry list of a section. (Pointers are swapped)
  1409. if (0 <= section < Sections.Count && 0 <= entry1 <= Entries.Count && 0 <= entry2 <= Entries.Count)
  1410. {
  1411. if (entry1 == Sections.FirstEntry [section])
  1412. Sections.FirstEntry [section] = entry2;
  1413. else if (entry2 == Sections.FirstEntry [section])
  1414. Sections.FirstEntry [section] = entry1;
  1415. if (entry1 == Sections.LastEntry [section])
  1416. Sections.LastEntry [section] = entry2;
  1417. else if (entry2 == Sections.LastEntry [section])
  1418. Sections.LastEntry [section] = entry1;
  1419. if (Entries.NextEntry [entry1] == entry2)
  1420. {
  1421. Entries.NextEntry [entry1] = Entries.NextEntry [entry2];
  1422. Entries.PreviousEntry [entry2] = Entries.PreviousEntry [entry1];
  1423. if (Entries.PreviousEntry [entry1] != INVALID_ENTRY)
  1424. Entries.NextEntry [Entries.PreviousEntry [entry1]] = entry2;
  1425. if (Entries.NextEntry [entry2] != INVALID_ENTRY)
  1426. Entries.PreviousEntry [Entries.NextEntry [entry2]] = entry1;
  1427. Entries.NextEntry [entry2] = entry1;
  1428. Entries.PreviousEntry [entry1] = entry2;
  1429. }
  1430. else if (Entries.NextEntry [entry2] == entry1)
  1431. {
  1432. Entries.NextEntry [entry2] = Entries.NextEntry [entry1];
  1433. Entries.PreviousEntry [entry1] = Entries.PreviousEntry [entry2];
  1434. if (Entries.PreviousEntry [entry2] != INVALID_ENTRY)
  1435. Entries.NextEntry [Entries.PreviousEntry [entry2]] = entry1;
  1436. if (Entries.NextEntry [entry1] != INVALID_ENTRY)
  1437. Entries.PreviousEntry [Entries.NextEntry [entry1]] = entry2;
  1438. Entries.NextEntry [entry1] = entry2;
  1439. Entries.PreviousEntry [entry2] = entry1;
  1440. }
  1441. else
  1442. {
  1443. new pointer;
  1444. if (Entries.PreviousEntry [entry1] != INVALID_ENTRY)
  1445. Entries.NextEntry [Entries.PreviousEntry [entry1]] = entry2;
  1446. if (Entries.NextEntry [entry1] != INVALID_ENTRY)
  1447. Entries.PreviousEntry [Entries.NextEntry [entry1]] = entry2;
  1448. if (Entries.PreviousEntry [entry2] != INVALID_ENTRY)
  1449. Entries.NextEntry [Entries.PreviousEntry [entry2]] = entry1;
  1450. if (Entries.NextEntry [entry2] != INVALID_ENTRY)
  1451. Entries.PreviousEntry [Entries.NextEntry [entry2]] = entry1;
  1452. pointer = Entries.NextEntry [entry1];
  1453. Entries.NextEntry [entry1] = Entries.NextEntry [entry2];
  1454. Entries.NextEntry [entry2] = pointer;
  1455. pointer = Entries.PreviousEntry [entry1];
  1456. Entries.PreviousEntry [entry1] = Entries.PreviousEntry [entry2];
  1457. Entries.PreviousEntry [entry2] = pointer;
  1458. }
  1459. return 1;
  1460. }
  1461. return 0;
  1462. }
  1463. private DOF2::HashKey (key [])
  1464. {
  1465. new
  1466. h = -1,
  1467. i,
  1468. j;
  1469. if (CaseSensitive)
  1470. {
  1471. while ((j = key [i++]))
  1472. h = h * 33 + j;
  1473. }
  1474. else
  1475. {
  1476. while ((j = tolower (key [i++])))
  1477. h = h * 33 + j;
  1478. }
  1479. return h;
  1480. }
  1481. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1482. stock DOF2::strcpy (dest [], const src [], size = sizeof (dest))
  1483. {
  1484. dest [0] = '\0';
  1485. strcat (dest, src, size);
  1486. }
  1487. // Replace [oldstr] with [newstr] in [srcstr] and copy write the new string to 'deststr'.
  1488. stock DOF2::strreplace (const newstr [], const oldstr [], const srcstr [], deststr [], bool: ignorecase = false, size = sizeof (deststr))
  1489. {
  1490. new
  1491. newlen = strlen (newstr),
  1492. oldlen = strlen (oldstr),
  1493. srclen = strlen (srcstr),
  1494. idx,
  1495. rep;
  1496. for (new i = 0; i < srclen; ++i)
  1497. {
  1498. if (idx < (size - 1))
  1499. {
  1500. if ((i + oldlen) <= srclen)
  1501. {
  1502. if (!strcmp (srcstr [i], oldstr, ignorecase, oldlen))
  1503. {
  1504. deststr [idx] = '\0';
  1505. strcat (deststr, newstr, size);
  1506. ++rep;
  1507. idx += newlen;
  1508. i += oldlen - 1;
  1509. }
  1510. else
  1511. deststr [idx++] = srcstr [i];
  1512. }
  1513. else
  1514. deststr [idx++] = srcstr [i];
  1515. }
  1516. else
  1517. return rep;
  1518. }
  1519. deststr [idx] = '\0';
  1520. return rep;
  1521. }
  1522. stock DOF2::udb_encode (nickname [])
  1523. {
  1524. new
  1525. buf [256],
  1526. result [256];
  1527. static const symbols [][2][] =
  1528. {
  1529. {"_", "_00"},
  1530. {";", "_01"},
  1531. {"!", "_02"},
  1532. {"/", "_03"},
  1533. {"\\", "_04"},
  1534. {"[", "_05"},
  1535. {"]", "_06"},
  1536. {"?", "_07"},
  1537. {".", "_08"},
  1538. {"*", "_09"},
  1539. {"<", "_10"},
  1540. {">", "_11"},
  1541. {"{", "_12"},
  1542. {"}", "_13"},
  1543. {" ", "_14"},
  1544. {"\"", "_15"},
  1545. {":", "_16"},
  1546. {"|", "_17"},
  1547. {"=", "_18"}
  1548. };
  1549. strcat (buf, nickname);
  1550. for (new i = 0; i < sizeof (symbols); ++i)
  1551. {
  1552. DOF2::strreplace (symbols [i][1], symbols [i][0], buf, result);
  1553. DOF2::strcpy (buf, result);
  1554. }
  1555. return result;
  1556. }
  1557. stock DOF2::udb_decode (nickname [])
  1558. {
  1559. new
  1560. buf [256],
  1561. result [256];
  1562. static const symbols [][2][] =
  1563. {
  1564. {"_", "_00"},
  1565. {";", "_01"},
  1566. {"!", "_02"},
  1567. {"/", "_03"},
  1568. {"\\", "_04"},
  1569. {"[", "_05"},
  1570. {"]", "_06"},
  1571. {"?", "_07"},
  1572. {".", "_08"},
  1573. {"*", "_09"},
  1574. {"<", "_10"},
  1575. {">", "_11"},
  1576. {"{", "_12"},
  1577. {"}", "_13"},
  1578. {" ", "_14"},
  1579. {"\"", "_15"},
  1580. {":", "_16"},
  1581. {"|", "_17"},
  1582. {"=", "_18"}
  1583. };
  1584. strcat (buf, nickname);
  1585. for (new i = 0; i < sizeof (symbols); ++i)
  1586. {
  1587. DOF2::strreplace (symbols [i][0], symbols [i][1], buf, result);
  1588. DOF2::strcpy (buf, result);
  1589. }
  1590. return result;
  1591. }
  1592. stock DOF2::num_hash (buf [])
  1593. {
  1594. new
  1595. length = strlen (buf),
  1596. s1 = 1,
  1597. s2 = 0,
  1598. n;
  1599. for (n = 0; n < length; n++)
  1600. {
  1601. s1 = (s1 + buf [n]) % 65521;
  1602. s2 = (s2 + s1) % 65521;
  1603. }
  1604. return (s2 << 16) + s1;
  1605. }
  1606. /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1607. #if defined DUDB_CONVERT
  1608. #tryinclude <dutils>
  1609. #define dUser(%0).( DOF2_GetString(DOF2_File(%0),
  1610. #define dUserSet(%0).( DOF2_SetString(DOF2_File(%0),
  1611. #define dUserINT(%0).( DOF2_GetInt(DOF2_File(%0),
  1612. #define dUserSetINT(%0).( DOF2_SetInt(DOF2_File(%0),
  1613. #define dUserFLOAT(%0).( DOF2_GetFloat(DOF2_File(%0),
  1614. #define dUserSetFLOAT(%0).( DOF2_SetFloat(DOF2_File(%0),
  1615. #define udb_Create(%0,%1) DOF2_CreateFile(DOF2_File(%0),%1)
  1616. #define udb_RenameUser(%0,%1) DOF2_RenameFile(DOF2_File(%0),DOF2_File(%1))
  1617. #define udb_Exists(%0) DOF2_FileExists(DOF2_File(%0))
  1618. #define udb_Remove(%0) DOF2_RemoveFile(DOF2_File(%0))
  1619. #define udb_CheckLogin(%0,%1) DOF2_CheckLogin(DOF2_File(%0),%1)
  1620. #if !defined _dudb_included
  1621. #define _dudb_included
  1622. #endif
  1623. #endif
  1624. #if defined DINI_CONVERT
  1625. #define dini_Exists DOF2_FileExists
  1626. #define dini_Remove DOF2_RemoveFile
  1627. #define dini_Create DOF2_CreateFile
  1628. #define dini_Set DOF2_SetString
  1629. #define dini_Get DOF2_GetString
  1630. #define dini_IntSet DOF2_SetInt
  1631. #define dini_Int DOF2_GetInt
  1632. #define dini_BoolSet DOF2_SetBool
  1633. #define dini_Bool DOF2_GetBool
  1634. #define dini_FloatSet DOF2_SetFloat
  1635. #define dini_Float DOF2_GetFloat
  1636. #define dini_Unset DOF2_Unset
  1637. #define dini_Isset DOF2_IsSet
  1638. #if !defined _dini_included
  1639. #define _dini_included
  1640. #endif
  1641. #endif
  1642. /*
  1643. #if defined DINI_CONVERT || defined DUDB_CONVERT
  1644. #define udb_hash DOF2_num_hash
  1645. #define num_hash DOF2_num_hash
  1646. #define udb_encode DOF2_udb_encode
  1647. #define udb_decode DOF2_udb_decode
  1648. #endif
  1649. */