aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqorg11 <qorg@vxempire.xyz>2020-11-08 21:52:31 +0100
committerqorg11 <qorg@vxempire.xyz>2020-11-08 21:52:31 +0100
commit8dc1039990c2352b7fb70fa054eeb5a60e63f3a1 (patch)
tree6a33971cd3bd95a7d0854548fd765f5d39eefefb
parenta43985bfdfaea01c90fbd249eb01fece7f4faf99 (diff)
downloadk9core-8dc1039990c2352b7fb70fa054eeb5a60e63f3a1.tar.gz
k9core-8dc1039990c2352b7fb70fa054eeb5a60e63f3a1.zip
Added the -p flag to ls
-rw-r--r--src/ls.c57
1 files changed, 35 insertions, 22 deletions
diff --git a/src/ls.c b/src/ls.c
index 10bdf71..63c4ede 100644
--- 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;
}