load config using c
I’m working on my little window manager and it needs to be configured, such as colors, key bindings and so on.
We usually use getopt()
to set some options like -d
debug, -h
help and
-v
version. It is not graceful to add lots of config here, human type short.
Some options are easy, we can also simply pass value through environment and
read with getenv()
. However, key-bindings are different, data structure is
relatively complex:
- There is always more than one key binding (array)
- Key bindings have multiple combinations (struct)
Most importantly, I want to parse them within very short code thus free to review.
These days I read dwl’s source code and find one way
我的英语好差,哭了
First, main process use pipe to generate piperw[2] and then fork another process, thus both processes could send and read message with each other. Second the child process bind its STDOUT to piprw and call exec to change itself to run shell script
#!/bin/sh
wprint-bind -a -k 6 -- echo 666
wprint-bind -a -k 3 -- echo 333
// TO BE CONTINUE