-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
73 lines (63 loc) · 2.01 KB
/
main.c
File metadata and controls
73 lines (63 loc) · 2.01 KB
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
#include "include/thread_control.h"
bool recursion;
int main(int argc, char const *argv[])
{
if(argc <= 1){
printf("too few argments, use -h for help.\n");
return -1;
}
bool single_file = false;
recursion = true;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--file") == 0) {
single_file = true;
}
if (strcmp(argv[i], "--norecursion") == 0) {
recursion = false;
}
}
char const *file_path = argv[1];
double elapsed;
#if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER frequency, start, end;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
#elif defined(__linux__)
struct timeval start, end;
long seconds, microseconds;
gettimeofday(&start, NULL);
#endif
if(single_file){
counter ctr;
init_counter(&ctr);
sem_init(&write_lock, 0, 1);
single_file_count(file_path, &ctr);
char *sp, *bk, *ct, *ce, *tt, *sm;
sp = "";
bk = "Blank";
ct = "Comment";
ce = "Code";
tt = "Total";
sm = "Sum";
printf("%3s %10s %10s %10s %10s\n",sp, bk, ct, ce, tt);
printf("%-3s %10d %10d %10d %10d\n", sm,ctr.blank, ctr.comment, ctr.code, ctr.line);
printf("-----------------------------------------------\n");
}
else{
pcenter(file_path);
}
#if defined(_WIN32) || defined(_WIN64)
QueryPerformanceCounter(&end);
elapsed = (double)(end.QuadPart - start.QuadPart) / frequency.QuadPart;
#elif defined(__linux__)
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
microseconds = end.tv_usec - start.tv_usec;
elapsed = seconds + microseconds * 1e-6;
#endif
printf("C file %8d \nHeader file %8d \n", cfile, hfile);
printf("-----------------------------------------------\n");
printf("Function execution time: %.6f seconds\n", elapsed);
printf("-----------------------------------------------\n");
return 0;
}