-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
60 lines (47 loc) · 1.32 KB
/
main.c
File metadata and controls
60 lines (47 loc) · 1.32 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
#include <ctype.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "utilities.h"
#include "options.h"
#include "io.h"
#include "main.h"
static volatile sig_atomic_t sigint_count = 0;
static void sigint_handler(int sig) {
if (is_main_process()) {
++sigint_count;
if (sigint_count == 1) {
puts("Press CTRL-C again to quit.");
} else {
running = false;
}
}
}
void print_usage(char* program) {
printf("\nUsage: %s [files] [directories] [options]\n", program);
puts("\nOptions:\n");
puts(" --verbose [-v]");
puts(" --recursive [-r]");
puts(" --extensions [-e] .c,.py,...");
puts(" --logging=[logfile](optional) / -l (default logfile)");
putchar('\n');
}
int main(int argc, char *argv[]) {
// initialize signal handler
running = true;
if (signal(SIGINT, sigint_handler) == SIG_ERR)
perror("Initializing SIGINT signal handler failed.");
struct str_array args;
init_options(&options);
int rc = get_options(&options, &args, argc, argv);
if (rc < 0) {
print_usage(argv[0]);
return EXIT_FAILURE;
}
if (options.verbose)
print_options(&options, &args);
clean_files(&args);
free_options(&options, &args);
return EXIT_SUCCESS;
}