wm: teppich

Download patch

ref: 8d3dbfa11753101bdfdc9fcce43ed5c0756cf0a5
parent: fda16cc781136673518f9f04ebd907c0e96cda86
author: mkf <mkf@cloud9p.org>
date: Tue Nov 28 23:24:14 EST 2023

cmd/ls: add lflag

--- a/cmd/ls.c
+++ b/cmd/ls.c
@@ -1,8 +1,6 @@
 #include <u.h>
 #include <libc.h>
-
 #include <err.h>
-
 #include <mem.h>
 #include <vfs.h>
 
@@ -15,6 +13,7 @@
 
 	i = 0;
 	j = 0;
+
 	while(i < 9)
 	{
 		s[j++] = (perms & (4 << i)) ? 'r' : '-';
@@ -29,6 +28,7 @@
 	return s;
 }
 
+
 int
 ls_main(int argc, char **argv, char *cwd)
 {
@@ -36,12 +36,19 @@
 	fs_t *fs;
 	file_t *f, *dir;
 	char *perms;
+	int lflag;
 
+	lflag = 0;
 	if(argc == 1)
 	{
 		argv[1] = "/";
 		argc = 2;
 	}
+	if(argc > 1 && !strcmp(argv[1], "-l"))
+	{
+		lflag = 1;
+		argv++;
+	}
 	
 	fs = getfs(argv[1]);
 	if(fs == nil)
@@ -63,16 +70,25 @@
 	while(t != nil)
 	{
 		f = ((file_t*)t->val);
-	
-		printf("%d\t", f->fid);
-		printf("%d\t", f->size);
+		if(lflag)
+		{
+			printf("%d\t", f->fid);
+			printf("%d\t", f->size);
 
-		printf("%d\t", f->owner);
-		printf("%s\t", permtoletter(f->perms));
+			printf("%d\t", f->owner);
+			perms = permtoletter(f->perms);
+			printf("%s\t", perms);
 
-		printf("%s", f->path);
-		printf("%s\n", f->name);
-			
+			printf("%s", f->path);
+			printf("%s\n", f->name);
+		}
+		else
+		{
+
+			printf("%s", f->path);
+			printf("%s\n", f->name);
+		}
+
 		t = (ll_t*)t->next;
 	}