2009-09-10 10:31:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Martin Willi
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2009-09-10 10:31:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup command command
|
|
|
|
* @{ @ingroup pki
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMMAND_H_
|
|
|
|
#define COMMAND_H_
|
|
|
|
|
2009-09-10 10:44:06 +00:00
|
|
|
/**
|
2013-12-11 16:24:03 +00:00
|
|
|
* Maximum number of commands (+1).
|
2009-09-10 10:44:06 +00:00
|
|
|
*/
|
2015-08-06 16:04:38 +00:00
|
|
|
#define MAX_COMMANDS 14
|
2009-09-10 10:44:06 +00:00
|
|
|
|
2009-09-10 10:31:40 +00:00
|
|
|
/**
|
2013-12-11 16:38:18 +00:00
|
|
|
* Maximum number of options in a command (+3)
|
2009-09-10 10:31:40 +00:00
|
|
|
*/
|
2014-03-27 14:45:52 +00:00
|
|
|
#define MAX_OPTIONS 36
|
2009-09-10 10:31:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of usage summary lines (+1)
|
|
|
|
*/
|
2020-01-20 18:08:14 +00:00
|
|
|
#define MAX_LINES 13
|
2009-09-10 10:31:40 +00:00
|
|
|
|
|
|
|
typedef struct command_t command_t;
|
2009-09-15 09:49:14 +00:00
|
|
|
typedef struct command_option_t command_option_t;
|
2009-09-10 10:31:40 +00:00
|
|
|
typedef enum command_type_t command_type_t;
|
|
|
|
|
2009-09-15 09:49:14 +00:00
|
|
|
/**
|
|
|
|
* Option specification
|
|
|
|
*/
|
|
|
|
struct command_option_t {
|
|
|
|
/** long option string of the option */
|
|
|
|
char *name;
|
|
|
|
/** short option character of the option */
|
|
|
|
char op;
|
|
|
|
/** expected argument to option, no/req/opt_argument */
|
|
|
|
int arg;
|
|
|
|
/** description of the option */
|
|
|
|
char *desc;
|
|
|
|
};
|
|
|
|
|
2009-09-10 10:31:40 +00:00
|
|
|
/**
|
|
|
|
* Command specification.
|
|
|
|
*/
|
|
|
|
struct command_t {
|
|
|
|
/** Function implementing the command */
|
2009-09-15 09:49:14 +00:00
|
|
|
int (*call)();
|
2009-09-10 10:31:40 +00:00
|
|
|
/** short option character */
|
|
|
|
char op;
|
|
|
|
/** long option string */
|
|
|
|
char *cmd;
|
|
|
|
/** description of the command */
|
|
|
|
char *description;
|
|
|
|
/** usage summary of the command */
|
|
|
|
char *line[MAX_LINES];
|
|
|
|
/** list of options the command accepts */
|
2009-09-15 09:49:14 +00:00
|
|
|
command_option_t options[MAX_OPTIONS];
|
2009-09-10 10:31:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-09-15 09:49:14 +00:00
|
|
|
* Get the next option, as with getopt.
|
2009-09-15 08:20:22 +00:00
|
|
|
*/
|
2009-09-15 09:49:14 +00:00
|
|
|
int command_getopt(char **arg);
|
2009-09-15 08:20:22 +00:00
|
|
|
|
2009-09-10 10:31:40 +00:00
|
|
|
/**
|
|
|
|
* Register a command.
|
|
|
|
*/
|
2009-09-10 10:44:06 +00:00
|
|
|
void command_register(command_t command);
|
2009-09-10 10:31:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch commands.
|
|
|
|
*/
|
|
|
|
int command_dispatch(int argc, char *argv[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show usage information of active command.
|
|
|
|
*/
|
2009-09-10 10:44:06 +00:00
|
|
|
int command_usage(char *error);
|
2009-09-10 10:31:40 +00:00
|
|
|
|
2013-03-02 14:26:45 +00:00
|
|
|
#endif /** COMMAND_H_ @}*/
|