1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 /* 9 * $Header: /src/master/dx/src/exec/dpexec/utils.h,v 1.9 2004/06/09 16:14:29 davidt Exp $ 10 */ 11 12 #include <dxconfig.h> 13 14 #ifndef _UTILS_H 15 #define _UTILS_H 16 17 #include <string.h> 18 #include <stddef.h> 19 #include <dx/dx.h> 20 #include <dx/arch.h> 21 22 #if defined(__cplusplus) || defined(c_plusplus) 23 extern "C" { 24 #endif 25 26 #ifndef NULL 27 #define NULL 0 28 #endif 29 30 #ifndef TRUE 31 #define TRUE 1 32 #define FALSE 0 33 #endif 34 35 char *_dxf_ExStrSave (char *old); 36 37 #define exJID (_dxd_exMyPID+1) 38 39 #define KILO(n) ((n) << 10) 40 #define MEGA(n) ((n) << 20) 41 42 /* 43 * Covers for useful functions to make lint shut up about type problems 44 */ 45 46 #define ExZero(p,n) memset ((void *) (p), 0, (size_t) (n)) 47 #define ExCopy(d,s,n) memcpy ((void *) (d), (const void *) s, (size_t) (n)) 48 49 /* 50 * Make it easy to put function pointers into structures. 51 */ 52 53 typedef char (*PFC)(); 54 typedef short (*PFS)(); 55 typedef int (*PFI)(); 56 typedef int (*PFIP)(void *); 57 typedef long (*PFL)(); 58 typedef float (*PFF)(); 59 typedef double (*PFD)(); 60 typedef void (*PFV)(); 61 62 typedef unsigned char (*PFUC)(); 63 typedef unsigned short (*PFUS)(); 64 typedef unsigned int (*PFUI)(); 65 typedef unsigned long (*PFUL)(); 66 67 typedef Error (*PFE)(); 68 typedef Pointer (*PFP)(); 69 70 /* 71 * Useful functions. 72 */ 73 74 Pointer _dxf_ExAlignBoundary (long n, Pointer p); 75 char *_dxf_ExCopyString (char *old); 76 char *_dxf_ExCopyStringN (char *old, int len); 77 char *_dxf_ExCopyStringLocal (char *old); 78 int _dxf_ExNextPowerOf2 (int n); 79 Array _dxfExNewInteger (int n); 80 81 82 #define LIST(type) struct {int nalloc; int nused; type *vals;} 83 #define INIT_LIST(list) ((list).nalloc = (list).nused = 0, (list).vals = NULL) 84 #define INIT_LIST_LOCAL(t, list) ( \ 85 (list).nalloc = (list).nused = 0, \ 86 (list).vals = (t *) DXAllocateLocal(1) \ 87 ) 88 #define COPY_LIST(dstlist, srclist) ( \ 89 (dstlist).nalloc = (srclist).nalloc, (dstlist).nused = (srclist).nused, \ 90 (dstlist).vals = (srclist).vals \ 91 ) 92 #define APPEND_LIST(t,list,val) \ 93 do \ 94 { \ 95 if ((list).nalloc == (list).nused) \ 96 { \ 97 (list).nalloc += 10; \ 98 (list).vals = (t *) DXReAllocate ( \ 99 (Pointer)((list).vals), \ 100 (list).nalloc * sizeof ((list).vals[0])); \ 101 if ((list).vals == NULL) \ 102 { \ 103 _dxf_ExDie("Can't Reallocate list"); \ 104 } \ 105 } \ 106 (list).vals[(list).nused++] = (val); \ 107 } while (0) 108 #define GROW_LIST(t,list,num) \ 109 do \ 110 { \ 111 int _grow; \ 112 _grow = (num) - ((list).nalloc - (list).nused); \ 113 if(_grow > 0) { \ 114 (list).nalloc += _grow; \ 115 (list).vals = (t *) DXReAllocate ((Pointer)((list).vals),\ 116 (list).nalloc * sizeof ((list).vals[0])); \ 117 if ((list).vals == NULL) \ 118 { \ 119 _dxf_ExDie("Can't Grow list"); \ 120 } \ 121 } \ 122 } while (0) 123 #define DELETE_LIST(t,list,ind) \ 124 do \ 125 { \ 126 int _i; \ 127 for(_i = ind; _i < (list).nused-1; _i++) \ 128 (list).vals[_i] = (list).vals[_i+1]; \ 129 (list).nused--; \ 130 } while (0) 131 #define INSERT_LIST(t,list,val,ind) \ 132 do \ 133 { \ 134 int _i; \ 135 if ((list).nalloc == (list).nused) \ 136 { \ 137 (list).nalloc += 10; \ 138 (list).vals = (t *) DXReAllocate ( \ 139 (Pointer)((list).vals), \ 140 (list).nalloc * sizeof ((list).vals[0])); \ 141 if ((list).vals == NULL) \ 142 { \ 143 _dxf_ExDie("Can't Reallocate list"); \ 144 } \ 145 } \ 146 for(_i = (list).nused; _i > ind; _i--) \ 147 (list).vals[_i] = (list).vals[_i-1]; \ 148 (list).vals[ind] = (val); \ 149 (list).nused++; \ 150 } while (0) 151 #define UPDATE_LIST(list,val,ind) \ 152 do \ 153 { \ 154 (list).vals[ind] = (val); \ 155 } while (0) 156 #define FETCH_LIST(list,ind) (((ind) < (list).nused)? (list).vals + (ind): 0) 157 #define INDEX_LIST(list,ind) ((list).vals + (ind)) 158 #define SIZE_LIST(list) ((list).nused) 159 #define FREE_LIST(list) (DXFree((Pointer)((list).vals)), INIT_LIST(list)) 160 161 #define ExDebug if (_dxd_exEnableDebug) DXDebug 162 163 #define ExMarkTime(_m,_t) if (_m & _dxd_exMarkMask) DXMarkTime (_t) 164 #define ExMarkTimeLocal(_m,_t) if (_m & _dxd_exMarkMask) DXMarkTimeLocal (_t) 165 166 #if defined(__cplusplus) || defined(c_plusplus) 167 } 168 #endif 169 170 #endif /* __EX_UTILS_H */ 171