tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

util.h (1269B)


      1#pragma once
      2
      3#include <stdbool.h>
      4#include <stdint.h>
      5#include <stdio.h>
      6
      7#define MAX(a, b) ((a) > (b) ? (a) : (b))
      8#define MIN(a, b) ((a) > (b) ? (b) : (a))
      9#define ARRLEN(x) (sizeof(x)/sizeof((x)[0]))
     10
     11#define PANIC(...) panic(__FILE__, __LINE__, "" __VA_ARGS__)
     12#define ASSERT(x) assert((x), __FILE__, __LINE__, #x)
     13#define WARNX(...) warn(false, __VA_ARGS__);
     14#define WARN(...) warn(true, __VA_ARGS__);
     15#define ERRORX(...) error(false, __VA_ARGS__);
     16#define ERROR(...) error(true, __VA_ARGS__);
     17
     18#define UPCAST(iter, type, link) LINK_UPCAST(iter, type, link)
     19
     20enum {
     21	USER,
     22	SYSTEM,
     23	INTERNAL
     24};
     25
     26void panic(const char *file, int line, const char *msg, ...);
     27void assert(int cond, const char *file, int line, const char *condstr);
     28void warn(bool add_error, int type, const char *fmtstr, ...);
     29void error(bool add_error, int type, const char *fmtstr, ...);
     30
     31char *astrdup(const char *str);
     32char *aprintf(const char *fmtstr, ...);
     33char *appendstrf(char *alloc, const char *fmtstr, ...);
     34
     35char *sanitized(const char *instr);
     36
     37const char *timestr(unsigned int seconds);
     38
     39uint64_t current_ms(void);
     40
     41size_t text_width(const char *utf8, size_t len);
     42
     43size_t utf8_next_break_left(const char *utf8, size_t pos);
     44size_t utf8_next_break_right(const char *utf8, size_t pos);