Mercurial > repos > blastem
diff menu.c @ 870:f173317ecdb4
More efficient handling of going up one directory in menu
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 06 Nov 2015 18:07:40 -0800 |
parents | 1bab7e01ae98 |
children | 7022ba865cfd |
line wrap: on
line diff
--- a/menu.c Fri Nov 06 18:04:43 2015 -0800 +++ b/menu.c Fri Nov 06 18:07:40 2015 -0800 @@ -111,9 +111,20 @@ 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: