*/}}

la_util.h 24 KB

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