Numworks Epsilon  1.4.1
Graphing Calculator Operating System
misc.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Classes

struct  _vstr_t
 

Macros

#define MIN(x, y)   ((x) < (y) ? (x) : (y))
 
#define MAX(x, y)   ((x) > (y) ? (x) : (y))
 
#define _MP_STRINGIFY(x)   #x
 
#define MP_STRINGIFY(x)   _MP_STRINGIFY(x)
 
#define m_new(type, num)   ((type*)(m_malloc(sizeof(type) * (num))))
 
#define m_new_maybe(type, num)   ((type*)(m_malloc_maybe(sizeof(type) * (num))))
 
#define m_new0(type, num)   ((type*)(m_malloc0(sizeof(type) * (num))))
 
#define m_new_obj(type)   (m_new(type, 1))
 
#define m_new_obj_maybe(type)   (m_new_maybe(type, 1))
 
#define m_new_obj_var(obj_type, var_type, var_num)   ((obj_type*)m_malloc(sizeof(obj_type) + sizeof(var_type) * (var_num)))
 
#define m_new_obj_var_maybe(obj_type, var_type, var_num)   ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num)))
 
#define m_new_obj_with_finaliser(type)   m_new_obj(type)
 
#define m_renew(type, ptr, old_num, new_num)   ((type*)(m_realloc((ptr), sizeof(type) * (new_num))))
 
#define m_renew_maybe(type, ptr, old_num, new_num, allow_move)   ((type*)(m_realloc_maybe((ptr), sizeof(type) * (new_num), (allow_move))))
 
#define m_del(type, ptr, num)   ((void)(num), m_free(ptr))
 
#define m_del_var(obj_type, var_type, var_num, ptr)   ((void)(var_num), m_free(ptr))
 
#define m_del_obj(type, ptr)   (m_del(type, ptr, 1))
 
#define MP_ARRAY_SIZE(a)   (sizeof(a) / sizeof((a)[0]))
 
#define MP_ALIGN(ptr, alignment)   (void*)(((uintptr_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
 
#define UTF8_IS_NONASCII(ch)   ((ch) & 0x80)
 
#define UTF8_IS_CONT(ch)   (((ch) & 0xC0) == 0x80)
 
#define VSTR_FIXED(vstr, alloc)   vstr_t vstr; char vstr##_buf[(alloc)]; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf);
 
#define CHECKBUF(buf, max_size)   char buf[max_size + 1]; size_t buf##_len = max_size; char *buf##_p = buf;
 
#define CHECKBUF_RESET(buf, max_size)   buf##_len = max_size; buf##_p = buf;
 
#define CHECKBUF_APPEND(buf, src, src_len)
 
#define CHECKBUF_APPEND_0(buf)   { *buf##_p = 0; }
 
#define CHECKBUF_LEN(buf)   (buf##_p - buf)
 

Typedefs

typedef unsigned char byte
 
typedef unsigned int uint
 
typedef uint unichar
 
typedef struct _vstr_t vstr_t
 

Functions

void * m_malloc (size_t num_bytes)
 
void * m_malloc_maybe (size_t num_bytes)
 
void * m_malloc_with_finaliser (size_t num_bytes)
 
void * m_malloc0 (size_t num_bytes)
 
void * m_realloc (void *ptr, size_t new_num_bytes)
 
void * m_realloc_maybe (void *ptr, size_t new_num_bytes, bool allow_move)
 
void m_free (void *ptr)
 
NORETURN void m_malloc_fail (size_t num_bytes)
 
unichar utf8_get_char (const byte *s)
 
const byteutf8_next_char (const byte *s)
 
bool unichar_isspace (unichar c)
 
bool unichar_isalpha (unichar c)
 
bool unichar_isprint (unichar c)
 
bool unichar_isdigit (unichar c)
 
bool unichar_isxdigit (unichar c)
 
bool unichar_isident (unichar c)
 
bool unichar_isupper (unichar c)
 
bool unichar_islower (unichar c)
 
unichar unichar_tolower (unichar c)
 
unichar unichar_toupper (unichar c)
 
mp_uint_t unichar_xdigit_value (unichar c)
 
mp_uint_t unichar_charlen (const char *str, mp_uint_t len)
 
void vstr_init (vstr_t *vstr, size_t alloc)
 
void vstr_init_len (vstr_t *vstr, size_t len)
 
void vstr_init_fixed_buf (vstr_t *vstr, size_t alloc, char *buf)
 
