cmd.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __COMMAND_H__
  18. #define __COMMAND_H__
  19. #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */
  20. typedef int (*cfunc_t)(int argc, char **argv);
  21. typedef void (*helpfunc_t)(void);
  22. typedef struct cmdinfo {
  23. const char *name;
  24. const char *altname;
  25. cfunc_t cfunc;
  26. int argmin;
  27. int argmax;
  28. int canpush;
  29. int flags;
  30. const char *args;
  31. const char *oneline;
  32. helpfunc_t help;
  33. } cmdinfo_t;
  34. extern cmdinfo_t *cmdtab;
  35. extern int ncmds;
  36. void help_init(void);
  37. void quit_init(void);
  38. typedef int (*argsfunc_t)(int index);
  39. typedef int (*checkfunc_t)(const cmdinfo_t *ci);
  40. void add_command(const cmdinfo_t *ci);
  41. void add_user_command(char *optarg);
  42. void add_args_command(argsfunc_t af);
  43. void add_check_command(checkfunc_t cf);
  44. const cmdinfo_t *find_command(const char *cmd);
  45. void command_loop(void);
  46. int command_usage(const cmdinfo_t *ci);
  47. int command(const cmdinfo_t *ci, int argc, char **argv);
  48. /* from input.h */
  49. char **breakline(char *input, int *count);
  50. void doneline(char *input, char **vec);
  51. char *fetchline(void);
  52. long long cvtnum(char *s);
  53. void cvtstr(double value, char *str, size_t sz);
  54. struct timeval tsub(struct timeval t1, struct timeval t2);
  55. double tdiv(double value, struct timeval tv);
  56. enum {
  57. DEFAULT_TIME = 0x0,
  58. TERSE_FIXED_TIME = 0x1,
  59. VERBOSE_FIXED_TIME = 0x2
  60. };
  61. void timestr(struct timeval *tv, char *str, size_t sz, int flags);
  62. extern char *progname;
  63. #endif /* __COMMAND_H__ */