Skip to content

Commit a184a53

Browse files
committed
tool: add skeleton
1 parent 78c919a commit a184a53

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
SUBDIRS = libecdsaauth
1+
SUBDIRS = libecdsaauth tool
2+
3+
tool: libecdsaauth
24

35
include buildsys.mk

tool/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROG = ecdsatool
2+
3+
SRCS = main.c
4+
5+
include ../buildsys.mk

tool/main.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2013 William Pitcock <[email protected]>.
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18+
* POSSIBILITY OF SUCH DAMAGE.
19+
*/
20+
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
24+
#include "tool-applet.h"
25+
26+
static tool_applet_t tool_applets[] = {
27+
{NULL, NULL}
28+
};
29+
30+
static inline tool_applet_t *tool_applet_find(const char *name)
31+
{
32+
tool_applet_t *iter;
33+
34+
for (iter = tool_applets; iter->name != NULL; iter++)
35+
{
36+
if (!strcmp(iter->name, name))
37+
return iter;
38+
}
39+
40+
return NULL;
41+
}
42+
43+
int main(int argc, const char *argv[])
44+
{
45+
tool_applet_t *tool;
46+
47+
if (argv[1] == NULL)
48+
argv[1] = "usage";
49+
50+
tool = tool_applet_find(argv[1]);
51+
if (tool == NULL)
52+
{
53+
fprintf(stderr, "%s: not implemented\n", argv[1]);
54+
return EXIT_FAILURE;
55+
}
56+
57+
return tool->main(argc - 1, argv + 1);
58+
}

tool/tool-applet.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2013 William Pitcock <[email protected]>.
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18+
* POSSIBILITY OF SUCH DAMAGE.
19+
*/
20+
21+
#ifndef TOOL_APPLET_H
22+
#define TOOL_APPLET_H
23+
24+
typedef struct tool_applet_s {
25+
char *name;
26+
int (*main)(int argc, const char **argv);
27+
} tool_applet_t;
28+
29+
#endif

0 commit comments

Comments
 (0)