Advertisement
Guest User

anthony gorecki anthony@anthonygorecki.ca

a guest
Nov 21st, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.15 KB | None | 0 0
  1. Sat Nov 21 02:16:02 EST 2015
  2. ./dev/gc-base-lib/proj-make.txt
  3. //==============================================================================
  4. // This file is part of Gc-Base-Lib.
  5. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  6. //
  7. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  8. // the terms of the GNU General Public License as published by the Free Software
  9. // Foundation, either version 3 of the License, or (at your option) any later
  10. // version.
  11. //
  12. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  13. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. // details.
  16. //
  17. // You should have received a copy of the GNU General Public License along with
  18. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  19. //==============================================================================
  20. # gc-proj-conf (tracks config; can reconfigure)
  21. # gc-proj-make (will rebuild changed files; will rebuild only necessary after conf change)
  22. # gc-proj-inst (installs all built targets)
  23.  
  24. DTGT gc-proj
  25.  
  26. TGEN dev
  27. MAKE
  28. EXEC lib/pkgconfig/make.sh $PREF
  29. INST
  30. COPY include/gc $PREF/include
  31. MOVE lib/pkgconfig/gc-proj.pc.tmp $PREF/lib/pkgconfig/gc-proj.pc
  32.  
  33. TLIB gc-proj
  34. ./dev/gc-base-lib/src/ct/u8_bcss.c
  35. //==============================================================================
  36. // This file is part of Gc-Base-Lib.
  37. // Lockless circular buffer, supporting a single producer and single consumer.
  38. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  39. //
  40. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  41. // the terms of the GNU General Public License as published by the Free Software
  42. // Foundation, either version 3 of the License, or (at your option) any later
  43. // version.
  44. //
  45. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  46. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  47. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  48. // 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. #include <gc/mem.h>
  54.  
  55. #include <gc/u8_bcss.h>
  56.  
  57. // Two variable "u8_a" type, member 1 is "dbeg", member 2 is "cbeg".
  58. //
  59. // Minimum size for this buffer implementation is two bytes. Check for this in
  60. // conf validation.
  61.  
  62.  
  63.  
  64. //==============================================================================
  65. // Initialization
  66. //==============================================================================
  67. u8 u8_bcss_init(struct u8_bcss_i *buf, __unused struct u8_bcss_c *conf)
  68. {
  69. buf->cin = buf->cbeg;
  70. buf->cout = 0;
  71. buf->din = buf->dbeg;
  72. buf->dout = buf->dbeg;
  73. return 0;
  74. }
  75.  
  76.  
  77.  
  78. //==============================================================================
  79. // Advance
  80. //==============================================================================
  81. void u8_bcss_ia(struct u8_bcss_i *buf, u32 size)
  82. {
  83. u32 off = buf->din - buf->dbeg + size;
  84.  
  85. if (off < buf->cbeg - 1)
  86. buf->din += size;
  87.  
  88. else // Wrap around.
  89. buf->din = buf->dbeg + off - buf->cbeg;
  90.  
  91. atmc_fsub(&buf->cin, size);
  92. atmc_fadd(&buf->cout, size);
  93. }
  94.  
  95.  
  96. void u8_bcss_oa(struct u8_bcss_i *buf, u32 size)
  97. {
  98. u32 off = buf->dout - buf->dbeg + size;
  99.  
  100. if (off < buf->cbeg - 1)
  101. buf->dout += size;
  102.  
  103. else // Wrap around.
  104. buf->dout = buf->dbeg + off - buf->cbeg;
  105.  
  106. atmc_fsub(&buf->cout, size);
  107. atmc_fadd(&buf->cin, size);
  108. }
  109.  
  110.  
  111.  
  112. //==============================================================================
  113. // Count
  114. //==============================================================================
  115. u32 u8_bcss_igc(struct u8_bcss_i *buf)
  116. {
  117. return atmc_load(&buf->cin);
  118. }
  119.  
  120.  
  121. u32 u8_bcss_ogc(struct u8_bcss_i *buf)
  122. {
  123. return atmc_load(&buf->cout);
  124. }
  125.  
  126.  
  127.  
  128. //==============================================================================
  129. // Contiguous count and pointer
  130. //==============================================================================
  131. u32 u8_bcss_igcc(struct u8_bcss_i *buf)
  132. {
  133. u32 off_in = buf->din - buf->dbeg;
  134. u32 orig_cin = atmc_load(&buf->cin);
  135.  
  136. if (off_in + orig_cin < buf->cbeg - 1)
  137. return orig_cout;
  138.  
  139. return buf->cbeg - off_in;
  140. }
  141.  
  142.  
  143. u8 *u8_bcss_igcp(struct u8_bcss_i *buf)
  144. {
  145. return buf->din;
  146. }
  147.  
  148.  
  149. u32 u8_bcss_ogcc(struct u8_bcss_i *buf)
  150. {
  151. u32 off_out = buf->dout - buf->dbeg;
  152. u32 orig_cout = atmc_load(&buf->cout);
  153.  
  154. if (off_out + orig_cout < buf->cbeg - 1)
  155. return orig_cout;
  156.  
  157. return buf->cbeg - off_out;
  158. }
  159.  
  160.  
  161. u8 *u8_bcss_ogcp(struct u8_bcss_i *buf)
  162. {
  163. return buf->dout;
  164. }
  165.  
  166.  
  167.  
  168. //==============================================================================
  169. // Peeking
  170. //==============================================================================
  171. u8 u8_bcss_op1(struct u8_bcss_i *buf)
  172. {
  173. return buf->dout[0];
  174. }
  175.  
  176.  
  177. u16 u8_bcss_op2(struct u8_bcss_i *buf)
  178. {
  179. u8 data[2];
  180.  
  181. data[0] = buf->dout[0];
  182.  
  183. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  184. data[1] = buf->dout[1];
  185.  
  186. else
  187. data[1] = buf->dbeg[0];
  188.  
  189. return (u16)data;
  190. }
  191.  
  192.  
  193.  
  194. //==============================================================================
  195. // Input and output
  196. //==============================================================================
  197. u8 u8_bcss_if(struct u8_bcss_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  198. void *arg)
  199. {
  200. u32 ret;
  201.  
  202. if (unlikely(fin(arg, buf->din, u8_bcss_igcc(buf), &ret)))
  203. return 1;
  204.  
  205. u8_bcss_ia(buf, ret);
  206. return 0;
  207. }
  208.  
  209.  
  210. u8 u8_bcss_of(struct u8_bcss_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  211. void *arg)
  212. {
  213. u32 ret;
  214.  
  215. if (unlikely(fout(arg, buf->dout, u8_bcss_ogcc(buf), &ret)))
  216. return 1;
  217.  
  218. u8_bcss_oa(buf, ret);
  219. return 0;
  220. }
  221. ./dev/gc-base-lib/src/ct/u8_a.c
  222. //==============================================================================
  223. // This file is part of Gc-Base-Lib.
  224. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  225. //
  226. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  227. // the terms of the GNU General Public License as published by the Free Software
  228. // Foundation, either version 3 of the License, or (at your option) any later
  229. // version.
  230. //
  231. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  232. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  233. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  234. // details.
  235. //
  236. // You should have received a copy of the GNU General Public License along with
  237. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  238. //==============================================================================
  239. #include <gc/mem.h>
  240.  
  241. #include <gc/u8_a.h>
  242.  
  243. // Configuration for composite type "u8_a": CT_M1V
  244.  
  245.  
  246.  
  247. //==============================================================================
  248. // Initialization and deinitialization
  249. //==============================================================================
  250. u8 u8_a_init(u8 *data, u32 *size, struct u8_a_c *conf)
  251. {
  252. *data = mem_alloc(conf->size);
  253.  
  254. if (unlikely(*data == NULL && conf->size))
  255. return 1;
  256.  
  257. *size = conf->size;
  258. return 0;
  259. }
  260.  
  261.  
  262. void u8_a_deinit(u8 *data)
  263. {
  264. mem_dealloc(*data);
  265. }
  266. ./dev/gc-base-lib/src/ct/u8_ib.c
  267. //==============================================================================
  268. // This file is part of Gc-Base-Lib.
  269. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  270. //
  271. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  272. // the terms of the GNU General Public License as published by the Free Software
  273. // Foundation, either version 3 of the License, or (at your option) any later
  274. // version.
  275. //
  276. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  277. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  278. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  279. // details.
  280. //
  281. // You should have received a copy of the GNU General Public License along with
  282. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  283. //==============================================================================
  284. #include <gc/mem.h>
  285.  
  286. #include <gc/u8_ib.h>
  287.  
  288.  
  289.  
  290. //==============================================================================
  291. // Initialization and deinitialization
  292. //==============================================================================
  293. CT_WRAP_IDMS(u8_ib);
  294.  
  295.  
  296. u8 u8_ib_init_ms(struct u8_ib_i *ibuf, struct u8_ib_c *conf)
  297. {
  298. MS_BEG(0);
  299.  
  300. MS_SP {
  301. ibuf->buf = mem_alloc(conf->sbuf);
  302. MS_EV(ibuf->buf != NULL || !conf->sbuf);
  303. }
  304.  
  305. MS_SP { MS_EV(!conf->f->init(ibuf->buf, conf->buf)); }
  306. MS_SP { ibuf->f = conf->f; }
  307. return 0;
  308. }
  309.  
  310.  
  311. void u8_ib_deinit_ms(struct u8_ib_i *ibuf, u8 step)
  312. {
  313. MS_BEG(step);
  314. MS_EM;
  315. MS_SP { ibuf->f->deinit(ibuf->buf); }
  316. MS_SP { mem_dealloc(ibuf->buf); }
  317. }
  318.  
  319.  
  320.  
  321. //==============================================================================
  322. // Advance
  323. //==============================================================================
  324. void u8_ib_ia(struct u8_ib_i *ibuf, u32 size)
  325. {
  326. ibuf->f->ia(ibuf->buf, size);
  327. }
  328.  
  329.  
  330. void u8_ib_oa(struct u8_ib_i *ibuf, u32 size)
  331. {
  332. ibuf->f->oa(ibuf->buf, size);
  333. }
  334.  
  335.  
  336.  
  337. //==============================================================================
  338. // Count
  339. //==============================================================================
  340. u32 u8_ib_igc(struct u8_ib_i *ibuf)
  341. {
  342. return ibuf->f->igc(ibuf->buf);
  343. }
  344.  
  345.  
  346. u32 u8_ib_ogc(struct u8_ib_i *ibuf)
  347. {
  348. return ibuf->f->ogc(ibuf->buf);
  349. }
  350.  
  351.  
  352.  
  353. //==============================================================================
  354. // Contiguous count and pointer
  355. //==============================================================================
  356. u32 u8_ib_igcc(struct u8_ib_i *ibuf)
  357. {
  358. return ibuf->f->igcc(ibuf->buf);
  359. }
  360.  
  361.  
  362. u8 *u8_ib_igcp(struct u8_ib_i *ibuf)
  363. {
  364. return ibuf->f->igcp(ibuf->buf);
  365. }
  366.  
  367.  
  368. u32 u8_ib_ogcc(struct u8_ib_i *ibuf)
  369. {
  370. return ibuf->f->ogcc(ibuf->buf);
  371. }
  372.  
  373.  
  374. u8 *u8_ib_ogcp(struct u8_ib_i *ibuf)
  375. {
  376. return ibuf->f->ogcp(ibuf->buf);
  377. }
  378.  
  379.  
  380.  
  381. //==============================================================================
  382. // Peeking
  383. //==============================================================================
  384. u8 u8_ib_op1(struct u8_ib_i *ibuf)
  385. {
  386. return ibuf->f->op1(ibuf->buf);
  387. }
  388.  
  389.  
  390. u16 u8_ib_op2(struct u8_ib_i *ibuf)
  391. {
  392. return ibuf->f->op2(ibuf->buf);
  393. }
  394.  
  395.  
  396.  
  397. //==============================================================================
  398. // Input and output
  399. //==============================================================================
  400. u8 u8_ib_if(struct u8_ib_i *ibuf, u8 (*fin)(void*, u8*, u32, u32*), void *arg)
  401. {
  402. return ibuf->if(ibuf->buf, fin, arg);
  403. }
  404.  
  405.  
  406. u8 u8_ib_of(struct u8_ib_i *ibuf, u8 (*fout)(void*, u8*, u32, u32*), void *arg)
  407. {
  408. return ibuf->of(ibuf->buf, fout, arg);
  409. }
  410. ./dev/gc-base-lib/src/ct/u8_b.c
  411. ./dev/gc-base-lib/src/ct/u8_bc.c
  412. //==============================================================================
  413. // This file is part of Gc-Base-Lib.
  414. // Simple circular buffer, supporting nonsimultaneous input and output.
  415. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  416. //
  417. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  418. // the terms of the GNU General Public License as published by the Free Software
  419. // Foundation, either version 3 of the License, or (at your option) any later
  420. // version.
  421. //
  422. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  423. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  424. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  425. // details.
  426. //
  427. // You should have received a copy of the GNU General Public License along with
  428. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  429. //==============================================================================
  430. #include <gc/mem.h>
  431.  
  432. #include <gc/u8_bc.h>
  433.  
  434.  
  435.  
  436. //==============================================================================
  437. // Initialization and deinitialization
  438. //==============================================================================
  439. u8 u8_bc_init(struct u8_bc_i *buf, struct u8_bc_c *conf)
  440. {
  441. // Minimum size for this buffer implementation is two bytes. Check for this
  442. // in conf validation.
  443.  
  444. buf->dbeg = mem_alloc(conf->size);
  445.  
  446. if (unlikely(buf->dbeg == NULL))
  447. return 1;
  448.  
  449. buf->cbeg = size;
  450. return 0;
  451. }
  452.  
  453.  
  454. void u8_bc_deinit(struct u8_bc_i *buf)
  455. {
  456. mem_dealloc(buf->dbeg);
  457. }
  458.  
  459.  
  460.  
  461. //==============================================================================
  462. // Advance
  463. //==============================================================================
  464. void u8_bc_ia(struct u8_bc_i *buf, u32 size)
  465. {
  466. u32 off = buf->din - buf->dbeg + size;
  467.  
  468. if (off < buf->cbeg - 1)
  469. buf->din += size;
  470.  
  471. else // Wrap around.
  472. buf->din = buf->dbeg + off - buf->cbeg;
  473.  
  474. atmc_fsub(&buf->cin, size);
  475. atmc_fadd(&buf->cout, size);
  476. }
  477.  
  478.  
  479. void u8_bc_oa(struct u8_bc_i *buf, u32 size)
  480. {
  481. u32 off = buf->dout - buf->dbeg + size;
  482.  
  483. if (off < buf->cbeg - 1)
  484. buf->dout += size;
  485.  
  486. else // Wrap around.
  487. buf->dout = buf->dbeg + off - buf->cbeg;
  488.  
  489. atmc_fsub(&buf->cout, size);
  490. atmc_fadd(&buf->cin, size);
  491. }
  492.  
  493.  
  494.  
  495. //==============================================================================
  496. // Count
  497. //==============================================================================
  498. u32 u8_bc_igc(struct u8_bc_i *buf)
  499. {
  500. return atmc_load(&buf->cin);
  501. }
  502.  
  503.  
  504. u32 u8_bc_ogc(struct u8_bc_i *buf)
  505. {
  506. return atmc_load(&buf->cout);
  507. }
  508.  
  509.  
  510.  
  511. //==============================================================================
  512. // Contiguous count and pointer
  513. //==============================================================================
  514. u32 u8_bc_igcc(struct u8_bc_i *buf)
  515. {
  516. u32 off_in = buf->din - buf->dbeg;
  517. u32 orig_cin = atmc_load(&buf->cin);
  518.  
  519. if (off_in + orig_cin < buf->cbeg - 1)
  520. return orig_cout;
  521.  
  522. return buf->cbeg - off_in;
  523. }
  524.  
  525.  
  526. u8 *u8_bc_igcp(struct u8_bc_i *buf)
  527. {
  528. return buf->din;
  529. }
  530.  
  531.  
  532. u32 u8_bc_ogcc(struct u8_bc_i *buf)
  533. {
  534. u32 off_out = buf->dout - buf->dbeg;
  535. u32 orig_cout = atmc_load(&buf->cout);
  536.  
  537. if (off_out + orig_cout < buf->cbeg - 1)
  538. return orig_cout;
  539.  
  540. return buf->cbeg - off_out;
  541. }
  542.  
  543.  
  544. u8 *u8_bc_ogcp(struct u8_bc_i *buf)
  545. {
  546. return buf->dout;
  547. }
  548.  
  549.  
  550.  
  551. //==============================================================================
  552. // Peeking
  553. //==============================================================================
  554. u8 u8_bc_op1(struct u8_bc_i *buf)
  555. {
  556. return buf->dout[0];
  557. }
  558.  
  559.  
  560. u16 u8_bc_op2(struct u8_bc_i *buf)
  561. {
  562. u8 data[2];
  563.  
  564. data[0] = buf->dout[0];
  565.  
  566. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  567. data[1] = buf->dout[1];
  568.  
  569. else
  570. data[1] = buf->dbeg[0];
  571.  
  572. return (u16)data;
  573. }
  574.  
  575.  
  576.  
  577. //==============================================================================
  578. // Input and output
  579. //==============================================================================
  580. u8 u8_bc_if(struct u8_bc_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  581. void *arg)
  582. {
  583. u32 ret;
  584.  
  585. if (unlikely(fin(arg, buf->din, u8_bc_igcc(buf), &ret)))
  586. return 1;
  587.  
  588. u8_bc_ia(buf, ret);
  589. return 0;
  590. }
  591.  
  592.  
  593. u8 u8_bc_of(struct u8_bc_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  594. void *arg)
  595. {
  596. u32 ret;
  597.  
  598. if (unlikely(fout(arg, buf->dout, u8_bc_ogcc(buf), &ret)))
  599. return 1;
  600.  
  601. u8_bc_oa(buf, ret);
  602. return 0;
  603. }
  604. ./dev/gc-base-lib/src/util/pars.c
  605. //==============================================================================
  606. // This file is part of Gc-Base-Lib.
  607. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  608. //
  609. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  610. // the terms of the GNU General Public License as published by the Free Software
  611. // Foundation, either version 3 of the License, or (at your option) any later
  612. // version.
  613. //
  614. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  615. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  616. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  617. // details.
  618. //
  619. // You should have received a copy of the GNU General Public License along with
  620. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  621. //==============================================================================
  622. #include <gc/pars.h>
  623.  
  624.  
  625.  
  626. //==============================================================================
  627. // "u8's"
  628. //==============================================================================
  629. u8 pars_u8c(struct pars_i *pars, u8 data)
  630. {
  631. u32 orig_cnt = u8b_cnt(&pars->buf);
  632.  
  633. while (u8b_cnt(&pars->buf)) {
  634. if (u8b_peek1(&pars->buf) != data)
  635. break;
  636.  
  637. u8b_adv(&pars->buf, 1);
  638. }
  639.  
  640. return !(u8b_cnt(&pars->buf) < orig_cnt);
  641. }
  642.  
  643.  
  644. u8 pars_u8c2(struct pars_i *pars, u8 data1, u8 data2)
  645. {
  646. u8 cdata[] = {data1, data2};
  647. u32 orig_cnt = u8b_cnt(&pars->buf);
  648.  
  649. while (u8b_cnt(&pars->buf) >= 2) {
  650. if (u8b_peek2(&pars->buf) != (u16)cdata)
  651. break;
  652.  
  653. u8b_adv(&pars->buf, 2);
  654. }
  655.  
  656. return !(u8b_cnt(&pars->buf) < orig_cnt);
  657. }
  658.  
  659.  
  660.  
  661. //==============================================================================
  662. // New line characters
  663. //==============================================================================
  664. u8 pars_nld(struct pars_i *pars, u8 types)
  665. {
  666. assert((types & NL_RN) || (types & NL_N) || (types & NL_R));
  667.  
  668. u8 rn[] = {'\r', '\n'};
  669.  
  670. if (u8b_cnt(&pars->buf) >= 2 && (types & NL_RN)
  671. && u8b_peek2(&pars->buf) == (u16)rn)
  672. return NL_RN;
  673.  
  674. if (u8b_cnt(&pars->buf)) {
  675. if ((types & NL_N) && u8b_peek(&pars->buf) == '\n')
  676. return NL_N;
  677.  
  678. if ((types & NL_R) && u8b_peek(&pars->buf) == '\r')
  679. return NL_R;
  680. }
  681.  
  682. return 0;
  683. }
  684.  
  685.  
  686. u8 pars_nlcs(struct pars_i *pars, u8 types)
  687. {
  688. u8 dtype = pars_nld(pars, types);
  689.  
  690. if (unlikely(!dtype))
  691. return 1;
  692.  
  693. if ((dtype & NL_RN)) {
  694. u8b_adv(&pars->buf, 2);
  695. pars_u8c2(pars, '\r', '\n');
  696. }
  697.  
  698. else {
  699. u8b_adv(&pars->buf, 1);
  700.  
  701. if ((dtype & NL_N))
  702. pars_u8c(pars, '\n');
  703.  
  704. if ((dtype & NL_R))
  705. pars_u8c(pars, '\r');
  706. }
  707.  
  708. return 0;
  709. }
  710.  
  711.  
  712. u8 pars_nlcm(struct pars_i *pars, u8 types)
  713. {
  714. u8 ret = 1;
  715.  
  716. for (;;) {
  717. if (pars_nlcs(pars, types))
  718. break;
  719.  
  720. ret = 0;
  721. }
  722.  
  723. return ret;
  724. }
  725.  
  726. ./dev/gc-base-lib/src/os/unix/proc.c
  727. //==============================================================================
  728. // This file is part of Gc-Base-Lib.
  729. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  730. //
  731. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  732. // the terms of the GNU General Public License as published by the Free Software
  733. // Foundation, either version 3 of the License, or (at your option) any later
  734. // version.
  735. //
  736. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  737. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  738. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  739. // details.
  740. //
  741. // You should have received a copy of the GNU General Public License along with
  742. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  743. //==============================================================================
  744. // proc_st_init, proc_st_next, ...
  745. #include <gc/proc.h>
  746.  
  747.  
  748.  
  749. //==============================================================================
  750. // Execution
  751. //==============================================================================
  752. u8 proc_exec(void)
  753. {
  754. }
  755. ./dev/gc-base-lib/src/os/unix/mem.c
  756. //==============================================================================
  757. // This file is part of Gc-Base-Lib.
  758. // Copyright (C) 2015 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 <stdlib.h>
  776. #include <string.h>
  777.  
  778.  
  779.  
  780. //==============================================================================
  781. // Allocation, reallocation and deallocation
  782. //==============================================================================
  783. void *mem_alloc(size_t size)
  784. {
  785. return malloc(size);
  786. }
  787.  
  788.  
  789. void *mem_realloc(void *ptr, size_t size)
  790. {
  791. return realloc(ptr, size);
  792. }
  793.  
  794.  
  795. void mem_dealloc(void *ptr)
  796. {
  797. free(ptr);
  798. }
  799.  
  800.  
  801.  
  802. //==============================================================================
  803. // Utility
  804. //==============================================================================
  805. s8 mem_comp(void *data1, void *data2, size_t size)
  806. {
  807. return memcmp(data1, data2, size);
  808. }
  809.  
  810.  
  811. void mem_copy(void *dest, void *src, size_t size)
  812. {
  813. memcpy(dest, src, size);
  814. }
  815.  
  816.  
  817. void mem_move(void *dest, void *src, size_t size)
  818. {
  819. memmove(dest, src, size);
  820. }
  821.  
  822.  
  823. void mem_set(void *ptr, u8 data, size_t size)
  824. {
  825. memset(ptr, data, size);
  826. }
  827. ./dev/gc-base-lib/src/os/unix/file.c
  828. //==============================================================================
  829. // This file is part of Gc-Base-Lib.
  830. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  831. //
  832. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  833. // the terms of the GNU General Public License as published by the Free Software
  834. // Foundation, either version 3 of the License, or (at your option) any later
  835. // version.
  836. //
  837. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  838. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  839. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  840. // details.
  841. //
  842. // You should have received a copy of the GNU General Public License along with
  843. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  844. //==============================================================================
  845. #include <gc/file.h>
  846.  
  847. #include <unistd.h>
  848.  
  849.  
  850.  
  851. //==============================================================================
  852. // Initialization and deinitialization
  853. //==============================================================================
  854. u8 file_init(struct file_i *file, struct file_c *conf)
  855. {
  856. if (!(conf->flags & FILE_CREAT))
  857. file->fd = open(conf->path, conf->flags);
  858.  
  859. else
  860. file->fd = open(conf->path, conf->flags, conf->mode);
  861.  
  862. if (unlikely(file->fd == -1))
  863. return 1;
  864.  
  865. return 0;
  866. }
  867.  
  868.  
  869. void file_deinit(struct file_i *file)
  870. {
  871. close(file->fd);
  872. }
  873.  
  874.  
  875.  
  876. //==============================================================================
  877. // Read and write
  878. //==============================================================================
  879. u8 file_read(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  880. {
  881. ssize_t bytes = read(file->fd, buf, size);
  882.  
  883. if (unlikely(bytes == -1))
  884. return 1;
  885.  
  886. *ret = bytes;
  887. return 0;
  888. }
  889.  
  890.  
  891. u8 file_write(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  892. {
  893. ssize_t bytes = write(file->fd, buf, size);
  894.  
  895. if (unlikely(bytes == -1))
  896. return 1;
  897.  
  898. *ret = bytes;
  899. return 0;
  900. }
  901.  
  902.  
  903.  
  904. //==============================================================================
  905. // Utility
  906. //==============================================================================
  907. u8 file_gstats(struct file_i *file, struct file_stats *stats)
  908. {
  909. if (unlikely(fstat(file->fd, &stats->data)))
  910. return 1;
  911.  
  912. return 0;
  913. }
  914. ./dev/gc-base-lib/make.sh
  915. gcc -o libgc-base -shared -I include -std=c11 -Wall -Wextra -Wpedantic -Werror `find src -type f -name '*.c'`
  916. ./dev/gc-base-lib/inc/gc/macro/ms.h
  917. //==============================================================================
  918. // This file is part of Gc-Base-Lib.
  919. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  920. //
  921. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  922. // the terms of the GNU General Public License as published by the Free Software
  923. // Foundation, either version 3 of the License, or (at your option) any later
  924. // version.
  925. //
  926. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  927. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  928. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  929. // details.
  930. //
  931. // You should have received a copy of the GNU General Public License along with
  932. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  933. //==============================================================================
  934. #pragma once
  935.  
  936. #define MS_BEG(STEP)
  937. #define MS_EM
  938. #define MS_SP
  939. #define MS_EV
  940. ./dev/gc-base-lib/inc/gc/proc.h
  941. //==============================================================================
  942. // This file is part of Gc-Base-Lib.
  943. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  944. //
  945. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  946. // the terms of the GNU General Public License as published by the Free Software
  947. // Foundation, either version 3 of the License, or (at your option) any later
  948. // version.
  949. //
  950. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  951. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  952. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  953. // details.
  954. //
  955. // You should have received a copy of the GNU General Public License along with
  956. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  957. //==============================================================================
  958. #pragma once
  959.  
  960. #include <gc/common.h>
  961.  
  962. #if defined(__use_gnu_bktrc)
  963. #include <gc/proc-gnu-bktrc.h>
  964. #endif
  965.  
  966. #if defined(__use_lunwind)
  967. #include <gc/proc-lunwind.h>
  968. #endif
  969.  
  970. // Null function pointers for systems where back traces are not supported.
  971. ./dev/gc-base-lib/inc/gc/common.h
  972. //==============================================================================
  973. // This file is part of Gc-Base-Lib.
  974. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  975. //
  976. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  977. // the terms of the GNU General Public License as published by the Free Software
  978. // Foundation, either version 3 of the License, or (at your option) any later
  979. // version.
  980. //
  981. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  982. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  983. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  984. // details.
  985. //
  986. // You should have received a copy of the GNU General Public License along with
  987. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  988. //==============================================================================
  989. #pragma once
  990.  
  991. #include <stddef.h>
  992. #include <stdint.h>
  993.  
  994. // "__unused" is expected to be provided by a system library. Define it in this
  995. // file only if it is missing on the host system.
  996.  
  997. #define likely(EXPR) __builtin_expect(EXPR, 1)
  998. #define unlikely(EXPR) __builtin_expect(EXPR, 0)
  999.  
  1000. typedef int8_t s8;
  1001. typedef int16_t s16;
  1002. typedef int32_t s32;
  1003. typedef int64_t s64;
  1004.  
  1005. typedef uint8_t u8;
  1006. typedef uint16_t u16;
  1007. typedef uint32_t u32;
  1008. typedef uint64_t u64;
  1009. ./dev/gc-base-lib/inc/gc/u8_ib.h
  1010. //==============================================================================
  1011. // This file is part of Gc-Base-Lib.
  1012. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1013. //
  1014. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1015. // the terms of the GNU General Public License as published by the Free Software
  1016. // Foundation, either version 3 of the License, or (at your option) any later
  1017. // version.
  1018. //
  1019. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1020. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1021. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1022. // details.
  1023. //
  1024. // You should have received a copy of the GNU General Public License along with
  1025. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1026. //==============================================================================
  1027. #pragma once
  1028.  
  1029. #include <gc/ct.h>
  1030.  
  1031. struct u8_ib_i {
  1032. };
  1033.  
  1034. struct u8_ib_c {
  1035. };
  1036. ./dev/gc-base-lib/inc/gc/atmc.h
  1037. //==============================================================================
  1038. // This file is part of Gc-Base-Lib.
  1039. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1040. //
  1041. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1042. // the terms of the GNU General Public License as published by the Free Software
  1043. // Foundation, either version 3 of the License, or (at your option) any later
  1044. // version.
  1045. //
  1046. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1047. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1048. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1049. // details.
  1050. //
  1051. // You should have received a copy of the GNU General Public License along with
  1052. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1053. //==============================================================================
  1054. #pragma once
  1055.  
  1056. #include <gc/common.h>
  1057.  
  1058. typedef _Atomic s8 as8;
  1059. typedef _Atomic s16 as16;
  1060. typedef _Atomic s32 as32;
  1061. typedef _Atomic s64 as64;
  1062.  
  1063. typedef _Atomic u8 au8;
  1064. typedef _Atomic u16 au16;
  1065. typedef _Atomic u32 au32;
  1066. typedef _Atomic u64 au64;
  1067.  
  1068. #define atmc_fadd atomic_fetch_add
  1069. #define atmc_fsub atomic_fetch_sub
  1070. #define atmc_load atomic_load
  1071. ./dev/gc-base-lib/inc/gc/ct.h
  1072. //==============================================================================
  1073. // This file is part of Gc-Base-Lib.
  1074. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1075. //
  1076. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1077. // the terms of the GNU General Public License as published by the Free Software
  1078. // Foundation, either version 3 of the License, or (at your option) any later
  1079. // version.
  1080. //
  1081. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1082. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1083. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1084. // details.
  1085. //
  1086. // You should have received a copy of the GNU General Public License along with
  1087. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1088. //==============================================================================
  1089. #pragma once
  1090.  
  1091. #include <gc/macro/ms.h>
  1092.  
  1093. // Configuration for composite types needs space for two offsets (u16's), to
  1094. // allow for two variable types (such as "u8_a").
  1095.  
  1096. #define CT_M1V 1 // Member 1 pass by value.
  1097. #define CT_M2V 2 // Member 2 pass by value.
  1098. #define CT_M2D 4 // Member 2 pass to deinit.
  1099.  
  1100. #define CT_WRAP_IDMS(PREF) \
  1101. u8 PREF##_init(struct PREF##_i *info, struct PREF##_c *conf) \
  1102. { \
  1103. u8 step = PREF##_init_ms(info, conf); \
  1104. if (!step) \
  1105. return 0; \
  1106. PREF##_deinit_ms(info, step); \
  1107. return 1; \
  1108. } \
  1109. void PREF##_deinit(struct PREF##_i *info) \
  1110. { \
  1111. PREF##_deinit_ms(info, 0); \
  1112. }
  1113. ./dev/gc-base-lib/inc/gc/u8b.h
  1114. //==============================================================================
  1115. // This file is part of Gc-Base-Lib.
  1116. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1117. //
  1118. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1119. // the terms of the GNU General Public License as published by the Free Software
  1120. // Foundation, either version 3 of the License, or (at your option) any later
  1121. // version.
  1122. //
  1123. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1124. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1125. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1126. // details.
  1127. //
  1128. // You should have received a copy of the GNU General Public License along with
  1129. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1130. //==============================================================================
  1131. #pragma once
  1132.  
  1133. #include <gc/atmc.h>
  1134.  
  1135. struct u8b_i {
  1136. u32 cbeg;
  1137. au32 cin;
  1138. au32 cout;
  1139. u8 *dbeg;
  1140. u8 *din;
  1141. u8 *dout;
  1142. };
  1143. ./dev/gc-base-lib/inc/gc/pars.h
  1144. //==============================================================================
  1145. // This file is part of Gc-Base-Lib.
  1146. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1147. //
  1148. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1149. // the terms of the GNU General Public License as published by the Free Software
  1150. // Foundation, either version 3 of the License, or (at your option) any later
  1151. // version.
  1152. //
  1153. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1154. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1155. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1156. // details.
  1157. //
  1158. // You should have received a copy of the GNU General Public License along with
  1159. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1160. //==============================================================================
  1161. #pragma once
  1162.  
  1163. #include <gc/u8b.h>
  1164.  
  1165. struct pars_i {
  1166. struct u8b_i buf;
  1167. };
  1168. ./dev/gc-base-lib/inc/gc/file.h
  1169. //==============================================================================
  1170. // This file is part of Gc-Base-Lib.
  1171. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1172. //
  1173. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1174. // the terms of the GNU General Public License as published by the Free Software
  1175. // Foundation, either version 3 of the License, or (at your option) any later
  1176. // version.
  1177. //
  1178. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1179. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1180. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1181. // details.
  1182. //
  1183. // You should have received a copy of the GNU General Public License along with
  1184. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1185. //==============================================================================
  1186. #pragma once
  1187.  
  1188. #include <gc/u8b.h>
  1189.  
  1190. #include <sys/stat.h>
  1191. #include <fcntl.h>
  1192.  
  1193. struct file_i {
  1194. int fd;
  1195. };
  1196.  
  1197. struct file_c {
  1198. const char *path;
  1199. int flags;
  1200. mode_t mode;
  1201. };
  1202.  
  1203. struct file_stats {
  1204. struct stat data;
  1205. };
  1206. ./dev/gc-base-lib/inc/gc/mem.h
  1207. //==============================================================================
  1208. // This file is part of Gc-Base-Lib.
  1209. // Copyright (C) 2015 Anthony Gorecki <agorecki@gcproj.org>
  1210. //
  1211. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1212. // the terms of the GNU General Public License as published by the Free Software
  1213. // Foundation, either version 3 of the License, or (at your option) any later
  1214. // version.
  1215. //
  1216. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1217. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1218. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1219. // details.
  1220. //
  1221. // You should have received a copy of the GNU General Public License along with
  1222. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1223. //==============================================================================
  1224. #pragma once
  1225.  
  1226. #include <gc/common.h>
  1227.  
  1228. void* mem_alloc(size_t);
  1229. void* mem_realloc(void*, size_t);
  1230. void mem_dealloc(void*);
  1231.  
  1232. u8 mem_comp(void*, void*, size_t);
  1233. void mem_copy(void*, void*, size_t);
  1234. void mem_move(void*, void*, size_t);
  1235. void mem_set(void*, u8, size_t);
  1236. ./dev/doc/includes.txt
  1237. External Gc headers, Gc header for local file, all other headers; groups
  1238. separated by a single new line.
  1239. ./dev/doc/func-args.txt
  1240. Structs are always used for info and conf varaibles so their contents /
  1241. implementation can easily be changed later and without modifying the code of
  1242. software using the libraries.
  1243. ./dev/doc/code-style.txt
  1244. Soft limit for line length is 80 characters, hard limit is 100 characters.
  1245.  
  1246. Conditional statements requiring multiple lines should indent the subsequent
  1247. lines with two tabs (one additional tab, relative the the code following the
  1248. conditional statement).
  1249. ./dev/doc/func-naming.txt
  1250. Hard limit for function name first part is five characters. Soft limit is
  1251. four characters.
  1252.  
  1253. Function name hard limit for second part is five characters (initialization /
  1254. activation). Does not apply to names that have been shortened to individual
  1255. characters per word.
  1256.  
  1257. Struct member name soft limit is four characters.
  1258. ./script/upload-pastebin.sh
  1259. cd /root
  1260.  
  1261. echo 'Files:'
  1262.  
  1263. files=$(find -name '*.c' -o -name '*.h' -o -name '*.py' -o -name '*.sh' -o -name '*.txt' -o -name '.vimrc')
  1264.  
  1265. date > upload-data.txt
  1266.  
  1267. for file in $files; do
  1268. echo " $file"
  1269. echo $file >> upload-data.txt
  1270. cat $file >> upload-data.txt
  1271. done
  1272.  
  1273. echo
  1274. echo -n 'URL: '
  1275. python ./script/intrn/upload-pastebin.py `cat script/intrn/dev-key`
  1276. rm upload-data.txt
  1277. ./script/intrn/upload-pastebin.py
  1278. import pastebin_python
  1279. import sys
  1280.  
  1281. pb = pastebin_python.pastebin.PastebinPython(api_dev_key=sys.argv[1])
  1282. print pb.createPasteFromFile('upload-data.txt', 'anthony gorecki anthony@anthonygorecki.ca', '', '0', 'N')
  1283. ./.vimrc
  1284. set ts=4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement