mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-02-13 04:28:13 -05:00
fix: -p exits with failure if there are parse failures
This commit is contained in:
parent
0d413a5503
commit
ebd83d8e13
2 changed files with 16 additions and 12 deletions
|
|
@ -342,7 +342,7 @@ typedef struct {
|
|||
typedef int32_t (*FuncType)(const Arg *);
|
||||
Config config;
|
||||
|
||||
void parse_config_file(Config *config, const char *file_path);
|
||||
bool parse_config_file(Config *config, const char *file_path);
|
||||
|
||||
// Helper function to trim whitespace from start and end of a string
|
||||
void trim_whitespace(char *str) {
|
||||
|
|
@ -2556,7 +2556,7 @@ bool parse_config_line(Config *config, const char *line) {
|
|||
return parse_option(config, key, value);
|
||||
}
|
||||
|
||||
void parse_config_file(Config *config, const char *file_path) {
|
||||
bool parse_config_file(Config *config, const char *file_path) {
|
||||
FILE *file;
|
||||
char full_path[1024];
|
||||
|
||||
|
|
@ -2575,7 +2575,7 @@ void parse_config_file(Config *config, const char *file_path) {
|
|||
fprintf(stderr,
|
||||
"\033[1m\033[31m[ERROR]:\033[33m HOME environment "
|
||||
"variable not set.\n");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
snprintf(full_path, sizeof(full_path), "%s/.config/mango/%s", home,
|
||||
file_path + 1);
|
||||
|
|
@ -2590,7 +2590,7 @@ void parse_config_file(Config *config, const char *file_path) {
|
|||
if (!home) {
|
||||
fprintf(stderr, "\033[1m\033[31m[ERROR]:\033[33m HOME environment "
|
||||
"variable not set.\n");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
snprintf(full_path, sizeof(full_path), "%s%s", home, file_path + 1);
|
||||
file = fopen(full_path, "r");
|
||||
|
|
@ -2605,19 +2605,21 @@ void parse_config_file(Config *config, const char *file_path) {
|
|||
"\033[1;31m\033[1;33m[ERROR]:\033[0m Failed to open "
|
||||
"config file: %s\n",
|
||||
file_path);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
bool parse_correct = true;
|
||||
bool parse_line_correct = true;
|
||||
uint32_t line_count = 0;
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
line_count++;
|
||||
if (line[0] == '#' || line[0] == '\n') {
|
||||
continue;
|
||||
}
|
||||
parse_correct = parse_config_line(config, line);
|
||||
if (!parse_correct) {
|
||||
parse_line_correct = parse_config_line(config, line);
|
||||
if (!parse_line_correct) {
|
||||
parse_correct = false;
|
||||
fprintf(stderr,
|
||||
"\033[1;31m╰─\033[1;33m[Index]\033[0m "
|
||||
"\033[1;36m%s\033[0m:\033[1;35m%d\033[0m\n"
|
||||
|
|
@ -2627,6 +2629,7 @@ void parse_config_file(Config *config, const char *file_path) {
|
|||
}
|
||||
|
||||
fclose(file);
|
||||
return parse_correct;
|
||||
}
|
||||
|
||||
void free_circle_layout(Config *config) {
|
||||
|
|
@ -3248,7 +3251,7 @@ void set_default_key_bindings(Config *config) {
|
|||
config->key_bindings_count += default_key_bindings_count;
|
||||
}
|
||||
|
||||
void parse_config(void) {
|
||||
bool parse_config(void) {
|
||||
|
||||
char filename[1024];
|
||||
|
||||
|
|
@ -3301,7 +3304,7 @@ void parse_config(void) {
|
|||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
// 如果获取失败,则无法继续
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// 构建日志文件路径
|
||||
snprintf(filename, sizeof(filename), "%s/.config/mango/config.conf",
|
||||
|
|
@ -3315,10 +3318,12 @@ void parse_config(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool parse_correct = true;
|
||||
set_value_default();
|
||||
parse_config_file(&config, filename);
|
||||
parse_correct = parse_config_file(&config, filename);
|
||||
set_default_key_bindings(&config);
|
||||
override_config();
|
||||
return parse_correct;
|
||||
}
|
||||
|
||||
void reapply_monitor_rules(void) {
|
||||
|
|
|
|||
|
|
@ -6123,8 +6123,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
|||
} else if (c == 'c') {
|
||||
cli_config_path = optarg;
|
||||
} else if (c == 'p') {
|
||||
parse_config();
|
||||
return EXIT_SUCCESS;
|
||||
return parse_config() ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue