*/}}

la_util.h 24 KB

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