aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 16 | */ |
| 17 | #ifndef __COMMAND_H__ |
| 18 | #define __COMMAND_H__ |
| 19 | |
| 20 | #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */ |
| 21 | |
| 22 | typedef int (*cfunc_t)(int argc, char **argv); |
| 23 | typedef void (*helpfunc_t)(void); |
| 24 | |
| 25 | typedef struct cmdinfo { |
| 26 | const char *name; |
| 27 | const char *altname; |
| 28 | cfunc_t cfunc; |
| 29 | int argmin; |
| 30 | int argmax; |
| 31 | int canpush; |
| 32 | int flags; |
| 33 | const char *args; |
| 34 | const char *oneline; |
| 35 | helpfunc_t help; |
| 36 | } cmdinfo_t; |
| 37 | |
| 38 | extern cmdinfo_t *cmdtab; |
| 39 | extern int ncmds; |
| 40 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 41 | void help_init(void); |
| 42 | void quit_init(void); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 43 | |
| 44 | typedef int (*argsfunc_t)(int index); |
| 45 | typedef int (*checkfunc_t)(const cmdinfo_t *ci); |
| 46 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 47 | void add_command(const cmdinfo_t *ci); |
| 48 | void add_user_command(char *optarg); |
| 49 | void add_args_command(argsfunc_t af); |
| 50 | void add_check_command(checkfunc_t cf); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 51 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 52 | const cmdinfo_t *find_command(const char *cmd); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 53 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 54 | void command_loop(void); |
| 55 | int command_usage(const cmdinfo_t *ci); |
| 56 | int command(const cmdinfo_t *ci, int argc, char **argv); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 57 | |
| 58 | /* from input.h */ |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 59 | char **breakline(char *input, int *count); |
| 60 | void doneline(char *input, char **vec); |
| 61 | char *fetchline(void); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 62 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 63 | long long cvtnum(char *s); |
| 64 | void cvtstr(double value, char *str, size_t sz); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 65 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 66 | struct timeval tsub(struct timeval t1, struct timeval t2); |
| 67 | double tdiv(double value, struct timeval tv); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 68 | |
| 69 | enum { |
| 70 | DEFAULT_TIME = 0x0, |
| 71 | TERSE_FIXED_TIME = 0x1, |
| 72 | VERBOSE_FIXED_TIME = 0x2 |
| 73 | }; |
| 74 | |
Blue Swirl | 64b85a8 | 2011-01-23 16:21:20 +0000 | [diff] [blame] | 75 | void timestr(struct timeval *tv, char *str, size_t sz, int flags); |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 76 | |
blueswir1 | 856ae5c | 2009-04-07 17:57:09 +0000 | [diff] [blame] | 77 | extern char *progname; |
| 78 | |
aliguori | e3aff4f | 2009-04-05 19:14:04 +0000 | [diff] [blame] | 79 | #endif /* __COMMAND_H__ */ |