-
Notifications
You must be signed in to change notification settings - Fork 0
/
lit.c
57 lines (54 loc) · 1.34 KB
/
lit.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
// Include standard libraries
// Include headers
#include "utility.h"
#include "exec-cmd.h"
int (*CMD_FUNCTIONS[N_COMMANDS])(int, char*[]) = {
exec_config,
exec_init,
exec_add,
exec_reset,
exec_status,
exec_commit,
exec_set,
exec_replace,
exec_remove,
exec_log,
exec_branch,
exec_checkout,
exec_revert,
exec_merge,
exec_diff,
exec_tag,
exec_grep
}; // Array of function pointers, indexes are respective to the indexes of strings in COMMANDS
// Main command handler function
int main(int argc, char *argv[])
{
if (argc == 1) {
printf(USAGE);
return 1;
}
int command_ind = search_str(COMMANDS, argv[1], N_COMMANDS);
if (command_ind == -1) {
char* alias_command = get_alias(argv[1]);
if (alias_command == NULL) {
printf(USAGE);
return 1;
}
// Append extra arguments to the command
for (int i = 2; i < argc; i++) {
strcat(alias_command, " ");
if ( strchr(argv[i], ' ') != NULL ) {
strcat(alias_command, "\"");
strcat(alias_command, argv[i]);
strcat(alias_command, "\"");
} else {
strcat(alias_command, argv[i]);
}
}
system(alias_command);
}
int call_result;
call_result = (CMD_FUNCTIONS[command_ind])(argc, argv);
return call_result;
}