/* * Software License * * Copyright (c) 2001 Joshua M. Deutsch. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed Joshua M. Deutsch * Dept of Physics University of California, Santa Cruz" * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The name "GESSES" * must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact josh@physics.ucsc.edu. * * 5. Products derived from this software may not be called "gesses" * nor may "gesses" appear in their names without prior written * permission of Joshua M. Deutsch. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL JOSHUA M. DEUTSCH OR THE UNIVERSITY * OF CALIFORNIA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== */ #ifndef DEFS_H #define DEFS_H #include #include #include #define __USE_GNU typedef unsigned char uchar; #define memcmp_(a,b,l) memcmp(a,b,l*sizeof(a[0])) #define memcpy_(dest,src,l) memcpy((dest),(src),(l)*sizeof((src)[0])) #define memmove_(dest,src,l) memmove((dest),(src),(l)*sizeof((src)[0])) #define memset_(dest,int_const,l) memset((dest),(int_const),(l)*sizeof((dest)[0])) #define free_(pointer) do {if (pointer) free(pointer);} while(0) #define calloc_(pointer,l) pointer = (typeof(pointer)) calloc((l),sizeof((pointer)[0])) #define malloc_(pointer,l) (pointer) = (typeof(pointer)) malloc((l)*sizeof((pointer)[0])) #define realloc_(pointer,l) pointer = (typeof(pointer)) realloc ((pointer), (l)*sizeof((pointer)[0])) #define size_2d(pointer,i,j) do{ \ int _j; \ calloc_ (pointer,(i)); \ for(_j=0; _j < i; _j++) calloc_((pointer)[_j],j); \ } while (0) #define free_2d(pointer,i) do{ \ int _j; \ for(_j=0; _j < i; _j++) free((pointer)[_j]); \ free (pointer); \ } while (0) #define alloca_(pointer,l) (pointer) = (typeof(pointer)) alloca((l)*sizeof((pointer)[0])); #define alloca_0(pointer,l) do { \ (pointer) = (typeof(pointer)) alloca((l)*sizeof((pointer)[0])); \ memset(pointer,0, l * sizeof((pointer)[0])); \ } while (0) #define alloca_2d(pointer,i,j) do{ \ int _j; \ alloca_ ((pointer),(i)); \ for(_j=0; _j < i; _j++) alloca_((pointer)[_j],j); \ } while (0) #define alloca_2d_0(pointer,i,j) do{ \ int _j; \ alloca_0 ((pointer),(i)); \ for(_j=0; _j < i; _j++) alloca_0((pointer)[_j],j); \ } while (0) inline void * concat(void * a1, size_t n1, void * a2, size_t n2); void reverse_int_array(int * a, int length); #define concat_(array_1,n_1,array_2,n2) ((typeof(array_1)) concat(array_1,n_1*sizeof(array_1[0]),array_2,n2*sizeof(array_2[0]))) #define SQR(x) (x)*(x) #define CUBE(x) (x)*(x)*(x) #define ran() rand()/(RAND_MAX+1.0) #define SWAP(a,b) do { \ typeof(a) tmp = (a); \ (a)=b; \ (b)=tmp; \ } while(0) #define min(a,b) ((a) < (b)?(a):(b)) #define max(a,b) ((a) > (b)?(a):(b)) #endif// DEFS_H