-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
108 lines (88 loc) · 1.77 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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#ifndef OMIT_GETOPT_LONG
#include <getopt.h>
#endif
struct command {
char *command_name;
void (*command_function)(int argc, char **argv);
};
void command_init(int argc, char **argv)
{
}
void command_using(int argc, char **argv)
{
}
void command_track(int argc, char **argv)
{
}
void command_forget(int argc, char **argv)
{
}
void command_go(int argc, char **argv)
{
}
void command_restore(int argc, char **argv)
{
}
void command_history(int argc, char **argv)
{
}
void command_status(int argc, char **argv)
{
}
void execute_command(char *command_name, int argc, char **argv)
{
int c;
static struct command commands[] = {
{ "init", command_init },
{ "using", command_using },
{ "track", command_track },
{ "forget", command_forget },
{ "go", command_go },
{ "restore", command_restore },
{ "history", command_history },
{ "status", command_status },
{ 0, 0 }
};
for (c = 0; commands[c].command_name != 0; ++c)
{
if (strcmp(commands[c].command_name, command_name) == 0)
{
commands[c].command_function(argc, argv);
return;
}
}
printf("keep: '%s' is not a keep command.\n", command_name);
}
int main(int argc, char **argv)
{
int opt;
static char *options = "";
#ifndef OMIT_GETOPT_LONG
static struct option long_options[] =
{
{ 0, 0, 0, 0 }
};
while ((opt = getopt_long(argc, argv, options, long_options, NULL)) != EOF)
#else
while ((opt = getopt(argc, argv, options)) != EOF)
#endif
{
switch (opt)
{
default:
fprintf(stderr, "Try `keep --help' for more information.\n");
exit(1);
}
}
if (optind >= argc)
{
printf("keep: No command given.\n");
return 1;
}
execute_command(argv[optind], argc - optind - 1, argv + optind + 1);
return 0;
}