*/}}

la_util.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #define _CRT_SECURE_NO_WARNINGS
  20. #define _GNU_SOURCE
  21. #include <time.h>
  22. #ifdef LA_USE_GLES
  23. #include <EGL/egl.h>
  24. #include <GL/gl.h>
  25. #ifdef LA_ANDROID
  26. #include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
  27. #include <android_native_app_glue.h> // Required for: android_app struct and activity management
  28. #include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL()]
  29. #endif
  30. #else
  31. #include <GL/glew.h>
  32. #include <GL/gl.h>
  33. #endif
  34. #include "ft2build.h"
  35. #include "freetype/freetype.h"
  36. #include "la_icon.h"
  37. #include <stddef.h>
  38. #include <stdint.h>
  39. #include <ctype.h>
  40. #ifdef __linux__
  41. #include <fcntl.h>
  42. #include <unistd.h>
  43. #include <errno.h>
  44. #include <wchar.h>
  45. #define SYSWINDOW Window
  46. #ifdef LA_USE_GLES
  47. #define SYSGLCONTEXT EGLContext
  48. #else
  49. #define SYSGLCONTEXT GLXContext
  50. #endif
  51. #define SYSTEMDC DC
  52. #define SYSTEMRC RC
  53. #define SYSTEMDISPLAY Display
  54. #define SYSLOCK pthread_spinlock_t
  55. #endif
  56. #ifdef _WIN32
  57. #include <Windows.h>
  58. #include "Shlwapi.h"
  59. #define SYSWINDOW HWND
  60. #define SYSGLCONTEXT HGLRC
  61. #define SYSTEMDC HDC
  62. #define SYSTEMRC HRC
  63. #define SYSTEMDISPLAY int
  64. #define PATH_MAX 4096
  65. #define SYSLOCK CRITICAL_SECTION
  66. #ifndef off_t
  67. typedef long off_t;
  68. #endif
  69. #endif
  70. #ifdef LA_WITH_LUAJIT
  71. #define luajit_c
  72. #include "lua.h"
  73. #include "lauxlib.h"
  74. #include "lualib.h"
  75. #include "luajit.h"
  76. void tnsLuaInit(lua_State* L);
  77. void la_luaPrintStatus(lua_State *L);
  78. void la_luaLoadLibs(lua_State *L);
  79. void la_luaDumpStack(lua_State *L);
  80. #ifdef __cplusplus
  81. extern "C"{
  82. #endif
  83. extern const char* LA_LUA_LIB_COMMON;
  84. extern const char* LA_LUA_LIB_AUDIO;
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* luajit */
  89. #define NEED_STRUCTURE(a) \
  90. typedef struct _##a a;
  91. #define STRUCTURE(a) \
  92. typedef struct _##a a;\
  93. struct _##a
  94. #define lengthof(a) \
  95. (sizeof(a)/sizeof(a[0]))
  96. #ifdef _WIN32
  97. #define LA_PATH_SEP '\\'
  98. #define LA_PATH_SEPSTR "\\"
  99. #define realpath(N,R) _fullpath((R),(N),PATH_MAX)
  100. #else
  101. #define LA_PATH_SEP '/'
  102. #define LA_PATH_SEPSTR "/"
  103. #endif
  104. #define DBL_TRIANGLE_LIM 1e-11
  105. #define DBL_EDGE_LIM 1e-9
  106. #ifndef LAGUI_GIT_BRANCH
  107. #define LAGUI_GIT_BRANCH "Release 1"
  108. #endif
  109. // No need to show hash when not compiled from git repo.
  110. //#ifndef LAGUI_GIT_HASH
  111. //#define LAGUI_GIT_HASH "?"
  112. //#endif
  113. #define LA_HYPER_CREATED_TIME(hi) \
  114. hi->TimeCreated.Year,hi->TimeCreated.Month,hi->TimeCreated.Day,hi->TimeCreated.Hour,hi->TimeCreated.Minute,hi->TimeCreated.Second
  115. typedef double real;
  116. typedef unsigned long long u64bit;
  117. typedef unsigned int u32bit;
  118. typedef unsigned short u16bit;
  119. typedef unsigned short ushort;
  120. typedef unsigned char u8bit;
  121. typedef struct _laListSingle laListSingle;
  122. struct _laListSingle {
  123. void* pNext;
  124. };
  125. typedef struct _laListHandle laListHandle;
  126. struct _laListHandle {
  127. void* pFirst;
  128. void* pLast;
  129. };
  130. typedef struct _laListWithPivot laListWithPivot;
  131. struct _laListWithPivot {
  132. void* pFirst;
  133. void* pLast;
  134. void* Pivot;
  135. };
  136. typedef struct _laListItem laListItem;
  137. struct _laListItem {
  138. void* pPrev;
  139. void* pNext;
  140. };
  141. typedef struct _laListItem2 laListItem2;
  142. struct _laListItem2 {
  143. void* O1;
  144. void* O2;
  145. void* pPrev;
  146. void* pNext;
  147. };
  148. typedef struct _laListItem3 laListItem3;
  149. struct _laListItem3 {
  150. void* O1;
  151. void* O2;
  152. void* O3;
  153. void* O4;
  154. void* pPrev;
  155. void* pNext;
  156. };
  157. NEED_STRUCTURE(laSafeString);
  158. STRUCTURE(laAuthorInfo) {
  159. laListItem Item;
  160. laSafeString* Name;
  161. laSafeString* CopyrightString;
  162. };
  163. STRUCTURE(laTimeInfo) {
  164. u16bit Year;//Also Used As Timer [ms] counter
  165. u8bit Month;
  166. u8bit Day;
  167. u8bit Hour;
  168. u8bit Minute;
  169. u8bit Second;
  170. };
  171. NEED_STRUCTURE(laPropContainer);
  172. typedef struct _laUID laUID;
  173. struct _laUID {
  174. char String[32];//a simplified uuid, example: 0E3F9BA4802FDDC2-20160601123546 [\0]
  175. };
  176. typedef struct _laListItemPointer laListItemPointer;
  177. struct _laListItemPointer {
  178. void* pPrev;
  179. void* pNext;
  180. void* p;
  181. };
  182. typedef struct _laItemUserLinker laItemUserLinker;
  183. typedef void(*laUserRemoveFunc)(void* This, laItemUserLinker* iul);
  184. NEED_STRUCTURE(laProp);
  185. struct _laItemUserLinker {
  186. laListItemPointer Pointer;
  187. laUserRemoveFunc Remove;
  188. laProp* Which;
  189. void* Additional;
  190. unsigned int FrameDistinguish;
  191. int ForceRecalc;
  192. };
  193. typedef struct _laItemUserLinkerLocal laItemUserLinkerLocal;
  194. struct _laItemUserLinkerLocal {
  195. laItemUserLinker Link;
  196. void* Instance;
  197. };
  198. typedef struct _laElementListItem laElementListItem;
  199. struct _laElementListItem {
  200. laListItem Item;
  201. void* Ext;
  202. };
  203. typedef struct _laListNonRecursiveRoot laListNonRecursiveRoot;
  204. struct _laListNonRecursiveRoot {
  205. laListHandle NSItems;
  206. };
  207. typedef int(*laCompareFunc)(void*, void*);
  208. typedef void(*laListDoFunc)(void*);
  209. typedef void(*laListNonRecursiveDoFunc)(laListNonRecursiveRoot*, void*, void*);//item,custom
  210. typedef void(*laListNonRecursiveCopyFunc)(laListNonRecursiveRoot*, void*, void*, void*);//old,new,custom
  211. typedef void(*laListDoFuncArgp)(void*, void*);
  212. typedef void(*laCopyListFunc)(void*, void*);
  213. typedef void(*laListCustomDataRemover)(void*);
  214. //typedef void(*ListMatcherFunc)(void*,void*);//gotten value,enumed curent lst item.
  215. typedef struct _laListNonRecursiveItem laListNonRecursiveItem;
  216. struct _laListNonRecursiveItem {
  217. laListItem Item;
  218. laListHandle handle;
  219. laListHandle *ToHandle;//This Is Pointer!
  220. laListNonRecursiveDoFunc func;
  221. laListNonRecursiveCopyFunc CopyFunc;
  222. laListCustomDataRemover remover;
  223. void* CustomData;
  224. int bFreeList;
  225. int SizeEachNode;
  226. };
  227. typedef struct _laHash256 laHash256;
  228. struct _laHash256 {
  229. laListHandle Entries[256];
  230. };
  231. typedef struct _laHash65536 laHash65536;
  232. struct _laHash65536 {
  233. laListHandle Entries[65536];
  234. };
  235. typedef struct _laSafeString laSafeString;
  236. struct _laSafeString {
  237. laListItem Item;
  238. char * Ptr;
  239. };
  240. typedef struct _laSafeStringCollection laSafeStringCollection;
  241. struct _laSafeStringCollection {
  242. laListHandle SafeStrings;
  243. };
  244. typedef struct _laStringSplitor laStringSplitor;
  245. struct _laStringSplitor {
  246. int NumberParts;
  247. laListHandle parts;
  248. };
  249. typedef struct _laStringPart laStringPart;
  250. struct _laStringPart {
  251. laListItem Item;
  252. char * Content;
  253. int IntValue;
  254. real FloatValue;
  255. char Type;
  256. };
  257. STRUCTURE(laStringLine) {
  258. laListItem Item;
  259. uint32_t Buf[1024];//unicode
  260. };
  261. STRUCTURE(laStringEdit) {
  262. laListHandle Lines;
  263. int CursorLine, CursorBefore, CursorPreferBefore;
  264. int BeginLine, BeginBefore;
  265. int EndLine, EndBefore;
  266. int _BeginLine, _BeginBefore; // selection order
  267. int _EndLine, _EndBefore;
  268. int TotalLines;
  269. int ViewStartLine, ViewStartCol;
  270. int ViewHeight, ViewWidth;
  271. int MouseSelecting;
  272. };
  273. #define LA_SWAP(T,x,y) \
  274. { T SWAP = x; x = y; y = SWAP; }
  275. #define LA_MEMORY_POOL_1MB 1048576
  276. #define LA_MEMORY_POOL_128MB 134217728
  277. #define LA_MEMORY_POOL_256MB 268435456
  278. #define LA_MEMORY_POOL_512MB 536870912
  279. STRUCTURE(laMemoryPool) {
  280. laListItem Item;
  281. int NodeSize;
  282. int NextCount;
  283. int UsableCount;
  284. int Hyperlevel;
  285. laListHandle Pools;
  286. };
  287. STRUCTURE(laMemoryPoolPart) {
  288. laListItem Item;
  289. laListHandle FreeMemoryNodes;
  290. int UsedCount;
  291. laMemoryPool* PoolRoot;
  292. //<------Pool mem starts here
  293. };
  294. NEED_STRUCTURE(laDBInst);
  295. STRUCTURE(laMemNode0){
  296. laListItem Item;
  297. laMemoryPoolPart* InPool;//<---- Keep at the last
  298. //<------User mem starts here
  299. };
  300. STRUCTURE(laMemNode) {
  301. laListItem Item;
  302. laListHandle Users; //<---- Keep at the second
  303. void* ReadInstance;
  304. laMemoryPoolPart* InPool; //<---- Keep at the last
  305. //<------User mem starts here
  306. };
  307. NEED_STRUCTURE(laManagedUDF);
  308. STRUCTURE(laMemNodeHyper) {
  309. laListItem Item;
  310. laListHandle Users; //<---- Keep at the second
  311. laUID NUID;
  312. laTimeInfo TimeCreated;
  313. laManagedUDF* FromFile;
  314. int Modified;
  315. int UNUSEDUndoDirty;
  316. laMemoryPoolPart* InPool; //<---- Keep at the last
  317. //<------User mem starts here
  318. };
  319. STRUCTURE(laStaticMemoryPoolNode) {
  320. laListItem Item;
  321. int UsedByte;
  322. //<------User mem starts here
  323. };
  324. STRUCTURE(laStaticMemoryPool) {
  325. int EachSize;
  326. laListHandle Pools;
  327. //SYSLOCK csMem;
  328. };
  329. STRUCTURE(laAVLNodeReal64) {
  330. laAVLNodeReal64* Parent;
  331. u64bit Index;
  332. real Value;
  333. //real SmallestValue;
  334. //real GreatestValue;
  335. laAVLNodeReal64* Smaller;
  336. laAVLNodeReal64* Greater;
  337. char Height;
  338. void* Pointer;
  339. };
  340. STRUCTURE(laAVLTreeReal64) {
  341. laAVLNodeReal64* Root;
  342. u64bit ItemCount;
  343. laMemoryPool MemoryPool;
  344. };
  345. STRUCTURE(laTimeRecorder) {
  346. #ifdef __linux__
  347. struct timespec ts;
  348. #endif
  349. #ifdef _WIN32
  350. LARGE_INTEGER tm;
  351. #endif
  352. };
  353. STRUCTURE(laTranslationNode) {
  354. laListItem Item;
  355. laSafeString* LanguageName;
  356. laHash256 Matches;
  357. };
  358. STRUCTURE(laTranslation) {
  359. int EnableTranslation;
  360. laListHandle Languages;
  361. laTranslationNode* CurrentLanguage;
  362. laHash256 MisMatches;
  363. };
  364. STRUCTURE(laTranslationMatch) {
  365. laListItem Item;
  366. char * Target;
  367. char * Replacement;
  368. };
  369. NEED_STRUCTURE(laRackPage);
  370. STRUCTURE(laNodeVisitInfo){
  371. laListHandle* l;
  372. laListHandle* br;
  373. uint64_t Branch;
  374. int NextBranch;
  375. laRackPage* Page;
  376. };
  377. NEED_STRUCTURE(laBaseNode);
  378. typedef void (*laBaseNodeInitF)(laBaseNode*, int NoCreate);
  379. typedef void (*laBaseNodeDestroyF)(laBaseNode*);
  380. typedef int (*laBaseNodeVisitF)(laBaseNode*, laNodeVisitInfo*);
  381. typedef int (*laBaseNodeEvalF)(laBaseNode*);
  382. typedef void (*laBaseNodeCopyF)(laBaseNode* _new, laBaseNode* _old, int DoRematch);
  383. STRUCTURE(laBaseNodeType){
  384. laBaseNodeInitF Init;
  385. laBaseNodeDestroyF Destroy;
  386. laBaseNodeVisitF Visit;
  387. laBaseNodeEvalF Eval;
  388. laBaseNodeCopyF Copy;
  389. laPropContainer* pc;
  390. char* TypeName;
  391. char* Name;
  392. int Icon;
  393. int NodeSize;
  394. };
  395. NEED_STRUCTURE(laNodeRack);
  396. STRUCTURE(laBaseNode){
  397. laListItem Item;
  398. laSafeString* Name;
  399. laBaseNodeType* Type;
  400. laNodeRack* InRack;
  401. int Gap; int InitDone;
  402. uint64_t EvalMagic;
  403. uint64_t Branch;
  404. uint64_t BranchTemp;
  405. laBaseNode* Duplicated;
  406. };
  407. #define CreateNew(Type) \
  408. calloc(sizeof(Type),1)
  409. #define CreateNew_Size(size) \
  410. calloc(size,1)
  411. #define CreateNewBuffer(Type,Num) \
  412. calloc(sizeof(Type),Num);
  413. #define FreeMem(ptr) \
  414. nutFreeMem((&ptr))
  415. #define elif \
  416. else if
  417. #define LA_UNAVAILABLE_NAME "- Unknown -"
  418. uint32_t laToUnicode(const unsigned char* ch, int* advance);
  419. int laToUTF8(const uint32_t ch, unsigned char* out, unsigned char** next);
  420. int strToUnicode(uint32_t* target, unsigned char* const src);
  421. int strToUTF8(unsigned char* target, uint32_t* const src);
  422. int strlenU(uint32_t* const str);
  423. int strcpyU(uint32_t* target, uint32_t* const source );
  424. int strcatU(uint32_t* target, uint32_t* const source );
  425. struct tm* laGetFullTime();
  426. void laRecordTime(laTimeRecorder* tr);
  427. real laTimeElapsedSecondsf(laTimeRecorder* End, laTimeRecorder* Begin);
  428. int laTimeElapsedMilliseconds(laTimeRecorder* End, laTimeRecorder* Begin);
  429. void laSetAuthorInfo(char * Name, char * CopyrightString);
  430. void memCreateNUID(char* buf,laMemNodeHyper* Hyper);
  431. NEED_STRUCTURE(laPropPack);
  432. int nutHyperUserCount(void* instance, laProp* p_optional, int *p_count);
  433. void memHyperInfo(laPropPack* pp, char* buf);
  434. void memMakeHyperData(laMemNodeHyper* hi);
  435. void nutFreeMem(void** ptr);
  436. int nutFloatCompare(real l, real r);
  437. int nutSameAddress(void* l, void* r);
  438. void* arrElement(void* head, int i, int size);
  439. int arrEnsureLength(void** head, int next, int* max, size_t ElementSize);
  440. int arrInitLength(void** head, int max, int* pmax, size_t ElementSize);
  441. void arrFree(void** head, int* max);
  442. void lstPushSingle(void** Head, laListSingle* Item);
  443. void* lstPopSingle(void** Head, laListSingle* Item);
  444. void lstClearPrevNext(laListItem* li);
  445. int lstCountElements(laListHandle* Handle);
  446. void lstAppendItem(laListHandle* Handle, void* Item);
  447. void lstPushItem(laListHandle* Handle, void* Item);
  448. void* lstPopItem(laListHandle* Handle) ;
  449. void lstAppendItem2(laListHandle* Handle, void* Item);
  450. void* lstPopItem2(laListHandle* Handle);
  451. void lstPushItem2(laListHandle* Handle, void* Item);
  452. void lstAppendItem3(laListHandle* Handle, void* Item);
  453. void* lstPopItem3(laListHandle* Handle);
  454. void lstPushItem3(laListHandle* Handle, void* Item);
  455. int lstRemoveItem(laListHandle* Handle, laListItem* li) ;
  456. int lstRemoveItem2(laListHandle* Handle, laListItem2* li);
  457. int lstRemoveSegment(laListHandle* Handle, laListItem* Begin, laListItem* End);
  458. void lstInsertItemBefore(laListHandle* Handle, laListItem* toIns, laListItem* pivot);
  459. void lstInsertItemAfter(laListHandle* Handle, laListItem* toIns, laListItem* pivot);
  460. void lstInsertSegmentBefore(laListHandle* Handle, laListItem* Begin, laListItem* End, laListItem* pivot);
  461. void lstInsertSegmentAfter(laListHandle* Handle, laListItem* Begin, laListItem* End, laListItem* pivot);
  462. int lstHaveItemInList(laListHandle* Handle);
  463. /**/ void* lstGetTop(laListHandle* Handle);
  464. void lstPushSimpleItem(void** first, laItemUserLinker* iul);
  465. void* lstPushItemUser(void** first, void* p);
  466. void* lstPushItemUsing(void** first, void* p);
  467. void* lstAppendPointerOnly(laListHandle* h, void* p);
  468. void* lstAppendPointerSizedOnly(laListHandle* h, void* p, int size);
  469. void* lstPushPointerOnly(laListHandle* h, void* p);
  470. void* lstPushPointerSizedOnly(laListHandle* h, void* p, int size);
  471. void lstReverse(laListHandle* h);
  472. int lstHasPointer(laListHandle* h, void *p);
  473. void* lstAppendPointer(laListHandle* h, void* p);
  474. void* lstAppendPointerSized(laListHandle* h, void* p, int size);
  475. void* lstPushPointer(laListHandle* h, void* p);
  476. void* lstPushPointerSized(laListHandle* h, void* p, int size);
  477. void* lstAppendPointerStatic(laListHandle* h, laStaticMemoryPool* smp, void* p);
  478. void* lstAppendPointerStaticSized(laListHandle* h, laStaticMemoryPool* smp, void* p, int size);
  479. void* lstPushPointerStatic(laListHandle* h, laStaticMemoryPool* smp, void* p);
  480. void* lstPushPointerStaticSized(laListHandle* h, laStaticMemoryPool* smp, void* p, int size);
  481. void* lstPopPointerOnly(laListHandle* h);
  482. void lstRemovePointerItemOnly(laListHandle* h, laListItemPointer* lip);
  483. void lstRemovePointerOnly(laListHandle* h, void* p);
  484. void lstClearPointerOnly(laListHandle* h);
  485. void lstGeneratePointerListOnly(laListHandle* from1, laListHandle* from2, laListHandle* to);
  486. void* lstPopPointer(laListHandle* h);
  487. void lstRemovePointerItem(laListHandle* h, laListItemPointer* lip);
  488. void lstRemovePointer(laListHandle* h, void* p);
  489. void lstRemovePointerLeave(laListHandle *h, void *p);
  490. void lstClearPointer(laListHandle* h);
  491. void lstGeneratePointerList(laListHandle* from1, laListHandle* from2, laListHandle* to);
  492. void lstCopyHandle(laListHandle* target, laListHandle* src);
  493. void* lstAppendPointerStaticPool(laStaticMemoryPool* mph, laListHandle* h, void* p);
  494. void* lstPopPointerLeave(laListHandle* h);
  495. void lstRemovePointerItemNoFree(laListHandle* h, laListItemPointer* lip);
  496. void lstMoveUp(laListHandle* h, laListItem* li);
  497. void lstMoveDown(laListHandle* h, laListItem* li);
  498. void lstForAllItemsDo(laListDoFunc func, laListHandle* hList);
  499. void lstForAllItemsDoLNRR(laListNonRecursiveDoFunc func, laListHandle* hList);
  500. void lstForAllItemsDo_DirectFree(laListDoFunc func, laListHandle* hList);
  501. void lstForAllItemsDo_arg_ptr(laListDoFuncArgp func, laListHandle* hList, void* arg);
  502. void lstForAllItemsDo_NonRecursive_Root(laListHandle* FirstHandle, laListNonRecursiveDoFunc func, int bFreeItem, void* custom_data, laListCustomDataRemover remover);
  503. void lstCopy_NonRecursive_Root(laListHandle* FromHandle, laListHandle* ToHandle, int SizeEachNode, laListNonRecursiveCopyFunc func, void* custom_data, laListCustomDataRemover remover);
  504. void lstAddNonRecursiveListHandle(laListNonRecursiveRoot* root, laListHandle* newHandle, laListNonRecursiveDoFunc nrFunc, int bFreeList, void* custom_data, laListCustomDataRemover remover);
  505. void lstAddNonRecursiveListCopier(laListNonRecursiveRoot* root, laListHandle* oldHandle, laListHandle* newHandle, int sizeEach, laListNonRecursiveCopyFunc nrCpyFunc, void* custom_data, laListCustomDataRemover remover);
  506. void* lstFindItem(void* CmpData, laCompareFunc func, laListHandle* hList);
  507. void lstCombineLists(laListHandle* dest, laListHandle* src);
  508. void lstDestroyList(laListHandle* hlst);
  509. void* lstReMatch(laListHandle* SearchHandle, laListHandle* CurrentHandle, void* ItemToFind);
  510. typedef int(*MatcherFunc)(void*, void*);
  511. void* lstReMatchEx(laListHandle* SearchHandle, laListHandle* CurrentHandle, void* ItemToFind, MatcherFunc func);
  512. void lstAddElement(laListHandle* hlst, void* ext);
  513. void lstDestroyElementList(laListHandle* hlst);
  514. void hsh256InsertItemCSTR(laHash256* hash, laListItem* li, char * buckle);
  515. void hsh256InsertItem(laHash256* hash, laListItem* li, char buckle);
  516. void hsh65536InsertItem(laHash65536* hash, laListItem* li, long buckle);
  517. void hsh65536Init(laHash65536** h);
  518. void hshFree(laHash65536** h);
  519. laListHandle* hsh65536DoHashLongPtr(laHash65536* hash, u64bit buckle);
  520. laListHandle* hsh65536DoHashNUID(laHash65536* hash, char * NUID);
  521. laListItem* hsh256FindItemSTR(laHash256* hash, laCompareFunc func, char * buckle);
  522. unsigned char hsh256DoHashSTR(char * buckle);
  523. void memResetByteCount();
  524. int memGetByteCount();
  525. void* memGetHead(void* UserMem, int* HyperLevel);
  526. laListHandle* memGetUserList(void* UserMem);
  527. laMemoryPool *memInitPool(int NodeSize, int HyperLevel);
  528. void memInitPoolSmall(laMemoryPool* mph, int NodeSize);
  529. laMemoryPoolPart* memNewPoolPart(laMemoryPool* mph);
  530. void* memAcquireH(laMemoryPool* Handle);
  531. void* memAcquireSimple(int Size);
  532. void* memAcquireNoAppend(int Size);
  533. void* memAcquireHyperNoAppend(int Size);
  534. void* memAcquire(int Size);
  535. void* memAcquireHyper(int Size);
  536. void memFree(void* Data);
  537. void memDestroyPool(laMemoryPool* Handle);
  538. void memNoLonger();
  539. void memMarkClean(void* HyperUserMem);
  540. void memLeave(void *Data);
  541. void memTake(void* Data);
  542. void memFreeRemainingLeftNodes();
  543. laStaticMemoryPoolNode* memNewStaticPool(laStaticMemoryPool* smp);
  544. void* memStaticAcquire(laStaticMemoryPool*smp, int size);
  545. void* memStaticAcquireThread(laStaticMemoryPool*smp, int size);
  546. void* memStaticDestroy(laStaticMemoryPool*smp);
  547. NEED_STRUCTURE(laSubProp);
  548. void memAssignRef(void* This, void** ptr, void* instance);
  549. void memAssignRefSafe(laSubProp* sp, void* This, void** ptr, void* instance);
  550. char * strSub(char *input, char *substring, char *replace);
  551. int strGetStringTerminateBy(char * content, char terminator, char * Out);
  552. int strHeadOfStringMatch(char * Str, char * SubStr);
  553. int strSkipSegmet(char ** pivot, char * content);
  554. char * strGetLastSegment(char * Content, char Seperator);
  555. void strDiscardLastSegmentSeperateBy(char * Content, char Seperator);
  556. void strDiscardSameBeginningSeperatedBy(char * s1, char * s2, char ** Result1, char ** Result2, char Seperator);
  557. int strCountSegmentSeperateBy(char * Content, char Seperator);
  558. void strMakeDifferentName(char * Target);
  559. void strReplaceCharacter(char * Str, char Find, char Replace);
  560. void strToUpper(char * Str);
  561. void strToLower(char * Str);
  562. int tolowerGuarded(int a);
  563. laStringSplitor *strSplitPath(char *path,char terminator);
  564. int strMakeInstructions(laStringSplitor** result,char * content);
  565. laStringPart* strGetArgument(laStringSplitor* ss, char * content);
  566. char * strGetArgumentString(laStringSplitor* ss, char * content);
  567. int strArgumentMatch(laStringSplitor* ss, char * id, char * value);
  568. int strDestroyStringSplitor(laStringSplitor** ss);
  569. int strGetIntSimple(char * content);
  570. real strGetFloatSimple(char * content);
  571. void strConvInt_CString(int src, char * dest, int lenth);
  572. void strConvFloat_CString(real src, char * dest, int lenth);
  573. void strCopyFull(char * dest, char * src);
  574. void strCopySized(char * dest, int LenthLim, char * src);
  575. #define strAppend strcat
  576. void strPrintFloatAfter(char * dest, int LenthLim, int bits, real data);
  577. void strPrintIntAfter(char * dest, int LenthLim, int data);
  578. int strSame(char * src, char *dest);
  579. void strEscapePath(char* OutCanBeSame, char* path);
  580. void strSafeDestroy(laSafeString** ss);
  581. void strSafeSet(laSafeString** ss, char * Content);
  582. void strSafeAppend(laSafeString **ss, char *Content);
  583. void strSafePrint(laSafeString **ss, char *Format, ...);
  584. void strSafePrintV(laSafeString **ss, char *Format, va_list arg);
  585. void strSafeDump();
  586. #define SSTR(str) (((str) && (str)->Ptr)?(str)->Ptr:"")
  587. void strBeginEdit(laStringEdit** se, char * FullStr);
  588. char* strGetEditString(laStringEdit *se, int SelectionOnly);
  589. char* strEndEdit(laStringEdit** se, int FreeString);
  590. void strSetEditViewRange(laStringEdit* se, int Lines, int Cols);
  591. void strEnsureCursorVisible(laStringEdit* se);
  592. void strRemoveLine(laStringEdit* se, laStringLine* sl);
  593. void strRemoveLineI(laStringEdit* se, int LineIndex);
  594. void strSetCursor(laStringEdit* se, int LineIndex, int BeforeIndex);
  595. void strMoveCursor(laStringEdit* se, int Left, int Select);
  596. void strMoveCursorLine(laStringEdit *se, int Up, int Select);
  597. int strHasSelection(laStringEdit* se);
  598. void strCancelSelect(laStringEdit *se);
  599. void strLazySelect(laStringEdit *se);
  600. void strEndSelect(laStringEdit *se);
  601. void strSelectLineAll(laStringEdit* se);
  602. void strDeselectAll(laStringEdit* se);
  603. void strPanFoward(uint32_t * str, int Before, int Offset);
  604. void strSquishBackward(uint32_t * str, int Before, int EndBefore);
  605. void strClearSelection(laStringEdit* se);
  606. laStringLine *strGetCursorLine(laStringEdit *se, int* IndexIfLast);
  607. laStringLine* strGetBeginLine(laStringEdit* se);
  608. void strInsertChar(laStringEdit* se, uint32_t a);
  609. void strBackspace(laStringEdit* se);
  610. void strMoveView(laStringEdit *se, int DownLines, int RightCharacters);
  611. int laCopyFile(char *to, char *from);
  612. int laEnsureDir(const char *dir);
  613. void transNewLanguage(const char * LanguageID);
  614. void transSetLanguage(const char * LanguageID);
  615. void transDumpMissMatchRecord(const char * filename);
  616. void transNewEntry(const char * Target, const char * replacement);
  617. char * transLate(char * Target);
  618. void transState(void* UNUSED, int val);
  619. void transInitTranslation_zh_cn();
  620. #include <stdlib.h>
  621. #include <stdbool.h>
  622. typedef struct barray barray_t;
  623. typedef unsigned bit_t;
  624. barray_t *barray_init(size_t num_bits);
  625. void barray_free(barray_t *barray);
  626. u64bit *barray_data(barray_t *barray);
  627. size_t barray_count_set(barray_t *barray);
  628. void barray_set(barray_t *barray, bit_t bit);
  629. void barray_clear(barray_t *barray, bit_t bit);
  630. bool barray_is_set(barray_t *barray, bit_t bit);
  631. typedef void (*barray_callback_t)(bit_t bit, void *arg);
  632. void barray_foreach_set(barray_t *barray, barray_callback_t callback, void *arg);
  633. #define BITS_PER_LONG (sizeof(u64bit) * 8)
  634. #define BITS_TO_LONGS(n) (((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)
  635. struct barray
  636. {
  637. size_t num_bits;
  638. size_t num_longs;
  639. u64bit data[0];
  640. };
  641. typedef struct{
  642. uint64_t size; // Size of input in bytes
  643. uint32_t buffer[4]; // Current accumulation of hash
  644. uint8_t input[64]; // Input to be used in the next step
  645. uint8_t digest[16]; // Result of algorithm
  646. }MD5Context;
  647. void md5Init(MD5Context *ctx);
  648. void md5Update(MD5Context *ctx, uint8_t *input, size_t input_len);
  649. void md5Finalize(MD5Context *ctx);
  650. void md5Step(uint32_t *buffer, uint32_t *input);
  651. void md5String(char *input, uint8_t *result);
  652. void md5File(FILE *file, uint8_t *result);
  653. void toHexString(char* text, char* hex);
  654. void laOpenInternetLink(char* url);
  655. #define SEND_PANIC_ERROR(msg) \
  656. {printf(msg); exit(0);}
  657. #ifdef _WIN32
  658. void usleep(unsigned int usec);
  659. #endif
  660. void laSpinInit(SYSLOCK* lock);
  661. void laSpinDestroy(SYSLOCK * lock);
  662. void laSpinLock(SYSLOCK* lock);
  663. void laSpinUnlock(SYSLOCK* lock);
  664. int terLoadLine(char* buf, int firstline);