htonf.c

Go to the documentation of this file.
00001 /*                         H T O N F . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup hton */
00023 /*@{*/
00024 /** @file htonf.c
00025  *
00026  *@brief convert floats to host/network format
00027  *
00028  * Host to Network Floats  +  Network to Host Floats.
00029  *  Author -
00030  *      Michael John Muuss
00031  *
00032  *  Source -
00033  *      SECAD/VLD Computing Consortium, Bldg 394
00034  *      The U. S. Army Ballistic Research Laboratory
00035  *      Aberdeen Proving Ground, Maryland  21005-5066
00036  */
00037 
00038 
00039 #ifndef lint
00040 static const char libbu_htond_RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/htonf.c,v 14.13 2006/09/03 15:14:07 lbutler Exp $ (BRL)";
00041 #endif
00042 
00043 #include "common.h"
00044 
00045 
00046 #include <stdio.h>
00047 #include "machine.h"
00048 #include "bu.h"
00049 
00050 #ifdef HAVE_MEMORY_H
00051 #  include <memory.h>
00052 #endif
00053 #include <stdio.h>
00054 
00055 /**
00056  *                      H T O N F
00057  *
00058  *  Host to Network Floats
00059  */
00060 void
00061 htonf(register unsigned char *out, register const unsigned char *in, int count)
00062 {
00063 #if     defined(NATURAL_IEEE)
00064         /*
00065          *  First, the case where the system already operates in
00066          *  IEEE format internally, using big-endian order.
00067          *  These are the lucky ones.
00068          */
00069 #       ifdef HAVE_MEMORY_H
00070                 memcpy( out, in, count*SIZEOF_NETWORK_FLOAT );
00071 #       else
00072                 bcopy( in, out, count*SIZEOF_NETWORK_FLOAT );
00073 #       endif
00074         return;
00075 #       define  HTONF   yes1
00076 #endif
00077 
00078 #if     defined(REVERSE_IEEE)
00079         /* This machine uses IEEE, but in little-endian byte order */
00080         register int    i;
00081         for( i=count-1; i >= 0; i-- )  {
00082                 *out++ = in[3];
00083                 *out++ = in[2];
00084                 *out++ = in[1];
00085                 *out++ = in[0];
00086                 in += SIZEOF_NETWORK_FLOAT;
00087         }
00088         return;
00089 #       define  HTONF   yes2
00090 #endif
00091 
00092         /* Now, for the machine-specific stuff. */
00093 
00094 #ifndef HTONF
00095 # include "ntohf.c:  ERROR, no NtoHD conversion for this machine type"
00096 #endif
00097 }
00098 
00099 
00100 /**
00101  *                      N T O H F
00102  *
00103  *  Network to Host Floats
00104  */
00105 void
00106 ntohf(register unsigned char *out, register const unsigned char *in, int count)
00107 {
00108 #ifdef NATURAL_IEEE
00109         /*
00110          *  First, the case where the system already operates in
00111          *  IEEE format internally, using big-endian order.
00112          *  These are the lucky ones.
00113          */
00114         if( sizeof(float) != SIZEOF_NETWORK_FLOAT )
00115                 bu_bomb("ntohf:  sizeof(float) != SIZEOF_NETWORK_FLOAT\n");
00116 #       ifdef HAVE_MEMORY_H
00117                 memcpy( out, in, count*SIZEOF_NETWORK_FLOAT );
00118 #       else
00119                 bcopy( in, out, count*SIZEOF_NETWORK_FLOAT );
00120 #       endif
00121         return;
00122 #       define  NTOHF   yes1
00123 #endif
00124 #if     defined(REVERSE_IEEE)
00125         /* This machine uses IEEE, but in little-endian byte order */
00126         register int    i;
00127         for( i=count-1; i >= 0; i-- )  {
00128                 *out++ = in[3];
00129                 *out++ = in[2];
00130                 *out++ = in[1];
00131                 *out++ = in[0];
00132                 in += SIZEOF_NETWORK_FLOAT;
00133         }
00134         return;
00135 #       define  NTOHF   yes2
00136 #endif
00137 
00138 #ifndef NTOHF
00139 # include "ntohf.c:  ERROR, no NtoHD conversion for this machine type"
00140 #endif
00141 }
00142 /*@}*/
00143 /*
00144  * Local Variables:
00145  * mode: C
00146  * tab-width: 8
00147  * c-basic-offset: 4
00148  * indent-tabs-mode: t
00149  * End:
00150  * ex: shiftwidth=4 tabstop=8
00151  */

Generated on Mon Sep 18 01:24:48 2006 for BRL-CAD by  doxygen 1.4.6