Compare commits

...

162 Commits
0.6 ... master

Author SHA1 Message Date
Daniel Ziltener 99e8b1e8ed
toml 0.8 2024-03-26 13:58:22 +01:00
Daniel Ziltener 91ea498688 Add 'tomlc99/' from commit '5221b3d3d66c25a1dc6f0372b4f824f1202fe398'
git-subtree-dir: tomlc99
git-subtree-mainline: f2ccebdd2d
git-subtree-split: 5221b3d3d6
2024-03-26 13:44:04 +01:00
Daniel Ziltener f2ccebdd2d
Subtree removal 2024-03-26 13:43:57 +01:00
Daniel Ziltener b4b9e39c70
New repository URL 2023-11-24 22:25:34 +01:00
Martin Tournoij 5221b3d3d6
Fix toml_json.c output (#85)
* Fix toml_json.c output

There were two issues; partly related to changes in upstream toml-test:

- Use appropriate type for local date and times.

- The arrays would get printed as:

      {"type": "array", "value": [...the values...]}

  But this should just be:

      [...the values...]

  It also wouldn't print mixed arrays because 'm' was missing in the
  switch; I adapted this from toml_cat.c.

Before:

	toml-test [./toml_json]: using embedded tests: 328 passed, 87 failed

After:

	toml-test [./toml_json]: using embedded tests: 351 passed, 64 failed

The remaining test failures look like a few minor issues in toml.c,
rather than toml_json.c

* Also fix the "test1" toml-test runner
2023-09-30 12:36:59 -07:00
CK Tan 6fe7fee127 format and comment only 2023-09-18 20:28:16 -07:00
Vlad-Ștefan Harbuz 52e9c039c5
add missing null pointer checks (#80)
The result of copying a null pointer is undefined.
2023-05-29 12:36:32 -07:00
CK Tan d4c94500c4 fix: make install fail when libtoml.pc does not exist 2023-05-29 12:31:52 -07:00
Daniel Ziltener ec1ef8715a fix: date-only timestamp parsing 2022-10-14 15:26:14 +02:00
Daniel Ziltener d2e5d78a38 fix: date-only timestamp parsing 2022-10-14 15:24:52 +02:00
Daniel Ziltener c966b0e022 fix: date-only timestamp parsing 2022-10-14 15:20:11 +02:00
CK Tan 894902820a minor fix to CALLOC 2022-09-12 10:14:48 -07:00
Kamil Giszczak e4107c4554
Allow to use 't' (lower case T) as a date-time delimiter (#76)
as specified by TOML ABNF grammar:
https://github.com/toml-lang/toml/blob/1.0.0/toml.abnf#L169
2022-07-27 12:06:50 -07:00
Vladislav Laetansky 034b23ed3e
msvc warning 4996 disable pragma (#73) 2022-04-17 13:09:01 -07:00
CK Tan 4e7b082ccc removed pragma that caused warning on gcc 2022-04-04 11:28:49 -07:00
Vladislav Laetansky 8a863d1ec8
MSVC warnings fix (#72) 2022-04-04 11:24:53 -07:00
CK Tan 99c1e33222 minor 2022-03-28 05:54:28 -07:00
CK Tan d3a4391ae9 format 2022-01-05 06:02:11 +00:00
CK Tan 32c38751b9 format with clang-format 2021-12-25 23:42:50 -08:00
CK Tan 64e280e20b fix: Makefile install prefix missing for libtoml.pc #68 2021-12-16 13:36:32 -08:00
ownesis 8434e75006
Adding libtoml.pc for pkg-config (#63) 2021-12-10 17:01:52 -08:00
CK Tan 310f02dd67 comment 2021-12-10 16:59:47 -08:00
Toni 62320462f5
Avoid redefinition warnings from strdup functions (#67) 2021-12-10 16:57:07 -08:00
CK Tan 353c68c3df
Merge pull request #64 from moorereason/iss62-goget
fix toml-test build script for Go 1.17
2021-12-07 15:39:12 -08:00
Cameron Moore 1d4fc82ebc
fix toml-test build script for Go 1.17
Fixes #62
2021-11-22 19:26:59 -06:00
CK Tan 37954d9b20 add toml_key_exists() 2021-10-25 23:21:48 -07:00
CK Tan 208203af46 minor 2021-07-15 13:32:11 -07:00
CK Tan b5818182a4 fix an overflow bug in the scanner 2021-07-14 20:20:15 -07:00
CK Tan 4636173fed fix print of millisec 2021-07-05 09:51:50 -07:00
CK Tan 6b49aaf863 fix to make it run 2021-07-05 00:11:10 -07:00
CK Tan 45921ae3db add test for timestamp millisec 2021-07-04 19:41:16 -07:00
CK Tan bf0447ab49 add timestamp test 2021-07-04 19:25:24 -07:00
CK Tan 511749ebb9 fix bug in millisec parsing 2021-07-04 19:20:08 -07:00
CK Tan 24e4472b44 tabify 2021-07-04 19:10:32 -07:00
CK Tan 789930f7c9 when parsing millisec in timestamp, force use of base 10 in strtol() 2021-06-04 17:09:25 -07:00
CK Tan d7dd697c35 minor 2021-04-17 13:06:59 -07:00
CK Tan 22aa38e31d catch unexpected use of malloc 2021-04-17 12:55:51 -07:00
CK Tan 3c1107177f simplify 2021-04-11 18:48:41 -07:00
CK Tan 45e8f3c903 cleanup 2021-04-11 15:36:04 -07:00
CK Tan a7557174ae fix #52 2021-04-11 15:27:55 -07:00
CK Tan e9bfb63807 updated 2021-04-11 15:24:10 -07:00
CK Tan 06e2fceedf speed up parse 2021-04-11 15:18:32 -07:00
CK Tan 369fd2451b more tests 2021-03-07 17:41:18 -08:00
CK Tan dbc1ef26d6 more tests 2021-03-07 17:28:41 -08:00
CK Tan 937d88e009 more tests 2021-03-07 02:29:43 -08:00
CK Tan 836ac94afe bug fix for timestmap 2021-03-07 02:26:19 -08:00
CK Tan 20bee50b59 minor fix 2021-03-07 01:07:03 -08:00
CK Tan 715fa54d45 fixed issue #51 2021-03-06 23:54:24 -08:00
CK Tan 1cfa8e42c4
Merge pull request #49 from mweshahy/patch-1
Add proper SONAME to TOML shared library
2021-02-16 17:12:38 -08:00
CK Tan fd82018f79 fix #50: crash on input 2021-02-16 17:10:51 -08:00
mweshahy 970ab84bae
Add proper SONAME to TOML shared library
This patch renames the shared library output to libtoml.so.$(LIB_VERSION) instead of libtoml.so. This matches the Yocto standards so that the library can be integrated into Yocto build.
2021-02-16 12:45:18 +01:00
CK Tan c5d2e37db7
updated 2021-01-27 18:53:31 -08:00
CK Tan e97a56633e minor 2021-01-09 17:19:09 -08:00
CK Tan 94ded5f2c1 readme 2020-12-22 23:09:36 -08:00
CK Tan 63feb40e3b readme 2020-12-05 15:45:30 -08:00
CK Tan 5039045945 minor 2020-12-05 14:25:39 -08:00
CK Tan 61557dcbaa revise example 2020-12-05 14:21:40 -08:00
CK Tan ae9514e87b revised example 2020-12-05 14:19:53 -08:00
CK Tan 13b8fde204
Update README.md 2020-12-04 14:30:15 -08:00
CK Tan f7fde945e6
Update README.md 2020-12-03 23:16:55 -08:00
CK Tan a2d704c7af Merge branch 'master' of github.com:cktan/tomlc99 2020-12-02 13:22:54 -08:00
CK Tan 72eda69b5a cleanup 2020-12-02 13:22:46 -08:00
CK Tan 51e9daabd2
Update README.md 2020-12-01 15:04:13 -08:00
CK Tan f7c39273fe readme 2020-11-24 04:54:40 -08:00
CK Tan 0a280911de readme 2020-11-24 04:52:20 -08:00
CK Tan ba73b18f50
Update README.md 2020-11-24 04:50:13 -08:00
CK Tan 32636ccd01
Update README.md 2020-11-24 04:49:46 -08:00
CK Tan e9ea925e05
Update README.md 2020-11-24 04:48:46 -08:00
CK Tan 579e72c377
Update README.md 2020-11-24 04:47:23 -08:00
CK Tan 5fb977508a
Update README.md 2020-11-13 13:14:16 -08:00
CK Tan 577e48e03f minor 2020-11-09 22:39:39 -08:00
CK Tan 1ee269d00c Merge branch 'master' of github.com:cktan/tomlc99 2020-11-09 14:02:26 -08:00
CK Tan 94136b9f04 slight change in returning timestamp. now returns a malloc-ed ptr 2020-11-09 14:00:27 -08:00
CK Tan 6c72be57df
Update README.md 2020-11-09 13:45:25 -08:00
CK Tan 893f24e206 rename toml_access_t -> toml_datum_t 2020-11-02 10:08:47 -08:00
CK Tan 3fdd187b2a rename toml_access_t -> toml_datum_t 2020-11-02 10:07:33 -08:00
CK Tan 26fdad9205 readme 2020-11-01 18:56:36 -08:00
CK Tan 5c60d1e15c cleanup 2020-11-01 18:55:16 -08:00
CK Tan f01507cabe readme 2020-11-01 18:41:46 -08:00
CK Tan 6eb7ea27f2 readme 2020-11-01 18:39:32 -08:00
CK Tan 3941e0bade add sample program 2020-11-01 18:31:50 -08:00
CK Tan 7a3e402cee readme 2020-11-01 18:17:31 -08:00
CK Tan a28aae757f readme 2020-11-01 18:05:37 -08:00
CK Tan 6e1f2e3db8 readme 2020-11-01 17:55:33 -08:00
CK Tan 84fd6725e0 Merge branch 'master' of github.com:cktan/tomlc99 2020-11-01 17:53:04 -08:00
CK Tan 71a9fd9772 Add enhanced access methods 2020-11-01 17:52:57 -08:00
CK Tan d17c005da8
Update README.md 2020-11-01 01:18:30 -07:00
CK Tan 3c50f43516
Update README.md 2020-11-01 01:18:00 -07:00
CK Tan 7a3f8afc15
Update README.md 2020-11-01 01:17:17 -07:00
CK Tan 5be06807ad remove use of calloc 2020-10-27 16:59:43 -07:00
CK Tan bc6f2fa6b8 remove use of realloc 2020-10-27 03:32:22 -07:00
CK Tan 2e8feafae8 enhance toml_set_memutil to assign default 2020-10-26 13:52:28 -07:00
CK Tan 1901ac3166 remove use of setjmp/longjmp 2020-10-25 18:48:14 -07:00
CK Tan ddb9cc4eeb
Merge pull request #43 from TNTINC/patch-1
Update README.md
2020-09-21 21:47:58 -07:00
Fridfinnur M 4b42548c3d
Update README.md 2020-09-18 16:39:53 +00:00
CK Tan e3a03f5ec7
Update README.md 2020-08-18 14:46:20 -07:00
CK Tan 9ea8eedd85 updated Note.txt to reflect expected error conditions in test2/ 2020-07-14 16:57:35 -07:00
CK Tan b539e3f20e minor 2020-07-09 16:50:57 -07:00
CK Tan d879b89737
Merge pull request #42 from DerekCresswell/reformat-readme
Use custom types to help with clarity between raw and processed types
2020-07-09 16:48:05 -07:00
dcresswell 5d1d8e3389 Adds toml_raw_t to seperate raw and processed data
This just makes it more obvious that toml_raw_at returns a incomplete
bit of data. Users can easily see how to use rto* with this.
2020-07-08 21:45:48 -07:00
dcresswell e1e7369907 Reformats Readme to provide better instructions
This makes the Readme much cleaner so new users have an easier time
starting out with this library.
2020-07-08 21:39:34 -07:00
CK Tan a1d23056ac fixed const qual warning as suggested by @mheily 2020-07-08 02:26:12 -07:00
CK Tan 7af2dbf91f use static decl for local STRDUP, STRNDUP funcs 2020-07-08 02:13:18 -07:00
CK Tan 8a5050696f
Merge pull request #39 from gotnone/editorconfig
Add editorconfig file
2020-07-07 22:19:23 -07:00
CK Tan a94dbebc17
Merge pull request #40 from gotnone/const
Add const qualifiers for access functions
2020-07-07 22:15:40 -07:00
Stanley Pinchak f25dee1273 Add editorconfig file 2020-06-17 17:43:36 -05:00
Stanley Pinchak 8278e68df9 Add const qualifiers for access functions
The access functions do not mutate the toml_table.
Add const qualifiers to the parameters which are not mutated.
2020-06-17 17:39:24 -05:00
CK Tan c59fa7a058 Note.txt 2020-06-13 16:19:27 -07:00
CK Tan 5bc8f64fdd Note.txt 2020-06-13 16:18:57 -07:00
CK Tan cdbb9decfb Fixed issue #33 2020-02-08 12:54:09 -08:00
CK Tan eaa5d04539 fix memory leak 2020-01-18 10:46:14 -08:00
CK Tan 4078d23a33 restructure and clean up toml_rtos 2019-12-29 11:55:17 -08:00
CK Tan 416be8de63 re-indent 2019-12-29 11:35:24 -08:00
CK Tan 10787cbff9 re-indent 2019-12-29 11:34:12 -08:00
CK Tan 532239d83a
Merge pull request #30 from theakman2/issue_29_strndup_memory_leak_fix
Fix for #29: STRNDUP memory leak fix
2019-12-29 11:30:30 -08:00
Theak 7efd69ca83 Fix for #29: STRNDUP memory leak fix 2019-12-29 14:09:02 +00:00
CK Tan b92d6a2c82 remove use of dummy errbuf due to benign gcc warnings 2019-11-03 09:06:01 -08:00
CK Tan f31bcd0adf prettier prints 2019-10-10 17:34:45 -07:00
CK Tan f782b12864 test output from jq needs to be sorted 2019-10-10 17:32:54 -07:00
CK Tan 2453664abb updated test2/run.sh 2019-10-10 04:15:45 -07:00
CK Tan 987f4ef0d7 refine run.sh 2019-10-10 01:28:09 -07:00
CK Tan 685ca97470 refine run.sh 2019-10-10 01:23:20 -07:00
CK Tan 896561d5b7 update test2 2019-10-10 01:11:52 -07:00
CK Tan 9ed009b950 simplify example in README.md 2019-10-09 16:44:07 -07:00
CK Tan a1a8911503
Updated Readme.md
v0.5 compliant
2019-10-09 16:40:11 -07:00
CK Tan c32a6e92f1 v0.5 compliant 2019-10-08 16:58:18 -07:00
CK Tan 63793f92ef make STRDUP and STRNDUP static 2019-10-04 10:08:57 -07:00
CK Tan bc951780ab tabify 2019-10-02 01:12:46 -07:00
CK Tan 15f44eba49 tabify 2019-10-02 01:11:34 -07:00
CK Tan c5907e1504 use memutil functions for strdup and strndup 2019-09-27 16:32:59 -07:00
CK Tan 9394192bfc fix issue #22: add toml_set_memutil 2019-09-26 22:29:25 -07:00
CK Tan 4a31cd8cbf use the default CC per makefile var 2019-09-12 21:56:11 -07:00
CK Tan f12c8f00b4
Merge pull request #20 from Miniwoffer/gitignore
Added binary files to the gitignore
2019-08-16 05:04:20 -07:00
CK Tan 3bc235331f Handle more test cases 2019-08-16 04:35:14 -07:00
Odin Hultgren Van Der Horst aba3905eb8 Added binary files to the gitignore 2019-08-16 09:07:48 +02:00
CK Tan b701a09579
Merge pull request #17 from obreitwi/feature/libtoml.so
Add rules for libtoml.so to Makefile
2019-06-24 09:31:04 -07:00
Oliver Breitwieser 93cae7a0e6 Add rules for libtoml.so to Makefile 2019-06-24 16:53:21 +02:00
CK Tan e93b40c3ea
Merge pull request #16 from obloquy/master
Allow 0x/0o/0b integer prefixes
2019-05-30 18:24:12 -07:00
Jesper Peterson 386dccc84f Allow 0x/0o/0b integer prefixed in accordance with https://github.com/toml-lang/toml#integer 2019-05-10 17:17:29 +10:00
CK Tan bd76f1276e support SPC separator in timestamp 2019-03-06 11:44:14 -08:00
CK Tan c4325a38fb add toml_array_type() api 2019-02-27 11:31:49 -08:00
CK Tan 0ce0c0d9d0 handle make DEBUG=1 2019-02-19 15:52:01 -08:00
CK Tan 05e27a7cab copyright years 2019-02-19 10:51:51 -08:00
CK Tan 43f7a52064 Fix #14 and #13 2019-02-16 17:37:59 -08:00
CK Tan 3b6fe37d66
Merge pull request #12 from gotnone/helperfuncs
Helperfuncs
2019-01-09 12:48:25 -08:00
Stanley Pinchak 3fed0ab455 Add helper functions to access key
New functions for read only access to the key of toml_array_t and
toml_table_t structs
2019-01-08 13:31:10 -06:00
Stanley Pinchak b53c016877 Add helper function for arrays
New function for read only access to the internal nelem member of
toml_array_t structs
2019-01-08 13:31:04 -06:00
Stanley Pinchak 88eacb3fe0 Add helper functions for tables
New functions for read only access to internal nkval, narr and ntab
members of toml_table_t structs.
2019-01-08 13:30:54 -06:00
CK Tan f06bf3a5cc
Merge pull request #10 from iain-anderson/toml_cat_patch
Fix toml_cat abort on empty array
2018-07-09 18:45:26 -07:00
Iain Anderson 55334019ac Fix toml_cat abort on empty array 2018-07-04 14:30:45 +01:00
CK Tan 56c42b7aed Fix #7: toml_utf8_to_ucs() returns incorrect results 2018-06-08 14:41:44 -07:00
CK Tan 624013252b Small fix for WIN32 2018-01-04 03:18:08 -08:00
CK Tan 95ee4414f6
Merge pull request #6 from bamchoh/patch-2
string literal needs double quotation
2018-01-04 03:14:59 -08:00
bamchoh 79b40abd94
string literal needs double quatation 2018-01-04 18:56:40 +09:00
CK Tan 01ecb88d13 Fix issue #3 2017-11-18 11:57:45 -08:00
CK Tan edc6a13246 add readme 2017-11-17 13:52:59 -08:00
CK Tan a0b45225e2 Fixes as suggested by mytchel
1. A critical bug in toml_parse_file when the file is empty
2. Add toml_cat.c to makefile
3. Other misc fixes related to error handling
2017-08-07 14:47:59 -07:00
CK Tan e6a6db8bda Fix some warnings and provide strndup for WIN32 2017-08-06 16:02:12 -07:00
CK Tan 287defadb1 Add github link to license text 2017-04-16 23:19:51 -07:00
CK Tan a0b38a34ea Add comment 2017-03-18 14:23:25 -07:00
CK Tan 09de99f7a8 Init. 2017-03-18 14:20:51 -07:00
CK Tan 75aa7b2d5a Initial commit 2017-03-18 14:15:49 -07:00
17 changed files with 539 additions and 525 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use guix chicken chicken-r7rs chicken-rfc3339 chicken-coops chicken-test chicken-salmonella chicken-salmonella-html-report

View File

@ -1,14 +1,14 @@
##
# Toml
#
# @file
# @version 0.1
.PHONY: salmonella
salmonella:
rm -rf report
rm -f toml*.so
salmonella --keep-repo --repo-dir=./petri-dish; \
salmonella-html-report ./salmonella.log report
# end
##
# Toml
#
# @file
# @version 0.1
.PHONY: salmonella
salmonella:
rm -rf report
rm -f toml*.so
salmonella --keep-repo --repo-dir=./petri-dish; \
salmonella-html-report ./salmonella.log report
# end

View File

@ -1,67 +1,52 @@
(import (r7rs)
(scheme base)
(scheme write)
(srfi 64)
(srfi 152)
(test)
(rfc3339)
(toml))
(define (tap-test-runner)
(let ((runner (test-runner-null))
(testcounter 0))
(display "TAP version 13\n")
(test-runner-on-test-end! runner
(lambda (runner)
(set! testcounter (+ testcounter 1))
(display
(string-append
(if (test-passed? runner) "ok " "not ok ")
(number->string testcounter) " - "
(string-join (test-runner-group-path runner) " - ")
" - " (test-runner-test-name runner)
(if (eq? 'skip (test-result-kind runner)) "# SKIP" "")
"\n"))))
(test-runner-on-final! runner
(lambda (runner)
(display (string-append "1.." (number->string testcounter) "\n"))))
runner))
(test-group "Basic"
(let ((tdat (table-from-file "basic.toml")))
(test "7 Key-Value-Pairs"
7 (toml-count-key-vals tdat))
(test "Field name is TOML"
"TOML" (toml-string tdat "name"))
(test "Field language is Chicken Scheme"
"Chicken Scheme" (toml-string tdat "language"))
(test "has-bool is #t"
#t (toml-bool tdat "has-bool"))
(test "int is 5"
5 (toml-int tdat "int"))
(test "double is 10.8"
10.8 (toml-double tdat "double"))
(test "timestamp parsing"
#(1979 05 27 07 32 00 0.0 0)
(rfc3339->vector (toml-timestamp tdat "timestamp")))))
(test-runner-factory
(lambda () (tap-test-runner)))
(test-group "Table"
(let ((tdat (table-from-file "table.toml")))
(test "No top-level Key-Value-Pairs"
0 (toml-count-key-vals tdat))
(test "One top-level table"
1 (toml-count-tables tdat))
(let ((servertbl (toml-table tdat "server")))
(test "\"server\" table has 2 Key-Value-Pairs"
2 (toml-count-key-vals servertbl))
(test "host is www.example.com"
"www.example.com" (toml-string servertbl "host"))
(test "timestamp parsing"
#(2022 09 09 0 0 0 0.0 0)
(rfc3339->vector (toml-timestamp servertbl "timestamp"))))))
(test-begin "Basic")
(test-group "Array"
(let* ((tdat (table-from-file "table.toml"))
(tserv (toml-table tdat "server"))
(tarr (toml-array tserv "port")))
(test "There is one array"
1 (toml-count-arrays tserv))
(test "The array has three entries"
3 (toml-count-entries tarr))
(test "Element 0 is 8080"
8080 (toml-int tarr 0))
(test "Element 2 is 8282"
8282 (toml-int tarr 2))))
(let ((tdat (table-from-file "basic.toml")))
(test-equal 2 (toml-count-key-vals tdat))
(test-equal "TOML" (toml-string tdat "name"))
(test-equal "Chicken Scheme" (toml-string tdat "language"))
(test-equal #t (toml-bool tdat "has-bool"))
(test-equal 5 (toml-int tdat "int"))
(test-equal 10.8 (toml-double tdat "double"))
(test-equal (rfc3339->string (vector->rfc3339 #(1979 05 27 07 32 00 0 0)))
(rfc3339->string (toml-timestamp tdat "timestamp"))))
(test-end "Basic")
(test-begin "Table")
(let ((tdat (table-from-file "table.toml")))
(test-equal 0 (toml-count-key-vals tdat))
(test-equal 1 (toml-count-tables tdat))
(let ((servertbl (toml-table tdat "server")))
(test-equal 1 (toml-count-key-vals servertbl))
(test-equal "www.example.com" (toml-string servertbl "host"))))
(test-end "Table")
(test-begin "Array")
(let* ((tdat (table-from-file "table.toml"))
(tserv (toml-table tdat "server"))
(tarr (toml-array tserv "port")))
(test-equal 1 (toml-count-arrays tserv))
(test-equal 3 (toml-count-entries tarr))
(test-equal 8080 (toml-int tarr 0))
(test-equal 8282 (toml-int tarr 2)))
(test-end "Array")
(test-exit)

View File

@ -1,3 +1,4 @@
[server]
host = "www.example.com"
port = [ 8080, 8181, 8282 ]
timestamp = 2022-09-09

View File

@ -1,239 +1,234 @@
(import (chicken base)
scheme
(scheme base)
(chicken foreign)
(chicken memory)
(chicken gc)
(chicken format)
rfc3339
coops
coops-primitive-objects)
(foreign-declare "#include <toml.h>")
(define (zeropad n)
(if (< n 10)
(sprintf "0~S" n)
(sprintf "~S" n)))
(define (set-toml-table-finalizer ttable)
(set-finalizer! ttable
(lambda (obj)
((foreign-lambda* void ((c-pointer ttp))
"toml_free(ttp);")
(ptr ttable)))))
(define-class <TomlArray> ()
((ptr :accessor ptr :initform #f)))
(define-class <TomlTable> ()
((ptr :accessor ptr :initform #f)))
(define-method (toml-self-key (tarr <TomlArray>))
((foreign-lambda* c-string ((c-pointer tarr))
"C_return(toml_array_key(tarr));")
(ptr tarr)))
(define-method (toml-count-entries (tarr <TomlArray>))
((foreign-lambda* int ((c-pointer tarr))
"C_return(toml_array_nelem(tarr));")
(ptr tarr)))
(define-method (toml-string (tarr <TomlArray>) (index <integer>))
((foreign-primitive ((c-pointer tarr)
(int index))
"toml_datum_t datum = toml_string_at(tarr, index);"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
"free(datum.u.s);"
"C_values(3, data);")
(ptr tarr) index))
(define-method (toml-bool (tarr <TomlArray>) (index <integer>))
((foreign-lambda* bool ((c-pointer tarr)
(int index))
"C_return(toml_bool_at(tarr, index).u.b);")
(ptr tarr) index))
(define-method (toml-int (tarr <TomlArray>) (index <integer>))
((foreign-lambda* int ((c-pointer tarr)
(int index))
"C_return(toml_int_at(tarr, index).u.i);")
(ptr tarr) index))
(define-method (toml-double (tarr <TomlArray>) (index <integer>))
((foreign-lambda* double ((c-pointer tarr)
(int index))
"C_return(toml_double_at(tarr, index).u.d);")
(ptr tarr) index))
(define-method (toml-timestamp (tarr <TomlArray>) (index <integer>))
(let*-values (((Y M D h m s millis z)
((foreign-primitive ((c-pointer tarr)
(int index))
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
"toml_timestamp_t* stamp = datum.u.ts;"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
"C_string2(&s, stamp->z ?: \"Z\") } ;"
"free(datum.u.ts);"
"C_values(10, data);")
(ptr tarr) index))
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
Y (zeropad M) (zeropad D)
(zeropad h) (zeropad m) (zeropad s)
millis z)))
(string->rfc3339 rfcstr)))
(define-method (toml-array (tarr <TomlArray>) (index <integer>))
(make <TomlArray> 'ptr
((foreign-lambda* c-pointer ((c-pointer tarr)
(int index))
"C_return(toml_array_at(tarr, index));")
(ptr tarr) index)))
(define-method (toml-table (tarr <TomlArray>) (index <integer>))
(make <TomlTable> 'ptr
((foreign-lambda* c-pointer ((c-pointer tarr)
(int index))
"C_return(toml_table_at(tarr, index));")
(ptr tarr) index)))
(define (table-from-file filename)
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
"FILE* fp = fopen(fname, \"r\");"
"char errbuf[200];"
"toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));"
"fclose(fp);"
"C_return(conf);")
filename)))
(when (not (eq? ttp 0))
(let ((tomltable (make <TomlTable> 'ptr ttp)))
(set-toml-table-finalizer tomltable)
tomltable))))
(define (table-from-string str)
(let ((ttp ((foreign-lambda* c-pointer ((c-string confdata))
"char errbuf[200];"
"toml_table_t* conf = toml_parse(confdata, errbuf, sizeof(errbuf));"
"C_return(conf);")
str)))
(when (not (eq? ttp 0))
(let ((tomltable (make <TomlTable> 'ptr ttp)))
(set-toml-table-finalizer tomltable)
tomltable))))
(define (set-toml-datum-string-finalizer tdatum)
(set-finalizer! tdatum
(lambda (obj)
((foreign-lambda* void ((c-pointer tdat))
"free(tdat);")
(ptr tdatum)))))
(define-method (toml-self-key (ttbl <TomlTable>))
((foreign-lambda* c-string ((c-pointer ttbl))
"C_return(toml_table_key(ttbl));")
(ptr ttbl)))
(define-method (toml-key-exists? (ttbl <TomlTable>) (key <string>))
(= 1
((foreign-lambda* int ((c-pointer ttbl)
(c-string key))
"C_return(toml_key_exists(ttbl, key));")
(ptr ttbl) key)))
(define-method (toml-count-key-vals (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_nkval(ttbl));")
(ptr ttbl)))
(define-method (toml-count-arrays (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_narr(ttbl));")
(ptr ttbl)))
(define-method (toml-count-tables (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_ntab(ttbl));")
(ptr ttbl)))
(define-method (toml-key-at (ttbl <TomlTable>) (index <integer>))
((foreign-lambda* c-string ((c-pointer ttbl)
(int index))
"C_return(toml_key_in(ttbl, index));")
(ptr ttbl) index))
(define-method (toml-string (ttbl <TomlTable>) (key <string>))
((foreign-primitive ((c-pointer ttbl)
(c-string key))
"toml_datum_t datum = toml_string_in(ttbl, key);"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
"free(datum.u.s);"
"C_values(3, data);")
(ptr ttbl) key))
(define-method (toml-bool (ttbl <TomlTable>) (key <string>))
((foreign-lambda* bool ((c-pointer ttbl)
(c-string key))
"C_return(toml_bool_in(ttbl, key).u.b);")
(ptr ttbl) key))
(define-method (toml-int (ttbl <TomlTable>) (key <string>))
((foreign-lambda* int ((c-pointer ttbl)
(c-string key))
"C_return(toml_int_in(ttbl, key).u.i);")
(ptr ttbl) key))
(define-method (toml-double (ttbl <TomlTable>) (key <string>))
((foreign-lambda* double ((c-pointer ttbl)
(c-string key))
"C_return(toml_double_in(ttbl, key).u.d);")
(ptr ttbl) key))
(define-method (toml-timestamp (ttbl <TomlTable>) (key <string>))
(let*-values (((Y M D h m s millis z)
((foreign-primitive ((c-pointer ttbl)
(c-string key))
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
"toml_timestamp_t* stamp = datum.u.ts;"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
"C_string2(&s, stamp->z ?: \"Z\") } ;"
"free(datum.u.ts);"
"C_values(10, data);")
(ptr ttbl) key))
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
Y (zeropad M) (zeropad D)
(zeropad h) (zeropad m) (zeropad s)
millis z)))
(string->rfc3339 rfcstr)))
(define-method (toml-array (ttbl <TomlTable>) (key <string>))
(make <TomlArray> 'ptr
((foreign-lambda* c-pointer ((c-pointer ttbl)
(c-string key))
"C_return(toml_array_in(ttbl, key));")
(ptr ttbl) key)))
(define-method (toml-table (ttbl <TomlTable>) (key <string>))
(make <TomlTable> 'ptr
((foreign-lambda* c-pointer ((c-pointer ttbl)
(c-string key))
"C_return(toml_table_in(ttbl, key));")
(ptr ttbl) key)))
(import (chicken base)
scheme
(scheme base)
(chicken foreign)
(chicken memory)
(chicken gc)
(chicken format)
rfc3339
coops
coops-primitive-objects)
(foreign-declare "#include <toml.h>")
(define (zeropad n)
(if (< n 10)
(sprintf "0~S" n)
(sprintf "~S" n)))
(define (set-toml-table-finalizer ttable)
(set-finalizer! ttable
(lambda (obj)
((foreign-lambda* void ((c-pointer ttp))
"toml_free(ttp);")
(ptr ttable)))))
(define-class <TomlArray> ()
((ptr :accessor ptr :initform #f)))
(define-class <TomlTable> ()
((ptr :accessor ptr :initform #f)))
(define-method (toml-self-key (tarr <TomlArray>))
((foreign-lambda* c-string ((c-pointer tarr))
"C_return(toml_array_key(tarr));")
(ptr tarr)))
(define-method (toml-count-entries (tarr <TomlArray>))
((foreign-lambda* int ((c-pointer tarr))
"C_return(toml_array_nelem(tarr));")
(ptr tarr)))
(define-method (toml-string (tarr <TomlArray>) (index <integer>))
((foreign-primitive ((c-pointer tarr)
(int index))
"toml_datum_t datum = toml_string_at(tarr, index);"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
"free(datum.u.s);"
"C_values(3, data);")
(ptr tarr) index))
(define-method (toml-bool (tarr <TomlArray>) (index <integer>))
((foreign-lambda* bool ((c-pointer tarr)
(int index))
"C_return(toml_bool_at(tarr, index).u.b);")
(ptr tarr) index))
(define-method (toml-int (tarr <TomlArray>) (index <integer>))
((foreign-lambda* int ((c-pointer tarr)
(int index))
"C_return(toml_int_at(tarr, index).u.i);")
(ptr tarr) index))
(define-method (toml-double (tarr <TomlArray>) (index <integer>))
((foreign-lambda* double ((c-pointer tarr)
(int index))
"C_return(toml_double_at(tarr, index).u.d);")
(ptr tarr) index))
(define-method (toml-timestamp (tarr <TomlArray>) (index <integer>))
(let*-values (((Y M D h m s millis z)
((foreign-primitive ((c-pointer tarr)
(int index))
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
"toml_timestamp_t* stamp = datum.u.ts;"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
"C_string2(&s, stamp->z ?: \"Z\") } ;"
"free(datum.u.ts);"
"C_values(10, data);")
(ptr tarr) index))
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
Y (zeropad M) (zeropad D)
(zeropad h) (zeropad m) (zeropad s)
millis z)))
(string->rfc3339 rfcstr)))
(define-method (toml-array (tarr <TomlArray>) (index <integer>))
(make <TomlArray> 'ptr
((foreign-lambda* c-pointer ((c-pointer tarr)
(int index))
"C_return(toml_array_at(tarr, index));")
(ptr tarr) index)))
(define-method (toml-table (tarr <TomlArray>) (index <integer>))
(make <TomlTable> 'ptr
((foreign-lambda* c-pointer ((c-pointer tarr)
(int index))
"C_return(toml_table_at(tarr, index));")
(ptr tarr) index)))
(define (table-from-file filename)
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
"FILE* fp = fopen(fname, \"r\");"
"char errbuf[200];"
"toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));"
"fclose(fp);"
"C_return(conf);")
filename)))
(when (not (eq? ttp 0))
(let ((tomltable (make <TomlTable> 'ptr ttp)))
(set-toml-table-finalizer tomltable)
tomltable))))
(define (table-from-string str)
(let ((ttp ((foreign-lambda* c-pointer ((c-string confdata))
"char errbuf[200];"
"toml_table_t* conf = toml_parse(confdata, errbuf, sizeof(errbuf));"
"C_return(conf);")
str)))
(when (not (eq? ttp 0))
(let ((tomltable (make <TomlTable> 'ptr ttp)))
(set-toml-table-finalizer tomltable)
tomltable))))
(define (set-toml-datum-string-finalizer tdatum)
(set-finalizer! tdatum
(lambda (obj)
((foreign-lambda* void ((c-pointer tdat))
"free(tdat);")
(ptr tdatum)))))
(define-method (toml-self-key (ttbl <TomlTable>))
((foreign-lambda* c-string ((c-pointer ttbl))
"C_return(toml_table_key(ttbl));")
(ptr ttbl)))
(define-method (toml-key-exists? (ttbl <TomlTable>) (key <string>))
(= 1
((foreign-lambda* int ((c-pointer ttbl)
(c-string key))
"C_return(toml_key_exists(ttbl, key));")
(ptr ttbl) key)))
(define-method (toml-count-key-vals (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_nkval(ttbl));")
(ptr ttbl)))
(define-method (toml-count-arrays (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_narr(ttbl));")
(ptr ttbl)))
(define-method (toml-count-tables (ttbl <TomlTable>))
((foreign-lambda* int ((c-pointer ttbl))
"C_return(toml_table_ntab(ttbl));")
(ptr ttbl)))
(define-method (toml-key-at (ttbl <TomlTable>) (index <integer>))
((foreign-lambda* c-string ((c-pointer ttbl)
(int index))
"C_return(toml_key_in(ttbl, index));")
(ptr ttbl) index))
(define-method (toml-string (ttbl <TomlTable>) (key <string>))
((foreign-primitive ((c-pointer ttbl)
(c-string key))
"toml_datum_t datum = toml_string_in(ttbl, key);"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
"free(datum.u.s);"
"C_values(3, data);")
(ptr ttbl) key))
(define-method (toml-bool (ttbl <TomlTable>) (key <string>))
((foreign-lambda* bool ((c-pointer ttbl)
(c-string key))
"C_return(toml_bool_in(ttbl, key).u.b);")
(ptr ttbl) key))
(define-method (toml-int (ttbl <TomlTable>) (key <string>))
((foreign-lambda* int ((c-pointer ttbl)
(c-string key))
"C_return(toml_int_in(ttbl, key).u.i);")
(ptr ttbl) key))
(define-method (toml-double (ttbl <TomlTable>) (key <string>))
((foreign-lambda* double ((c-pointer ttbl)
(c-string key))
"C_return(toml_double_in(ttbl, key).u.d);")
(ptr ttbl) key))
(define-method (toml-timestamp (ttbl <TomlTable>) (key <string>))
(let*-values (((Y M D h m s millis z)
((foreign-primitive ((c-pointer ttbl)
(c-string key))
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
"toml_timestamp_t* stamp = datum.u.ts;"
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
"C_string2(&s, stamp->z ?: \"Z\") } ;"
"free(datum.u.ts);"
"C_values(10, data);")
(ptr ttbl) key))
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
Y (zeropad M) (zeropad D)
(zeropad h) (zeropad m) (zeropad s)
millis z)))
(string->rfc3339 rfcstr)))
(define-method (toml-array (ttbl <TomlTable>) (key <string>))
(make <TomlArray> 'ptr
((foreign-lambda* c-pointer ((c-pointer ttbl)
(c-string key))
"C_return(toml_array_in(ttbl, key));")
(ptr ttbl) key)))
(define-method (toml-table (ttbl <TomlTable>) (key <string>))
(make <TomlTable> 'ptr
((foreign-lambda* c-pointer ((c-pointer ttbl)
(c-string key))
"C_return(toml_table_in(ttbl, key));")
(ptr ttbl) key)))

View File

@ -1,16 +1,16 @@
;; -*- mode: scheme -*-
((author "Daniel Ziltener")
(synopsis "A Chicken binding to read TOML configuration files")
(category parsing)
(license "MIT")
(version "0.6")
(dependencies r7rs rfc3339 coops)
(test-dependencies srfi-64 srfi-152)
(components
(c-object tomlc99/toml
(source "tomlc99/toml.c"))
(extension toml
(objects tomlc99/toml)
(csc-options "-X" "r7rs" "-R" "r7rs" "-K" "prefix" "-sJ"
"-Itomlc99"))))
;; -*- mode: scheme -*-
((author "Daniel Ziltener")
(synopsis "A Chicken binding to read TOML configuration files")
(category parsing)
(license "MIT")
(version "0.8")
(dependencies r7rs rfc3339 coops)
(test-dependencies test)
(components
(c-object tomlc99/toml
(source "tomlc99/toml.c"))
(extension toml
(objects tomlc99/toml)
(csc-options "-X" "r7rs" "-R" "r7rs" "-K" "prefix" "-sJ"
"-Itomlc99"))))

View File

@ -1,3 +1,6 @@
(repo git "https://gitea.lyrion.ch/zilti/toml.git")
(uri targz "https://gitea.lyrion.ch/zilti/toml/archive/{egg-release}.tar.gz")
(release "0.6")
;; -*- Scheme -*-
(repo git "https://gitea.lyrion.ch/Chicken/toml.git")
(uri targz "https://gitea.lyrion.ch/Chicken/toml/archive/{egg-release}.tar.gz")
(release "0.8")
(release "0.7")
(release "0.6")

241
toml.wiki
View File

@ -1,118 +1,123 @@
[[tags: egg]]
[[toc:]]
== TOML
A Chicken wrapper for the TOML configuration language
=== Requirements
[[/eggref/5/r7rs|r7rs]]
[[/eggref/5/rfc3339|rfc3339]]
[[/eggref/5/coops|coops]]
=== Usage
<enscript language=scheme>
(import toml)
</enscript>
=== Loading TOML configuration
<syntax>(table-from-file FILENAME) --> <TomlTable></syntax>
Loads {{FILENAME}} contents as a TOML configuration.
<syntax>(table-from-string STRING) --> <TomlTable></syntax>
Loads the contents of {{STRING}} as TOML configuration.
=== Tables
<syntax>(toml-self-key TOMLTABLE) --> string</syntax>
Returns the key, if any, to which {{TOMLTABLE}} is assigned.
<syntax>(toml-key-exists? TOMLTABLE KEY) --> bool</syntax>
Checks if {{KEY}} exists in {{TOMLTABLE}}.
<syntax>(toml-count-key-vals TOMLTABLE) --> int</syntax>
<syntax>(toml-count-arrays TOMLTABLE) --> int</syntax>
<syntax>(toml-count-tables TOMLTABLE) --> int</syntax>
Returns the number of key-value entries, arrays, or tables respectively in {{TOMLTABLE}}.
<syntax>(toml-key-at TOMLTABLE INDEX) --> string</syntax>
Returns the table key at position {{INDEX}} in {{TOMLTABLE}}.
<syntax>(toml-string TOMLTABLE KEY) --> string</syntax>
<syntax>(toml-bool TOMLTABLE KEY) --> bool</syntax>
<syntax>(toml-int TOMLTABLE KEY) --> int</syntax>
<syntax>(toml-double TOMLTABLE KEY) --> double</syntax>
<syntax>(toml-timestamp TOMLTABLE KEY) --> rfc3339</syntax>
<syntax>(toml-array TOMLTABLE KEY) --> <TomlArray></syntax>
<syntax>(toml-table TOMLTABLE KEY) --> <TomlTable></syntax>
Returns the element of the given type in {{TOMLTABLE}} at {{KEY}}.
=== Arrays
<syntax>(toml-self-key TOMLARRAY) --> string</syntax>
Returns the key, if any, to which {{TOMLARRAY}} is assigned.
<syntax>(toml-count-entries TOMLARRAY) --> int</syntax>
Returns the number of entries in {{TOMLARRAY}}.
<syntax>(toml-string TOMLARRAY KEY) --> string</syntax>
<syntax>(toml-bool TOMLARRAY KEY) --> bool</syntax>
<syntax>(toml-int TOMLARRAY KEY) --> int</syntax>
<syntax>(toml-double TOMLARRAY KEY) --> double</syntax>
<syntax>(toml-timestamp TOMLARRAY KEY) --> rfc3339</syntax>
<syntax>(toml-array TOMLARRAY KEY) --> <TomlArray></syntax>
<syntax>(toml-table TOMLARRAY KEY) --> <TomlTable></syntax>
Returns the element of the given type in {{TOMLARRAY}} at {{KEY}}.
== About this egg
=== Authors
Daniel Ziltener
CK Tan
=== Repository
The repository of the Chicken wrapper can be found at [[https://gitea.lyrion.ch/zilti/toml|https://gitea.lyrion.ch/zilti/toml]].
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
=== Version History
; 0.6 : first version of the wrapper
=== License
MIT License
Copyright (c) Daniel Ziltener
https://gitea.lyrion.ch/zilti/toml
Copyright (c) CK Tan
https://github.com/cktan/tomlc99
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[[tags: egg]]
[[toc:]]
== TOML
A Chicken wrapper for the TOML configuration language
=== Requirements
[[/eggref/5/r7rs|r7rs]]
[[/eggref/5/rfc3339|rfc3339]]
[[/eggref/5/coops|coops]]
=== Usage
<enscript language=scheme>
(import toml)
</enscript>
=== Loading TOML configuration
<syntax>(table-from-file FILENAME) --> <TomlTable></syntax>
Loads {{FILENAME}} contents as a TOML configuration.
<syntax>(table-from-string STRING) --> <TomlTable></syntax>
Loads the contents of {{STRING}} as TOML configuration.
=== Tables
<syntax>(toml-self-key TOMLTABLE) --> string</syntax>
Returns the key, if any, to which {{TOMLTABLE}} is assigned.
<syntax>(toml-key-exists? TOMLTABLE KEY) --> bool</syntax>
Checks if {{KEY}} exists in {{TOMLTABLE}}.
<syntax>(toml-count-key-vals TOMLTABLE) --> int</syntax>
<syntax>(toml-count-arrays TOMLTABLE) --> int</syntax>
<syntax>(toml-count-tables TOMLTABLE) --> int</syntax>
Returns the number of key-value entries, arrays, or tables respectively in {{TOMLTABLE}}.
<syntax>(toml-key-at TOMLTABLE INDEX) --> string</syntax>
Returns the table key at position {{INDEX}} in {{TOMLTABLE}}.
<syntax>(toml-string TOMLTABLE KEY) --> string</syntax>
<syntax>(toml-bool TOMLTABLE KEY) --> bool</syntax>
<syntax>(toml-int TOMLTABLE KEY) --> int</syntax>
<syntax>(toml-double TOMLTABLE KEY) --> double</syntax>
<syntax>(toml-timestamp TOMLTABLE KEY) --> rfc3339</syntax>
<syntax>(toml-array TOMLTABLE KEY) --> <TomlArray></syntax>
<syntax>(toml-table TOMLTABLE KEY) --> <TomlTable></syntax>
Returns the element of the given type in {{TOMLTABLE}} at {{KEY}}.
=== Arrays
<syntax>(toml-self-key TOMLARRAY) --> string</syntax>
Returns the key, if any, to which {{TOMLARRAY}} is assigned.
<syntax>(toml-count-entries TOMLARRAY) --> int</syntax>
Returns the number of entries in {{TOMLARRAY}}.
<syntax>(toml-string TOMLARRAY KEY) --> string</syntax>
<syntax>(toml-bool TOMLARRAY KEY) --> bool</syntax>
<syntax>(toml-int TOMLARRAY KEY) --> int</syntax>
<syntax>(toml-double TOMLARRAY KEY) --> double</syntax>
<syntax>(toml-timestamp TOMLARRAY KEY) --> rfc3339</syntax>
<syntax>(toml-array TOMLARRAY KEY) --> <TomlArray></syntax>
<syntax>(toml-table TOMLARRAY KEY) --> <TomlTable></syntax>
Returns the element of the given type in {{TOMLARRAY}} at {{KEY}}.
== About this egg
=== Authors
Daniel Ziltener
CK Tan
=== Repository
The repository of the Chicken wrapper can be found at [[https://gitea.lyrion.ch/Chicken/toml|https://gitea.lyrion.ch/Chicken/toml]].
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
=== Version History
; 0.8 : updated the tomlc99 dependency
; 0.7 : fixed an issue with timestamp parsing
; 0.6 : first version of the wrapper
=== License
MIT License
Copyright (c) Daniel Ziltener
https://gitea.lyrion.ch/zilti/toml
Copyright (c) CK Tan
https://github.com/cktan/tomlc99
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -37,8 +37,11 @@ install: all
install $(LIB) ${prefix}/lib
install $(LIB_SHARED) ${prefix}/lib
ifeq "$(prefix)" "/usr/local"
ifneq ("$(wildcard $(PCFILE))","")
install $(PCFILE) /usr/local/lib/pkgconfig
endif
endif
clean:
rm -f *.o $(EXEC) $(LIB) $(LIB_SHARED)

View File

@ -6,7 +6,7 @@ If you are looking for a C++ library, you might try this wrapper: [https://githu
* Compatible with [TOML v1.0.0](https://toml.io/en/v1.0.0).
* Tested with multiple test suites, including
[BurntSushi/toml-test](https://github.com/BurntSushi/toml-test) and
[toml-lang/toml-test](https://github.com/toml-lang/toml-test) and
[iarna/toml-spec-tests](https://github.com/iarna/toml-spec-tests).
* Provides very simple and intuitive interface.
@ -174,7 +174,7 @@ Alternatively, specify `make install prefix=/a/file/path` to install into
## Testing
To test against the standard test set provided by BurntSushi/toml-test:
To test against the standard test set provided by toml-lang/toml-test:
```sh
% make
@ -191,4 +191,4 @@ To test against the standard test set provided by iarna/toml:
% cd test2
% bash build.sh # do this once
% bash run.sh # this will run the test suite
```
```

9
tomlc99/test1/build.sh Normal file → Executable file
View File

@ -1,9 +1,6 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mkdir -p $DIR/goworkspace
export GOPATH=$DIR/goworkspace
go get github.com/BurntSushi/toml-test@latest # install test suite
go install github.com/BurntSushi/toml/cmd/toml-test-decoder@latest # e.g., install my parser
cp $GOPATH/bin/* .
export GOBIN=$DIR
go install github.com/toml-lang/toml-test/cmd/toml-test@latest # install test suite

6
tomlc99/test1/run.sh Normal file → Executable file
View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rm -f tests
ln -s ./goworkspace/pkg/mod/github.com/\!burnt\!sushi/toml-test@v0.1.0/tests
./toml-test ../toml_json
$DIR/toml-test $DIR/../toml_json

3
tomlc99/test2/build.sh Normal file → Executable file
View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[ -d toml-spec-tests ] || git clone https://github.com/cktan/toml-spec-tests.git

12
tomlc99/test2/run.sh Normal file → Executable file
View File

@ -1,4 +1,6 @@
if ! (which jq >& /dev/null); then
#!/usr/bin/env bash
if ! (which jq >& /dev/null); then
echo "ERROR: please install the 'jq' utility"
exit 1
fi
@ -12,11 +14,11 @@ for i in toml-spec-tests/values/*.toml; do
fname="${fname%.*}"
echo -n $fname ' '
res='[OK]'
if (../toml_json $fname.toml >& $fname.json.out); then
if (../toml_json $fname.toml >& $fname.json.out); then
jq -S . $fname.json.out > t.json
mv t.json $fname.json.out
if [ -f $fname.json ]; then
if ! (diff $fname.json $fname.json.out >& /dev/null); then
if ! (diff $fname.json $fname.json.out >& /dev/null); then
res='[FAILED]'
else
rm -f $fname.json.out
@ -32,10 +34,10 @@ done
#
# NEGATIVE tests
#
for i in toml-spec-tests/errors/*.toml; do
for i in toml-spec-tests/errors/*.toml; do
echo -n $i ' '
res='[OK]'
if (../toml_json $i >& $i.json.out); then
if (../toml_json $i >& $i.json.out); then
res='[FAILED]'
fi
echo ... $res

View File

@ -45,6 +45,7 @@ void toml_set_memutil(void *(*xxmalloc)(size_t), void (*xxfree)(void *)) {
ppfree = xxfree;
}
#define ALIGN8(sz) (((sz) + 7) & ~7)
#define MALLOC(a) ppmalloc(a)
#define FREE(a) ppfree(a)
@ -53,7 +54,7 @@ void toml_set_memutil(void *(*xxmalloc)(size_t), void (*xxfree)(void *)) {
#define calloc(x, y) error - forbidden - use CALLOC instead
static void *CALLOC(size_t nmemb, size_t sz) {
int nb = sz * nmemb;
int nb = ALIGN8(sz) * nmemb;
void *p = MALLOC(nb);
if (p) {
memset(p, 0, nb);
@ -220,8 +221,8 @@ int toml_ucs_to_utf8(int64_t code, char buf[6]) {
110xxxxx 10xxxxxx
*/
if (code <= 0x000007FF) {
buf[0] = (unsigned char) (0xc0 | (code >> 6));
buf[1] = (unsigned char) (0x80 | (code & 0x3f));
buf[0] = (unsigned char)(0xc0 | (code >> 6));
buf[1] = (unsigned char)(0x80 | (code & 0x3f));
return 2;
}
@ -229,9 +230,9 @@ int toml_ucs_to_utf8(int64_t code, char buf[6]) {
1110xxxx 10xxxxxx 10xxxxxx
*/
if (code <= 0x0000FFFF) {
buf[0] = (unsigned char) (0xe0 | (code >> 12));
buf[1] = (unsigned char) (0x80 | ((code >> 6) & 0x3f));
buf[2] = (unsigned char) (0x80 | (code & 0x3f));
buf[0] = (unsigned char)(0xe0 | (code >> 12));
buf[1] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
buf[2] = (unsigned char)(0x80 | (code & 0x3f));
return 3;
}
@ -239,10 +240,10 @@ int toml_ucs_to_utf8(int64_t code, char buf[6]) {
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
if (code <= 0x001FFFFF) {
buf[0] = (unsigned char) (0xf0 | (code >> 18));
buf[1] = (unsigned char) (0x80 | ((code >> 12) & 0x3f));
buf[2] = (unsigned char) (0x80 | ((code >> 6) & 0x3f));
buf[3] = (unsigned char) (0x80 | (code & 0x3f));
buf[0] = (unsigned char)(0xf0 | (code >> 18));
buf[1] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
buf[2] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
buf[3] = (unsigned char)(0x80 | (code & 0x3f));
return 4;
}
@ -250,11 +251,11 @@ int toml_ucs_to_utf8(int64_t code, char buf[6]) {
111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
if (code <= 0x03FFFFFF) {
buf[0] = (unsigned char) (0xf8 | (code >> 24));
buf[1] = (unsigned char) (0x80 | ((code >> 18) & 0x3f));
buf[2] = (unsigned char) (0x80 | ((code >> 12) & 0x3f));
buf[3] = (unsigned char) (0x80 | ((code >> 6) & 0x3f));
buf[4] = (unsigned char) (0x80 | (code & 0x3f));
buf[0] = (unsigned char)(0xf8 | (code >> 24));
buf[1] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));
buf[2] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
buf[3] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
buf[4] = (unsigned char)(0x80 | (code & 0x3f));
return 5;
}
@ -262,12 +263,12 @@ int toml_ucs_to_utf8(int64_t code, char buf[6]) {
1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
if (code <= 0x7FFFFFFF) {
buf[0] = (unsigned char) (0xfc | (code >> 30));
buf[1] = (unsigned char) (0x80 | ((code >> 24) & 0x3f));
buf[2] = (unsigned char) (0x80 | ((code >> 18) & 0x3f));
buf[3] = (unsigned char) (0x80 | ((code >> 12) & 0x3f));
buf[4] = (unsigned char) (0x80 | ((code >> 6) & 0x3f));
buf[5] = (unsigned char) (0x80 | (code & 0x3f));
buf[0] = (unsigned char)(0xfc | (code >> 30));
buf[1] = (unsigned char)(0x80 | ((code >> 24) & 0x3f));
buf[2] = (unsigned char)(0x80 | ((code >> 18) & 0x3f));
buf[3] = (unsigned char)(0x80 | ((code >> 12) & 0x3f));
buf[4] = (unsigned char)(0x80 | ((code >> 6) & 0x3f));
buf[5] = (unsigned char)(0x80 | (code & 0x3f));
return 6;
}
@ -411,8 +412,10 @@ static void *expand(void *p, int sz, int newsz) {
if (!s)
return 0;
memcpy(s, p, sz);
FREE(p);
if (p) {
memcpy(s, p, sz);
FREE(p);
}
return s;
}
@ -422,8 +425,10 @@ static void **expand_ptrarr(void **p, int n) {
return 0;
s[n] = 0;
memcpy(s, p, n * sizeof(void *));
FREE(p);
if (p) {
memcpy(s, p, n * sizeof(void *));
FREE(p);
}
return s;
}
@ -2211,6 +2216,7 @@ int toml_rtos(toml_raw_t src, char **ret) {
if (!src)
return -1;
// for strings, first char must be a s-quote or d-quote
int qchar = src[0];
int srclen = strlen(src);
if (!(qchar == '\'' || qchar == '"')) {
@ -2219,12 +2225,14 @@ int toml_rtos(toml_raw_t src, char **ret) {
// triple quotes?
if (qchar == src[1] && qchar == src[2]) {
multiline = 1;
sp = src + 3;
sq = src + srclen - 3;
/* last 3 chars in src must be qchar */
if (!(sp <= sq && sq[0] == qchar && sq[1] == qchar && sq[2] == qchar))
multiline = 1; // triple-quote implies multiline
sp = src + 3; // first char after quote
sq = src + srclen - 3; // first char of ending quote
if (!(sp <= sq && sq[0] == qchar && sq[1] == qchar && sq[2] == qchar)) {
// last 3 chars in src must be qchar
return -1;
}
/* skip new line immediate after qchar */
if (sp[0] == '\n')
@ -2233,13 +2241,18 @@ int toml_rtos(toml_raw_t src, char **ret) {
sp += 2;
} else {
sp = src + 1;
sq = src + srclen - 1;
/* last char in src must be qchar */
if (!(sp <= sq && *sq == qchar))
sp = src + 1; // first char after quote
sq = src + srclen - 1; // ending quote
if (!(sp <= sq && *sq == qchar)) {
/* last char in src must be qchar */
return -1;
}
}
// at this point:
// sp points to first valid char after quote.
// sq points to one char beyond last valid char.
// string len is (sq - sp).
if (qchar == '\'') {
*ret = norm_lit_str(sp, sq - sp, multiline, 0, 0);
} else {

View File

@ -26,7 +26,7 @@
#define TOML_H
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#pragma warning(disable : 4996)
#endif
#include <stdint.h>

View File

@ -91,15 +91,16 @@ static void print_raw(const char *s) {
else
millisec[0] = 0;
if (ts.year && ts.hour) {
printf("{\"type\":\"datetime\",\"value\":\"%04d-%02d-%02dT%02d:%02d:%02d%"
printf("{\"type\":\"%s\",\"value\":\"%04d-%02d-%02dT%02d:%02d:%02d%"
"s%s\"}",
(ts.z ? "datetime" : "datetime-local"),
*ts.year, *ts.month, *ts.day, *ts.hour, *ts.minute, *ts.second,
millisec, (ts.z ? ts.z : ""));
} else if (ts.year) {
printf("{\"type\":\"date\",\"value\":\"%04d-%02d-%02d\"}", *ts.year,
printf("{\"type\":\"date-local\",\"value\":\"%04d-%02d-%02d\"}", *ts.year,
*ts.month, *ts.day);
} else if (ts.hour) {
printf("{\"type\":\"time\",\"value\":\"%02d:%02d:%02d%s\"}", *ts.hour,
printf("{\"type\":\"time-local\",\"value\":\"%02d:%02d:%02d%s\"}", *ts.hour,
*ts.minute, *ts.second, millisec);
}
} else {
@ -149,36 +150,43 @@ static void print_table_array(toml_array_t *curarr) {
}
static void print_array(toml_array_t *curarr) {
toml_array_t *arr;
const char *raw;
int i;
if (toml_array_kind(curarr) == 't') {
print_table_array(curarr);
return;
}
printf("{\"type\":\"array\",\"value\":[");
switch (toml_array_kind(curarr)) {
printf("[");
case 'v':
for (i = 0; 0 != (raw = toml_raw_at(curarr, i)); i++) {
printf("%s", i > 0 ? "," : "");
print_raw(raw);
}
break;
const char *raw;
toml_array_t *arr;
toml_table_t *tab;
case 'a':
for (i = 0; 0 != (arr = toml_array_at(curarr, i)); i++) {
printf("%s", i > 0 ? "," : "");
const int n = toml_array_nelem(curarr);
for (int i = 0; i < n; i++) {
printf("%s", i > 0 ? "," : "");
if (0 != (arr = toml_array_at(curarr, i))) {
print_array(arr);
continue;
}
break;
default:
break;
if (0 != (tab = toml_table_at(curarr, i))) {
print_table(tab);
continue;
}
raw = toml_raw_at(curarr, i);
if (raw) {
print_raw(raw);
continue;
}
fflush(stdout);
fprintf(stderr, "ERROR: unable to decode value in array\n");
exit(1);
}
printf("]}");
printf("]");
}
static void cat(FILE *fp) {