home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / FLIPEND.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  7KB  |  188 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.5 com/src/utils/include/FlipEnd.h, odutils, od96os2, odos29646d 9/20/96 12:23:30 [ 11/15/96 15:28:59 ]
  28. /*
  29.     File:        FlipEnd.h
  30.  
  31.     Contains:    routines to manipulate endianness of memory
  32.  
  33.     Owned by:    David McCusker
  34.  
  35.     Copyright:    ⌐ 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     To Do:
  38.         Perhaps write assembler inlines for ODFlipShort() and ODFlipLong()
  39.         on the Mac platform.
  40.     In Progress:
  41.         
  42. */
  43.  
  44. #ifndef _FLIPEND_
  45. #define _FLIPEND_ 1
  46.  
  47. #ifndef _ODTYPES_
  48. #include <ODTypes.h>
  49. #endif
  50.  
  51.  
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55.  
  56. /* _PLATFORM_BIG_ENDIAN_ should be defined for big endian platforms
  57.  * near other platform related defines (e.g. see ODTypesM.idl)
  58.  */
  59.  
  60. /*=========================================================================*/
  61. /* 2 byte endianness flipping */
  62. /*=========================================================================*/
  63.  
  64. ODUShort ODFlipShort(ODUShort n);
  65.     /* n is a single 2-byte int; return it with flipped endianness */
  66.  
  67. void ODFlipShortArray(ODUShort* a, unsigned long count);
  68.     /* a points to count 2-byte ints; flip each int's endianness */
  69.  
  70. /*=========================================================================*/
  71. /* 4 byte endianness flipping */
  72. /*=========================================================================*/
  73.  
  74. ODULong ODFlipLong(ODULong n);
  75.     /* n is a single 4-byte int; return it with flipped endianness */
  76.  
  77. void ODFlipLongArray(ODULong* a, unsigned long count);
  78.     /* a points to count 4-byte ints; flip each int's endianness */
  79.  
  80. #ifndef OD_BUG // function doesn't work, and no one uses it.
  81. /*=========================================================================*/
  82. /* structure endianness flipping */
  83. /*=========================================================================*/
  84.  
  85. void ODFlipStruct(void* structure, const short* groups);
  86.     /* Invert the endianness of the contents of memory in structure
  87.      * according to the layout described by groups, which should
  88.      * be a zero-terminated array of shorts, where each short describes
  89.      * the size of the next chunk of memory in structure to be processed.
  90.      * A negative value -x in the groups array indicates a block
  91.      * of endianness-neutral memory, like a string, and causes x bytes
  92.      * of memory to be skipped over.  A positive value x in the groups
  93.      * array indicates an x byte block of memory which should have its
  94.      * bytes flipped end for end.  Only positive values in the set
  95.      * { 2, 4, 8 } are handled. (Other positive values are handled like
  96.      * negative values: space is skipped). Example:
  97.      *
  98.      * struct Foo {
  99.      *     long  beta;
  100.      *     char  gamma[8];
  101.      *     long  delta;
  102.      *     short alpha;
  103.      * };
  104.      * const short fooGroups[] = {
  105.      *     4, // beta
  106.      *    -8, // gamma 
  107.      *     4, // delta
  108.      *     2, // alpha
  109.      *     0, // zero-termination
  110.      * };
  111.      */
  112.  
  113. #endif // OD_BUG
  114.  
  115. /*=========================================================================*/
  116. /* macros for conversion to and from standard (little endian) format */
  117. /*=========================================================================*/
  118.  
  119. #ifdef _PLATFORM_BIG_ENDIAN_
  120.     
  121. #define ConvertODUShortToStd(n)        ODFlipShort(n)
  122. #define ConvertODUShortFromStd(n)      ODFlipShort(n)
  123.     
  124. #define ConvertODSShortToStd(n)        ((ODSShort) ODFlipShort((ODUShort) n))
  125. #define ConvertODSShortFromStd(n)      ((ODSShort) ODFlipShort((ODUShort) n))
  126.     
  127. #define ConvertODULongToStd(n)         ODFlipLong(n)
  128. #define ConvertODULongFromStd(n)       ODFlipLong(n)
  129.         
  130. #define ConvertODSLongToStd(n)         ((ODSLong) ODFlipLong((ODULong) n))
  131. #define ConvertODSLongFromStd(n)       ((ODSLong) ODFlipLong((ODULong) n))
  132.  
  133. #ifndef OD_BUG // function doesn't work, and no one uses it.
  134. #define ConvertODStructToStd(s, g)     ODFlipStruct((s),(g))
  135. #define ConvertODStructFromStd(s, g)   ODFlipStruct((s),(g))
  136. #endif
  137.  
  138. #define ConvertODUShortArrayToStd(a,c)    ODFlipShortArray((a),(c))
  139. #define ConvertODUShortArrayFromStd(a,c)  ODFlipShortArray((a),(c))
  140.  
  141. #define ConvertODSShortArrayToStd(a,c)    ODFlipShortArray((ODUShort*)(a),(c))
  142. #define ConvertODSShortArrayFromStd(a,c)  ODFlipShortArray((ODUShort*)(a),(c))
  143.  
  144. #define ConvertODULongArrayToStd(a,c)     ODFlipLongArray((a),(c))
  145. #define ConvertODULongArrayFromStd(a,c)   ODFlipLongArray((a),(c))
  146.  
  147. #define ConvertODSLongArrayToStd(a,c)     ODFlipLongArray((ODULong*)(a),(c))
  148. #define ConvertODSLongArrayFromStd(a,c)   ODFlipLongArray((ODULong*)(a),(c))
  149.  
  150. #else
  151.  
  152. #define ConvertODUShortToStd(n)        (n)
  153. #define ConvertODUShortFromStd(n)      (n)
  154.     
  155. #define ConvertODSShortToStd(n)        (n)
  156. #define ConvertODSShortFromStd(n)      (n)
  157.     
  158. #define ConvertODULongToStd(n)         (n)
  159. #define ConvertODULongFromStd(n)       (n)
  160.         
  161. #define ConvertODSLongToStd(n)         (n)
  162. #define ConvertODSLongFromStd(n)       (n)
  163.         
  164. #define ConvertODStructToStd(s, g)     /* do nothing */
  165. #define ConvertODStructFromStd(s, g)   /* do nothing */
  166.  
  167. #define ConvertODUShortArrayToStd(a,c)    /* do nothing */
  168. #define ConvertODUShortArrayFromStd(a,c)  /* do nothing */
  169.  
  170. #define ConvertODSShortArrayToStd(a,c)    /* do nothing */
  171. #define ConvertODSShortArrayFromStd(a,c)  /* do nothing */
  172.  
  173. #define ConvertODULongArrayToStd(a,c)     /* do nothing */
  174. #define ConvertODULongArrayFromStd(a,c)   /* do nothing */
  175.  
  176. #define ConvertODSLongArrayToStd(a,c)     /* do nothing */
  177. #define ConvertODSLongArrayFromStd(a,c)   /* do nothing */
  178.  
  179. #endif /* _PLATFORM_BIG_ENDIAN_ */
  180.  
  181.  
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185.  
  186. #endif
  187. /* _FLIPEND_ */
  188.