- A simple API in pure C without external dependencies
- Correct handling of escaped characters (
\"...\", etc.) inside quoted strings.
The .vdf file extension stands for Valve Data Format. It uses a key-value structure. I wanted to create a lib to parse/extract Steam data, and realized I needed a solid VDF parser. It is for anyone who wants to use it :).
Typical flow: read a file, parse it, walk the tree, free it.
#include<stdio.h>#include<vdfc/vdf.h>char*out;
size_tout_size;
VDFcodeerr;
err=vdf_read_file("path/to/file.vdf", &out, &out_size);
if (err!=VDF_OK) {
// handleexit(1);
}
VDFNode*node;
err=vdf_parse(out, &node);
if (err!=VDF_OK) {
// handleexit(1);
}
// Assuming file.vdf contains:// "AppState"// {// "name" "Counter-Strike"// "appid" "10"// }char*out;
err=vdf_dump_node(node, &out)
if (err!=VDF_OK)
{
// handleexit(1);
}
printf("%s\n", out);
// Should output something like:// (null): object// AppState: object// name: string// appid: stringVDFNode*appstate=vdf_get(node, "AppState");
constchar*name=vdf_get_string(appstate, "name", "unknown");
printf("%s\n", name);
free(out);
vdf_free_node(node);- A simple
make installto install it on your system andmake uninstallto uninstall it. - To specify the output path, use
PREFIX=/your/pathwithmake install/uninstall(default/usr/local). DESTDIR=/staging/pathis also supported, for packagers who need to install into a staging root before the realPREFIX.make test- run the test suite ( criterion is needed to run the test suites. )
git clone https://github.com/leberton-dev/libvdfc.git
cd libvdfc
make install
# to specify path :# make install PREFIX=/your/path# to install into a staging root (packaging) :# make install PREFIX=/your/path DESTDIR=/staging/path# in your project
cc your_file.{.c,.o} -lvdfc -o prog_name
# uninstall
make uninstall
# to specify path :# make uninstall PREFIX=/your/path DESTDIR=/staging/pathThe installed files are found under $PREFIX/lib/libvdfc.a, $PREFIX/include/vdfc/, and the man pages under $PREFIX/share/man/man3/.
$PREFIX being /usr/local by default.
man vdf_get- For bugs and suggestions see the issues
- PRs are welcome, please use
make testbefore submitting - Code style is enforced via
.clang-format; runclang-format -ibefore submitting