-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
142 lines (94 loc) · 2.38 KB
/
main.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
138
139
140
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define USE_BUSY_SLEEPING
#define BUF_SIZE 65536
bool isFeatureEnabled (const int argc, char *argv[], char FeatureName[]) {
for (int CurrentArg = 1; CurrentArg < argc; ++CurrentArg) {
if (strcmp(argv[CurrentArg],FeatureName) != 0){
return true;
}
}
return false;
}
int count_lines(FILE* file)
{
char buf[BUF_SIZE];
int counter = 0;
for(;;)
{
size_t res = fread(buf, 1, BUF_SIZE, file);
if (ferror(file))
return -1;
int i;
for(i = 0; i < res; i++)
if (buf[i] == '\n')
counter++;
if (feof(file))
break;
}
return counter;
}
void sleep_for_millisecs(unsigned Millisecs) {
printf("%s%d%s\n", "Sleeping for ", Millisecs, " milliseconds");
fflush(stdout);
sleep(1);
}
static bool __attribute__((feature_variable("F1"))) F1;
static bool __attribute__((feature_variable("F2"))) F2;
static bool __attribute__((feature_variable("F3"))) F3;
int main(const int argc, char *argv[])
{
F1 = isFeatureEnabled(argc, argv, "--f1");
F2 = isFeatureEnabled(argc, argv, "--f2");
F3 = isFeatureEnabled(argc, argv, "--f3");
if (argc < 1) {
printf("Please specify a file");
}
const char* filename = "";
for (int CurrentArg = 1; CurrentArg < argc; ++CurrentArg) {
char* argument = argv[CurrentArg];
if (strstr(argument, ".txt") != NULL) {
filename = argument;
}
}
int ch=0;
int lines=1;
if (F1) {
sleep_for_millisecs(200);
}
sleep_for_millisecs(111);
if (F2) {
sleep_for_millisecs(300);
}
sleep_for_millisecs(111);
if (F3) {
sleep_for_millisecs(400);
}
sleep_for_millisecs(111);
if (F1 && F2) {
sleep_for_millisecs(120);
}
sleep_for_millisecs(111);
if (F1 || F2) {
sleep_for_millisecs(210);
}
sleep_for_millisecs(111);
if (F1 && F2 || F3) {
sleep_for_millisecs(132);
}
sleep_for_millisecs(111);
if (F1 || F2 && F3) {
sleep_for_millisecs(213);
}
sleep_for_millisecs(111);
if (F1 && F2 && F3) {
sleep_for_millisecs(123);
}
sleep_for_millisecs(111);
if (F1 || F2 || F3) {
sleep_for_millisecs(321);
}
return 0;
}