From 250831f893ed3a35fc6f59203166341058845bb4 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Fri, 6 Nov 2015 18:07:40 -0800 Subject: More efficient handling of going up one directory in menu --- menu.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index 17cf181..d5dd26d 100644 --- a/menu.c +++ b/menu.c @@ -111,9 +111,20 @@ void * menu_write_w(uint32_t address, void * context, uint16_t value) break; } } - char *pieces[] = {menu->curpath, "/", buf}; - menu->curpath = alloc_concat_m(3, pieces); - free(pieces[0]); + if (!strcmp(buf, "..")) { + size_t len = strlen(menu->curpath); + while (len > 1) { + --len; + if (menu->curpath[len] == '/') { + menu->curpath[len] = 0; + break; + } + } + } else { + char *pieces[] = {menu->curpath, "/", buf}; + menu->curpath = alloc_concat_m(3, pieces); + free(pieces[0]); + } break; } default: -- cgit v1.2.3