diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index db871fd..3ea5dfc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,7 +1,10 @@ name: Push Checks on: - push + push: + pull_request: + types: + - opened jobs: check-and-build: diff --git a/assets/pkg/aur/lidm-bin/.SRCINFO b/assets/pkg/aur/lidm-bin/.SRCINFO index 997b90b..9499001 100644 --- a/assets/pkg/aur/lidm-bin/.SRCINFO +++ b/assets/pkg/aur/lidm-bin/.SRCINFO @@ -1,19 +1,19 @@ pkgbase = lidm-bin pkgdesc = A fully colorful customizable TUI display manager made in C. (release binary) - pkgver = 0.2.1 - pkgrel = 2 + pkgver = 0.2.2 + pkgrel = 1 url = https://github.com/javalsai/lidm arch = x86_64 license = GPL depends = pam provides = lidm conflicts = lidm - source = lidm::https://github.com/javalsai/lidm/releases/download/v0.2.1/lidm-amd64 - source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/themes/default.ini - source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm.1 - source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.2.1/assets/man/lidm-config.5 - sha256sums = 4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622 - sha256sums = 27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7 + source = lidm::https://github.com/javalsai/lidm/releases/download/v0.2.2/lidm-amd64 + source = default-theme.ini::https://raw.githubusercontent.com/javalsai/lidm/v0.2.2/themes/default.ini + source = lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v0.2.2/assets/man/lidm.1 + source = lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v0.2.2/assets/man/lidm-config.5 + sha256sums = be2307be9bef7b3ef294fb0e8178040e2d8ccff6b8efb7546514da8b0f69c179 + sha256sums = 68662430a6d262b35cc54d9f0e164ed935b7f7f4497a87cc94946c558bbe8a91 sha256sums = a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce sha256sums = 3adaae60f79dff1cef2b2aba7dcea04196cd49816759ad36afb9f7331ac9c3e4 diff --git a/assets/pkg/aur/lidm-bin/PKGBUILD b/assets/pkg/aur/lidm-bin/PKGBUILD index 448649e..f0733f0 100644 --- a/assets/pkg/aur/lidm-bin/PKGBUILD +++ b/assets/pkg/aur/lidm-bin/PKGBUILD @@ -1,8 +1,8 @@ # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # Maintainer: javalsai pkgname=lidm-bin -pkgver=0.2.1 -pkgrel=2 +pkgver=0.2.2 +pkgrel=1 depends=('pam') pkgdesc="A fully colorful customizable TUI display manager made in C. (release binary)" arch=('x86_64') @@ -16,8 +16,8 @@ source=( "lidm.1::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm.1" "lidm-config.5::https://raw.githubusercontent.com/javalsai/lidm/v$pkgver/assets/man/lidm-config.5" ) -sha256sums=('4969018d527613729336abd51e37283ce77d7c7a2233434642804b88e550e622' - '27db9b0cd2da80c0c60dcb13dfad0f9d65e7dddbb7b344b859803b9ac3943cd7' +sha256sums=('be2307be9bef7b3ef294fb0e8178040e2d8ccff6b8efb7546514da8b0f69c179' + '68662430a6d262b35cc54d9f0e164ed935b7f7f4497a87cc94946c558bbe8a91' 'a6807a55ff72ec5a5678583156b3efd0d367f0bcb79854094132771f0cb86bce' '3adaae60f79dff1cef2b2aba7dcea04196cd49816759ad36afb9f7331ac9c3e4') diff --git a/assets/pkg/aur/lidm-git/PKGBUILD b/assets/pkg/aur/lidm-git/PKGBUILD index 18fd78f..c01112e 100644 --- a/assets/pkg/aur/lidm-git/PKGBUILD +++ b/assets/pkg/aur/lidm-git/PKGBUILD @@ -1,7 +1,7 @@ # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # Maintainer: javalsai pkgname=lidm-git -pkgver=0.2.1.r0.ge2014f4 +pkgver=0.2.2.r0.gb22ae6b pkgrel=1 depends=('pam') makedepends=('git' 'make' 'gcc') diff --git a/assets/pkg/aur/lidm/.SRCINFO b/assets/pkg/aur/lidm/.SRCINFO index cce4623..ec7a48b 100644 --- a/assets/pkg/aur/lidm/.SRCINFO +++ b/assets/pkg/aur/lidm/.SRCINFO @@ -1,6 +1,6 @@ pkgbase = lidm pkgdesc = A fully colorful customizable TUI display manager made in C. (build latest tag) - pkgver = 0.2.1 + pkgver = 0.2.2 pkgrel = 1 url = https://github.com/javalsai/lidm arch = any @@ -8,7 +8,7 @@ pkgbase = lidm makedepends = git makedepends = gcc depends = pam - source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.2.1.tar.gz - sha256sums = 56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b + source = tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v0.2.2.tar.gz + sha256sums = 25523abc3ce6f2f261bff0cc52663607fe114692d6d3736f27fd843cae3f3a27 pkgname = lidm diff --git a/assets/pkg/aur/lidm/PKGBUILD b/assets/pkg/aur/lidm/PKGBUILD index 8e86d85..0eed7e1 100644 --- a/assets/pkg/aur/lidm/PKGBUILD +++ b/assets/pkg/aur/lidm/PKGBUILD @@ -1,7 +1,7 @@ # shellcheck disable=SC2034,SC2148,SC2128,SC2154,SC2164 # Maintainer: javalsai pkgname=lidm -pkgver=0.2.1 +pkgver=0.2.2 pkgrel=1 depends=('pam') makedepends=('git' 'gcc') @@ -10,7 +10,7 @@ arch=('any') url="https://github.com/javalsai/lidm" license=('GPL') source=("tarball.tar.gz::https://github.com/javalsai/lidm/archive/refs/tags/v$pkgver.tar.gz") -sha256sums=('56aaf8025fac16f5deef3058274635198fc3bf3f7eadc1de5c6539614f03d84b') +sha256sums=('25523abc3ce6f2f261bff0cc52663607fe114692d6d3736f27fd843cae3f3a27') build() { tar -xzf "tarball.tar.gz" diff --git a/assets/pkg/aur/test-makepkg.sh b/assets/pkg/aur/test-makepkg.sh index 302985c..3f79352 100755 --- a/assets/pkg/aur/test-makepkg.sh +++ b/assets/pkg/aur/test-makepkg.sh @@ -5,8 +5,14 @@ MYSELF=$(realpath "$0") MYDIR=$(dirname "$MYSELF") for pkg in "$MYDIR"/*/; do - cd "$pkg" printf "\x1b[1mEntering '%s'\x1b[0m\n" "$pkg" + cd "$pkg" + + # shellcheck disable=SC1091 + source "PKGBUILD" + for source in "${source[@]}"; do + awk -F'::' '{print $1}' <<<"$source" | xargs rm -rf + done rm -rf ./*.{gz,zst} src pkg makepkg -f . diff --git a/include/util.h b/include/util.h index 086afb8..a868865 100644 --- a/include/util.h +++ b/include/util.h @@ -15,12 +15,14 @@ void strcln(char **dest, const char *source); struct Vector { uint32_t length; - uint32_t alloc_len; - uint16_t alloc_size; + uint32_t capacity; void **pages; }; struct Vector vec_new(); +int vec_resize(struct Vector *, size_t size); +int vec_reserve(struct Vector *, size_t size); +int vec_reserve_exact(struct Vector *, size_t size); int vec_push(struct Vector *, void *item); void vec_free(struct Vector *); void vec_clear(struct Vector *); diff --git a/src/config.c b/src/config.c index 930be75..9488a23 100644 --- a/src/config.c +++ b/src/config.c @@ -4,6 +4,14 @@ #include "config.h" #include "util.h" +// Alr so ima explain the bitfield returned by `cb` a bit +// 4 bits: +// 0b0001: break out of parsing (returning true) +// 0b0010: free the value +// 0b0100: free the key +// 0b1000: break out of parsing (returning false) +// +// This would return true if everything goes fine, false otherwise (malloc error, broke parsing, etc) bool line_parser(FILE *fd, ssize_t *blksize, u_char (*cb)(char *key, char *value)) { size_t opt_size = 4096; @@ -41,19 +49,20 @@ bool line_parser(FILE *fd, ssize_t *blksize, if (ret & 0b1000) { free(buf); return false; - } - if (ret & 0b0001) { - free(buf); + } + if (ret & 0b0001) { + free(buf); break; - } + } } - free(buf); + free(buf); } return true; } struct config *__config; +// Yanderedev code (wanna fix this with a table or smth) u_char config_line_handler(char *k, char *v) { if (strcmp(k, "colors.bg") == 0) __config->theme.colors.bg = v; @@ -98,16 +107,13 @@ u_char config_line_handler(char *k, char *v) { else if (strcmp(k, "functions.poweroff") == 0) { __config->functions.poweroff = find_keyname(v); return 0b0110; - } - else if (strcmp(k, "functions.reboot") == 0) { + } else if (strcmp(k, "functions.reboot") == 0) { __config->functions.reboot = find_keyname(v); return 0b0110; - } - else if (strcmp(k, "functions.refresh") == 0) { + } else if (strcmp(k, "functions.refresh") == 0) { __config->functions.refresh = find_keyname(v); return 0b0110; - } - else if (strcmp(k, "strings.f_poweroff") == 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; @@ -126,15 +132,14 @@ u_char config_line_handler(char *k, char *v) { else if (strcmp(k, "behavior.include_defshell") == 0) { __config->behavior.include_defshell = strcmp(v, "true") == 0; return 0b0110; - } - else if (strcmp(k, "behavior.source") == 0) + } else if (strcmp(k, "behavior.source") == 0) vec_push(&__config->behavior.source, v); else if (strcmp(k, "behavior.user_source") == 0) vec_push(&__config->behavior.user_source, v); else return 0b1111; - return 0b100; + return 0b0100; } struct config *parse_config(char *path) { diff --git a/src/sessions.c b/src/sessions.c index 2bd0b54..7ffeaa0 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -54,6 +54,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { char *exec_buf = NULL; char *tryexec_buf = NULL; // This should be made a specific function + // Emm, if anything goes wrong just free the inner loop and `break;` fd and the rest is handled after while (true) { char *buf = malloc(sb->st_blksize); ssize_t read_size = getline(&buf, &alloc_size, fd); @@ -64,7 +65,19 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { uint read; char *key = malloc(read_size + sizeof(char)); + if(key == NULL) { + free(buf); + // TODO: more sophisticated error handling?? + break; + } char *value = malloc(read_size + sizeof(char)); + if(value == NULL) { + free(buf); + free(key); + // TODO: more sophisticated error handling?? + break; + } + value[0] = '\0'; // I'm not sure if sscanf would null this string out if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, value)) != 0) { if (strcmp(key, "Name") == 0) { found &= 0b001; @@ -78,13 +91,17 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { } else { free(value); } - } + } else { + free(value); + } free(key); - free(buf); + free(buf); if (found == 0b111) break; } /*printf("\nend parsing...\n");*/ + // Generic handling of exit + fclose(fd); // just add this to the list @@ -108,6 +125,7 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) { // This code is designed to be run purely single threaded struct Vector get_avaliable_sessions() { struct Vector sessions = vec_new(); + vec_reserve(&sessions, 8); cb_sessions = &sessions; for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) { diff --git a/src/ui.c b/src/ui.c index b05d0db..f97f276 100644 --- a/src/ui.c +++ b/src/ui.c @@ -322,6 +322,7 @@ void ffield_type(char *text) { print_ffield(); } +static char* unknown_str = "unknown"; int load(struct Vector *users, struct Vector *sessions) { /// SETUP gusers = users; @@ -331,9 +332,9 @@ int load(struct Vector *users, struct Vector *sessions) { char *hostname = malloc(16); if (gethostname(hostname, 16) != 0) { free(hostname); - hostname = "unknown"; + hostname = unknown_str; } else { - hostname = realloc(hostname, strlen(hostname) + 1); + hostname[15] = '\0'; } of_session = ofield_new(sessions->length + behavior.include_defshell); @@ -350,12 +351,14 @@ int load(struct Vector *users, struct Vector *sessions) { printf("\x1b[%d;%dH\x1b[%sm%s\x1b[%sm", boxstart.y + 2, boxstart.x + 12 - (uint)strlen(hostname), theme.colors.e_hostname, hostname, theme.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 + 2, boxstart.x + boxw - 3 - (uint)strlen(fmtd_time), theme.colors.e_date, fmtd_time, theme.colors.fg); + free(fmtd_time); print_field(SESSION); print_field(USER); diff --git a/src/users.c b/src/users.c index 67049a8..7cc3a7c 100644 --- a/src/users.c +++ b/src/users.c @@ -23,6 +23,7 @@ static struct user __new_user(struct passwd *p) { // This code is designed to be run purely single threaded struct Vector get_human_users() { struct Vector users = vec_new(); + vec_reserve(&users, 4); struct passwd *pwd; while ((pwd = getpwent()) != NULL) { diff --git a/src/util.c b/src/util.c index e2a95d2..d5138c7 100644 --- a/src/util.c +++ b/src/util.c @@ -75,20 +75,41 @@ struct Vector vec_new() { return vec; } -int vec_push(struct Vector *vec, void *item) { - if (vec->length >= vec->alloc_len) { - uint32_t new_size = vec->alloc_len + vec->alloc_size; - void **new_location = realloc(vec->pages, vec->alloc_size); - if (new_location != NULL) { - vec->alloc_size = new_size; - vec->pages = new_location; - } else { - return -1; - } +int vec_resize(struct Vector *vec, size_t size) { + void **new_location = realloc(vec->pages, size * sizeof(void*)); + if (new_location != NULL) { + if (vec->length > size) + vec->length = size; + vec->capacity = size; + vec->pages = new_location; + } else { + return -1; } + return 0; +} - vec->pages[vec->length] = item; - vec->length++; +int vec_reserve(struct Vector *vec, size_t size) { + uint32_t new_capacity = vec->capacity; + while (vec->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); +} + +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_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; } @@ -106,8 +127,7 @@ void vec_clear(struct Vector *vec) { void vec_reset(struct Vector *vec) { vec->length = 0; - vec->alloc_len = 0; - vec->alloc_size = 4096; // 4KiB page size? + vec->capacity = 0; vec->pages = NULL; }