aboutsummaryrefslogtreecommitdiffstats
path: root/inc/utility.h
diff options
context:
space:
mode:
Diffstat (limited to 'inc/utility.h')
-rw-r--r--inc/utility.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/inc/utility.h b/inc/utility.h
new file mode 100644
index 0000000..c8844e8
--- /dev/null
+++ b/inc/utility.h
@@ -0,0 +1,115 @@
+#ifndef __utility_h__
+#define __utility_h__
+
+#include <stddef.h>
+
+/**********************************************************/
+/* This object contain some useful functions, constants */
+/* and types. */
+/* Enums: */
+/* ErrorType contain kinds of errors. */
+/* */
+/* Structures: */
+/* */
+/* Types: */
+/* uint unsigned int */
+/* pchar char* */
+/* ppchar char** */
+/* pvoid void* */
+/* ppvoid void** */
+/* cchar const char */
+/* pcchar (const char)* */
+/* ppcchar (const char)** */
+/* cvoid const void */
+/* pcvoid (cosnt void)* */
+/* ppcvoid (const void)** */
+/* ... etc */
+/* */
+/* Type transform: */
+/* Char(), pChar(), ppChar() */
+/* Void(), pVoid(), ppVoid() */
+/* cChar(), pcChar(), ppcChar() */
+/* cVoid(), pcVoid(), ppcVoid() */
+/* ... etc */
+/* */
+/* Functions: */
+/* ctl_malloc like malloc(), but will exit on error */
+/* ctl_realloc like realloc(), but will exit on erro */
+/* ctl_free like free(), but will return NULL */
+/* ctl_die print some message and exit() */
+/* ctl_swap swap two elements with given type */
+/* ctl_max return the max of the two arguments */
+/* ctl_min return the min of the two arguments */
+/* */
+/**********************************************************/
+
+typedef enum{
+ CTL_MEMORY = 0x01,
+ CTL_USER = 0x02
+} ErrorType;
+
+// int
+typedef int* pint;
+typedef unsigned int uint;
+typedef uint* puint;
+typedef const int cint;
+typedef cint* pcint;
+typedef const uint cuint;
+typedef cuint* pcuint;
+#define Int(X) (( int)(X))
+#define pInt(X) (( pint)(X))
+#define uInt(X) (( uint)(X))
+#define puInt(X) (( puint)(X))
+#define cInt(X) (( cint)(X))
+#define pcInt(X) (( pcint)(X))
+#define cuInt(X) (( cuint)(X))
+#define pcuInt(X) ((pcuint)(X))
+
+// void
+typedef void* pvoid;
+typedef pvoid* ppvoid;
+typedef const void cvoid;
+typedef cvoid* pcvoid;
+typedef pcvoid* ppcvoid;
+#define Void(X) (( void)(X))
+#define pVoid(X) (( pvoid)(X))
+#define ppVoid(X) (( ppvoid)(X))
+#define cVoid(X) (( cvoid)(X))
+#define pcVoid(X) (( pcvoid)(X))
+#define ppcVoid(X) ((ppcvoid)(X))
+
+// char
+typedef char* pchar;
+typedef pchar* ppchar;
+typedef unsigned char uchar;
+typedef uchar* puchar;
+typedef puchar* ppuchar;
+typedef const char cchar;
+typedef cchar* pcchar;
+typedef pcchar* ppcchar;
+typedef const uchar cuchar;
+typedef cuchar* pcuchar;
+typedef pcuchar* ppcuchar;
+#define Char(X) (( char)(X))
+#define pChar(X) (( pchar)(X))
+#define ppChar(X) (( ppchar)(X))
+#define uChar(X) (( uchar)(X))
+#define puChar(X) (( puchar)(X))
+#define ppuChar(X) (( ppuchar)(X))
+#define cChar(X) (( cchar)(X))
+#define pcChar(X) (( pcchar)(X))
+#define ppcChar(X) (( ppcchar)(X))
+#define cuChar(X) (( cuchar)(X))
+#define pcuChar(X) (( pcuchar)(X))
+#define ppcuChar(X) ((ppcuchar)(X))
+
+pvoid ctl_malloc (size_t size);
+pvoid ctl_realloc(pvoid ptr, size_t size);
+pvoid ctl_free (pvoid ptr);
+void ctl_die (ErrorType e);
+
+#define ctl_swap(X,Y,Z) do{X zzzztmp=(Y);(Y)=(Z);(Z)=zzzztmp;}while(0)
+#define ctl_max(X,Y) ((X) > (Y) ? (X) : (Y))
+#define ctl_min(X,Y) ((X) < (Y) ? (X) : (Y))
+
+#endif /* __utility_h__ */