{"id":13493424,"url":"https://github.com/cktan/tomlc99","last_synced_at":"2025-10-21T05:57:20.797Z","repository":{"id":37492998,"uuid":"85432505","full_name":"cktan/tomlc99","owner":"cktan","description":"TOML C library","archived":false,"fork":false,"pushed_at":"2024-03-16T07:22:47.000Z","size":198,"stargazers_count":561,"open_issues_count":10,"forks_count":107,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-10-31T07:34:19.302Z","etag":null,"topics":["c","toml","toml-parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cktan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-18T21:15:48.000Z","updated_at":"2024-10-29T01:03:02.000Z","dependencies_parsed_at":"2022-08-02T01:09:48.581Z","dependency_job_id":"8a664c28-84ad-4c73-be83-a6fab88d1f50","html_url":"https://github.com/cktan/tomlc99","commit_stats":{"total_commits":134,"total_committers":18,"mean_commits":7.444444444444445,"dds":0.5074626865671642,"last_synced_commit":"894902820a3ea2f1ec470cd7fe338bde54045cf5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlc99","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlc99/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlc99/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cktan%2Ftomlc99/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cktan","download_url":"https://codeload.github.com/cktan/tomlc99/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246021436,"owners_count":20710939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","toml","toml-parser"],"created_at":"2024-07-31T19:01:15.088Z","updated_at":"2025-10-21T05:57:20.770Z","avatar_url":"https://github.com/cktan.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# tomlc99\n\n\u003e\n\u003e **Note: OBSOLETED. There is a newer version of this library available at [tomlc17](https://github.com/cktan/tomlc17), which is compatible with c99.**\n\u003e\n\nTOML in c99; v1.0 compliant.\n\nIf you are looking for a C++ library, you might try this wrapper: [https://github.com/cktan/tomlcpp](https://github.com/cktan/tomlcpp).\n\n* Compatible with [TOML v1.0.0](https://toml.io/en/v1.0.0).\n* Tested with multiple test suites, including\n[toml-lang/toml-test](https://github.com/toml-lang/toml-test) and\n[iarna/toml-spec-tests](https://github.com/iarna/toml-spec-tests).\n* Provides very simple and intuitive interface.\n\n\n## Usage\n\nPlease see the `toml.h` file for details. The following is a simple example that\nparses this config file:\n\n```toml\n[server]\n\thost = \"www.example.com\"\n\tport = [ 8080, 8181, 8282 ]\n```\n\nThese are the usual steps for getting values from a file:\n\n1. Parse the TOML file.\n2. Traverse and locate a table in TOML.\n3. Extract values from the table.\n4. Free up allocated memory.\n\nBelow is an example of parsing the values from the example table.\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n#include \u003cerrno.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"toml.h\"\n\nstatic void error(const char* msg, const char* msg1)\n{\n    fprintf(stderr, \"ERROR: %s%s\\n\", msg, msg1?msg1:\"\");\n    exit(1);\n}\n\n\nint main()\n{\n    FILE* fp;\n    char errbuf[200];\n\n    // 1. Read and parse toml file\n    fp = fopen(\"sample.toml\", \"r\");\n    if (!fp) {\n        error(\"cannot open sample.toml - \", strerror(errno));\n    }\n\n    toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));\n    fclose(fp);\n\n    if (!conf) {\n        error(\"cannot parse - \", errbuf);\n    }\n\n    // 2. Traverse to a table.\n    toml_table_t* server = toml_table_in(conf, \"server\");\n    if (!server) {\n        error(\"missing [server]\", \"\");\n    }\n\n    // 3. Extract values\n    toml_datum_t host = toml_string_in(server, \"host\");\n    if (!host.ok) {\n        error(\"cannot read server.host\", \"\");\n    }\n\n    toml_array_t* portarray = toml_array_in(server, \"port\");\n    if (!portarray) {\n        error(\"cannot read server.port\", \"\");\n    }\n\n    printf(\"host: %s\\n\", host.u.s);\n    printf(\"port: \");\n    for (int i = 0; ; i++) {\n        toml_datum_t port = toml_int_at(portarray, i);\n        if (!port.ok) break;\n        printf(\"%d \", (int)port.u.i);\n    }\n    printf(\"\\n\");\n\n    // 4. Free memory\n    free(host.u.s);\n    toml_free(conf);\n    return 0;\n}\n```\n\n#### Accessing Table Content\n\nTOML tables are dictionaries where lookups are done using string keys. In\ngeneral, all access functions on tables are named `toml_*_in(...)`.\n\nIn the normal case, you know the key and its content type, and retrievals can be done\nusing one of these functions:\n```c\ntoml_string_in(tab, key);\ntoml_bool_in(tab, key);\ntoml_int_in(tab, key);\ntoml_double_in(tab, key);\ntoml_timestamp_in(tab, key);\ntoml_table_in(tab, key);\ntoml_array_in(tab, key);\n```\n\nYou can also interrogate the keys in a table using an integer index:\n```c\ntoml_table_t* tab = toml_parse_file(...);\nfor (int i = 0; ; i++) {\n    const char* key = toml_key_in(tab, i);\n    if (!key) break;\n    printf(\"key %d: %s\\n\", i, key);\n}\n```\n\n#### Accessing Array Content\n\nTOML arrays can be deref-ed using integer indices. In general, all access methods on arrays are named `toml_*_at()`.\n\nTo obtain the size of an array:\n```c\nint size = toml_array_nelem(arr);\n```\n\nTo obtain the content of an array, use a valid index and call one of these functions:\n```c\ntoml_string_at(arr, idx);\ntoml_bool_at(arr, idx);\ntoml_int_at(arr, idx);\ntoml_double_at(arr, idx);\ntoml_timestamp_at(arr, idx);\ntoml_table_at(arr, idx);\ntoml_array_at(arr, idx);\n```\n\n#### toml_datum_t\n\nSome `toml_*_at` and `toml_*_in` functions return a toml_datum_t\nstructure. The `ok` flag in the structure indicates if the function\ncall was successful. If so, you may proceed to read the value\ncorresponding to the type of the content.\n\nFor example:\n```\ntoml_datum_t host = toml_string_in(tab, \"host\");\nif (host.ok) {\n\tprintf(\"host: %s\\n\", host.u.s);\n\tfree(host.u.s);   /* FREE applies to string and timestamp types only */\n}\n```\n\n** IMPORTANT: if the accessed value is a string or a timestamp, you must call `free(datum.u.s)` or `free(datum.u.ts)` respectively after usage. **\n\n## Building and installing\n\nA normal *make* suffices. You can also simply include the\n`toml.c` and `toml.h` files in your project.\n\nInvoking `make install` will install the header and library files into\n/usr/local/{include,lib}.\n\nAlternatively, specify `make install prefix=/a/file/path` to install into\n/a/file/path/{include,lib}.\n\n## Testing\n\nTo test against the standard test set provided by toml-lang/toml-test:\n\n```sh\n% make\n% cd test1\n% bash build.sh   # do this once\n% bash run.sh     # this will run the test suite\n```\n\n\nTo test against the standard test set provided by iarna/toml:\n\n```sh\n% make\n% cd test2\n% bash build.sh   # do this once\n% bash run.sh     # this will run the test suite\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Ftomlc99","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcktan%2Ftomlc99","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcktan%2Ftomlc99/lists"}