|  |     
/* -------------------------------------------------------------------------
 * Endianism management tools - Interface
 */
    
#if ( defined sparc || defined __hpux || defined _AIX || defined __sgi )
#define LITTLE_ENDIAN
#endif
    
/*
 * The following two routines will handle endianism for arrays of
 * respectively 16 or 32 bits long integers.  First parameter is a pointer
 * to the array, second parameter is the number of elements in the array.
 */
    
void handle_words_endianism( ushort16 * , int  );
void handle_longwords_endianism( ulong32 * , int );
    
/* -------------------------------------------------------------------------
 * Endianism management tools - Body
 */
/*
**++
**  FUNCTIONAL DESCRIPTION:    fliplongword()
**      Swaps a longword byte order, to cope with
**      little and big endian representations which are
**      different on SUN, HP, IBM, Silicon Graphics on one hand
**      and DEC on the other hand...
**
**     On SUN, HP, IBM or SGI which are
**            BIG endian on BYTES and LITTLE endian on BITS
**      we have the following
**
**      +------------------+-----------------+
**      | High order Bytes |Low order bytes  |
**      +------------------+-----------------+
**      Address            Address+1          
**  
**     On DEC which is
**            LITTLE endian on BYTES and LITTLE endian on BITS
**      we have the following
**
**      +------------------+-----------------+
**      | High order Bytes |Low order bytes  |
**      +------------------+-----------------+
**      Address+1          Address 
**
**     Hacked from Kasino::NEIDECKER (note 6622 on ULTRIX)
**
**  FORMAL PARAMETERS:
**      x  : long word to swap
**
**  RETURN VALUE:
**      Swapped long word
**
**  SIDE EFFECTS:
**      None.
**--
*/
ulong32 fliplongword( x )
     ulong32 x;
{
  ulong32 r;
  r =   ( x >> 24 );
  r |=  ( x << 24 );
  r |= (( x >>  8 ) & 0x0000ff00 );
  r |= (( x & 0x0000ff00 ) << 8 );
  return( r );
}
/* ------------------------------------------------------------------------- */
/*
**++
**  FUNCTIONAL DESCRIPTION:    flipword()
**      Swaps a word (16 bits, 2 bytes) byte order,
**      to cope with little and big endian representations which are
**      different on SUN, HP, IBM, Silicon Graphics on one hand
**      and DEC on the other hand...
**
**  FORMAL PARAMETERS:
**      x  : ushort16 to swap
**
**  RETURN VALUE:
**      Swapped short int
**
**  SIDE EFFECTS:
**      None.
**--
*/
ushort16 flipword( x )
     ushort16 x;
{
  ushort16 r;
  r =  ( x >> 8 );
  r |= ( x << 8 );
  return( r );
}
/* ------------------------------------------------------------------------- */
/*
**++
**  FUNCTIONAL DESCRIPTION:    handle_words_endianism()
**      Swaps individually <number> consecutive longwords
**      (16 bits, 2 bytes) byte order, only on SunOS, Solaris,
**      HP-UX, AIX and IRIX, to cope with little and big endian
**      representations which are different from Digital UNIX and ULTRIX.
**
**  FORMAL PARAMETERS:
**      word   : address of consecutive words to swap
**      number : number of words to process.
**
**  RETURN VALUE:
**      Swapped short int
**
**  SIDE EFFECTS:
**      None.
**--
*/
void handle_words_endianism( word , number )
     ushort16 *word;
     int       number;
{
/*
 * Do it only on SunOS, Solaris, HP-UX, AIX and IRIX
 */
#ifdef LITTLE_ENDIAN
  int i;
  ushort16 *ptr;
  for ( i = number, ptr = word ; i > 0 ; i-- , ptr++ )
    *ptr = flipword( *ptr );
#endif
} /* handle_words_endianism() */
/* ------------------------------------------------------------------------- */
/*
**++
**  FUNCTIONAL DESCRIPTION:    handle_longwords_endianism()
**      Swaps individually <number> consecutive longwords
**      (32 bits, 4 bytes) byte order, only on SunOS, Solaris,
**      HP-UX, AIX and IRIX, to cope with little and big endian
**      representations which are different from Digital UNIX and ULTRIX.
**
**  FORMAL PARAMETERS:
**      longword : address of consecutive ulong32's to swap
**      number   : number of longwords to process.
**
**  RETURN VALUE:
**      Swapped short int
**
**  SIDE EFFECTS:
**      None.
**--
*/
void handle_longwords_endianism( longword , number )
     ulong32 *longword;
     int      number;
{
/*
 * Do it only on SunOS, Solaris, HP-UX, AIX and IRIX
 */
#ifdef LITTLE_ENDIAN
  int i;
  ulong32 *ptr;
  for ( i = number, ptr = longword ; i > 0 ; i--, ptr++ )
    *ptr = fliplongword( *ptr );
#endif
} /* handle_longwords_endianism() */
 |