env_flags.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __ENV_FLAGS_H__
  24. #define __ENV_FLAGS_H__
  25. enum env_flags_vartype {
  26. env_flags_vartype_string,
  27. env_flags_vartype_decimal,
  28. env_flags_vartype_hex,
  29. env_flags_vartype_bool,
  30. #ifdef CONFIG_CMD_NET
  31. env_flags_vartype_ipaddr,
  32. env_flags_vartype_macaddr,
  33. #endif
  34. env_flags_vartype_end
  35. };
  36. #define ENV_FLAGS_VAR ".flags"
  37. #define ENV_FLAGS_ATTR_MAX_LEN 2
  38. #define ENV_FLAGS_VARTYPE_LOC 0
  39. #ifndef CONFIG_ENV_FLAGS_LIST_STATIC
  40. #define CONFIG_ENV_FLAGS_LIST_STATIC ""
  41. #endif
  42. #define ENV_FLAGS_LIST_STATIC \
  43. CONFIG_ENV_FLAGS_LIST_STATIC
  44. #ifdef CONFIG_CMD_ENV_FLAGS
  45. /*
  46. * Print the whole list of available type flags.
  47. */
  48. void env_flags_print_vartypes(void);
  49. /*
  50. * Return the name of the type.
  51. */
  52. const char *env_flags_get_vartype_name(enum env_flags_vartype type);
  53. #endif
  54. /*
  55. * Parse the flags string from a .flags attribute list into the vartype enum.
  56. */
  57. enum env_flags_vartype env_flags_parse_vartype(const char *flags);
  58. #ifdef USE_HOSTCC
  59. /*
  60. * Look up the type of a variable directly from the .flags var.
  61. */
  62. enum env_flags_vartype env_flags_get_type(const char *name);
  63. /*
  64. * Validate the newval for its type to conform with the requirements defined by
  65. * its flags (directly looked at the .flags var).
  66. */
  67. int env_flags_validate_type(const char *name, const char *newval);
  68. /*
  69. * Validate the parameters passed to "env set" for type compliance
  70. */
  71. int env_flags_validate_env_set_params(int argc, char * const argv[]);
  72. #else /* !USE_HOSTCC */
  73. #include <search.h>
  74. /*
  75. * When adding a variable to the environment, initialize the flags for that
  76. * variable.
  77. */
  78. void env_flags_init(ENTRY *var_entry);
  79. /*
  80. * Validate the newval for to conform with the requirements defined by its flags
  81. */
  82. int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
  83. int flag);
  84. /*
  85. * These are the binary flags used in the environment entry->flags variable to
  86. * decribe properties of veriables in the table
  87. */
  88. #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
  89. /* The actual variable type values use the enum value (within the mask) */
  90. #endif /* USE_HOSTCC */
  91. #endif /* __ENV_FLAGS_H__ */