tools.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Tools
  3. *
  4. * Philippe G. 2019, philippe_44@outlook.com
  5. *
  6. * This software is released under the MIT License.
  7. * https://opensource.org/licenses/MIT
  8. *
  9. */
  10. #pragma once
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #ifndef QUOTE
  15. #define QUOTE(name) #name
  16. #endif
  17. #ifndef STR
  18. #define STR(macro) QUOTE(macro)
  19. #endif
  20. #ifndef STR_OR_ALT
  21. #define STR_OR_ALT(str,alt) (str?str:alt)
  22. #endif
  23. #ifndef STR_OR_BLANK
  24. #define STR_OR_BLANK(p) p == NULL ? "" : p
  25. #endif
  26. #define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
  27. #ifdef ENABLE_MEMTRACE
  28. #define MEMTRACE_PRINT_DELTA() memtrace_print_delta(NULL,TAG,__FUNCTION__);
  29. #define MEMTRACE_PRINT_DELTA_MESSAGE(x) memtrace_print_delta(x,TAG,__FUNCTION__);
  30. #else
  31. #define MEMTRACE_PRINT_DELTA()
  32. #define MEMTRACE_PRINT_DELTA_MESSAGE(x) ESP_LOGD(TAG,"%s",x);
  33. #endif
  34. #ifndef FREE_AND_NULL
  35. #define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }
  36. #endif
  37. #ifndef CASE_TO_STR
  38. #define CASE_TO_STR(x) case x: return STR(x); break;
  39. #endif
  40. #define ENUM_TO_STRING(g) \
  41. case g: \
  42. return STR(g); \
  43. break;
  44. void utf8_decode(char *src);
  45. void url_decode(char *url);
  46. void* malloc_init_external(size_t sz);
  47. void* clone_obj_psram(void * source, size_t source_sz);
  48. char* strdup_psram(const char * source);
  49. const char* str_or_unknown(const char * str);
  50. const char* str_or_null(const char * str);
  51. extern const char unknown_string_placeholder[];
  52. #ifdef __cplusplus
  53. }
  54. #endif