conf_data.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "putty.h"
  2. #define CONF_ENUM(name, ...) \
  3. static const ConfSaveEnumValue conf_enum_values_##name[] = { \
  4. __VA_ARGS__ \
  5. }; const ConfSaveEnumType conf_enum_##name = { \
  6. .values = conf_enum_values_##name, \
  7. .nvalues = lenof(conf_enum_values_##name), \
  8. };
  9. #define VALUE(eval, sval) { eval, sval, false }
  10. #define VALUE_OBSOLETE(eval, sval) { eval, sval, true }
  11. #include "conf-enums.h"
  12. bool conf_enum_map_to_storage(const ConfSaveEnumType *etype,
  13. int confval, int *storageval_out)
  14. {
  15. for (size_t i = 0; i < etype->nvalues; i++)
  16. if (!etype->values[i].obsolete &&
  17. etype->values[i].confval == confval) {
  18. *storageval_out = etype->values[i].storageval;
  19. return true;
  20. }
  21. return false;
  22. }
  23. bool conf_enum_map_from_storage(const ConfSaveEnumType *etype,
  24. int storageval, int *confval_out)
  25. {
  26. for (size_t i = 0; i < etype->nvalues; i++)
  27. if (etype->values[i].storageval == storageval) {
  28. *confval_out = etype->values[i].confval;
  29. return true;
  30. }
  31. return false;
  32. }
  33. #define CONF_OPTION(id, ...) { __VA_ARGS__ },
  34. #define VALUE_TYPE(x) .value_type = CONF_TYPE_ ## x
  35. #define SUBKEY_TYPE(x) .subkey_type = CONF_TYPE_ ## x
  36. #define DEFAULT_INT(x) .default_value.ival = x
  37. #define DEFAULT_STR(x) .default_value.sval = x
  38. #define DEFAULT_BOOL(x) .default_value.bval = x
  39. #define SAVE_KEYWORD(x) .save_keyword = x
  40. #define STORAGE_ENUM(x) .storage_enum = &conf_enum_ ## x
  41. #define SAVE_CUSTOM .save_custom = true
  42. #define LOAD_CUSTOM .load_custom = true
  43. #define NOT_SAVED .not_saved = true
  44. const ConfKeyInfo conf_key_info[] = {
  45. #include "conf.h"
  46. };