cmdline.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. This file is part of UFFS, the Ultra-low-cost Flash File System.
  3. Copyright (C) 2005-2009 Ricky Zheng <ricky_gz_zheng@yahoo.co.nz>
  4. UFFS is free software; you can redistribute it and/or modify it under
  5. the GNU Library General Public License as published by the Free Software
  6. Foundation; either version 2 of the License, or (at your option) any
  7. later version.
  8. UFFS is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. or GNU Library General Public License, as applicable, for more details.
  12. You should have received a copy of the GNU General Public License
  13. and GNU Library General Public License along with UFFS; if not, write
  14. to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. As a special exception, if other files instantiate templates or use
  17. macros or inline functions from this file, or you compile this file
  18. and link it with other works to produce a work based on this file,
  19. this file does not by itself cause the resulting work to be covered
  20. by the GNU General Public License. However the source code for this
  21. file must still be made available in accordance with section (3) of
  22. the GNU General Public License v2.
  23. This exception does not invalidate any other reasons why a work based
  24. on this file might be covered by the GNU General Public License.
  25. */
  26. #ifndef _UFFS_CLI_H_
  27. #define _UFFS_CLI_H_
  28. #ifndef BOOL
  29. #define BOOL int
  30. #endif
  31. #ifndef TRUE
  32. #define TRUE 1
  33. #endif
  34. #ifndef FALSE
  35. #define FALSE 0
  36. #endif
  37. #define CLI_INVALID_ARG -100
  38. typedef int command_t(int argc, char *argv[]);
  39. struct cli_command {
  40. command_t *handler;
  41. const char *cmd;
  42. const char *args;
  43. const char *descr;
  44. };
  45. struct cli_commandset {
  46. const struct cli_command *cmds;
  47. struct cli_commandset *next;
  48. };
  49. void cli_add_commandset(struct cli_commandset *set);
  50. int cli_interpret(const char *line);
  51. int cli_env_get(char env);
  52. int cli_env_set(char env, int val);
  53. void cli_main_entry();
  54. #define u_assert(x) \
  55. ((x) ? TRUE : \
  56. (uffs_PerrorRaw(UFFS_MSG_NORMAL, \
  57. "Assert failed at %s:%s:%d: '%s' is not true.\n", \
  58. __FILE__, __FUNCTION__, __LINE__, #x), FALSE))
  59. #define CHK_ARGC(min, max) \
  60. if (argc < min || (max > 0 && argc > max)) \
  61. return CLI_INVALID_ARG
  62. #endif