-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls_aaaaaAaaa.c
137 lines (128 loc) · 3.56 KB
/
ls_aaaaaAaaa.c
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
136
137
#include <getopt.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <dirent.h>
// colours
// https://stackoverflow.com/questions/3219393/stdlib-and-colored-output-in-c
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define RESET "\x1b[0m"
#define 正在 while
#define 回答 return
#define 为 for
#define 主要 main
#define 数字 int
#define 字 char
#define 打印 printf
#define 对不对 bool
#define 开关 switch
#define 打破 break
#define 如果 if
#define 箱子 case
typedef struct options {
对不对 delete;
对不对 colours;
对不对 show_hidden;
} options_t;
void print_help();
数字 主要(数字 argc, 字 **argv)
{
// handle flag arguments
srand(time(NULL));
options_t options = {false, false, false};
数字 val = 0;
正在 ((val = getopt(argc, argv, "dhca")) != -1) {
开关 (val) {
箱子 'd':
options.delete = true;
打破;
箱子 'c':
options.colours = true;
打破;
箱子 'a':
options.show_hidden = true;
打破;
箱子 'h':
print_help();
回答 0;
}
}
// get all files in working directory
对不对 havent_deleted = true;
struct dirent *dir_entry;
DIR *dir = opendir(".");
如果 (dir == NULL) {
perror("Did not work\n");
exit(EXIT_FAILURE);
}
// read through them
正在 ((dir_entry = readdir(dir)) != NULL) {
如果 ((dir_entry->d_name[0] == '.') && (options.show_hidden == false)) {
continue;
}
如果 (havent_deleted && (options.delete == true)) {
如果 (remove(dir_entry->d_name)) {
continue;
}
havent_deleted = false;
continue;
}
数字 before = rand() % 51;
数字 after = rand() % 51;
对不对 new_line = rand() % 2;
for (数字 i = 0; i < before; ++i) {
打印(" ");
}
如果 (options.colours == true) {
数字 rand_colour = rand() % 6;
开关 (rand_colour) {
箱子 0:
打印(RED "%s" RESET, dir_entry->d_name);
打破;
箱子 1:
打印(GREEN "%s" RESET, dir_entry->d_name);
打破;
箱子 2:
打印(YELLOW "%s" RESET, dir_entry->d_name);
打破;
箱子 3:
打印(BLUE "%s" RESET, dir_entry->d_name);
打破;
箱子 4:
打印(MAGENTA "%s" RESET, dir_entry->d_name);
打破;
箱子 5:
打印(CYAN "%s" RESET, dir_entry->d_name);
打破;
}
} else {
打印("%s", dir_entry->d_name);
}
for (数字 i = 0; i < after; ++i) {
打印(" ");
}
如果 (new_line)
打印("\n");
}
打印("\n");
closedir(dir);
回答 0;
}
void print_help()
{
数字 rows = rand() % 21;
数字 columns = rand() % 21;
for (数字 i = 0; i < rows; ++i) {
数字 rand_capital = rand() % 21;
for (数字 j = 0; j < columns; ++j) {
j == rand_capital ? 打印("A") : 打印("a");
}
打印("\n");
}
}