*/}}

la_util.h 23 KB

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