r/cprogramming • u/Queasy-Pickle-8427 • 29d ago
Config File Recommendation
Helloo, I’ve just learned how to build a simple code editor using C, now, I’d like to add a config file so users can adjust settings like background/foreground colors, keybindings, and so on, so do you guys have any recommendations for a config file that would be suitable for this case?
12
Upvotes
5
u/pjl1967 28d ago
I went through this semi-recently with my own
include-tidyprogram. These days, there are JSON, TOML, XML, and YAML. You can read about my thought process and decision here (scroll down to Configuration).If your program accepts commands from a prompt (like
vican), then the config file can just be a set of commands the program accepts anyway, just from a file rather than interactively.4
u/The_Northern_Light 28d ago
Follow the KISS principle and use what’s most common; either json or toml (if being human friendly matters).
4
u/NaNpsycho 28d ago
A lot of ppl in the chat are suggesting json, toml, etc. good choices for simple requirements. But I would say if you're init for learning, try using lua.
I have sometimes felt that when I want to do something a little more complex, like enable a set of indentation rules, allman brace position, etall for C / C++ projects, while have different rules for rust or others, its quite a bit easy to do in nvim's lua configuration than vscode, now granted I might not have given vscode a fair chance due to bias, but the point stands, you'd eventually have a dsl for config management, why not offload that to something you can search more easily about if you're stuck than roll your own custom dsl.
Plus lua is fairly trivial to integrate in C / C++ codebase.
3
u/skmruiz 28d ago
Any actually, maybe you can take at how editorconfig files look like. Some editors use JSON, others XML, others toml...
3
u/Key_River7180 28d ago
You can make a rather simple format with scanf:
] section = key value ; comment
Or check out inih for an ini parser
3
u/actguru 28d ago
You might try a standard format like JSON, Apple Plist XML etc. This way if you later allow the user to pick colors and keystrokes in the program, you will be able to have the program update the configuration file.
2
u/WorriedTumbleweed289 28d ago
4
u/[deleted] 28d ago
[removed] — view removed comment