ZEDA  1.6.18
Macros | Functions
zeda_misc.h File Reference

miscellanies. More...

#include <zeda/zeda_defs.h>
#include <zeda/zeda_errmsg.h>
#include <assert.h>
Include dependency graph for zeda_misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define zAssert(func, expr)
 
#define _zMax(x, y)   ( (x)>=(y) ? (x) : (y) )
 
#define _zMin(x, y)   ( (x)<=(y) ? (x) : (y) )
 
#define _zLimit(x, l, u)   ( (x)<=(l) ? (l) : ( (x)>=(u) ? (u) : (x) ) )
 
#define zSwap(type, a, b)
 swap values of two data a and b. type the data type of a and b. More...
 
#define zAlloc(t, n)   ( (n) == 0 ? NULL : (t *)calloc( (n), sizeof(t) ) )
 
#define zAllocZero(t, n)   ( (n) == 0 ? NULL : (t *)calloc( (n), sizeof(t) ) )
 
#define zFree(m)   do{ if( (m) ){ free( m ); (m) = NULL; } } while(0)
 
#define zCopy(t, s, d)   ( (t *)memcpy( d, s, sizeof(t) ) )
 
#define zRealloc(m, t, n)   (t *)realloc( (void *)m, sizeof(t)*(n) )
 
#define eprintf(fmt, ...)   fprintf( stderr, fmt, ##__VA_ARGS__ )
 formatted output to stderr. More...
 
#define zEchoOn()   ( __zeda_echo = true )
 
#define zEchoOff()   ( __zeda_echo = false )
 
#define ZECHO(msg, ...)   ( __zeda_echo ? eprintf( msg " (%s).\n", ##__VA_ARGS__, __FUNCTION__ ) : 0 )
 
#define ZRUNERROR(msg, ...)   ZECHO( "run-time error: " msg, ##__VA_ARGS__ )
 
#define ZRUNWARN(msg, ...)   ZECHO( "warning: " msg, ##__VA_ARGS__ )
 
#define ZOPENERROR(m)   ZRUNERROR( "cannot open file: %s", (m) )
 
#define ZALLOCERROR()   ZRUNERROR( "cannot allocate memory" )
 
#define itoa_zerofill(v, s, b)   itoa_fill( (v), (s), '0', (b) )
 convert an integer to a string with blank filled by a charactor-zero. More...
 

Functions

double zMax (double x, double y)
 
double zMin (double x, double y)
 
double zLimit (double x, double l, double u)
 
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 and b2 does not matter. More...
 
void * zClone (void *src, size_t size)
 clone a memory space. More...
 
size_t zFileSize (FILE *fp)
 count the size of a file. More...
 
int fpeek (FILE *fp)
 peek charactor. More...
 
int atox_c (char c)
 convert a hexadecimal note to a value. More...
 
int atox (char *str)
 convert hexadecimal string to value. More...
 
char * itoa (int val, char *buf)
 convert an integer to a string. More...
 
char * ftoa (double val, char *buf)
 convert a d-float value to a string. More...
 
char * itoa_fill (int val, int size, char pat, char *buf)
 convert an integer to a string with a blank filled by a charactor. More...
 
char * itoa_ordinal (int val, char *buf, size_t size)
 convert an integer number to a string that represents an ordinal. More...
 

Detailed Description

miscellanies.

Author
Zhidao

Macro Definition Documentation

◆ zAssert

#define zAssert (   func,
  expr 
)
Value:
do{\
printf( "%s ... ", #func );\
assert( expr );\
printf( "OK\n" );\
} while(0)\

asserts expr and echo a message that func works fine; if not, it aborts.

◆ _zMax

#define _zMax (   x,
 
)    ( (x)>=(y) ? (x) : (y) )

◆ _zMin

#define _zMin (   x,
 
)    ( (x)<=(y) ? (x) : (y) )

◆ _zLimit

#define _zLimit (   x,
  l,
 
)    ( (x)<=(l) ? (l) : ( (x)>=(u) ? (u) : (x) ) )

◆ zSwap

#define zSwap (   type,
  a,
 
)
Value:
do{\
type __swap_tmp;\
__swap_tmp = a;\
a = b;\
b = __swap_tmp;\
} while(0)

swap values of two data a and b. type the data type of a and b.

Function Documentation

◆ zMax()

double zMax ( double  x,
double  y 
)

◆ zMin()

double zMin ( double  x,
double  y 
)

◆ zLimit()

double zLimit ( double  x,
double  l,
double  u 
)

◆ zBound()

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 and b2 does not matter.

◆ zFileSize()

size_t zFileSize ( FILE *  fp)

count the size of a file.

◆ fpeek()

int fpeek ( FILE *  fp)

peek charactor.

fpeek() picks up a charactor from the current position of the file pointed by fp without proceeding the pointer of fp.

Returns
the charactor picked up.