-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
42 lines (39 loc) · 1.1 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
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include "cli.h"
#include "commands.h"
#include "arena.h"
#include "utils.h"
#define ONE_MEG 1024 * 1024
int main(int argc, char **argv)
{
Arena arena;
init_arena(&arena, ONE_MEG);
Cli_args *args = parse_cli(argc, argv, &arena);
int exit_code = EXIT_SUCCESS;
if (argc == 2 && (strcmp(argv[1], "help") == 0 ||
strcmp(argv[1], "--help") == 0 ||
strcmp(argv[1], "-help") == 0 ||
strcmp(argv[1], "-h") == 0))
{
print_help(argv[0]);
}
else if (args->command == LS)
exit_code = command_ls(args, &arena);
else if (args->command == F)
exit_code = command_find(args, &arena);
else if (args->command == NEW)
exit_code = command_new(args, &arena);
else if (args->command == SIZE)
exit_code = command_size(args, &arena);
else if (args->command == CP)
exit_code = command_copy(args, &arena);
else
{
exit_code = EXIT_FAILURE;
}
destroy(&arena);
return exit_code;
}