[v0.98][Refactoring] Simplify parse_color

This commit is contained in:
Dr-Noob
2021-08-07 10:47:15 +02:00
parent 5737f1ecaf
commit d0ec0d8c0f

View File

@@ -117,33 +117,23 @@ bool parse_color(char* optarg_str, struct color*** cs) {
struct color** c = *cs; struct color** c = *cs;
int32_t ret; int32_t ret;
char* str_to_parse = NULL; char* str_to_parse = NULL;
bool free_ptr; char* color_to_copy = NULL;
bool free_ptr = true;
if(strcmp(optarg_str, COLOR_STR_INTEL) == 0) { if(strcmp(optarg_str, COLOR_STR_INTEL) == 0) color_to_copy = COLOR_DEFAULT_INTEL;
str_to_parse = emalloc(sizeof(char) * 46); else if(strcmp(optarg_str, COLOR_STR_AMD) == 0) color_to_copy = COLOR_DEFAULT_AMD;
strcpy(str_to_parse, COLOR_DEFAULT_INTEL); else if(strcmp(optarg_str, COLOR_STR_IBM) == 0) color_to_copy = COLOR_DEFAULT_IBM;
free_ptr = true; else if(strcmp(optarg_str, COLOR_STR_ARM) == 0) color_to_copy = COLOR_DEFAULT_ARM;
}
else if(strcmp(optarg_str, COLOR_STR_AMD) == 0) {
str_to_parse = emalloc(sizeof(char) * 44);
strcpy(str_to_parse, COLOR_DEFAULT_AMD);
free_ptr = true;
}
else if(strcmp(optarg_str, COLOR_STR_IBM) == 0) {
str_to_parse = emalloc(sizeof(char) * 45);
strcpy(str_to_parse, COLOR_DEFAULT_IBM);
free_ptr = true;
}
else if(strcmp(optarg_str, COLOR_STR_ARM) == 0) {
str_to_parse = emalloc(sizeof(char) * 46);
strcpy(str_to_parse, COLOR_DEFAULT_ARM);
free_ptr = true;
}
else { else {
str_to_parse = optarg_str; str_to_parse = optarg_str;
free_ptr = false; free_ptr = false;
} }
if(str_to_parse == NULL) {
str_to_parse = emalloc(sizeof(char) * (strlen(color_to_copy) + 1));
strcpy(str_to_parse, color_to_copy);
}
ret = sscanf(str_to_parse, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d", ret = sscanf(str_to_parse, "%d,%d,%d:%d,%d,%d:%d,%d,%d:%d,%d,%d",
&c[0]->R, &c[0]->G, &c[0]->B, &c[0]->R, &c[0]->G, &c[0]->B,
&c[1]->R, &c[1]->G, &c[1]->B, &c[1]->R, &c[1]->G, &c[1]->B,