fx9860g and fxcg50 2D math rendering library with support for TeX syntax.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
861 B

//---
// vector: Simple vectors that only grow
// Preprocessing is a bit ugly here, but it makes it really easy to use.
//---
#ifndef TEX_VECTOR
#define TEX_VECTOR
#include <stdint.h>
#include <stddef.h>
/* Declare three variables for every vector */
#define vector_type(type, name) \
type * name; \
short name ## _len; \
short name ## _size;
/* Trivial initialization */
#define vector_init(name) { \
name = NULL; \
name ## _len = 0; \
name ## _size = 0; \
}
/* Extension */
#define vector_extend(name) { \
if(name ## _len >= name ## _size) \
name = realloc(name, sizeof *name * \
(name ## _size += 8)); \
}
/* Append */
#define vector_append(name, value) { \
vector_extend(name); \
(name)[name ## _len++] = (value); \
}
/* Last elements */
#define vector_last(name) ((name)[name ## _len - 1])
#endif /* TEX_VECTOR */