cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
24ddc71998-03-28Henrik Grubbström (Grubba)  /*
ac3edc2000-06-27Henrik Grubbström (Grubba)  * $Id: pike_macros.h,v 1.16 2000/06/27 15:19:33 grubba Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef MACROS_H #define MACROS_H
bdfb861997-12-22Fredrik Hübinette (Hubbe) #include <global.h> #ifdef HAVE_SYS_PARAM_H
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <sys/param.h>
bdfb861997-12-22Fredrik Hübinette (Hubbe) #endif
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) #include "pike_memory.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
d4828c1997-07-17Fredrik Hübinette (Hubbe) #define OFFSETOF(str_type, field) ((long)& (((struct str_type *)0)->field))
5267b71995-08-09Fredrik Hübinette (Hubbe) #define BASEOF(ptr, str_type, field) \ ((struct str_type *)((char*)ptr - (char*)& (((struct str_type *)0)->field))) #define NELEM(a) (sizeof (a) / sizeof ((a)[0])) #define ALLOC_STRUCT(X) ( (struct X *)xalloc(sizeof(struct X)) ) #define MINIMUM(X,Y) ((X)<(Y)?(X):(Y)) #define MAXIMUM(X,Y) ((X)>(Y)?(X):(Y))
b432bb1996-10-29Per Hedbor 
4649141997-09-27Henrik Grubbström (Grubba) #define is8bitalnum(X) ("0000000000000000" \
2e104a1998-05-06Henrik Grubbström (Grubba)  "0000000000000000" \
4649141997-09-27Henrik Grubbström (Grubba)  "0000000000000000" \ "1111111111000000" \ "0111111111111111" \ "1111111111100001" \ "0111111111111111" \ "1111111111100000" \ "0000000000000000" \ "0000000000000000" \ "1011110101100010" \ "1011011001101110" \ "1111111111111111" \ "1111111011111111" \ "1111111111111111" \ "1111111011111111"[((unsigned)(X))&0xff] == '1')
b432bb1996-10-29Per Hedbor  #define isidchar(X) is8bitalnum(X)
5c8e891995-10-29Fredrik Hübinette (Hubbe) 
94eb311998-05-18Henrik Grubbström (Grubba) #ifndef HAVE_ISGRAPH #define isgraph(X) (ispunct(X) || isupper(X) || islower(X) || isdigit(X)) #endif /* !HAVE_ISGRAPH */
90e9781999-01-31Fredrik Hübinette (Hubbe) /* * #define ALIGNOF(X) __alignof__(X) * #define ALIGNOF(X) (sizeof(X)>ALIGN_BOUND?ALIGN_BOUND:( 1<<my_log2(sizeof(X))))
39125a1999-01-31Henrik Grubbström (Grubba)  */
5267b71995-08-09Fredrik Hübinette (Hubbe) 
90e9781999-01-31Fredrik Hübinette (Hubbe) #define ALIGNOF(X) ((int)&(((struct { char ignored_ ; X fooo_; } *)0)->fooo_))
1994981998-04-07Fredrik Hübinette (Hubbe)  #define DO_ALIGN(X,Y) (((long)(X)+((Y)-1)) & -(Y))
45ee5d1999-02-10Fredrik Hübinette (Hubbe) #define CONSTANT_STRLEN(X) (sizeof(X) - sizeof(""))
ac3edc2000-06-27Henrik Grubbström (Grubba) #define SET_NEXT_AND_FREE(p,free_item) do{ \
fccf992000-04-07Fredrik Hübinette (Hubbe)  next=p->next; \ while(p->refs == 1 && (next=p->next)) \ { \ add_ref(next); \
ac3edc2000-06-27Henrik Grubbström (Grubba)  free_item(p); \
fccf992000-04-07Fredrik Hübinette (Hubbe)  p=next; \ } \
ac3edc2000-06-27Henrik Grubbström (Grubba)  free_item(p); \
fccf992000-04-07Fredrik Hübinette (Hubbe) }while(0)
a4033e2000-04-14Fredrik Hübinette (Hubbe)  #define DOUBLELINK(first_object, o) do { \ o->next=first_object; \ o->prev=0; \ if(first_object) first_object->prev=o; \ first_object=o; \ }while(0) #define DOUBLEUNLINK(first_object,o) do{ \ if(o->prev) { \ o->prev->next=o->next; \ }else { \ DO_IF_DEBUG( \ if(first_object != o) \ fatal("Linked in wrong list!\n"); \ ) \ first_object=o->next; \ } \ \ if(o->next) o->next->prev=o->prev; \ }while(0)
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif