blob: c27f6fc2bcd5fb0f979b5e5ac0040b0368e783b6 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "net.h"
#include "commands.h"
static void help(void)
{
fprintf(stderr, "OFCL <command>\n"); \
size_t longestStr;
size_t length;
if (commands_size)
{
longestStr = 0;
for (size_t i = 0; i < commands_size; ++i)
{
length = strlen(commands[i].name);
if (length > longestStr) longestStr = length;
}
fprintf(stderr, "\nList of commands:\n");
for (size_t i = 0; i < commands_size; ++i)
{
fprintf(stderr, "\t%-*s\t %s\n", (int)longestStr, commands[i].name, commands[i].description);
}
}
}
int main(int argc, char** argv)
{
net_init();
atexit(net_deinit);
for (int i = 1; i < argc; ++i)
{
for (size_t j = 0; j < commands_size; ++j)
{
if (!strcmp(commands[j].name, argv[i]))
return commands[j].func(argc-i, argv+i);
}
}
help();
return EXIT_SUCCESS;
}
|