void vstr_init_print (vstr_t *vstr, size_t alloc, struct _mp_print_t *print)
 
void vstr_clear (vstr_t *vstr)
 
vstr_tvstr_new (size_t alloc)
 
void vstr_free (vstr_t *vstr)
 
void vstr_hint_size (vstr_t *vstr, size_t size)
 
char * vstr_extend (vstr_t *vstr, size_t size)
 
char * vstr_add_len (vstr_t *vstr, size_t len)
 
char * vstr_null_terminated_str (vstr_t *vstr)
 
void vstr_add_byte (vstr_t *vstr, byte v)
 
void vstr_add_char (vstr_t *vstr, unichar chr)
 
void vstr_add_str (vstr_t *vstr, const char *str)
 
void vstr_add_strn (vstr_t *vstr, const char *str, size_t len)
 
void vstr_ins_byte (vstr_t *vstr, size_t byte_pos, byte b)
 
void vstr_ins_char (vstr_t *vstr, size_t char_pos, unichar chr)
 
void vstr_cut_head_bytes (vstr_t *vstr, size_t bytes_to_cut)
 
void vstr_cut_tail_bytes (vstr_t *vstr, size_t bytes_to_cut)
 
void vstr_cut_out_bytes (vstr_t *vstr, size_t byte_pos, size_t bytes_to_cut)
 
void vstr_printf (vstr_t *vstr, const char *fmt,...)
 
int DEBUG_printf (const char *fmt,...)
 

Variables

mp_uint_t mp_verbose_flag
 

Macro Definition Documentation

◆ _MP_STRINGIFY

#define _MP_STRINGIFY (   x)    #x

Definition at line 50 of file misc.h.

◆ CHECKBUF

#define CHECKBUF (   buf,
  max_size 
)    char buf[max_size + 1]; size_t buf##_len = max_size; char *buf##_p = buf;

non-dynamic size-bounded variable buffer/string

Definition at line 180 of file misc.h.

◆ CHECKBUF_APPEND

#define CHECKBUF_APPEND (   buf,
  src,
  src_len 
)
Value:
{ size_t l = MIN(src_len, buf##_len); \
memcpy(buf##_p, src, l); \
buf##_len -= l; \
buf##_p += l; }
#define MIN(x, y)
Definition: misc.h:43

Definition at line 182 of file misc.h.

◆ CHECKBUF_APPEND_0

#define CHECKBUF_APPEND_0 (   buf)    { *buf##_p = 0; }

Definition at line 187 of file misc.h.

◆ CHECKBUF_LEN

#define CHECKBUF_LEN (   buf)    (buf##_p - buf)

Definition at line 188 of file misc.h.

◆ CHECKBUF_RESET

#define CHECKBUF_RESET (   buf,
  max_size 
)    buf##_len = max_size; buf##_p = buf;

Definition at line 181 of file misc.h.

◆ m_del

#define m_del (   type,
  ptr,
  num 
)    ((void)(num), m_free(ptr))

Definition at line 77 of file misc.h.

◆ m_del_obj

#define m_del_obj (   type,
  ptr 
)    (m_del(type, ptr, 1))

Definition at line 80 of file misc.h.

◆ m_del_var

#define m_del_var (   obj_type,
  var_type,
  var_num,
  ptr 
)    ((void)(var_num), m_free(ptr))

Definition at line 78 of file misc.h.

◆ m_new

#define m_new (   type,
  num 
)    ((type*)(m_malloc(sizeof(type) * (num))))

memory allocation

Definition at line 57 of file misc.h.

◆ m_new0

#define m_new0 (   type,
  num 
)    ((type*)(m_malloc0(sizeof(type) * (num))))

Definition at line 59 of file misc.h.

◆ m_new_maybe

#define m_new_maybe (   type,
  num 
)    ((type*)(m_malloc_maybe(sizeof(type) * (num))))

Definition at line 58 of file misc.h.

◆ m_new_obj

#define m_new_obj (   type)    (m_new(type, 1))

Definition at line 60 of file misc.h.

◆ m_new_obj_maybe

#define m_new_obj_maybe (   type)    (m_new_maybe(type, 1))

Definition at line 61 of file misc.h.

◆ m_new_obj_var

#define m_new_obj_var (   obj_type,
  var_type,
  var_num 
)    ((obj_type*)m_malloc(sizeof(obj_type) + sizeof(var_type) * (var_num)))

Definition at line 62 of file misc.h.

◆ m_new_obj_var_maybe

