common.h 517 B

123456789101112131415161718192021
  1. #pragma once
  2. #include "libc.h"
  3. #define STR1(m) #m
  4. #define STR(m) STR1(m)
  5. #define PRINTF(fmt, ...) XPRINTF(__FILE__ ":" STR(__LINE__) ": " fmt "\n", __VA_ARGS__)
  6. #define PRINT(msg) XPRINTF(__FILE__ ":" STR(__LINE__) ": %s\n", msg)
  7. void XPRINTF(const char* fmt, ...);
  8. #define ASSERT(cond) if (!(cond)){PRINTF("%s failed", #cond); abort();}
  9. #define COUNTOF(a) (sizeof(a) / sizeof(*(a)))
  10. typedef struct {
  11. const char *str;
  12. int length;
  13. } StringView;
  14. #define PRI_SV "%.*s"
  15. #define PRI_SVV(s) ((s).length), ((s).str)