yshui / picom

A lightweight compositor for X11
Other
3.92k stars 576 forks source link

options: refactor option parsing #1255

Closed yshui closed 1 month ago

yshui commented 1 month ago

The main objective is to remove the need to worry about option value assignment. Because of the way getopt works, we need to assign a number to each option, and later match the return value of getopt in a big switch. We have to make sure to not assign the same number to two options, and we have to carefully make sure the same number is used in two different places (once in the options table, once in the switch). And that is just annoying.

With this commit everything is in one place, and the compiler will yell at us if we assigned duplicated numbers.

Maybe this can also be a stepping stone for unifying command line options parsing and config file parsing.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 53.44828% with 108 lines in your changes are missing coverage. Please review.

Project coverage is 41.23%. Comparing base (4bb0a71) to head (43de276).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/yshui/picom/pull/1255/graphs/tree.svg?width=650&height=150&src=pr&token=NRSegi0Gze&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui)](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui) ```diff @@ Coverage Diff @@ ## next #1255 +/- ## ========================================== + Coverage 40.52% 41.23% +0.71% ========================================== Files 59 59 Lines 12466 12309 -157 ========================================== + Hits 5052 5076 +24 + Misses 7414 7233 -181 ``` | [Files](https://app.codecov.io/gh/yshui/picom/pull/1255?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui) | Coverage Δ | | |---|---|---| | [src/config.h](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Fconfig.h&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2NvbmZpZy5o) | `23.52% <100.00%> (ø)` | | | [src/log.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Flog.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2xvZy5j) | `67.06% <100.00%> (ø)` | | | [src/log.h](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Flog.h&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2xvZy5o) | `76.47% <ø> (ø)` | | | [src/picom.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Fpicom.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL3BpY29tLmM=) | `61.56% <100.00%> (-0.04%)` | :arrow_down: | | [src/dbus.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Fdbus.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2RidXMuYw==) | `25.12% <0.00%> (ø)` | | | [src/inspect.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Finspect.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2luc3BlY3QuYw==) | `0.00% <0.00%> (ø)` | | | [src/config.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Fconfig.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2NvbmZpZy5j) | `51.56% <60.00%> (-6.19%)` | :arrow_down: | | [src/config\_libconfig.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Fconfig_libconfig.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL2NvbmZpZ19saWJjb25maWcuYw==) | `58.63% <71.15%> (+0.04%)` | :arrow_up: | | [src/options.c](https://app.codecov.io/gh/yshui/picom/pull/1255?src=pr&el=tree&filepath=src%2Foptions.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui#diff-c3JjL29wdGlvbnMuYw==) | `43.52% <46.91%> (+18.58%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/yshui/picom/pull/1255/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Yuxuan+Shui)