#define m_new_obj_var_maybe (   obj_type,
  var_type,
  var_num 
)    ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num)))

Definition at line 63 of file misc.h.

◆ m_new_obj_with_finaliser

#define m_new_obj_with_finaliser (   type)    m_new_obj(type)

Definition at line 67 of file misc.h.

◆ m_renew

#define m_renew (   type,
  ptr,
  old_num,
  new_num 
)    ((type*)(m_realloc((ptr), sizeof(type) * (new_num))))

Definition at line 75 of file misc.h.

◆ m_renew_maybe

#define m_renew_maybe (   type,
  ptr,
  old_num,
  new_num,
  allow_move 
)    ((type*)(m_realloc_maybe((ptr), sizeof(type) * (new_num), (allow_move))))

Definition at line 76 of file misc.h.

◆ MAX

#define MAX (   x,
 
)    ((x) > (y) ? (x) : (y))

Definition at line 46 of file misc.h.

◆ MIN

#define MIN (   x,
 
)    ((x) < (y) ? (x) : (y))

generic ops

Definition at line 43 of file misc.h.

◆ MP_ALIGN

#define MP_ALIGN (   ptr,
  alignment 
)    (void*)(((uintptr_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))

Definition at line 109 of file misc.h.

◆ MP_ARRAY_SIZE

#define MP_ARRAY_SIZE (   a)    (sizeof(a) / sizeof((a)[0]))

array helpers

Definition at line 106 of file misc.h.

◆ MP_STRINGIFY

#define MP_STRINGIFY (   x)    _MP_STRINGIFY(x)

Definition at line 51 of file misc.h.

◆ UTF8_IS_CONT

#define UTF8_IS_CONT (   ch)    (((ch) & 0xC0) == 0x80)

Definition at line 138 of file misc.h.

◆ UTF8_IS_NONASCII

#define UTF8_IS_NONASCII (   ch)    ((ch) & 0x80)

Definition at line 137 of file misc.h.

◆ VSTR_FIXED

#define VSTR_FIXED (   vstr,
  alloc 
)    vstr_t vstr; char vstr##_buf[(alloc)]; vstr_init_fixed_buf(&vstr, (alloc), vstr##_buf);

Definition at line 150 of file misc.h.

Typedef Documentation

◆ byte

typedef unsigned char byte

types

Definition at line 37 of file misc.h.

◆ uint

typedef unsigned int uint

Definition at line 38 of file misc.h.

◆ unichar

typedef uint unichar

unichar / UTF-8

Definition at line 119 of file misc.h.

◆ vstr_t

typedef struct _vstr_t vstr_t

variable string

Function Documentation

◆ DEBUG_printf()

int DEBUG_printf ( const char *  fmt,
  ... 
)

◆ m_free()

void m_free ( void *  ptr)

Definition at line 178 of file malloc.c.

◆ m_malloc()

void* m_malloc ( size_t  num_bytes)

Definition at line 74 of file malloc.c.

◆ m_malloc0()

void* m_malloc0 ( size_t  num_bytes)

Definition at line 115 of file malloc.c.

◆ m_malloc_fail()

NORETURN void m_malloc_fail ( size_t  num_bytes)

Definition at line 1437 of file runtime.c.

◆ m_malloc_maybe()

void* m_malloc_maybe ( size_t  num_bytes)

Definition at line 88 of file malloc.c.

◆ m_malloc_with_finaliser()

void* m_malloc_with_finaliser ( size_t  num_bytes)

◆ m_realloc()

void* m_realloc ( void *  ptr,
size_t  new_num_bytes 
)

Definition at line 130 of file malloc.c.

◆ m_realloc_maybe()

void* m_realloc_maybe ( void *  ptr,
size_t  new_num_bytes,
bool  allow_move 
)

Definition at line 154 of file malloc.c.

◆ unichar_charlen()

mp_uint_t unichar_charlen ( const char *  str,
mp_uint_t  len 
)

Definition at line 113 of file unicode.c.

◆ unichar_isalpha()

bool unichar_isalpha ( unichar  c)

Definition at line 132 of file unicode.c.

◆ unichar_isdigit()

bool unichar_isdigit ( unichar  c)

Definition at line 142 of file unicode.c.

◆ unichar_isident()

bool unichar_isident ( unichar  c)

Definition at line 150 of file unicode.c.

◆ unichar_islower()

bool unichar_islower ( unichar  c)

Definition at line 158 of file unicode.c.

◆ unichar_isprint()

