From 33a1729792cfe7c06c030c317997134636da25af Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Thu, 17 Aug 2023 22:26:18 +0200 Subject: [PATCH] Added path_push_subdir function to path --- src/menu/path.c | 29 +++++++++++++++++++---------- src/menu/path.h | 4 +++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/menu/path.c b/src/menu/path.c index 2e49eadf..58638dea 100644 --- a/src/menu/path.c +++ b/src/menu/path.c @@ -88,16 +88,6 @@ bool path_is_root (path_t *path) { return (strcmp(path->root, "/") == 0); } -void path_push (path_t *path, char *string) { - if (path->buffer[strlen(path->buffer) - 1] != '/') { - path_append(path, "/"); - } - if (string[0] == '/') { - string += 1; - } - path_append(path, string); -} - void path_pop (path_t *path) { if (path_is_root(path)) { return; @@ -110,6 +100,25 @@ void path_pop (path_t *path) { } } +void path_push (path_t *path, char *string) { + if (path->buffer[strlen(path->buffer) - 1] != '/') { + path_append(path, "/"); + } + if (string[0] == '/') { + string += 1; + } + path_append(path, string); +} + +void path_push_subdir (path_t *path, char *string) { + char *file = path_last_get(path); + char *tmp = alloca(strlen(file) + 1); + strcpy(tmp, file); + path_pop(path); + path_push(path, string); + path_push(path, tmp); +} + char *path_ext_get (path_t *path) { char *buffer = path_last_get(path); char *last_dot = strrchr(buffer, '.'); diff --git a/src/menu/path.h b/src/menu/path.h index 9c02c179..3bf51950 100644 --- a/src/menu/path.h +++ b/src/menu/path.h @@ -9,6 +9,7 @@ #include +#include /** @brief Path Structure */ @@ -26,8 +27,9 @@ path_t *path_clone_push (path_t *path, char *string); char *path_get (path_t *path); char *path_last_get (path_t *path); bool path_is_root (path_t *path); -void path_push (path_t *path, char *string); void path_pop (path_t *path); +void path_push (path_t *path, char *string); +void path_push_subdir (path_t *path, char *string); char *path_ext_get (path_t *path); void path_ext_remove (path_t *path); void path_ext_replace (path_t *path, char *ext);