-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsls.h
135 lines (133 loc) · 3.69 KB
/
lsls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <unistd.h>
#include <stdio.h>
//#include<type.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string>
#include <errno.h>
#include <typeinfo>
#include <sys/stat.h>
#include <sys/types.h>
#include<dirent.h>
#include<sys/ioctl.h>
#include <pwd.h>
#include <grp.h>
#include<time.h>
#include<bits/stdc++.h>
//#include "minimal.h"
//#include"canonical.h"
//#include "non_canonical.h"
//#include "copy.h"
//#include "xdg_open.h"
#define clear() printf("\033[H\033[J")
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))
using namespace std;
void lsls(string s,int x)
{
//cout<<" *********************************************"<<endl;
/*struct termios initial_settings, new_settings;
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
if(tcsetattr(0, TCSANOW, &new_settings) != 0)
fprintf(stderr,"could not set attributes\n");
*/
DIR *mydir;
struct dirent *myfile;
struct stat mystat;
int ret;
struct passwd *pwd;
struct group *grp;
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
struct dirent **namelist;
int n;
//cout<<s.c_str()<<endl;
n=scandir(s.c_str(),&namelist,NULL,alphasort);
int i;
//cout<<n<<endl;
//ret=stat(s.c_str(), &mystat);
gotoxy(3,1);
i=x;
int j=3,k=1;
for(;i<min(w.ws_row-10+x,n);i++)
{
k=1;
//cout<<"hello"<<endl;
string d=s+"/"+namelist[i]->d_name;
stat(d.c_str(),&mystat);
int fileMode = mystat.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
//cout<<"hello"<<endl;
if (S_ISDIR(mystat.st_mode))
printf("d");
else
printf("-");
if ((fileMode & S_IRUSR) && (fileMode & S_IREAD))
printf("r");
else
printf("-");
if ((fileMode & S_IWUSR) && (fileMode & S_IWRITE))
printf("w");
else
printf("-");
if ((fileMode & S_IXUSR) && (fileMode & S_IEXEC))
printf("x");
else
printf("-");
/* Check group permissions */
if ((fileMode & S_IRGRP) && (fileMode & S_IREAD))
printf("r");
else
printf("-");
if ((fileMode & S_IWGRP) && (fileMode & S_IWRITE))
printf("w");
else
printf("-");
if ((fileMode & S_IXGRP) && (fileMode & S_IEXEC))
printf("x");
else
printf("-");
/* check other user permissions */
if ((fileMode & S_IROTH) && (fileMode & S_IREAD))
printf("r");
else
printf("-");
if ((fileMode & S_IWOTH) && (fileMode & S_IWRITE))
printf("w");
else
printf("-");
if ((fileMode & S_IXOTH) && (fileMode & S_IEXEC))
/* because this is the last permission, leave 3 blank spaces after print */
printf("x");
else
printf("-");
// printf(" ");
k=k+11;
gotoxy(j,k);
if ((pwd = getpwuid(mystat.st_uid)) != NULL)
printf("%s", pwd->pw_name);
k=k+10;
gotoxy(j,k);
if ((grp = getgrgid(mystat.st_gid)) != NULL)
printf("%s", grp->gr_name);
k=k+10;
gotoxy(j,k);
printf("%lld",(long long) mystat.st_size);
//printf("%lld ",(long long) mystat.st_blocks);
//Last status change:
k=k+6;
gotoxy(j,k);
if(namelist[i]->d_type!=8)
printf("\033[1;34m%s\033[0m",namelist[i]->d_name);
else
printf("%s",namelist[i]->d_name);
gotoxy(j,k+30);
printf("%s",ctime(&mystat.st_mtime));
j++;
}
gotoxy(3,1);
// closedir(mydir);
}