commit 8dc1039990c2352b7fb70fa054eeb5a60e63f3a1
parent a43985bfdfaea01c90fbd249eb01fece7f4faf99
Author: qorg11 <qorg@vxempire.xyz>
Date: Sun, 8 Nov 2020 21:52:31 +0100
Added the -p flag to ls
Diffstat:
M | src/ls.c | | | 57 | +++++++++++++++++++++++++++++++++++---------------------- |
1 file changed, 35 insertions(+), 22 deletions(-)
diff --git a/src/ls.c b/src/ls.c
@@ -5,28 +5,41 @@
int
main(int argc, char *argv[])
{
- int c = getopt(argc,argv,"a");
- int all;
- switch(c)
- {
- case 'a':
- all = 1;
- break;
- }
-
- DIR *dir = opendir(".");
- struct dirent *ent;
+ int c;
+ int all, show_slash;
+ all = show_slash = 0;
- if(dir != NULL)
- {
- while((ent = readdir(dir)) != NULL)
- {
- if(ent->d_name[0] == '.' && !all)
- continue;
- printf("%s\n",ent->d_name); /* TODO: sort, and do not display . and .. */
- }
- }
- closedir(dir);
+ while ((c = getopt(argc,argv,"ap")) != -1)
+ {
+ switch(c)
+ {
+ case 'a':
+ all = 1;
+ break;
+ case 'p':
+ show_slash = 1;
+ break;
+ }
- return 0;
+ }
+
+
+ DIR *dir = opendir(".");
+ struct dirent *ent;
+
+ if(dir != NULL)
+ {
+ while((ent = readdir(dir)) != NULL)
+ {
+ if(ent->d_name[0] == '.' && !all)
+ continue;
+ if(ent->d_type == DT_DIR && show_slash)
+ printf("%s/ ",ent->d_name);
+ else printf("%s ",ent->d_name);
+ }
+ }
+ puts("");
+ closedir(dir);
+
+ return 0;
}