00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef PACK_H
00024 #define PACK_H
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 #if defined(i386) || defined(WIN32)
00040 #define UGA_LITTLE_ENDIAN
00041 #endif
00042 
00043 
00044 
00045 #ifndef UGA_LITTLE_ENDIAN
00046 #define UGA_PACK_DOUBLE(QUAN, BUF, COUNT)           \
00047         do { char *_buf_ = BUF, *_ptr_ = (char *)&(QUAN);       \
00048         *((_buf_)++) = *((_ptr_)++);                \
00049         *((_buf_)++) = *((_ptr_)++);                \
00050         *((_buf_)++) = *((_ptr_)++);                \
00051         *((_buf_)++) = *((_ptr_)++);                \
00052         *((_buf_)++) = *((_ptr_)++);                \
00053         *((_buf_)++) = *((_ptr_)++);                \
00054         *((_buf_)++) = *((_ptr_)++);                \
00055         *((_buf_)++) = *((_ptr_)++);                \
00056         (BUF) = _buf_;                      \
00057         (COUNT) += 8; } while (0)
00058 #else
00059 #define UGA_PACK_DOUBLE(QUAN, BUF, COUNT)           \
00060         do { char *_buf_ = BUF, *_ptr_ = (char *)&(QUAN)+7;     \
00061         *((_buf_)++) = *((_ptr_)--);                \
00062         *((_buf_)++) = *((_ptr_)--);                \
00063         *((_buf_)++) = *((_ptr_)--);                \
00064         *((_buf_)++) = *((_ptr_)--);                \
00065         *((_buf_)++) = *((_ptr_)--);                \
00066         *((_buf_)++) = *((_ptr_)--);                \
00067         *((_buf_)++) = *((_ptr_)--);                \
00068         *((_buf_)++) = *((_ptr_)--);                \
00069         (BUF) = _buf_;                      \
00070         (COUNT) += 8; } while (0)
00071 #endif
00072 
00073 #define UGA_PACK_NDOUBLE(QUAN, BUF, NUM, COUNT)             \
00074         do { int _i;                        \
00075           for (_i=0; _i<(int)NUM; _i++)             \
00076                UGA_PACK_DOUBLE(QUAN[_i], BUF, COUNT); } while (0)
00077 
00078 #define UGA_PACK_WORD(QUAN, BUF, COUNT)             \
00079         do { u_long _long_ = htonl((u_long)QUAN);       \
00080         char *_buf_ = BUF, *_ptr_;              \
00081         _ptr_ = (char *)&_long_;                \
00082         *((_buf_)++) = *((_ptr_)++);                \
00083         *((_buf_)++) = *((_ptr_)++);                \
00084         *((_buf_)++) = *((_ptr_)++);                \
00085         *((_buf_)++) = *((_ptr_)++);                \
00086         (BUF) = _buf_;                      \
00087         (COUNT) += 4; } while (0)
00088 
00089 #define UGA_PACK_NWORD(QUAN, BUF, NUM, COUNT)           \
00090         do { int _i;                        \
00091           for (_i=0; _i<(int)NUM; _i++)             \
00092                 UGA_PACK_WORD(QUAN[_i], BUF, COUNT); } while (0)
00093 
00094 #define UGA_PACK_BYTES(PTR, BUF, SIZE, COUNT)           \
00095         ((void)bcopy((char *)(PTR),(char *)(BUF),(int)(SIZE)),  \
00096          BUF += (SIZE),(COUNT) += (SIZE))
00097 
00098 
00099 
00100 #ifndef UGA_LITTLE_ENDIAN
00101 #define UGA_UNPACK_DOUBLE(QUAN, BUF, COUNT)         \
00102         do { char *_buf_ = BUF, *_ptr_ = (char *)&(QUAN);   \
00103         *((_ptr_)++) = *((_buf_)++);                \
00104         *((_ptr_)++) = *((_buf_)++);                \
00105         *((_ptr_)++) = *((_buf_)++);                \
00106         *((_ptr_)++) = *((_buf_)++);                \
00107         *((_ptr_)++) = *((_buf_)++);                \
00108         *((_ptr_)++) = *((_buf_)++);                \
00109         *((_ptr_)++) = *((_buf_)++);                \
00110         *((_ptr_)++) = *((_buf_)++);                \
00111         (BUF) = _buf_;                      \
00112         (COUNT) += 8; } while (0)
00113 #else
00114 #define UGA_UNPACK_DOUBLE(QUAN, BUF, COUNT)         \
00115         do { char *_buf_ = BUF, *_ptr_ = (char *)&(QUAN)+7; \
00116         *((_ptr_)--) = *((_buf_)++);                \
00117         *((_ptr_)--) = *((_buf_)++);                \
00118         *((_ptr_)--) = *((_buf_)++);                \
00119         *((_ptr_)--) = *((_buf_)++);                \
00120         *((_ptr_)--) = *((_buf_)++);                \
00121         *((_ptr_)--) = *((_buf_)++);                \
00122         *((_ptr_)--) = *((_buf_)++);                \
00123         *((_ptr_)--) = *((_buf_)++);                \
00124         (BUF) = _buf_;                      \
00125         (COUNT) += 8; } while (0)
00126 #endif
00127 
00128 #define UGA_UNPACK_NDOUBLE(QUAN, BUF, NUM, COUNT)       \
00129         do { int _i;                        \
00130           for (_i=0; _i<(int)NUM; _i++)             \
00131                UGA_UNPACK_DOUBLE(QUAN[_i], BUF, COUNT); } while (0)
00132 
00133 #define UGA_UNPACK_WORD(QUAN, BUF, COUNT, TYPE)         \
00134         do { char *_buf_ = BUF, *_ptr_ = (char *)&(QUAN);   \
00135         *((_ptr_)++) = *((_buf_)++);                \
00136         *((_ptr_)++) = *((_buf_)++);                \
00137         *((_ptr_)++) = *((_buf_)++);                \
00138         *((_ptr_)++) = *((_buf_)++);                \
00139         (BUF) = _buf_;                      \
00140         (QUAN) = (TYPE)ntohl((u_long)QUAN);         \
00141         (COUNT) += 4; } while (0)
00142 
00143 #define UGA_UNPACK_NWORD(QUAN, BUF, NUM, COUNT, TYPE)       \
00144         do { int _i;                        \
00145           for (_i=0; _i<(int)NUM; _i++)             \
00146                 UGA_UNPACK_WORD(QUAN, BUF, COUNT, TYPE); } while (0)
00147 
00148 #define UGA_UNPACK_BYTES(PTR, BUF, SIZE, COUNT)         \
00149         ((void)bcopy((char *)(BUF), (char *)(PTR), (int)(SIZE)),\
00150          BUF += (SIZE),(COUNT) += (SIZE))
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 #define UGA_PACK_LONG(Q,B,C)        UGA_PACK_WORD(Q,B,C)
00162 #define UGA_PACK_NLONG(Q,B,N,C)     UGA_PACK_NWORD(Q,B,N,C)
00163 #define UGA_PACK_INTEGER(Q,B,C)     UGA_PACK_WORD(Q,B,C)
00164 #define UGA_PACK_NINTEGER(Q,B,N,C)  UGA_PACK_NWORD(Q,B,N,C)
00165 #define UGA_PACK_ENUM(Q,B,C)        UGA_PACK_WORD(Q,B,C)
00166 #define UGA_PACK_NENUM(Q,B,N,C)     UGA_PACK_NWORD(Q,B,N,C)
00167 #define UGA_PACK_POINTER(Q,B,C)     UGA_PACK_WORD(Q,B,C)
00168 #define UGA_PACK_NPOINTER(Q,B,N,C)  UGA_PACK_NWORD(Q,B,N,C)
00169 
00170 #define UGA_UNPACK_LONG(Q,B,C)      UGA_UNPACK_WORD(Q,B,C,long)
00171 #define UGA_UNPACK_NLONG(Q,B,N,C)   UGA_UNPACK_NWORD(Q,B,N,C,long)
00172 #define UGA_UNPACK_INTEGER(Q,B,C)   UGA_UNPACK_WORD(Q,B,C,int)
00173 #define UGA_UNPACK_NINTEGER(Q,B,N,C)    UGA_UNPACK_NWORD(Q,B,N,C,int)
00174 #define UGA_UNPACK_ENUM(Q,B,C,T)    UGA_UNPACK_WORD(Q,B,C,T)
00175 #define UGA_UNPACK_NENUM(Q,B,N,C,T) UGA_UNPACK_NWORD(Q,B,N,C,T)
00176 #define UGA_UNPACK_POINTER(Q,B,C,T) UGA_UNPACK_WORD(Q,B,C,T)
00177 #define UGA_UNPACK_NPOINTER(Q,B,N,C,T)  UGA_UNPACK_NWORD(Q,B,N,C,T)
00178 
00179 #define OPSYS_ALIGN_CHAR    sizeof(char)
00180 #define OPSYS_ALIGN_INT     sizeof(int)
00181 #define OPSYS_ALIGN_SHORT   sizeof(short)
00182 #define OPSYS_ALIGN_LONG    sizeof(long)
00183 #define OPSYS_ALIGN_FLOAT   sizeof(float)
00184 #define OPSYS_ALIGN_DOUBLE  sizeof(double)
00185 #define OPSYS_ALIGN_GENERIC (sizeof(double)>sizeof(long)?sizeof(double):sizeof(long))
00186 
00187 #endif