std-macros.h

00001 /****
00002  * Fisher's standard macros.  Use them if you like.
00003  */
00004 
00005 #ifndef std_macros_included
00006 #define std_macros_included
00007 
00008 /*
00009  * Very frequently used libraries.
00010  */
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <stdlib.h>
00014 
00015 /*
00016  * Boolean helpers.
00017  */
00018 #define bool unsigned char
00019 #define true 1
00020 #define false 0
00021 #define and &&
00022 #define or ||
00023 #define not !
00024 
00025 /*
00026  * Null.
00027  */
00028 #define null 0
00029 
00030 /*
00031  * Exception handling.
00032  */
00033 #define catch setjmp
00034 #define throw longjmp
00035 #define exception jmp_buf
00036 
00037 /*
00038  * General allocators.
00039  */
00040 #define new(t) (t*) malloc(sizeof(t))
00041 #define newblock(t, size) (t*) malloc(sizeof(t) * size)
00042 #define newc(t) (t*) calloc(1, sizeof(t))
00043 
00044 /*
00045  * String helpers.
00046  */
00047 #define newstr(s) strcpy((char*) malloc(strlen(s)+1), s)
00048 #define newstrcat(s1,s2) \
00049     strcat(strcpy(newblock(char, strlen(s1)+strlen(s2)+1), s1), s2)
00050 #define streq(s1,s2) strcmp(s1,s2) == 0
00051 
00052 #endif

Generated on Fri Apr 20 09:49:47 2007 by  doxygen 1.4.6