mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-13 00:45:58 +01:00
util: Introduce env helpers
This commit is contained in:
parent
e7477c7114
commit
31a9fc1fb6
3 changed files with 50 additions and 0 deletions
11
include/util/env.h
Normal file
11
include/util/env.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef UTIL_ENV_H
|
||||
#define UTIL_ENV_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool env_parse_bool(const char *option);
|
||||
|
||||
ssize_t env_parse_switch(const char *option, const char **switches);
|
||||
|
||||
#endif
|
38
util/env.c
Normal file
38
util/env.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/env.h"
|
||||
|
||||
bool env_parse_bool(const char *option) {
|
||||
const char *env = getenv(option);
|
||||
if (env) {
|
||||
wlr_log(WLR_INFO, "Loading %s option: %s", option, env);
|
||||
}
|
||||
|
||||
if (!env || strcmp(env, "0") == 0) {
|
||||
return false;
|
||||
} else if (strcmp(env, "1") == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env);
|
||||
return false;
|
||||
}
|
||||
|
||||
ssize_t env_parse_switch(const char *option, const char **switches) {
|
||||
const char *env = getenv(option);
|
||||
if (env) {
|
||||
wlr_log(WLR_INFO, "Loading %s option: %s", option, env);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (ssize_t i = 0; switches[i]; i++) {
|
||||
if (strcmp(env, switches[i]) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_log(WLR_ERROR, "Unknown %s option: %s", option, env);
|
||||
return 0;
|
||||
}
|
|
@ -2,6 +2,7 @@ wlr_files += files(
|
|||
'addon.c',
|
||||
'array.c',
|
||||
'box.c',
|
||||
'env.c',
|
||||
'global.c',
|
||||
'log.c',
|
||||
'region.c',
|
||||
|
|
Loading…
Reference in a new issue