*/}}

la_util.h 24 KB

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