bool unichar_isprint ( unichar  c)

◆ unichar_isspace()

bool unichar_isspace ( unichar  c)

Definition at line 128 of file unicode.c.

◆ unichar_isupper()

bool unichar_isupper ( unichar  c)

Definition at line 154 of file unicode.c.

◆ unichar_isxdigit()

bool unichar_isxdigit ( unichar  c)

Definition at line 146 of file unicode.c.

◆ unichar_tolower()

unichar unichar_tolower ( unichar  c)

Definition at line 162 of file unicode.c.

◆ unichar_toupper()

unichar unichar_toupper ( unichar  c)

Definition at line 169 of file unicode.c.

◆ unichar_xdigit_value()

mp_uint_t unichar_xdigit_value ( unichar  c)

Definition at line 176 of file unicode.c.

◆ utf8_get_char()

unichar utf8_get_char ( const byte s)

Definition at line 71 of file unicode.c.

◆ utf8_next_char()

const byte* utf8_next_char ( const byte s)

Definition at line 89 of file unicode.c.

◆ vstr_add_byte()

void vstr_add_byte ( vstr_t vstr,
byte  v 
)

Definition at line 141 of file vstr.c.

◆ vstr_add_char()

void vstr_add_char ( vstr_t vstr,
unichar  chr 
)

Definition at line 146 of file vstr.c.

◆ vstr_add_len()

char* vstr_add_len ( vstr_t vstr,
size_t  len 
)

Definition at line 124 of file vstr.c.

◆ vstr_add_str()

void vstr_add_str ( vstr_t vstr,
const char *  str 
)

Definition at line 175 of file vstr.c.

◆ vstr_add_strn()

void vstr_add_strn ( vstr_t vstr,
const char *  str,
size_t  len 
)

Definition at line 179 of file vstr.c.

◆ vstr_clear()

void vstr_clear ( vstr_t vstr)

Definition at line 70 of file vstr.c.

◆ vstr_cut_head_bytes()

void vstr_cut_head_bytes ( vstr_t vstr,
size_t  bytes_to_cut 
)

Definition at line 212 of file vstr.c.

◆ vstr_cut_out_bytes()

void vstr_cut_out_bytes ( vstr_t vstr,
size_t  byte_pos,
size_t  bytes_to_cut 
)

Definition at line 224 of file vstr.c.

◆ vstr_cut_tail_bytes()

void vstr_cut_tail_bytes ( vstr_t vstr,
size_t  bytes_to_cut 
)

Definition at line 216 of file vstr.c.

◆ vstr_extend()

char* vstr_extend ( vstr_t vstr,
size_t  size 
)

Definition at line 93 of file vstr.c.

◆ vstr_free()

void vstr_free ( vstr_t vstr)

Definition at line 83 of file vstr.c.

◆ vstr_hint_size()

void vstr_hint_size ( vstr_t vstr,
size_t  size 
)

Definition at line 120 of file vstr.c.

◆ vstr_init()

void vstr_init ( vstr_t vstr,
size_t  alloc 
)

Definition at line 40 of file vstr.c.

◆ vstr_init_fixed_buf()

void vstr_init_fixed_buf ( vstr_t vstr,
size_t  alloc,
char *  buf 
)

Definition at line 57 of file vstr.c.

◆ vstr_init_len()

void vstr_init_len ( vstr_t vstr,
size_t  len 
)

Definition at line 52 of file vstr.c.

◆ vstr_init_print()

void vstr_init_print ( vstr_t vstr,
size_t  alloc,
struct _mp_print_t print 
)

Definition at line 64 of file vstr.c.

◆ vstr_ins_byte()

void vstr_ins_byte ( vstr_t vstr,
size_t  byte_pos,
byte  b 
)

Definition at line 201 of file vstr.c.

◆ vstr_ins_char()

void vstr_ins_char ( vstr_t vstr,
size_t  char_pos,
unichar  chr 
)

Definition at line 206 of file vstr.c.

◆ vstr_new()

vstr_t* vstr_new ( size_t  alloc)

Definition at line 77 of file vstr.c.

◆ vstr_null_terminated_str()

char* vstr_null_terminated_str ( vstr_t vstr)

Definition at line 132 of file vstr.c.

◆ vstr_printf()

void vstr_printf ( vstr_t vstr,
const char *  fmt,
  ... 
)

Definition at line 235 of file vstr.c.

Variable Documentation

◆ mp_verbose_flag

mp_uint_t mp_verbose_flag