9 #ifndef __ZEDA_MISC_H__ 10 #define __ZEDA_MISC_H__ 23 #define zAssert( func, expr ) do{\ 24 printf( "%s ... ", #func );\ 38 #define _zMax(x,y) ( (x)>=(y) ? (x) : (y) ) 40 #define _zMin(x,y) ( (x)<=(y) ? (x) : (y) ) 42 #define _zLimit(x,l,u) ( (x)<=(l) ? (l) : ( (x)>=(u) ? (u) : (x) ) ) 56 #define zSwap(type,a,b) do{\ 81 #define zAlloc(t,n) ( (n) == 0 ? NULL : (t *)calloc( (n), sizeof(t) ) ) 82 #define zAllocZero(t,n) ( (n) == 0 ? NULL : (t *)calloc( (n), sizeof(t) ) ) 84 #define zFree(m) do{ if( (m) ){ free( m ); (m) = NULL; } } while(0) 90 #define zCopy(t,s,d) ( (t *)memcpy( d, s, sizeof(t) ) ) 100 #define zRealloc(m,t,n) (t *)realloc( (void *)m, sizeof(t)*(n) ) 143 #define eprintf(fmt,...) fprintf( stderr, fmt, ##__VA_ARGS__ ) 145 #define eprintf printk 155 extern bool __zeda_echo;
157 #define zEchoOn() ( __zeda_echo = true ) 158 #define zEchoOff() ( __zeda_echo = false ) 172 #define ZECHO(msg,...) ( __zeda_echo ? eprintf( msg " (%s).\n", ##__VA_ARGS__, __FUNCTION__ ) : 0 ) 173 #define ZRUNERROR(msg,...) ZECHO( "run-time error: " msg, ##__VA_ARGS__ ) 174 #define ZRUNWARN(msg,...) ZECHO( "warning: " msg, ##__VA_ARGS__ ) 176 #define ZOPENERROR(m) ZRUNERROR( "cannot open file: %s", (m) ) 177 #define ZALLOCERROR() ZRUNERROR( "cannot allocate memory" ) 257 #define itoa_zerofill(v,s,b) itoa_fill( (v), (s), '0', (b) )
int fpeek(FILE *fp)
peek charactor.
char * ftoa(double val, char *buf)
convert a d-float value to a string.
double zBound(double x, double b1, double b2)
return a saturated value of x with two boundaries b1 and b2, where the magnitude relation between b1 ...
#define __END_DECLS
Definition: zeda_defs.h:30
void * zClone(void *src, size_t size)
clone a memory space.
double zMax(double x, double y)
int atox_c(char c)
convert a hexadecimal note to a value.
size_t zFileSize(FILE *fp)
count the size of a file.
char * itoa_ordinal(int val, char *buf, size_t size)
convert an integer number to a string that represents an ordinal.
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
double zMin(double x, double y)
#define __EXPORT
Definition: zeda_compat.h:32
int atox(char *str)
convert hexadecimal string to value.
char * itoa(int val, char *buf)
convert an integer to a string.
double zLimit(double x, double l, double u)
char * itoa_fill(int val, int size, char pat, char *buf)
convert an integer to a string with a blank filled by a charactor.