blob: 6641542650cfde1cb93a9469a70a339f8479c014 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
Travis Geiselbrecht0166fb22009-01-24 20:05:47 -080023#ifndef __LIB_CONSOLE_H
24#define __LIB_CONSOLE_H
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070025
26#include <sys/types.h>
27#include <compiler.h>
28
29/* command args */
30typedef struct {
31 const char *str;
32 unsigned int u;
33 int i;
34} cmd_args;
35
36typedef int (*console_cmd)(int argc, const cmd_args *argv);
37
38/* a block of commands to register */
39typedef struct {
40 const char *cmd_str;
41 const char *help_str;
42 const console_cmd cmd_callback;
43} cmd;
44
45typedef struct _cmd_block {
46 struct _cmd_block *next;
47 size_t count;
48 const cmd *list;
49} cmd_block;
50
51/* register a static block of commands at init time */
52#define STATIC_COMMAND_START static const cmd _cmd_list[] = {
53#define STATIC_COMMAND_END(name) }; const cmd_block _cmd_block_##name __SECTION(".commands")= { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
54
55/* external api */
56int console_init(void);
57void console_start(void);
58void console_register_commands(cmd_block *block);
59int console_run_command(const char *string);
60
61#endif
62