Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 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 Geiselbrecht | 0166fb2 | 2009-01-24 20:05:47 -0800 | [diff] [blame] | 23 | #ifndef __LIB_CONSOLE_H |
| 24 | #define __LIB_CONSOLE_H |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 25 | |
| 26 | #include <sys/types.h> |
| 27 | #include <compiler.h> |
| 28 | |
| 29 | /* command args */ |
| 30 | typedef struct { |
| 31 | const char *str; |
| 32 | unsigned int u; |
| 33 | int i; |
| 34 | } cmd_args; |
| 35 | |
| 36 | typedef int (*console_cmd)(int argc, const cmd_args *argv); |
| 37 | |
| 38 | /* a block of commands to register */ |
| 39 | typedef struct { |
| 40 | const char *cmd_str; |
| 41 | const char *help_str; |
| 42 | const console_cmd cmd_callback; |
| 43 | } cmd; |
| 44 | |
| 45 | typedef 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 */ |
| 56 | int console_init(void); |
| 57 | void console_start(void); |
| 58 | void console_register_commands(cmd_block *block); |
| 59 | int console_run_command(const char *string); |
| 60 | |
| 61 | #endif |
| 62 | |