From dbbab78e23bc05537e0f5c99720bacc3775336bc Mon Sep 17 00:00:00 2001 From: javalsai Date: Thu, 5 Sep 2024 20:26:58 +0200 Subject: [PATCH] format: let clang-format run ._. (won't even talk about clang-tidy) --- include/chvt.h | 2 +- include/config.h | 5 +- include/efield.h | 8 ++-- include/keys.h | 118 +++++++++++++++++++++++------------------------ include/ui.h | 6 +-- include/util.h | 6 +-- src/config.c | 86 +++++++++++++++++----------------- src/efield.c | 28 ++++++----- src/main.c | 5 +- src/sessions.c | 3 +- src/ui.c | 6 +-- src/util.c | 4 +- 12 files changed, 142 insertions(+), 135 deletions(-) diff --git a/include/chvt.h b/include/chvt.h index a39af33..0637b22 100644 --- a/include/chvt.h +++ b/include/chvt.h @@ -20,6 +20,6 @@ int chvt(int n); * @param str virtual terminal number (string) * @return int non-negative value on success */ -int chvt_str(char* str); +int chvt_str(char *str); #endif diff --git a/include/config.h b/include/config.h index d6e086f..76e4430 100644 --- a/include/config.h +++ b/include/config.h @@ -74,10 +74,9 @@ struct config { }; bool line_parser( - FILE* fd, - ssize_t* blksize, + FILE *fd, ssize_t *blksize, u_char (*cb)(char *key, - char *value)); // might use this for parsing .desktop files too + char *value)); // might use this for parsing .desktop files too struct config *parse_config(char *path); #endif diff --git a/include/efield.h b/include/efield.h index ed03c32..68b1db0 100644 --- a/include/efield.h +++ b/include/efield.h @@ -10,9 +10,9 @@ struct editable_field { char content[255]; }; -struct editable_field field_new(char*); -void field_trim(struct editable_field*, u_char); -void field_update(struct editable_field*, char*); -bool field_seek(struct editable_field*, char); +struct editable_field field_new(char *); +void field_trim(struct editable_field *, u_char); +void field_update(struct editable_field *, char *); +bool field_seek(struct editable_field *, char); #endif diff --git a/include/keys.h b/include/keys.h index 5933f32..cd34031 100644 --- a/include/keys.h +++ b/include/keys.h @@ -4,37 +4,37 @@ #include enum keys { - ESC, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12, - A_UP, - A_DOWN, - A_RIGHT, - A_LEFT, - N_CENTER, - N_UP, - N_DOWN, - N_RIGHT, - N_LEFT, - INS, - SUPR, - HOME, - END, - PAGE_UP, - PAGE_DOWN, + ESC, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + A_UP, + A_DOWN, + A_RIGHT, + A_LEFT, + N_CENTER, + N_UP, + N_DOWN, + N_RIGHT, + N_LEFT, + INS, + SUPR, + HOME, + END, + PAGE_UP, + PAGE_DOWN, }; -static const char * const key_names[] = { +static const char *const key_names[] = { [ESC] = "ESC", [F1] = "F1", [F2] = "F2", @@ -66,39 +66,39 @@ static const char * const key_names[] = { }; struct key_mapping { - enum keys key; - const char *sequences[3]; + enum keys key; + const char *sequences[3]; }; static const struct key_mapping key_mappings[] = { - { ESC, { "\x1b", NULL }}, - { F1, { "\x1bOP", "\x1b[[A", NULL }}, - { F2, { "\x1bOQ", "\x1b[[B", NULL }}, - { F3, { "\x1bOR", "\x1b[[C", NULL }}, - { F4, { "\x1bOS", "\x1b[[D", NULL }}, - { F5, { "\x1b[15~", "\x1b[[E", NULL }}, - { F6, { "\x1b[17~", NULL }}, - { F7, { "\x1b[18~", NULL }}, - { F8, { "\x1b[19~", NULL }}, - { F9, { "\x1b[20~", NULL }}, - { F10, { "\x1b[21~", NULL }}, - { F11, { "\x1b[23~", NULL }}, - { F12, { "\x1b[24~", NULL }}, - { A_UP, { "\x1b[A", NULL }}, - { A_DOWN, { "\x1b[B", NULL }}, - { A_RIGHT, { "\x1b[C", NULL }}, - { A_LEFT, { "\x1b[D", NULL }}, - { N_CENTER, { "\x1b[E", NULL }}, - { N_UP, { "\x1bOA", NULL }}, - { N_DOWN, { "\x1bOB", NULL }}, - { N_RIGHT, { "\x1bOC", NULL }}, - { N_LEFT, { "\x1bOD", NULL }}, - { INS, { "\x1b[2~", NULL }}, - { SUPR, { "\x1b[3~", NULL }}, - { HOME, { "\x1b[H", NULL }}, - { END, { "\x1b[F", NULL }}, - { PAGE_UP, { "\x1b[5~", NULL }}, - { PAGE_DOWN, { "\x1b[6~", NULL }}, + {ESC, {"\x1b", NULL}}, + {F1, {"\x1bOP", "\x1b[[A", NULL}}, + {F2, {"\x1bOQ", "\x1b[[B", NULL}}, + {F3, {"\x1bOR", "\x1b[[C", NULL}}, + {F4, {"\x1bOS", "\x1b[[D", NULL}}, + {F5, {"\x1b[15~", "\x1b[[E", NULL}}, + {F6, {"\x1b[17~", NULL}}, + {F7, {"\x1b[18~", NULL}}, + {F8, {"\x1b[19~", NULL}}, + {F9, {"\x1b[20~", NULL}}, + {F10, {"\x1b[21~", NULL}}, + {F11, {"\x1b[23~", NULL}}, + {F12, {"\x1b[24~", NULL}}, + {A_UP, {"\x1b[A", NULL}}, + {A_DOWN, {"\x1b[B", NULL}}, + {A_RIGHT, {"\x1b[C", NULL}}, + {A_LEFT, {"\x1b[D", NULL}}, + {N_CENTER, {"\x1b[E", NULL}}, + {N_UP, {"\x1bOA", NULL}}, + {N_DOWN, {"\x1bOB", NULL}}, + {N_RIGHT, {"\x1bOC", NULL}}, + {N_LEFT, {"\x1bOD", NULL}}, + {INS, {"\x1b[2~", NULL}}, + {SUPR, {"\x1b[3~", NULL}}, + {HOME, {"\x1b[H", NULL}}, + {END, {"\x1b[F", NULL}}, + {PAGE_UP, {"\x1b[5~", NULL}}, + {PAGE_DOWN, {"\x1b[6~", NULL}}, }; #endif diff --git a/include/ui.h b/include/ui.h index 56ddaaf..fdb08b1 100644 --- a/include/ui.h +++ b/include/ui.h @@ -4,8 +4,8 @@ #include void setup(struct config); -int load(struct users_list*, struct sessions_list*); -void print_err(const char*); -void print_errno(const char*); +int load(struct users_list *, struct sessions_list *); +void print_err(const char *); +void print_errno(const char *); #endif diff --git a/include/util.h b/include/util.h index 4759221..fcfca0c 100644 --- a/include/util.h +++ b/include/util.h @@ -5,9 +5,9 @@ #include #include -enum keys find_keyname(char*); -enum keys find_ansi(char*); -void read_press(u_char*, char*); +enum keys find_keyname(char *); +enum keys find_ansi(char *); +void read_press(u_char *, char *); void strcln(char **dest, const char *source); #endif diff --git a/src/config.c b/src/config.c index deb990f..903c45a 100644 --- a/src/config.c +++ b/src/config.c @@ -45,72 +45,72 @@ bool line_parser(FILE *fd, ssize_t *blksize, struct config *__config; u_char config_line_handler(char *k, char *v) { - if(strcmp(k, "colors.bg") == 0) + if (strcmp(k, "colors.bg") == 0) __config->theme.colors.bg = v; - else if(strcmp(k, "colors.fg") == 0) + else if (strcmp(k, "colors.fg") == 0) __config->theme.colors.fg = v; - else if(strcmp(k, "colors.err") == 0) + else if (strcmp(k, "colors.err") == 0) __config->theme.colors.err = v; - else if(strcmp(k, "colors.s_wl") == 0) + else if (strcmp(k, "colors.s_wl") == 0) __config->theme.colors.s_wl = v; - else if(strcmp(k, "colors.s_xorg") == 0) + else if (strcmp(k, "colors.s_xorg") == 0) __config->theme.colors.s_xorg = v; - else if(strcmp(k, "colors.s_shell") == 0) + else if (strcmp(k, "colors.s_shell") == 0) __config->theme.colors.s_shell = v; - else if(strcmp(k, "colors.f_other") == 0) + else if (strcmp(k, "colors.f_other") == 0) __config->theme.colors.f_other = v; - else if(strcmp(k, "colors.e_hostname") == 0) + else if (strcmp(k, "colors.e_hostname") == 0) __config->theme.colors.e_hostname = v; - else if(strcmp(k, "colors.e_date") == 0) + else if (strcmp(k, "colors.e_date") == 0) __config->theme.colors.e_date = v; - else if(strcmp(k, "colors.e_box") == 0) + else if (strcmp(k, "colors.e_box") == 0) __config->theme.colors.e_box = v; - else if(strcmp(k, "colors.e_header") == 0) + else if (strcmp(k, "colors.e_header") == 0) __config->theme.colors.e_header = v; - else if(strcmp(k, "colors.e_user") == 0) + else if (strcmp(k, "colors.e_user") == 0) __config->theme.colors.e_user = v; - else if(strcmp(k, "colors.e_passwd") == 0) + else if (strcmp(k, "colors.e_passwd") == 0) __config->theme.colors.e_passwd = v; - else if(strcmp(k, "colors.e_badpasswd") == 0) + else if (strcmp(k, "colors.e_badpasswd") == 0) __config->theme.colors.e_badpasswd = v; - else if(strcmp(k, "colors.e_key") == 0) + else if (strcmp(k, "colors.e_key") == 0) __config->theme.colors.e_key = v; - else if(strcmp(k, "chars.hb") == 0) + else if (strcmp(k, "chars.hb") == 0) __config->theme.chars.hb = v; - else if(strcmp(k, "chars.vb") == 0) + else if (strcmp(k, "chars.vb") == 0) __config->theme.chars.vb = v; - else if(strcmp(k, "chars.ctl") == 0) + else if (strcmp(k, "chars.ctl") == 0) __config->theme.chars.ctl = v; - else if(strcmp(k, "chars.ctr") == 0) + else if (strcmp(k, "chars.ctr") == 0) __config->theme.chars.ctr = v; - else if(strcmp(k, "chars.cbl") == 0) + else if (strcmp(k, "chars.cbl") == 0) __config->theme.chars.cbl = v; - else if(strcmp(k, "chars.cbr") == 0) + else if (strcmp(k, "chars.cbr") == 0) __config->theme.chars.cbr = v; - else if(strcmp(k, "functions.poweroff") == 0) + else if (strcmp(k, "functions.poweroff") == 0) __config->functions.poweroff = find_keyname(v); - else if(strcmp(k, "functions.reboot") == 0) + else if (strcmp(k, "functions.reboot") == 0) __config->functions.reboot = find_keyname(v); - else if(strcmp(k, "functions.refresh") == 0) + else if (strcmp(k, "functions.refresh") == 0) __config->functions.refresh = find_keyname(v); - else if(strcmp(k, "strings.f_poweroff") == 0) - __config->strings.f_poweroff= v; - else if(strcmp(k, "strings.f_reboot") == 0) - __config->strings.f_reboot= v; - else if(strcmp(k, "strings.f_refresh") == 0) - __config->strings.f_refresh= v; - else if(strcmp(k, "strings.e_user") == 0) - __config->strings.e_user= v; - else if(strcmp(k, "strings.e_passwd") == 0) - __config->strings.e_passwd= v; - else if(strcmp(k, "strings.s_xorg") == 0) - __config->strings.s_xorg= v; - else if(strcmp(k, "strings.s_wayland") == 0) - __config->strings.s_wayland= v; - else if(strcmp(k, "strings.s_shell") == 0) - __config->strings.s_shell= v; - else if(strcmp(k, "behavior.include_defshell") == 0) - __config->behavior.include_defshell= strcmp(v, "true") == 0; + else if (strcmp(k, "strings.f_poweroff") == 0) + __config->strings.f_poweroff = v; + else if (strcmp(k, "strings.f_reboot") == 0) + __config->strings.f_reboot = v; + else if (strcmp(k, "strings.f_refresh") == 0) + __config->strings.f_refresh = v; + else if (strcmp(k, "strings.e_user") == 0) + __config->strings.e_user = v; + else if (strcmp(k, "strings.e_passwd") == 0) + __config->strings.e_passwd = v; + else if (strcmp(k, "strings.s_xorg") == 0) + __config->strings.s_xorg = v; + else if (strcmp(k, "strings.s_wayland") == 0) + __config->strings.s_wayland = v; + else if (strcmp(k, "strings.s_shell") == 0) + __config->strings.s_shell = v; + else if (strcmp(k, "behavior.include_defshell") == 0) + __config->behavior.include_defshell = strcmp(v, "true") == 0; else return 0b1111; @@ -128,7 +128,7 @@ struct config *parse_config(char *path) { __config = malloc(sizeof(struct config)); if (__config == NULL) return NULL; - bool ret = line_parser(fd, (ssize_t*)&sb.st_blksize, config_line_handler); + bool ret = line_parser(fd, (ssize_t *)&sb.st_blksize, config_line_handler); if (!ret) { free(__config); return NULL; diff --git a/src/efield.c b/src/efield.c index 12f7bcf..daa798c 100644 --- a/src/efield.c +++ b/src/efield.c @@ -3,9 +3,9 @@ #include #include -struct editable_field field_new(char* content) { +struct editable_field field_new(char *content) { struct editable_field __efield; - if(content != NULL) { + if (content != NULL) { __efield.length = __efield.pos = strlen(content); memcpy(__efield.content, content, __efield.length); } else { @@ -30,10 +30,11 @@ void field_update(struct editable_field *field, char *update) { if (insert_len == 1) { // backspace if (*update == 127) { - if (field->pos == 0) return; + if (field->pos == 0) + return; if (field->pos < field->length) { memmove(&field->content[field->pos - 1], &field->content[field->pos], - field->length - field->pos); + field->length - field->pos); } (field->pos)--; (field->length)--; @@ -48,8 +49,8 @@ void field_update(struct editable_field *field, char *update) { } if (field->pos < field->length) { // move with immediate buffer - memmove(&field->content[field->pos + insert_len], &field->content[field->pos], - field->length - field->pos); + memmove(&field->content[field->pos + insert_len], + &field->content[field->pos], field->length - field->pos); } memcpy(&field->content[field->pos], update, insert_len); @@ -60,13 +61,18 @@ void field_update(struct editable_field *field, char *update) { // returns bool depending if it was able to "use" the seek bool field_seek(struct editable_field *field, char seek) { - if(field->length == 0) return false; + if (field->length == 0) + return false; - if(seek < 0 && -seek > field->pos) field->pos = 0; - else if(seek > 0 && 255 - field->pos < seek) field->pos = 255; - else field->pos += seek; + if (seek < 0 && -seek > field->pos) + field->pos = 0; + else if (seek > 0 && 255 - field->pos < seek) + field->pos = 255; + else + field->pos += seek; - if(field->pos > field->length) field->pos = field->length; + if (field->pos > field->length) + field->pos = field->length; return true; } diff --git a/src/main.c b/src/main.c index c7ff917..c09ceba 100644 --- a/src/main.c +++ b/src/main.c @@ -14,8 +14,9 @@ int main(int argc, char *argv[]) { if (argc == 2) chvt_str(argv[1]); - char* conf_override = getenv("LIDM_CONF"); - struct config *config = parse_config(conf_override == NULL ? "/etc/lidm.ini" : conf_override); + char *conf_override = getenv("LIDM_CONF"); + struct config *config = + parse_config(conf_override == NULL ? "/etc/lidm.ini" : conf_override); if (config == NULL) { fprintf(stderr, "error parsing config\n"); return 1; diff --git a/src/sessions.c b/src/sessions.c index 8b8f14b..4086ff1 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -40,7 +40,8 @@ static u_int16_t used_size = 0; static struct session *sessions = NULL; static struct sessions_list *__sessions_list = NULL; -// NOTE: commented printf's here would be nice to have debug logs if I ever implement it +// NOTE: commented printf's here would be nice to have debug logs if I ever +// implement it static enum session_type session_type; static int fn(const char *fpath, const struct stat *sb, int typeflag) { // practically impossible to reach this diff --git a/src/ui.c b/src/ui.c index b72bf3c..3c364a8 100644 --- a/src/ui.c +++ b/src/ui.c @@ -228,8 +228,8 @@ struct user get_current_user() { struct session get_current_session() { if (of_session.current_opt != 0) { - // this is for the default user shell :P, not the greatest implementation - // but I want to get his done + // this is for the default user shell :P, not the greatest + // implementation but I want to get his done if (behavior.include_defshell && of_session.current_opt == gsessions->length + 1) { struct session shell_session; @@ -506,7 +506,7 @@ static void print_empty_row(uint w, uint n, char *edge1, char *edge2) { static void print_row(uint w, uint n, char *edge1, char *edge2, char *filler) { for (uint i = 0; i < n; i++) { printf("%s", edge1); - for(uint i = 0; i < w; i++) { + for (uint i = 0; i < w; i++) { printf("%s", filler); } printf("%s\x1b[%dD\x1b[1B", edge2, w + 2); diff --git a/src/util.c b/src/util.c index a7e95b8..a15ce80 100644 --- a/src/util.c +++ b/src/util.c @@ -15,9 +15,9 @@ void strcln(char **dest, const char *source) { strcpy(*dest, source); } -enum keys find_keyname(char* name) { +enum keys find_keyname(char *name) { for (size_t i = 0; i < sizeof(key_mappings) / sizeof(key_mappings[0]); i++) { - if(strcmp(key_names[i], name) == 0) + if (strcmp(key_names[i], name) == 0) return (enum keys)i; }