OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
commander.h
Go to the documentation of this file.
1 
2 //
3 // commander.h
4 //
5 // Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
6 //
7 
8 #ifndef COMMANDER_H
9 #define COMMANDER_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /*
16  * Max options that can be defined.
17  */
18 
19 #ifndef COMMANDER_MAX_OPTIONS
20 #define COMMANDER_MAX_OPTIONS 32
21 #endif
22 
23 /*
24  * Max arguments that can be passed.
25  */
26 
27 #ifndef COMMANDER_MAX_ARGS
28 #define COMMANDER_MAX_ARGS 32
29 #endif
30 
31 /*
32  * Command struct.
33  */
34 
35 struct command;
36 
37 /*
38  * Option callback.
39  */
40 
41 typedef void (* command_callback_t)(struct command *self);
42 
43 /*
44  * Command option.
45  */
46 
47 typedef struct {
50  char *argname;
51  char *large;
52  const char *small;
53  const char *large_with_arg;
54  const char *description;
57 
58 /*
59  * Command.
60  */
61 
62 typedef struct command {
63  void *data;
64  const char *usage;
65  const char *arg;
66  const char *name;
67  const char *version;
70  int argc;
71  char *argv[COMMANDER_MAX_ARGS];
72  char **nargv;
73 } command_t;
74 
75 // prototypes
76 
77 void
78 command_init(command_t *self, const char *name, const char *version);
79 
80 void
81 command_free(command_t *self);
82 
83 void
84 command_help(command_t *self);
85 
86 void
87 command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb);
88 
89 void
90 command_parse(command_t *self, int argc, char **argv);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif /* COMMANDER_H */
void command_option(command_t *self, const char *small, const char *large, const char *desc, command_callback_t cb)
Definition: commander.c:173
const char * version
Definition: commander.h:67
const char * description
Definition: commander.h:54
char * argname
Definition: commander.h:50
void command_parse(command_t *self, int argc, char **argv)
Definition: commander.c:266
int option_count
Definition: commander.h:68
void * data
Definition: commander.h:63
void(* command_callback_t)(struct command *self)
Definition: commander.h:41
const char * small
Definition: commander.h:52
int argc
Definition: commander.h:70
#define COMMANDER_MAX_ARGS
Definition: commander.h:28
void command_init(command_t *self, const char *name, const char *version)
Definition: commander.c:66
void command_help(command_t *self)
Definition: commander.c:40
const char * usage
Definition: commander.h:64
const char * arg
Definition: commander.h:65
const char * large_with_arg
Definition: commander.h:53
char ** nargv
Definition: commander.h:72
const char * name
Definition: commander.h:66
void command_free(command_t *self)
Definition: commander.c:82
#define COMMANDER_MAX_OPTIONS
Definition: commander.h:20
command_callback_t cb
Definition: commander.h:55