changeset 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 4298db923cf8
children f364f4f22f8f
files menu.c
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
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: