commit ff388fb3498387b4f6ecb7b4f1a71d3bb876d03a
parent 85dcfcaca8052b1f9bbc5280e18e03091596d490
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 5 Sep 2021 21:14:49 +0000
extra/Dir: add ../ line, add */ marker for specific file types, make whole line a link
Diffstat:
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/extra/Dir.c b/extra/Dir.c
@@ -41,31 +41,32 @@ main(int argc, char **argv)
int fd;
long i, n;
Dir *dp, *dbuf;
- char *path, buf[4096];
+ char *path, buf[4096], *id, *spacer;
path = getwd(buf, sizeof(buf));
if (argc == 2) path = argv[1];
fd = open(path, OREAD);
if (fd < 0) sysfatal("%r");
dp = dirfstat(fd);
if (dp == nil) sysfatal("%r");
+
+ id = getnewid();
+ rprint(id, "text", "../\n");
+ rprint(id, "link", "..");
+ free(id);
+
if (dp->mode & DMDIR) {
dbuf = mallocz(DIRMAX, 1);
n = dirreadall(fd, &dbuf);
for (i = 0; i < n; i++) {
- char *id, *link, *text;
+ char *label;
+ spacer = "";
+ if (dbuf[i].mode & DMEXEC) spacer = "*";
+ if (dbuf[i].mode & DMDIR) spacer = "/";
+ label = smprint("%s%s\n", dbuf[i].name, spacer);
id = getnewid();
- text = smprint("%s/%s/text", rroot, id);
- link = smprint("%s/%s/link", rroot, id);
- rprint(id, "text", dbuf[i].name);
+ rprint(id, "text", label);
rprint(id, "link", dbuf[i].name);
free(id);
- free(link);
- free(text);
- id = getnewid();
- text = smprint("%s/%s/text", rroot, id);
- rprint(id, "text", "\n");
- free(id);
- free(text);
}
} else sysfatal("not a directory");
}