mirror of
https://github.com/javalsai/lidm.git
synced 2025-08-31 18:38:00 +02:00
lint: fix code for clang-tidy
This commit is contained in:
20
src/config.c
20
src/config.c
@@ -126,7 +126,10 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
|
||||
aux_str = strdup(key);
|
||||
if (!aux_str) FAIL("allocation failure");
|
||||
aux_err = parse_str_inplace(aux_str);
|
||||
if (aux_err.msg != NULL) return aux_err;
|
||||
if (aux_err.msg != NULL) {
|
||||
free(aux_str);
|
||||
return aux_err;
|
||||
}
|
||||
// FIXME: it be broken, prob the ptr arithmetic or smth, we mem leak
|
||||
// instead 😎 If the ptr is not the default it means it was prev
|
||||
// allocated, we should free if (*(char**)((uintptr_t)(&default_config) +
|
||||
@@ -154,7 +157,10 @@ struct parser_error parse_key(enum introspection_type typ, union typ_ptr at,
|
||||
aux_str = strdup(key);
|
||||
if (!aux_str) FAIL("allocation failure");
|
||||
aux_err = parse_str_inplace(aux_str);
|
||||
if (aux_err.msg != NULL) return aux_err;
|
||||
if (aux_err.msg != NULL) {
|
||||
free(aux_str);
|
||||
return aux_err;
|
||||
}
|
||||
vec_push(at.vec, aux_str);
|
||||
break;
|
||||
}
|
||||
@@ -171,12 +177,12 @@ struct status config_line_handler(void* _config, char* table, char* k,
|
||||
struct status ret = {.finish = false};
|
||||
|
||||
const struct introspection_table* this_intros_table = NULL;
|
||||
for (size_t i = 0; i < LEN(config_instrospection); i++) {
|
||||
for (size_t i = 0; i < LEN(CONFIG_INSTROSPECTION); i++) {
|
||||
if (table == NULL) {
|
||||
if (table != config_instrospection[i].tname) continue;
|
||||
} else if (strcmp(config_instrospection[i].tname, table) != 0)
|
||||
if (table != CONFIG_INSTROSPECTION[i].tname) continue;
|
||||
} else if (strcmp(CONFIG_INSTROSPECTION[i].tname, table) != 0)
|
||||
continue;
|
||||
this_intros_table = &config_instrospection[i];
|
||||
this_intros_table = &CONFIG_INSTROSPECTION[i];
|
||||
break;
|
||||
}
|
||||
if (this_intros_table == NULL) {
|
||||
@@ -202,7 +208,7 @@ struct status config_line_handler(void* _config, char* table, char* k,
|
||||
struct parser_error err = parse_key(this_intros_key->typ, k_addr, v, offset);
|
||||
if (err.msg != NULL) {
|
||||
log_printf("[E] cfg parser, failed to parse [%s.%s] (%s): %s\n", table, k,
|
||||
intros_tys_names[this_intros_key->typ], err.msg);
|
||||
INTROS_TYS_NAMES[this_intros_key->typ], err.msg);
|
||||
log_printf("%s\n%*c^\n", v, err.col);
|
||||
return ret;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ char* trim_str(char* str) {
|
||||
while (*str == ' ' || *str == '\t')
|
||||
str++;
|
||||
|
||||
size_t i = strlen(str);
|
||||
size_t i = strlen(str); // NOLINT(readability-identifier-length)
|
||||
while (i > 0) {
|
||||
if (str[i - 1] != ' ' && str[i - 1] != '\t' && str[i - 1] != '\n') break;
|
||||
i--;
|
||||
|
@@ -36,7 +36,7 @@ void efield_update(struct editable_field* self, char* update) {
|
||||
if (*update == BACKSPACE_CODE) {
|
||||
if (self->pos == 0) return;
|
||||
char* curr = &self->content[self->pos];
|
||||
char* prev = utf8back(curr);
|
||||
char* prev = (char*)utf8back(curr);
|
||||
memmove(prev, curr, strlen(self->content) - self->pos + 1);
|
||||
|
||||
self->pos -= curr - prev;
|
||||
|
@@ -30,7 +30,7 @@ int main(int argc, char* argv[]) {
|
||||
// Chvt
|
||||
if (argc == 2) chvt_str(argv[1]);
|
||||
|
||||
struct config config = default_config;
|
||||
struct config config = DEFAULT_CONFIG;
|
||||
char* conf_override = getenv("LIDM_CONF");
|
||||
char* conf_path = conf_override ? conf_override : "/etc/lidm.ini";
|
||||
if (parse_config(&config, conf_path) != 0) {
|
||||
|
@@ -16,7 +16,7 @@ struct source_dir {
|
||||
enum session_type type;
|
||||
char* dir;
|
||||
};
|
||||
static const struct source_dir sources[] = {
|
||||
static const struct source_dir SOURCES[] = {
|
||||
{XORG, "/usr/share/xsessions"},
|
||||
{WAYLAND, "/usr/share/wayland-sessions"},
|
||||
};
|
||||
@@ -120,10 +120,10 @@ struct Vector get_avaliable_sessions() {
|
||||
vec_reserve(&sessions, LIKELY_BOUND_SESSIONS);
|
||||
|
||||
cb_sessions = &sessions;
|
||||
for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) {
|
||||
log_printf("[I] parsing into %s\n", sources[i].dir);
|
||||
session_type = sources[i].type;
|
||||
ftw(sources[i].dir, &fn, 1);
|
||||
for (size_t i = 0; i < (sizeof(SOURCES) / sizeof(SOURCES[0])); i++) {
|
||||
log_printf("[I] parsing into %s\n", SOURCES[i].dir);
|
||||
session_type = SOURCES[i].type;
|
||||
ftw(SOURCES[i].dir, &fn, 1);
|
||||
}
|
||||
cb_sessions = NULL;
|
||||
|
||||
|
28
src/ui.c
28
src/ui.c
@@ -27,7 +27,7 @@
|
||||
#include "users.h"
|
||||
#include "util.h"
|
||||
|
||||
const u_char inputs_n = 3;
|
||||
const u_char INPUTS_N = 3;
|
||||
|
||||
static void print_box();
|
||||
static void print_footer();
|
||||
@@ -182,21 +182,21 @@ int load(struct Vector* users, struct Vector* sessions) {
|
||||
of_passwd = ofield_new(0);
|
||||
|
||||
/// PRINTING
|
||||
const struct uint_point boxstart = box_start();
|
||||
const struct uint_point BOXSTART = box_start();
|
||||
|
||||
// printf box
|
||||
print_box();
|
||||
|
||||
// put hostname
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + HEAD_ROW,
|
||||
boxstart.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
|
||||
BOXSTART.x + VALUES_COL - VALUES_SEPR - (uint)utf8len(hostname),
|
||||
g_config->colors.e_hostname, hostname, g_config->colors.fg);
|
||||
if (hostname != unknown_str) free(hostname);
|
||||
|
||||
// put date
|
||||
char* fmtd_time = fmt_time();
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + HEAD_ROW,
|
||||
boxstart.x + BOX_WIDTH - 1 - BOX_HMARGIN - (uint)utf8len(fmtd_time),
|
||||
printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", BOXSTART.y + HEAD_ROW,
|
||||
BOXSTART.x + BOX_WIDTH - 1 - BOX_HMARGIN - (uint)utf8len(fmtd_time),
|
||||
g_config->colors.e_date, fmtd_time, g_config->colors.fg);
|
||||
free(fmtd_time);
|
||||
|
||||
@@ -392,9 +392,9 @@ static void print_row(uint wid, uint n, char* edge1, char* edge2,
|
||||
}
|
||||
|
||||
static void print_box() {
|
||||
const struct uint_point bstart = box_start();
|
||||
const struct uint_point BSTART = box_start();
|
||||
|
||||
printf("\x1b[%d;%dH\x1b[%sm", bstart.y, bstart.x, g_config->colors.e_box);
|
||||
printf("\x1b[%d;%dH\x1b[%sm", BSTART.y, BSTART.x, g_config->colors.e_box);
|
||||
print_row(BOX_WIDTH - 2, 1, g_config->chars.ctl, g_config->chars.ctr,
|
||||
g_config->chars.hb);
|
||||
print_empty_row(BOX_WIDTH - 2, BOX_HEIGHT - 2, g_config->chars.vb,
|
||||
@@ -408,9 +408,9 @@ static void print_box() {
|
||||
static void print_footer() {
|
||||
size_t bsize = snprintf(
|
||||
NULL, 0, "%s %s %s %s %s %s", g_config->strings.f_poweroff,
|
||||
key_names[g_config->functions.poweroff], g_config->strings.f_reboot,
|
||||
key_names[g_config->functions.reboot], g_config->strings.f_refresh,
|
||||
key_names[g_config->functions.refresh]);
|
||||
KEY_NAMES[g_config->functions.poweroff], g_config->strings.f_reboot,
|
||||
KEY_NAMES[g_config->functions.reboot], g_config->strings.f_refresh,
|
||||
KEY_NAMES[g_config->functions.refresh]);
|
||||
|
||||
uint row = window.ws_row - 1;
|
||||
uint col = window.ws_col - 2 - bsize;
|
||||
@@ -418,9 +418,9 @@ static void print_footer() {
|
||||
"\x1b[%3$d;%4$dH%8$s \x1b[%1$sm%5$s\x1b[%2$sm %9$s "
|
||||
"\x1b[%1$sm%6$s\x1b[%2$sm %10$s \x1b[%1$sm%7$s\x1b[%2$sm",
|
||||
g_config->colors.e_key, g_config->colors.fg, row, col,
|
||||
key_names[g_config->functions.poweroff],
|
||||
key_names[g_config->functions.reboot],
|
||||
key_names[g_config->functions.refresh], g_config->strings.f_poweroff,
|
||||
KEY_NAMES[g_config->functions.poweroff],
|
||||
KEY_NAMES[g_config->functions.reboot],
|
||||
KEY_NAMES[g_config->functions.refresh], g_config->strings.f_poweroff,
|
||||
g_config->strings.f_reboot, g_config->strings.f_refresh);
|
||||
(void)fflush(stdout);
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ struct session st_session(bool include_defshell) {
|
||||
}
|
||||
|
||||
void st_ch_focus(char direction) {
|
||||
focused_input = (focused_input + direction) % inputs_n;
|
||||
focused_input = (focused_input + direction) % INPUTS_N;
|
||||
ui_update_cursor_focus();
|
||||
}
|
||||
|
||||
|
82
src/util.c
82
src/util.c
@@ -12,8 +12,8 @@
|
||||
static int selret_magic();
|
||||
|
||||
int find_keyname(enum keys* at, const char* name) {
|
||||
for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) {
|
||||
if (strcmp(key_names[i], name) == 0) {
|
||||
for (size_t i = 0; i < LEN(KEY_MAPPINGS); i++) {
|
||||
if (strcmp(KEY_NAMES[i], name) == 0) {
|
||||
*at = (enum keys)i;
|
||||
return 0;
|
||||
}
|
||||
@@ -23,8 +23,8 @@ int find_keyname(enum keys* at, const char* name) {
|
||||
}
|
||||
|
||||
enum keys find_ansi(const char* seq) {
|
||||
for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) {
|
||||
struct key_mapping mapping = key_mappings[i];
|
||||
for (size_t i = 0; i < LEN(KEY_MAPPINGS); i++) {
|
||||
struct key_mapping mapping = KEY_MAPPINGS[i];
|
||||
for (size_t j = 0; mapping.sequences[j] != NULL; j++) {
|
||||
if (strcmp(mapping.sequences[j], seq) == 0) {
|
||||
return (enum keys)i;
|
||||
@@ -115,72 +115,72 @@ const struct Vector VEC_NEW = {
|
||||
.pages = NULL,
|
||||
};
|
||||
|
||||
int vec_resize(struct Vector* vec, size_t size) {
|
||||
void** new_location = realloc(vec->pages, size * sizeof(void*));
|
||||
int vec_resize(struct Vector* self, size_t size) {
|
||||
void** new_location =
|
||||
(void**)realloc((void*)self->pages, size * sizeof(void*));
|
||||
if (new_location != NULL) {
|
||||
if (vec->length > size) vec->length = size;
|
||||
vec->capacity = size;
|
||||
vec->pages = new_location;
|
||||
if (self->length > size) self->length = size;
|
||||
self->capacity = size;
|
||||
self->pages = new_location;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vec_reserve(struct Vector* vec, size_t size) {
|
||||
uint32_t new_capacity = vec->capacity;
|
||||
while (vec->length + size > new_capacity) {
|
||||
int vec_reserve(struct Vector* self, size_t size) {
|
||||
uint32_t new_capacity = self->capacity;
|
||||
while (self->length + size > new_capacity) {
|
||||
new_capacity = new_capacity + (new_capacity >> 1) +
|
||||
1; // cap * 1.5 + 1; 0 1 2 4 7 11...
|
||||
}
|
||||
return vec_resize(vec, new_capacity);
|
||||
return vec_resize(self, new_capacity);
|
||||
}
|
||||
|
||||
int vec_reserve_exact(struct Vector* vec, size_t size) {
|
||||
uint32_t needed_capacity = vec->length + size;
|
||||
if (vec->capacity < needed_capacity) {
|
||||
return vec_resize(vec, needed_capacity);
|
||||
} else {
|
||||
return 0;
|
||||
int vec_reserve_exact(struct Vector* self, size_t size) {
|
||||
uint32_t needed_capacity = self->length + size;
|
||||
if (self->capacity < needed_capacity) {
|
||||
return vec_resize(self, needed_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
int vec_push(struct Vector* vec, void* item) {
|
||||
int res_ret = vec_reserve(vec, 1);
|
||||
if (res_ret != 0) return res_ret;
|
||||
|
||||
vec->pages[vec->length++] = item;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vec_free(struct Vector* vec) {
|
||||
while (vec->length > 0)
|
||||
free(vec->pages[--vec->length]);
|
||||
int vec_push(struct Vector* self, void* item) {
|
||||
int res_ret = vec_reserve(self, 1);
|
||||
if (res_ret != 0) return res_ret;
|
||||
|
||||
vec_clear(vec);
|
||||
self->pages[self->length++] = item;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vec_clear(struct Vector* vec) {
|
||||
free(vec->pages);
|
||||
vec_reset(vec);
|
||||
void vec_free(struct Vector* self) {
|
||||
while (self->length > 0)
|
||||
free(self->pages[--self->length]);
|
||||
|
||||
vec_clear(self);
|
||||
}
|
||||
|
||||
void vec_reset(struct Vector* vec) {
|
||||
*vec = (struct Vector){
|
||||
void vec_clear(struct Vector* self) {
|
||||
free((void*)self->pages);
|
||||
vec_reset(self);
|
||||
}
|
||||
|
||||
void vec_reset(struct Vector* self) {
|
||||
*self = (struct Vector){
|
||||
.length = 0,
|
||||
.capacity = 0,
|
||||
.pages = NULL,
|
||||
};
|
||||
}
|
||||
|
||||
void* vec_pop(struct Vector* vec) {
|
||||
if (vec->length == 0) return NULL;
|
||||
void* vec_pop(struct Vector* self) {
|
||||
if (self->length == 0) return NULL;
|
||||
|
||||
return vec->pages[--vec->length];
|
||||
return self->pages[--self->length];
|
||||
}
|
||||
|
||||
void* vec_get(struct Vector* vec, size_t index) {
|
||||
if (index >= vec->length) return NULL;
|
||||
void* vec_get(struct Vector* self, size_t index) {
|
||||
if (index >= self->length) return NULL;
|
||||
|
||||
return vec->pages[index];
|
||||
return self->pages[index];
|
||||
}
|
||||
|
Reference in New Issue
Block a user