Advertisement
Guest User

anthony gorecki anthony@anthonygorecki.ca

a guest
Dec 6th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.63 KB | None | 0 0
  1. Sun, Dec 06, 2015 12:21:50 AM
  2. ./doc/code-style.txt
  3. Soft limit for line length is 80 characters, hard limit is 100 characters.
  4.  
  5. Conditional statements requiring multiple lines should indent the subsequent
  6. lines with two tabs (one additional tab, relative the the code following the
  7. conditional statement).
  8. ./doc/errors.txt
  9. Code that is (potentially) buggy enough to need asserts should include <gc/err.h>.
  10. ./doc/func-args.txt
  11. Structs are always used for info and conf varaibles so their contents /
  12. implementation can easily be changed later and without modifying the code of
  13. software using the libraries.
  14. ./doc/func-naming.txt
  15. Hard limit for function name first part is five characters. Soft limit is
  16. four characters.
  17.  
  18. Function name hard limit for second part is five characters (initialization /
  19. activation). Does not apply to names that have been shortened to individual
  20. characters per word.
  21.  
  22. Struct member name soft limit is four characters.
  23. ./doc/includes.txt
  24. External Gc headers, Gc header for local file, all other headers; groups
  25. separated by a single new line.
  26.  
  27. All Gc headers must ultimately include <gc/base.h>. This is to get system
  28. wide defines like _GNU_SOURCE and primitive types (u8, etc).
  29.  
  30. Includes for files that have a one line description must duplicate that
  31. description.
  32. ./doc/secure-coding.txt
  33. Parser memory errors are treated as "no match".
  34.  
  35. Invalid flag arguments are treated as "no match".
  36. ./gc-base-lib/1/0/gc-proj.txt
  37. #===============================================================================
  38. # This file is part of Gc-Base-Lib.
  39. # Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  40. #
  41. # Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  42. # the terms of the GNU General Public License as published by the Free Software
  43. # Foundation, either version 3 of the License, or (at your option) any later
  44. # version.
  45. #
  46. # Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  47. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  48. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  49. #
  50. # You should have received a copy of the GNU General Public License along with
  51. # Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  52. #===============================================================================
  53. # gc-proj-conf (tracks config; can reconfigure; if you aren't going to make 'dev'
  54. # it won't be configured -- per target config)
  55. # gc-proj-make (will rebuild changed files; will rebuild only necessary after conf change)
  56. # gc-proj-inst (installs all built targets)
  57. #
  58. # Note: This file does not include operating system specific support yet.
  59.  
  60.  
  61. TGEN dev # Make this into TDEV after parser works properly.
  62. CONF
  63. VARS
  64. DIR inc
  65. DIR pkgconfig
  66.  
  67. MAKE
  68. EXEC lib/pkgconfig/make.sh $DPKGCONFIG # This should be replaced with 'sed'.
  69.  
  70. INST
  71. COPY inc/gc $DINC
  72. MOVE lib/pkgconfig/gc-base.pc.tmp $DPKGCONFIG/gc-base.pc
  73.  
  74.  
  75. TLIB lib
  76. CONF
  77. # DEF (default target; overrides first lib or exe target if specified)
  78. # note that the precedence of targets to be chosen first could (and
  79. # probably should be determined by selecting a profile for the given
  80. # programming language / project type. Documentation projects, for
  81. # instance would not have the same precedence settings as a c project.
  82.  
  83. # NDIR LIB (implied by target type).
  84.  
  85. DLNK pthread # Need pthread library.
  86.  
  87. FEAT alloc # Feature to select memory allocator.
  88. llalloc # Lockless alloc. Default option is first.
  89. DLNK llalloc # Add to the list of libraries to link dynamically.
  90.  
  91. libc # Fall back to standard libc allocator.
  92. # Nothing to do.
  93.  
  94. FEAT st # Feature to select stack tracing implementation.
  95. unwind # libunwind
  96. PCFG unwind # Use pkg-config to add cflags and libs.
  97.  
  98. gnubt # GNU backtrace functions
  99. LNKF rdynamic # Add -rdynamic linker flag.
  100. ./gc-base-lib/1/0/inc/gc/atmc.h
  101. //==============================================================================
  102. // This file is part of Gc-Base-Lib.
  103. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  104. //
  105. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  106. // the terms of the GNU General Public License as published by the Free Software
  107. // Foundation, either version 3 of the License, or (at your option) any later
  108. // version.
  109. //
  110. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  111. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  112. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  113. // details.
  114. //
  115. // You should have received a copy of the GNU General Public License along with
  116. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  117. //==============================================================================
  118. #pragma once
  119.  
  120. #include <gc/common.h>
  121.  
  122. typedef _Atomic s8 as8;
  123. typedef _Atomic s16 as16;
  124. typedef _Atomic s32 as32;
  125. typedef _Atomic s64 as64;
  126.  
  127. typedef _Atomic u8 au8;
  128. typedef _Atomic u16 au16;
  129. typedef _Atomic u32 au32;
  130. typedef _Atomic u64 au64;
  131.  
  132. #define atmc_fadd atomic_fetch_add
  133. #define atmc_fsub atomic_fetch_sub
  134. #define atmc_load atomic_load
  135. ./gc-base-lib/1/0/inc/gc/base.h
  136. //==============================================================================
  137. // This file is part of Gc-Base-Lib.
  138. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  139. //
  140. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  141. // the terms of the GNU General Public License as published by the Free Software
  142. // Foundation, either version 3 of the License, or (at your option) any later
  143. // version.
  144. //
  145. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  146. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  147. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  148. // details.
  149. //
  150. // You should have received a copy of the GNU General Public License along with
  151. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  152. //==============================================================================
  153. #pragma once
  154.  
  155. #include <stddef.h>
  156. #include <stdint.h>
  157.  
  158. // "__unused" is expected to be provided by a system library. Define it in this
  159. // file only if it is missing on the host system.
  160.  
  161. #define likely(EXPR) __builtin_expect(EXPR, 1)
  162. #define unlikely(EXPR) __builtin_expect(EXPR, 0)
  163.  
  164. typedef int8_t s8;
  165. typedef int16_t s16;
  166. typedef int32_t s32;
  167. typedef int64_t s64;
  168.  
  169. typedef uint8_t u8;
  170. typedef uint16_t u16;
  171. typedef uint32_t u32;
  172. typedef uint64_t u64;
  173. ./gc-base-lib/1/0/inc/gc/ct.h
  174. //==============================================================================
  175. // This file is part of Gc-Base-Lib.
  176. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  177. //
  178. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  179. // the terms of the GNU General Public License as published by the Free Software
  180. // Foundation, either version 3 of the License, or (at your option) any later
  181. // version.
  182. //
  183. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  184. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  185. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  186. // details.
  187. //
  188. // You should have received a copy of the GNU General Public License along with
  189. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  190. //==============================================================================
  191. #pragma once
  192.  
  193. #include <gc/macro/ms.h>
  194.  
  195. // Configuration for composite types needs space for two offsets (u16's), to
  196. // allow for two variable types (such as "u8_a").
  197.  
  198. #define CT_M1V 1 // Member 1 pass by value.
  199. #define CT_M2V 2 // Member 2 pass by value.
  200. #define CT_M2D 4 // Member 2 pass to deinit.
  201.  
  202. #define CT_WRAP_MSI2D1(PREF) \
  203. u8 PREF##_init_ms(struct PREF##_i*, struct PREF##_c*); \
  204. void PREF##_deinit_ms(struct PREF##_i*); \
  205. u8 PREF##_init(struct PREF##_i *info, struct PREF##_c *conf) \
  206. { \
  207. u8 step = PREF##_init_ms(info, conf); \
  208. if (!step) \
  209. return 0; \
  210. PREF##_deinit_ms(info, step); \
  211. return 1; \
  212. } \
  213. void PREF##_deinit(struct PREF##_i *info) \
  214. { \
  215. PREF##_deinit_ms(info, 0); \
  216. }
  217. ./gc-base-lib/1/0/inc/gc/err.h
  218. //==============================================================================
  219. // This file is part of Gc-Base-Lib.
  220. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  221. //
  222. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  223. // the terms of the GNU General Public License as published by the Free Software
  224. // Foundation, either version 3 of the License, or (at your option) any later
  225. // version.
  226. //
  227. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  228. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  229. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  230. // details.
  231. //
  232. // You should have received a copy of the GNU General Public License along with
  233. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  234. //==============================================================================
  235. #pragma once
  236.  
  237. #include <gc/base.h>
  238.  
  239. #include <assert.h>
  240.  
  241.  
  242.  
  243. //==============================================================================
  244. // Configurable definitions
  245. //==============================================================================
  246. // These definitions should be set by "gc-proj-conf" in the future.
  247. #define ERR_ENBEG 2200 // Begin numbering of additional error types from here.
  248. #define ERR_ENMAX 3000 // Maximum sane value of "errno". Must be "<= U16_MAX".
  249.  
  250.  
  251.  
  252. //==============================================================================
  253. // Additional error types
  254. //==============================================================================
  255. #define EINVALRET (ERR_ENBEG + 0)
  256.  
  257.  
  258.  
  259. //==============================================================================
  260. // Function prototypes
  261. //==============================================================================
  262. __dllexp void err(void);
  263. __dllexp void err_en(int);
  264. __dllexp void err_msg(const char*);./gc-base-lib/1/0/inc/gc/file.h
  265. //==============================================================================
  266. // This file is part of Gc-Base-Lib.
  267. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  268. //
  269. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  270. // the terms of the GNU General Public License as published by the Free Software
  271. // Foundation, either version 3 of the License, or (at your option) any later
  272. // version.
  273. //
  274. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  275. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  276. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  277. // details.
  278. //
  279. // You should have received a copy of the GNU General Public License along with
  280. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  281. //==============================================================================
  282. #pragma once
  283.  
  284. #include <gc/u8b.h>
  285.  
  286. #include <sys/stat.h>
  287. #include <fcntl.h>
  288.  
  289. struct file_i {
  290. int fd;
  291. };
  292.  
  293. struct file_c {
  294. const char *path;
  295. int flags;
  296. mode_t mode;
  297. };
  298.  
  299. struct file_stats {
  300. struct stat data;
  301. };
  302. ./gc-base-lib/1/0/inc/gc/macro/ms.h
  303. //==============================================================================
  304. // This file is part of Gc-Base-Lib.
  305. // Copyright (C) 2015-2016 Anthony Gorecki <agorecki@gcproj.org>
  306. //
  307. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  308. // the terms of the GNU General Public License as published by the Free Software
  309. // Foundation, either version 3 of the License, or (at your option) any later
  310. // version.
  311. //
  312. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  313. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  314. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  315. // details.
  316. //
  317. // You should have received a copy of the GNU General Public License along with
  318. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  319. //==============================================================================
  320. #pragma once
  321.  
  322. #define MS_BEG(STEP)
  323. #define MS_EM
  324. #define MS_SP
  325. #define MS_EV
  326. ./gc-base-lib/1/0/inc/gc/macro/wrap_posix.h
  327. //==============================================================================
  328. // This file is part of Gc-Base-Lib.
  329. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  330. //
  331. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  332. // the terms of the GNU General Public License as published by the Free Software
  333. // Foundation, either version 3 of the License, or (at your option) any later
  334. // version.
  335. //
  336. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  337. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  338. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  339. // details.
  340. //
  341. // You should have received a copy of the GNU General Public License along with
  342. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  343. //==============================================================================
  344. #pragma once
  345.  
  346. #include <gc/err.h>
  347.  
  348.  
  349.  
  350. //==============================================================================
  351. // Templates
  352. //==============================================================================
  353. #define _WRAP_POSIX(SUCC, FAIL, FNAME, ...) \
  354. { \
  355. int _ret = FNAME(__VA_ARGS__); \
  356. if (unlikely(_ret)) { \
  357. err_en(_ret); \
  358. FAIL; \
  359. } \
  360. SUCC; \
  361. }
  362.  
  363.  
  364.  
  365. //==============================================================================
  366. // Wrappers
  367. //==============================================================================
  368. #define WRAP_POSIX(FNAME, ...) \
  369. _WRAP_POSIX(return 0, return 1, FNAME, __VA_ARGS__);
  370.  
  371. #define WRAP_POSIX_NR(FNAME, ...) \
  372. _WRAP_POSIX(,, FNAME, __VA_ARGS__);./gc-base-lib/1/0/inc/gc/macro/wrap_unix.h
  373. //==============================================================================
  374. // This file is part of Gc-Base-Lib.
  375. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  376. //
  377. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  378. // the terms of the GNU General Public License as published by the Free Software
  379. // Foundation, either version 3 of the License, or (at your option) any later
  380. // version.
  381. //
  382. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  383. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  384. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  385. // details.
  386. //
  387. // You should have received a copy of the GNU General Public License along with
  388. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  389. //==============================================================================
  390. #pragma once
  391.  
  392. #include <gc/err.h>
  393.  
  394.  
  395.  
  396. //==============================================================================
  397. // Templates
  398. //==============================================================================
  399. #define _WRAP_UNIX(SUCC, FAIL, FNAME, ...) \
  400. { \
  401. int _ret = FNAME(__VA_ARGS__); \
  402. if (unlikely(_ret)) { \
  403. if (unlikely(_ret != -1)) \
  404. errno = EINVALRET; \
  405. err(); \
  406. FAIL; \
  407. } \
  408. SUCC; \
  409. }
  410.  
  411.  
  412.  
  413. //==============================================================================
  414. // Wrappers
  415. //==============================================================================
  416. #define WRAP_UNIX(FNAME, ...) \
  417. _WRAP_UNIX(return 0, return 1, FNAME, __VA_ARGS__);
  418.  
  419. #define WRAP_UNIX_NR(FNAME, ...) \
  420. _WRAP_UNIX(,, FNAME, __VA_ARGS__);./gc-base-lib/1/0/inc/gc/mem.h
  421. //==============================================================================
  422. // This file is part of Gc-Base-Lib.
  423. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  424. //
  425. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  426. // the terms of the GNU General Public License as published by the Free Software
  427. // Foundation, either version 3 of the License, or (at your option) any later
  428. // version.
  429. //
  430. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  431. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  432. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  433. // details.
  434. //
  435. // You should have received a copy of the GNU General Public License along with
  436. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  437. //==============================================================================
  438. #pragma once
  439.  
  440. #include <gc/common.h>
  441.  
  442. void* mem_alloc(size_t);
  443. void* mem_realloc(void*, size_t);
  444. void mem_dealloc(void*);
  445.  
  446. u8 mem_comp(void*, void*, size_t);
  447. void mem_copy(void*, void*, size_t);
  448. void mem_move(void*, void*, size_t);
  449. void mem_set(void*, u8, size_t);
  450. ./gc-base-lib/1/0/inc/gc/pars.h
  451. //==============================================================================
  452. // This file is part of Gc-Base-Lib.
  453. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  454. //
  455. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  456. // the terms of the GNU General Public License as published by the Free Software
  457. // Foundation, either version 3 of the License, or (at your option) any later
  458. // version.
  459. //
  460. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  461. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  462. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  463. // details.
  464. //
  465. // You should have received a copy of the GNU General Public License along with
  466. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  467. //==============================================================================
  468. #pragma once
  469.  
  470. #include <gc/u8b.h>
  471.  
  472. struct pars_i {
  473. struct u8b_i buf;
  474. };
  475. ./gc-base-lib/1/0/inc/gc/proc.h
  476. //==============================================================================
  477. // This file is part of Gc-Base-Lib.
  478. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  479. //
  480. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  481. // the terms of the GNU General Public License as published by the Free Software
  482. // Foundation, either version 3 of the License, or (at your option) any later
  483. // version.
  484. //
  485. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  486. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  487. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  488. // details.
  489. //
  490. // You should have received a copy of the GNU General Public License along with
  491. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  492. //==============================================================================
  493. #pragma once
  494.  
  495. #include <gc/common.h>
  496.  
  497. #if defined(__use_gnu_bktrc)
  498. #include <gc/proc-gnu-bktrc.h>
  499. #endif
  500.  
  501. #if defined(__use_lunwind)
  502. #include <gc/proc-lunwind.h>
  503. #endif
  504.  
  505. // Null function pointers for systems where back traces are not supported.
  506. ./gc-base-lib/1/0/inc/gc/u8b.h
  507. //==============================================================================
  508. // This file is part of Gc-Base-Lib.
  509. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  510. //
  511. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  512. // the terms of the GNU General Public License as published by the Free Software
  513. // Foundation, either version 3 of the License, or (at your option) any later
  514. // version.
  515. //
  516. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  517. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  518. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  519. // details.
  520. //
  521. // You should have received a copy of the GNU General Public License along with
  522. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  523. //==============================================================================
  524. #pragma once
  525.  
  526. #include <gc/atmc.h>
  527.  
  528. struct u8b_i {
  529. u32 cbeg;
  530. au32 cin;
  531. au32 cout;
  532. u8 *dbeg;
  533. u8 *din;
  534. u8 *dout;
  535. };
  536. ./gc-base-lib/1/0/inc/gc/u8_ib.h
  537. //==============================================================================
  538. // This file is part of Gc-Base-Lib.
  539. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  540. //
  541. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  542. // the terms of the GNU General Public License as published by the Free Software
  543. // Foundation, either version 3 of the License, or (at your option) any later
  544. // version.
  545. //
  546. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  547. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  548. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  549. // details.
  550. //
  551. // You should have received a copy of the GNU General Public License along with
  552. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  553. //==============================================================================
  554. #pragma once
  555.  
  556. #include <gc/ct.h>
  557.  
  558. struct u8_ib_i {
  559. };
  560.  
  561. struct u8_ib_c {
  562. };
  563. ./gc-base-lib/1/0/make.sh
  564. gcc -o libgc-base -shared -I inc \
  565. -std=c11 \
  566. -Wall \
  567. -Wextra \
  568. -Wpedantic -Werror \
  569. src/ct/u8a.c \
  570. src/os/unix/*.c \
  571. src/pt/u8.c
  572. # `find src -type f -name '*.c'`
  573. ./gc-base-lib/1/0/src/ct/u8a.c
  574. //==============================================================================
  575. // This file is part of Gc-Base-Lib.
  576. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  577. //
  578. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  579. // the terms of the GNU General Public License as published by the Free Software
  580. // Foundation, either version 3 of the License, or (at your option) any later
  581. // version.
  582. //
  583. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  584. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  585. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  586. // details.
  587. //
  588. // You should have received a copy of the GNU General Public License along with
  589. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  590. //==============================================================================
  591. #include <gc/mem.h>
  592.  
  593. #include <gc/u8a.h>
  594.  
  595.  
  596.  
  597. //==============================================================================
  598. // Initialization and deinitialization
  599. //==============================================================================
  600. __dllexp u8 u8a_init(u8 **arr, u32 *size, struct u8a_c *conf)
  601. {
  602. *arr = mem_alloc(conf->size);
  603.  
  604. if (unlikely(*arr == NULL && conf->size))
  605. return 1;
  606.  
  607. *size = conf->size;
  608. return 0;
  609. }
  610.  
  611.  
  612. __dllexp void u8a_deinit(u8 **arr)
  613. {
  614. mem_dealloc(*arr);
  615. }
  616.  
  617.  
  618.  
  619. //==============================================================================
  620. // Ranges
  621. //==============================================================================
  622. __dllexp u32 u8a_rm(u8 *arr, u32 size, u8 lower, u8 upper)
  623. {
  624. while (size && *arr >= lower && *arr <= upper) {
  625. ++arr;
  626. --size;
  627. }
  628.  
  629. return size;
  630. }
  631.  
  632.  
  633. __dllexp u32 u8a_rma(u8 *arr, u32 size, u8 *arng, u8 crng)
  634. {
  635. while (size && !u8_rma(*arr, arng, crng)) {
  636. ++arr;
  637. --size;
  638. }
  639.  
  640. return size;
  641. }
  642.  
  643.  
  644.  
  645. //==============================================================================
  646. // Values
  647. //==============================================================================
  648. __dllexp u32 u8a_vm(u8 *arr, u32 size, u8 val)
  649. {
  650. while (size && *arr == val) {
  651. ++arr;
  652. --size;
  653. }
  654.  
  655. return size;
  656. }
  657.  
  658.  
  659. __dllexp u32 u8a_vm2(u8 *arr, u32 size, u8 val1, u8 val2) // For new lines.
  660. {
  661. while (size >= 2 && *arr == val1 && *(arr+1) == val2) {
  662. arr += 2;
  663. size -= 2;
  664. }
  665.  
  666. return size;
  667. }
  668.  
  669.  
  670. __dllexp u32 u8a_vma(u8 *arr, u32 size, u8 *aval, u8 cval)
  671. {
  672. while (size && !u8_vma(*arr, aval, cval)) {
  673. ++arr;
  674. --size;
  675. }
  676.  
  677. return size;
  678. }
  679.  
  680.  
  681.  
  682. //==============================================================================
  683. // Special characters
  684. //==============================================================================
  685. __dllexp u32 u8a_sm(u8 *arr, u32 size, u8 spec, u8 esc)
  686. {
  687. return size;
  688. }
  689.  
  690.  
  691. __dllexp u32 u8a_sma(u8 *arr, u32 size, u8 *aspec, u8 cspec, u8 esc)
  692. {
  693. // Match array of nonescaped special characters; escape character can also
  694. // be escaped (use bool "escaped" var)
  695. //
  696. // use separate function to match escape char?
  697.  
  698. return size;
  699. }
  700.  
  701.  
  702.  
  703. //==============================================================================
  704. // New line characters
  705. //==============================================================================
  706. __dllexp u8 u8a_nld(u8 *arr, u32 size, u8 types)
  707. {
  708. assert((types & NL_RN) || (types & NL_N) || (types & NL_R));
  709.  
  710. if (size >= 2 && (types & NL_RN) && *arr == '\r' && *(arr+1) == '\n')
  711. return NL_RN;
  712.  
  713. if (size) {
  714. if ((types & NL_N) && *arr == '\n')
  715. return NL_N;
  716.  
  717. if ((types & NL_R) && *arr == '\r')
  718. return NL_R;
  719. }
  720.  
  721. return 0;
  722. }
  723.  
  724.  
  725. __dllexp u32 u8a_nlm(u8 *arr, u32 size, u8 types)
  726. {
  727. assert((types & NL_RN) || (types & NL_N) || (types & NL_R));
  728.  
  729. if ((types & NL_RN))
  730. return u8a_vm2(arr, size, '\r', '\n');
  731.  
  732. if ((types & NL_N))
  733. return u8a_vm(arr, size, '\n');
  734.  
  735. return u8a_vm(arr, size, '\r');
  736. }
  737.  
  738.  
  739. __dllexp u32 u8a_nlmm(u8 *arr, u32 size, u8 types)
  740. {
  741. u32 rem;
  742.  
  743. for (;;) {
  744. rem = u8a_nlm(arr, size, types);
  745.  
  746. if (rem >= size)
  747. break;
  748.  
  749. arr += size - rem;
  750. size = rem;
  751. }
  752.  
  753. return size;
  754. }
  755. ./gc-base-lib/1/0/src/ct/u8b.c
  756. //==============================================================================
  757. // This file is part of Gc-Base-Lib.
  758. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  759. //
  760. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  761. // the terms of the GNU General Public License as published by the Free Software
  762. // Foundation, either version 3 of the License, or (at your option) any later
  763. // version.
  764. //
  765. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  766. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  767. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  768. // details.
  769. //
  770. // You should have received a copy of the GNU General Public License along with
  771. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  772. //==============================================================================
  773. #include <gc/mem.h>
  774.  
  775. #include <gc/u8b.h>./gc-base-lib/1/0/src/ct/u8bc.c
  776. //==============================================================================
  777. // This file is part of Gc-Base-Lib.
  778. // Simple circular buffer, supporting nonsimultaneous input and output.
  779. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  780. //
  781. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  782. // the terms of the GNU General Public License as published by the Free Software
  783. // Foundation, either version 3 of the License, or (at your option) any later
  784. // version.
  785. //
  786. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  787. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  788. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  789. // details.
  790. //
  791. // You should have received a copy of the GNU General Public License along with
  792. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  793. //==============================================================================
  794. #include <gc/mem.h>
  795.  
  796. #include <gc/u8bc.h>
  797.  
  798.  
  799.  
  800. //==============================================================================
  801. // Initialization and deinitialization
  802. //==============================================================================
  803. u8 u8bc_init(struct u8bc_i *buf, struct u8bc_c *conf)
  804. {
  805. // Minimum size for this buffer implementation is two bytes. Check for this
  806. // in conf validation.
  807.  
  808. buf->dbeg = mem_alloc(conf->size);
  809.  
  810. if (unlikely(buf->dbeg == NULL))
  811. return 1;
  812.  
  813. buf->cbeg = size;
  814. return 0;
  815. }
  816.  
  817.  
  818. void u8bc_deinit(struct u8bc_i *buf)
  819. {
  820. mem_dealloc(buf->dbeg);
  821. }
  822.  
  823.  
  824.  
  825. //==============================================================================
  826. // Advance
  827. //==============================================================================
  828. void u8bc_ia(struct u8bc_i *buf, u32 size)
  829. {
  830. u32 off = buf->din - buf->dbeg + size;
  831.  
  832. if (off < buf->cbeg - 1)
  833. buf->din += size;
  834.  
  835. else // Wrap around.
  836. buf->din = buf->dbeg + off - buf->cbeg;
  837.  
  838. atmc_fsub(&buf->cin, size);
  839. atmc_fadd(&buf->cout, size);
  840. }
  841.  
  842.  
  843. void u8bc_oa(struct u8bc_i *buf, u32 size)
  844. {
  845. u32 off = buf->dout - buf->dbeg + size;
  846.  
  847. if (off < buf->cbeg - 1)
  848. buf->dout += size;
  849.  
  850. else // Wrap around.
  851. buf->dout = buf->dbeg + off - buf->cbeg;
  852.  
  853. atmc_fsub(&buf->cout, size);
  854. atmc_fadd(&buf->cin, size);
  855. }
  856.  
  857.  
  858.  
  859. //==============================================================================
  860. // Count
  861. //==============================================================================
  862. u32 u8bc_igc(struct u8bc_i *buf)
  863. {
  864. return atmc_load(&buf->cin);
  865. }
  866.  
  867.  
  868. u32 u8bc_ogc(struct u8bc_i *buf)
  869. {
  870. return atmc_load(&buf->cout);
  871. }
  872.  
  873.  
  874.  
  875. //==============================================================================
  876. // Contiguous count and pointer
  877. //==============================================================================
  878. u32 u8bc_igcc(struct u8bc_i *buf)
  879. {
  880. u32 off_in = buf->din - buf->dbeg;
  881. u32 orig_cin = atmc_load(&buf->cin);
  882.  
  883. if (off_in + orig_cin < buf->cbeg - 1)
  884. return orig_cout;
  885.  
  886. return buf->cbeg - off_in;
  887. }
  888.  
  889.  
  890. u8 *u8bc_igcp(struct u8bc_i *buf)
  891. {
  892. return buf->din;
  893. }
  894.  
  895.  
  896. u32 u8bc_ogcc(struct u8bc_i *buf)
  897. {
  898. u32 off_out = buf->dout - buf->dbeg;
  899. u32 orig_cout = atmc_load(&buf->cout);
  900.  
  901. if (off_out + orig_cout < buf->cbeg - 1)
  902. return orig_cout;
  903.  
  904. return buf->cbeg - off_out;
  905. }
  906.  
  907.  
  908. u8 *u8bc_ogcp(struct u8bc_i *buf)
  909. {
  910. return buf->dout;
  911. }
  912.  
  913.  
  914.  
  915. //==============================================================================
  916. // Peeking
  917. //==============================================================================
  918. u8 u8bc_op1(struct u8bc_i *buf)
  919. {
  920. return buf->dout[0];
  921. }
  922.  
  923.  
  924. u16 u8bc_op2(struct u8bc_i *buf)
  925. {
  926. u8 data[2];
  927.  
  928. data[0] = buf->dout[0];
  929.  
  930. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  931. data[1] = buf->dout[1];
  932.  
  933. else
  934. data[1] = buf->dbeg[0];
  935.  
  936. return (u16)data;
  937. }
  938.  
  939.  
  940.  
  941. //==============================================================================
  942. // Input and output
  943. //==============================================================================
  944. u8 u8bc_if(struct u8bc_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  945. void *arg)
  946. {
  947. u32 ret;
  948.  
  949. if (unlikely(fin(arg, buf->din, u8bc_igcc(buf), &ret)))
  950. return 1;
  951.  
  952. u8bc_ia(buf, ret);
  953. return 0;
  954. }
  955.  
  956.  
  957. u8 u8bc_of(struct u8bc_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  958. void *arg)
  959. {
  960. u32 ret;
  961.  
  962. if (unlikely(fout(arg, buf->dout, u8bc_ogcc(buf), &ret)))
  963. return 1;
  964.  
  965. u8bc_oa(buf, ret);
  966. return 0;
  967. }
  968. ./gc-base-lib/1/0/src/ct/u8bcss.c
  969. //==============================================================================
  970. // This file is part of Gc-Base-Lib.
  971. // Lockless circular buffer, supporting a single producer and single consumer.
  972. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  973. //
  974. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  975. // the terms of the GNU General Public License as published by the Free Software
  976. // Foundation, either version 3 of the License, or (at your option) any later
  977. // version.
  978. //
  979. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  980. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  981. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  982. // details.
  983. //
  984. // You should have received a copy of the GNU General Public License along with
  985. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  986. //==============================================================================
  987. #include <gc/mem.h>
  988.  
  989. #include <gc/u8bcss.h>
  990.  
  991. // Two variable "u8_a" type, member 1 is "dbeg", member 2 is "cbeg".
  992. //
  993. // Minimum size for this buffer implementation is two bytes. Check for this in
  994. // conf validation.
  995. //
  996. // Implementation should work out figures using the nonatomic 'scout' member.
  997. // Contig is inteded for buffer output, where parsers might need a certain
  998. // number of contiguous bytes to function properly. Support is also provided for
  999. // contiguous bytes for buffer input, should it be useful. These numbers are
  1000. // designed to represent the /minimum/ that the application can handle.
  1001. //
  1002. // This buffer is not designed to handle circumstances in which the read or
  1003. // write address needs to be aligned to some specific value, or when the reads
  1004. // and writes need to be of a particular size. In other words, it is not
  1005. // designed for linux kernel aio or any other kind of disk aio.
  1006. //
  1007. // This buffer is a candidate for sync and async network io, and sync disk io,
  1008. // as well as unix pipes.
  1009. //
  1010. // Buffer conversion will be available: u8bcss -> u8_b for pars_ -> publish
  1011. // changes back to original u8bcss once finished. This will work for more
  1012. // advanced to less advanced buffers, and the other way around. Will have a
  1013. // similar style to the (file) input and output functions at the end of this
  1014. // file. This might only be for contiguous io segments. The buffer conversion
  1015. // function is not responsible for doing any initialization or deinitialization
  1016. // of the target buffer.
  1017.  
  1018.  
  1019.  
  1020. //==============================================================================
  1021. // Initialization
  1022. //==============================================================================
  1023. __dllexp u8 u8bcss_init(struct u8bcss_i *buf, struct u8bcss_c *conf)
  1024. {
  1025. // Atomic members need to be initialized before being used. Do that here.
  1026.  
  1027. buf->scin = conf->scin; // U16
  1028. buf->scout = conf->scout;
  1029. buf->cin = buf->cbeg - conf->scntg;
  1030. buf->cout = 0;
  1031. buf->din = buf->dbeg + conf->scntg;
  1032. buf->dout = buf->dbeg + conf->scntg;
  1033. return 0;
  1034. }
  1035.  
  1036.  
  1037.  
  1038. //==============================================================================
  1039. // Advance
  1040. //==============================================================================
  1041. __dllexp void u8bcss_ia(struct u8bcss_i *buf, u32 size)
  1042. {
  1043. u32 off = buf->din - buf->dbeg + size;
  1044.  
  1045. if (off < buf->cbeg - 1)
  1046. buf->din += size;
  1047.  
  1048. else // Wrap around.
  1049. buf->din = buf->dbeg + off - buf->cbeg;
  1050.  
  1051. atmc_fsub(&buf->cin, size);
  1052. atmc_fadd(&buf->cout, size);
  1053. }
  1054.  
  1055.  
  1056. __dllexp void u8bcss_oa(struct u8bcss_i *buf, u32 size)
  1057. {
  1058. u32 off = buf->dout - buf->dbeg + size;
  1059.  
  1060. if (off < buf->cbeg - 1)
  1061. buf->dout += size;
  1062.  
  1063. else // Wrap around.
  1064. buf->dout = buf->dbeg + off - buf->cbeg;
  1065.  
  1066. atmc_fsub(&buf->cout, size);
  1067. atmc_fadd(&buf->cin, size);
  1068. }
  1069.  
  1070.  
  1071.  
  1072. //==============================================================================
  1073. // Count
  1074. //==============================================================================
  1075. __dllexp u32 u8bcss_igc(struct u8bcss_i *buf)
  1076. {
  1077. return atmc_load(&buf->cin);
  1078. }
  1079.  
  1080.  
  1081. __dllexp u32 u8bcss_ogc(struct u8bcss_i *buf)
  1082. {
  1083. return atmc_load(&buf->cout);
  1084. }
  1085.  
  1086.  
  1087.  
  1088. //==============================================================================
  1089. // Contiguous count and pointer
  1090. //==============================================================================
  1091. __dllexp u32 u8bcss_igcc(struct u8bcss_i *buf)
  1092. {
  1093. u32 off_in = buf->din - buf->dbeg;
  1094. u32 orig_cin = atmc_load(&buf->cin);
  1095.  
  1096. if (off_in + orig_cin < buf->cbeg - 1)
  1097. return orig_cout;
  1098.  
  1099. return buf->cbeg - off_in;
  1100. }
  1101.  
  1102.  
  1103. __dllexp u8 *u8bcss_igcp(struct u8bcss_i *buf)
  1104. {
  1105. return buf->din;
  1106. }
  1107.  
  1108.  
  1109. __dllexp u32 u8bcss_ogcc(struct u8bcss_i *buf)
  1110. {
  1111. u32 off_out = buf->dout - buf->dbeg;
  1112. u32 orig_cout = atmc_load(&buf->cout);
  1113.  
  1114. if (off_out + orig_cout < buf->cbeg - 1)
  1115. return orig_cout;
  1116.  
  1117. return buf->cbeg - off_out;
  1118. }
  1119.  
  1120.  
  1121. __dllexp u8 *u8bcss_ogcp(struct u8bcss_i *buf)
  1122. {
  1123. return buf->dout;
  1124. }
  1125.  
  1126.  
  1127.  
  1128. //==============================================================================
  1129. // Peeking
  1130. //==============================================================================
  1131. __dllexp u8 u8bcss_op1(struct u8bcss_i *buf)
  1132. {
  1133. return buf->dout[0];
  1134. }
  1135.  
  1136.  
  1137. __dllexp u16 u8bcss_op2(struct u8bcss_i *buf)
  1138. {
  1139. u8 data[2];
  1140.  
  1141. data[0] = buf->dout[0];
  1142.  
  1143. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  1144. data[1] = buf->dout[1];
  1145.  
  1146. else
  1147. data[1] = buf->dbeg[0];
  1148.  
  1149. return (u16)data;
  1150. }
  1151.  
  1152.  
  1153.  
  1154. //==============================================================================
  1155. // Input and output
  1156. //==============================================================================
  1157. __dllexp u8 u8bcss_if(struct u8bcss_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  1158. void *arg)
  1159. {
  1160. u32 ret;
  1161.  
  1162. if (unlikely(fin(arg, buf->din, u8bcss_igcc(buf), &ret)))
  1163. return 1;
  1164.  
  1165. u8bcss_ia(buf, ret);
  1166. return 0;
  1167. }
  1168.  
  1169.  
  1170. __dllexp u8 u8bcss_of(struct u8bcss_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  1171. void *arg)
  1172. {
  1173. u32 ret;
  1174.  
  1175. if (unlikely(fout(arg, buf->dout, u8bcss_ogcc(buf), &ret)))
  1176. return 1;
  1177.  
  1178. u8bcss_oa(buf, ret);
  1179. return 0;
  1180. }
  1181. ./gc-base-lib/1/0/src/ct/u8ib.c
  1182. //==============================================================================
  1183. // This file is part of Gc-Base-Lib.
  1184. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1185. //
  1186. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1187. // the terms of the GNU General Public License as published by the Free Software
  1188. // Foundation, either version 3 of the License, or (at your option) any later
  1189. // version.
  1190. //
  1191. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1192. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1193. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1194. // details.
  1195. //
  1196. // You should have received a copy of the GNU General Public License along with
  1197. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1198. //==============================================================================
  1199. #include <gc/mem.h>
  1200.  
  1201. #include <gc/u8ib.h>
  1202.  
  1203.  
  1204.  
  1205. //==============================================================================
  1206. // Initialization and deinitialization
  1207. //==============================================================================
  1208. CT_WRAP_MSI2D1(__dllexp, u8ib);
  1209.  
  1210.  
  1211. u8 u8ib_init_ms(struct u8ib_i *ibuf, struct u8ib_c *conf)
  1212. {
  1213. MS_BEG(0);
  1214.  
  1215. MS_SP {
  1216. ibuf->buf = mem_alloc(conf->sbuf);
  1217. MS_EV(ibuf->buf != NULL || !conf->sbuf);
  1218. }
  1219.  
  1220. MS_SP { MS_EV(!conf->f->init(ibuf->buf, conf->buf)); }
  1221. MS_SP { ibuf->f = conf->f; }
  1222. return 0;
  1223. }
  1224.  
  1225.  
  1226. void u8ib_deinit_ms(struct u8ib_i *ibuf, u8 step)
  1227. {
  1228. MS_BEG(step);
  1229. MS_EM;
  1230. MS_SP { ibuf->f->deinit(ibuf->buf); }
  1231. MS_SP { mem_dealloc(ibuf->buf); }
  1232. }
  1233.  
  1234.  
  1235.  
  1236. //==============================================================================
  1237. // Advance
  1238. //==============================================================================
  1239. __dllexp void u8ib_ia(struct u8ib_i *ibuf, u32 size)
  1240. {
  1241. ibuf->f->ia(ibuf->buf, size);
  1242. }
  1243.  
  1244.  
  1245. __dllexp void u8ib_oa(struct u8ib_i *ibuf, u32 size)
  1246. {
  1247. ibuf->f->oa(ibuf->buf, size);
  1248. }
  1249.  
  1250.  
  1251.  
  1252. //==============================================================================
  1253. // Count
  1254. //==============================================================================
  1255. __dllexp u32 u8ib_igc(struct u8ib_i *ibuf)
  1256. {
  1257. return ibuf->f->igc(ibuf->buf);
  1258. }
  1259.  
  1260.  
  1261. __dllexp u32 u8ib_ogc(struct u8ib_i *ibuf)
  1262. {
  1263. return ibuf->f->ogc(ibuf->buf);
  1264. }
  1265.  
  1266.  
  1267.  
  1268. //==============================================================================
  1269. // Contiguous count and pointer
  1270. //==============================================================================
  1271. __dllexp u32 u8ib_igcc(struct u8ib_i *ibuf)
  1272. {
  1273. return ibuf->f->igcc(ibuf->buf);
  1274. }
  1275.  
  1276.  
  1277. __dllexp u8 *u8ib_igcp(struct u8ib_i *ibuf)
  1278. {
  1279. return ibuf->f->igcp(ibuf->buf);
  1280. }
  1281.  
  1282.  
  1283. __dllexp u32 u8ib_ogcc(struct u8ib_i *ibuf)
  1284. {
  1285. return ibuf->f->ogcc(ibuf->buf);
  1286. }
  1287.  
  1288.  
  1289. __dllexp u8 *u8ib_ogcp(struct u8ib_i *ibuf)
  1290. {
  1291. return ibuf->f->ogcp(ibuf->buf);
  1292. }
  1293.  
  1294.  
  1295.  
  1296. //==============================================================================
  1297. // Peeking
  1298. //==============================================================================
  1299. __dllexp u8 u8ib_op1(struct u8ib_i *ibuf)
  1300. {
  1301. return ibuf->f->op1(ibuf->buf);
  1302. }
  1303.  
  1304.  
  1305. __dllexp u16 u8ib_op2(struct u8ib_i *ibuf)
  1306. {
  1307. return ibuf->f->op2(ibuf->buf);
  1308. }
  1309.  
  1310.  
  1311.  
  1312. //==============================================================================
  1313. // Input and output
  1314. //==============================================================================
  1315. __dllexp u8 u8ib_if(struct u8ib_i *ibuf, u8 (*fin)(void*, u8*, u32, u32*),
  1316. void *arg)
  1317. {
  1318. return ibuf->if(ibuf->buf, fin, arg);
  1319. }
  1320.  
  1321.  
  1322. __dllexp u8 u8ib_of(struct u8ib_i *ibuf, u8 (*fout)(void*, u8*, u32, u32*),
  1323. void *arg)
  1324. {
  1325. return ibuf->of(ibuf->buf, fout, arg);
  1326. }
  1327. ./gc-base-lib/1/0/src/os/unix/err.c
  1328. //==============================================================================
  1329. // This file is part of Gc-Base-Lib.
  1330. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1331. //
  1332. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1333. // the terms of the GNU General Public License as published by the Free Software
  1334. // Foundation, either version 3 of the License, or (at your option) any later
  1335. // version.
  1336. //
  1337. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1338. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1339. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1340. // details.
  1341. //
  1342. // You should have received a copy of the GNU General Public License along with
  1343. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1344. //==============================================================================
  1345. #include <gc/err.h>
  1346.  
  1347. #include <stdio.h>
  1348. #include <string.h>
  1349.  
  1350.  
  1351.  
  1352. //==============================================================================
  1353. // Error handling
  1354. //==============================================================================
  1355. __dllexp void err(void)
  1356. {
  1357. err_en(errno);
  1358. }
  1359.  
  1360.  
  1361. __dllexp void err_en(int en)
  1362. {
  1363. char *msg;
  1364. char buf[256];
  1365.  
  1366. msg = strerror_r(en, buf, 256);
  1367. assert(msg != NULL);
  1368.  
  1369. if (msg != NULL) // Sanity checking.
  1370. err_msg(msg);
  1371. }
  1372.  
  1373.  
  1374. __dllexp void err_msg(const char *msg)
  1375. {
  1376. fprintf(stderr, "%s" ENDL);
  1377. }./gc-base-lib/1/0/src/os/unix/file.c
  1378. //==============================================================================
  1379. // This file is part of Gc-Base-Lib.
  1380. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1381. //
  1382. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1383. // the terms of the GNU General Public License as published by the Free Software
  1384. // Foundation, either version 3 of the License, or (at your option) any later
  1385. // version.
  1386. //
  1387. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1388. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1389. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1390. // details.
  1391. //
  1392. // You should have received a copy of the GNU General Public License along with
  1393. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1394. //==============================================================================
  1395. #include <gc/file.h>
  1396.  
  1397. #include <unistd.h>
  1398.  
  1399.  
  1400.  
  1401. //==============================================================================
  1402. // Initialization and deinitialization
  1403. //==============================================================================
  1404. __dllexp u8 file_init(struct file_i *file, struct file_c *conf)
  1405. {
  1406. if (!(conf->flags & FILE_CREAT))
  1407. file->fd = open(conf->path, conf->flags);
  1408.  
  1409. else
  1410. file->fd = open(conf->path, conf->flags, conf->mode);
  1411.  
  1412. if (unlikely(file->fd == -1))
  1413. return 1;
  1414.  
  1415. return 0;
  1416. }
  1417.  
  1418.  
  1419. __dllexp void file_deinit(struct file_i *file)
  1420. {
  1421. close(file->fd);
  1422. }
  1423.  
  1424.  
  1425.  
  1426. //==============================================================================
  1427. // Read and write
  1428. //==============================================================================
  1429. __dllexp u8 file_read(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  1430. {
  1431. ssize_t bytes = read(file->fd, buf, size);
  1432.  
  1433. if (unlikely(bytes == -1))
  1434. return 1;
  1435.  
  1436. *ret = bytes;
  1437. return 0;
  1438. }
  1439.  
  1440.  
  1441. __dllexp u8 file_write(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  1442. {
  1443. ssize_t bytes = write(file->fd, buf, size);
  1444.  
  1445. if (unlikely(bytes == -1))
  1446. return 1;
  1447.  
  1448. *ret = bytes;
  1449. return 0;
  1450. }
  1451.  
  1452.  
  1453.  
  1454. //==============================================================================
  1455. // Utility
  1456. //==============================================================================
  1457. __dllexp u8 file_gstats(struct file_i *file, struct file_stats *stats)
  1458. {
  1459. if (unlikely(fstat(file->fd, &stats->data)))
  1460. return 1;
  1461.  
  1462. return 0;
  1463. }
  1464. ./gc-base-lib/1/0/src/os/unix/mem.c
  1465. //==============================================================================
  1466. // This file is part of Gc-Base-Lib.
  1467. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1468. //
  1469. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1470. // the terms of the GNU General Public License as published by the Free Software
  1471. // Foundation, either version 3 of the License, or (at your option) any later
  1472. // version.
  1473. //
  1474. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1475. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1476. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1477. // details.
  1478. //
  1479. // You should have received a copy of the GNU General Public License along with
  1480. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1481. //==============================================================================
  1482. #include <gc/mem.h>
  1483.  
  1484. #include <stdlib.h>
  1485. #include <string.h>
  1486.  
  1487.  
  1488.  
  1489. //==============================================================================
  1490. // Allocation, reallocation and deallocation
  1491. //==============================================================================
  1492. __dllexp void *mem_alloc(size_t size)
  1493. {
  1494. return malloc(size);
  1495. }
  1496.  
  1497.  
  1498. __dllexp void *mem_realloc(void *ptr, size_t size)
  1499. {
  1500. return realloc(ptr, size);
  1501. }
  1502.  
  1503.  
  1504. __dllexp void mem_dealloc(void *ptr)
  1505. {
  1506. free(ptr);
  1507. }
  1508.  
  1509.  
  1510.  
  1511. //==============================================================================
  1512. // Utility
  1513. //==============================================================================
  1514. __dllexp s8 mem_comp(void *data1, void *data2, size_t size)
  1515. {
  1516. return memcmp(data1, data2, size);
  1517. }
  1518.  
  1519.  
  1520. __dllexp void mem_copy(void *dest, void *src, size_t size)
  1521. {
  1522. memcpy(dest, src, size);
  1523. }
  1524.  
  1525.  
  1526. __dllexp void mem_move(void *dest, void *src, size_t size)
  1527. {
  1528. memmove(dest, src, size);
  1529. }
  1530.  
  1531.  
  1532. __dllexp void mem_set(void *ptr, u8 data, size_t size)
  1533. {
  1534. memset(ptr, data, size);
  1535. }
  1536. ./gc-base-lib/1/0/src/os/unix/proc.c
  1537. //==============================================================================
  1538. // This file is part of Gc-Base-Lib.
  1539. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1540. //
  1541. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1542. // the terms of the GNU General Public License as published by the Free Software
  1543. // Foundation, either version 3 of the License, or (at your option) any later
  1544. // version.
  1545. //
  1546. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1547. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1548. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1549. // details.
  1550. //
  1551. // You should have received a copy of the GNU General Public License along with
  1552. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1553. //==============================================================================
  1554. // proc_st_init, proc_st_next, ...
  1555. #include <gc/proc.h>
  1556.  
  1557.  
  1558.  
  1559. //==============================================================================
  1560. // Execution
  1561. //==============================================================================
  1562. __dllexp u8 proc_exec(void)
  1563. {
  1564. }
  1565. ./gc-base-lib/1/0/src/pt/u8.c
  1566. //==============================================================================
  1567. // This file is part of Gc-Base-Lib.
  1568. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1569. //
  1570. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1571. // the terms of the GNU General Public License as published by the Free Software
  1572. // Foundation, either version 3 of the License, or (at your option) any later
  1573. // version.
  1574. //
  1575. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1576. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1577. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1578. // details.
  1579. //
  1580. // You should have received a copy of the GNU General Public License along with
  1581. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1582. //==============================================================================
  1583. #include <gc/u8.h>
  1584.  
  1585.  
  1586.  
  1587. //==============================================================================
  1588. // Ranges and values
  1589. //==============================================================================
  1590. __dllexp u8 u8_rma(u8 data, u8 *arng, u8 crng)
  1591. {
  1592. while (crng) {
  1593. if (data >= *arng && data <= *(++arng))
  1594. return 0;
  1595.  
  1596. ++arng;
  1597. --crng;
  1598. }
  1599.  
  1600. return 1;
  1601. }
  1602.  
  1603.  
  1604. __dllexp u8_vma(u8 data, u8 *aval, u8 cval)
  1605. {
  1606. while (cval) {
  1607. if (data == *aval)
  1608. return 0;
  1609.  
  1610. ++aval;
  1611. --cval;
  1612. }
  1613.  
  1614. return 1;
  1615. }
  1616. ./gc-base-lib/1/0/src/util/pars.c
  1617. //==============================================================================
  1618. // This file is part of Gc-Base-Lib.
  1619. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1620. //
  1621. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1622. // the terms of the GNU General Public License as published by the Free Software
  1623. // Foundation, either version 3 of the License, or (at your option) any later
  1624. // version.
  1625. //
  1626. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1627. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1628. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1629. // details.
  1630. //
  1631. // You should have received a copy of the GNU General Public License along with
  1632. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1633. //==============================================================================
  1634. #include <gc/pars.h>
  1635.  
  1636. // If it is possible to convert between buffer types, this should probably be
  1637. // moved to u8_a. u8_a_nlcs et al.
  1638. //
  1639. // This parser requires exclusive access the the buffer region provided by buf.
  1640. // For multiple reader buffers, it's expected that a block of data will be read,
  1641. // converted to a u8_b for the parser, and treated as a contiguous array.
  1642.  
  1643. ./gc-base-lib/1/0/test/conf/strerror_r-1.c
  1644. //==============================================================================
  1645. // This file is part of Gc-Base-Lib.
  1646. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1647. //
  1648. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1649. // the terms of the GNU General Public License as published by the Free Software
  1650. // Foundation, either version 3 of the License, or (at your option) any later
  1651. // version.
  1652. //
  1653. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1654. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1655. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1656. // details.
  1657. //
  1658. // You should have received a copy of the GNU General Public License along with
  1659. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1660. //==============================================================================
  1661. #include <gc/err.h>
  1662.  
  1663. #include <string.h>
  1664.  
  1665.  
  1666.  
  1667. //==============================================================================
  1668. // Handle invalid "errno"
  1669. //==============================================================================
  1670. // Ideally, this kind of test would be loaded by "dlopen()", used and then
  1671. // unloaded.
  1672. int main(void)
  1673. {
  1674. int aen[] = {INT_MIN, -ERR_ENMAX, -1, ERR_ENMAX, INT_MAX};
  1675. char *msg;
  1676. char buf[256];
  1677.  
  1678. for (i = 0; i < 5; ++i) {
  1679. // The manual page for "strerror()" states that the function can return
  1680. // "NULL" on some systems if it encounters an unknown error number.
  1681. //
  1682. // This test verifies that "strerror_r()" does not return "NULL" if it
  1683. // encounters an unknown error number. It does not, however, confirm
  1684. // that the system actually has an implementation of "strerror()" that
  1685. // is problematic. In the future, dependency tracking for tests should
  1686. // be added to ensure that the number of unnecessary tests being run is
  1687. // kept to a minimum.
  1688. msg = strerror_r(aen[i], buf, 256);
  1689.  
  1690. if (msg != NULL)
  1691. continue;
  1692.  
  1693. fprintf(stderr,
  1694. "Test failed: \"strerror_r()\" - Handle invalid \"errno\"." ENDL);
  1695. return 1;
  1696. }
  1697.  
  1698. return 0;
  1699. }./gc-base-lib/2/0/inc/gc/aiobk.h
  1700. 3//==============================================================================
  1701. // This file is part of Gc-Base-Lib.
  1702. // Kernel asynchronous, unbuffered I/O for block devices and files
  1703. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1704. //
  1705. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1706. // the terms of the GNU General Public License as published by the Free Software
  1707. // Foundation, either version 3 of the License, or (at your option) any later
  1708. // version.
  1709. //
  1710. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1711. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1712. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1713. // details.
  1714. //
  1715. // You should have received a copy of the GNU General Public License along with
  1716. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1717. //==============================================================================
  1718. #pragma once
  1719.  
  1720. #include <gc/base.h>
  1721.  
  1722. #include <linux/aio_abi.h>
  1723.  
  1724.  
  1725.  
  1726. //==============================================================================
  1727. // General
  1728. //==============================================================================
  1729. struct aiobk_i {
  1730. aio_context_t ctx;
  1731. };
  1732.  
  1733. struct aiobk_c {
  1734. u16 cev;
  1735. };./gc-base-lib/2/0/src/ct/it.c
  1736. ./gc-base-lib/2/0/src/ct/tavl.c
  1737. ./gc-base-lib/2/0/src/ct/trbll.c
  1738. ./gc-base-lib/2/0/src/os/linux/aio.txt
  1739. kernel aio linux 512, 2048 or other sector size, as determined by the underlying
  1740. block device. can get this value via ioctl.
  1741.  
  1742. also can do simple kernel aio implementation better than libaio. use this instead.
  1743. see firefox bookmark "own aio impl" x2
  1744.  
  1745. aio works for block size increments. reads / writes other than that size to the
  1746. beginning or end of the file will be blocking. see firefox bookmark "blocking aio".
  1747. this has not been verified.
  1748. ./gc-base-lib/2/0/src/os/linux/aiobk.c
  1749. //==============================================================================
  1750. // This file is part of Gc-Base-Lib.
  1751. // Kernel asynchronous, unbuffered I/O for block devices and files
  1752. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1753. //
  1754. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1755. // the terms of the GNU General Public License as published by the Free Software
  1756. // Foundation, either version 3 of the License, or (at your option) any later
  1757. // version.
  1758. //
  1759. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1760. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1761. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1762. // details.
  1763. //
  1764. // You should have received a copy of the GNU General Public License along with
  1765. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1766. //==============================================================================
  1767. #include <gc/macro/wrap_unix.h>
  1768.  
  1769. #include <gc/aiobk.h>
  1770.  
  1771. #include <sys/syscall.h>
  1772.  
  1773.  
  1774.  
  1775. //==============================================================================
  1776. // Initialization and deinitialization
  1777. //==============================================================================
  1778. __dllexp u8 aiobk_init(struct aiobk_i *aiobk, struct aiobk_c *conf)
  1779. {
  1780. aiobk->ctx = 0; // Required by the kernel.
  1781. WRAP_UNIX(io_setup(conf->cev, &aiobk->ctx));
  1782. }
  1783.  
  1784.  
  1785. __dllexp void aiobk_deinit(struct aiobk_i *aiobk)
  1786. WRAP_UNIX_NR(io_destroy(aiobk->ctx));./gc-base-lib/2/0/src/os/linux/this_dir.txt
  1787. linux specific things like signalfd, timerfd, kernel aio go in this directory
  1788. ./gc-base-lib/2/0/src/os/unix/cnd.c
  1789. ./gc-base-lib/2/0/src/os/unix/cnd_attr.c
  1790. ./gc-base-lib/2/0/src/os/unix/mtx.c
  1791. ./gc-base-lib/2/0/src/os/unix/mtx_attr.c
  1792. ./gc-base-lib/2/0/src/os/unix/pcnd.c
  1793. ./gc-base-lib/2/0/src/os/unix/pmtx.c
  1794. ./gc-base-lib/2/0/src/os/unix/thrd.c
  1795. ./gc-base-lib/2/0/src/svc/atq.c
  1796. ./gc-base-lib/2/0/src/svc/tpool_a.c
  1797. ./gc-base-lib/backup_location.txt
  1798. ./_script/intrn/upload-pastebin.py
  1799. import pastebin_python
  1800. import sys
  1801.  
  1802. pb = pastebin_python.pastebin.PastebinPython(api_dev_key=sys.argv[1])
  1803. print pb.createPasteFromFile('upload-data.txt', 'anthony gorecki anthony@anthonygorecki.ca', '', '0', 'N')
  1804. ./_script/upload-pastebin.sh
  1805. cd /home/agorecki/dev
  1806.  
  1807. echo 'Files:'
  1808.  
  1809. files=$(find -name '*.c' -o -name '*.h' -o -name '*.py' -o -name '*.sh' -o -name '*.txt' -o -name '.vimrc')
  1810.  
  1811. date > upload-data.txt
  1812.  
  1813. for file in $files; do
  1814. echo " $file"
  1815. echo $file >> upload-data.txt
  1816. cat $file >> upload-data.txt
  1817. done
  1818.  
  1819. echo
  1820. echo -n 'URL: '
  1821. url=$(python2 ./_script/intrn/upload-pastebin.py `cat _script/intrn/dev-key`)
  1822. echo $url
  1823. rm upload-data.txt
  1824.  
  1825. echo -n `date` >> gc-base-lib/backup_location.txt
  1826. echo ": $url" >> gc-base-lib/backup_location.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement