*/}}

la_util.h 24 KB

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