*/}}

la_util.h 24 KB

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