00001 /* Copyright (C) 1988-1991 Apple Computer, Inc. 00002 * All Rights Reserved. 00003 * 00004 * Warranty Information 00005 * Even though Apple has reviewed this software, Apple makes no warranty 00006 * or representation, either express or implied, with respect to this 00007 * software, its quality, accuracy, merchantability, or fitness for a 00008 * particular purpose. As a result, this software is provided "as is," 00009 * and you, its user, are assuming the entire risk as to its quality 00010 * and accuracy. 00011 * 00012 * This code may be used and freely distributed as long as it includes 00013 * this copyright notice and the warranty information. 00014 * 00015 * 00016 * Motorola processors (Macintosh, Sun, Sparc, MIPS, etc) 00017 * pack bytes from high to low (they are big-endian). 00018 * Use the HighLow routines to match the native format 00019 * of these machines. 00020 * 00021 * Intel-like machines (PCs, Sequent) 00022 * pack bytes from low to high (the are little-endian). 00023 * Use the LowHigh routines to match the native format 00024 * of these machines. 00025 * 00026 * These routines have been tested on the following machines: 00027 * Apple Macintosh, MPW 3.1 C compiler 00028 * Apple Macintosh, THINK C compiler 00029 * Silicon Graphics IRIS, MIPS compiler 00030 * Cray X/MP and Y/MP 00031 * Digital Equipment VAX 00032 * 00033 * 00034 * Implemented by Malcolm Slaney and Ken Turkowski. 00035 * 00036 * Malcolm Slaney contributions during 1988-1990 include big- and little- 00037 * endian file I/O, conversion to and from Motorola's extended 80-bit 00038 * FLOATing-point format, and conversions to and from IEEE single- 00039 * precision FLOATing-point format. 00040 * 00041 * In 1991, Ken Turkowski implemented the conversions to and from 00042 * IEEE double-precision format, added more precision to the extended 00043 * conversions, and accommodated conversions involving +/- infinity, 00044 * NaN's, and denormalized numbers. 00045 * 00046 * $Id: portableio.c,v 1.1 2003/10/04 00:11:19 herman Exp $ 00047 * 00048 * $Log: portableio.c,v $ 00049 * Revision 1.1 2003/10/04 00:11:19 herman 00050 * New file from 1.1.7 (not in 1.1.6) added from Rich's automakified src tree. 00051 * 00052 * Revision 1.1 2003/07/29 04:17:52 heroine 00053 * *** empty log message *** 00054 * 00055 * Revision 2.6 91/04/30 17:06:02 malcolm 00056 * Apr 2000 00057 * MFC - hacked out everything we don't need for layer II 00058 */ 00059 00060 #include <stdio.h> 00061 #include <math.h> 00062 #include "portableio.h" 00063 #include "common.h" 00064 00065 /**************************************************************** 00066 * Big/little-endian independent I/O routines. 00067 ****************************************************************/ 00068 int Read16BitsHighLow (fp) 00069 FILE *fp; 00070 { 00071 int first, second, result; 00072 00073 first = 0xff & getc (fp); 00074 second = 0xff & getc (fp); 00075 00076 result = (first << 8) + second; 00077 #ifndef THINK_C42 00078 if (result & 0x8000) 00079 result = result - 0x10000; 00080 #endif /* THINK_C */ 00081 return (result); 00082 } 00083 00084 double ReadIeeeExtendedHighLow (fp) 00085 FILE *fp; 00086 { 00087 char bits[kExtendedLength]; 00088 00089 ReadBytes (fp, bits, kExtendedLength); 00090 return ConvertFromIeeeExtended (bits); 00091 } 00092 00093 int Read32BitsHighLow (fp) 00094 FILE *fp; 00095 { 00096 int first, second, result; 00097 00098 first = 0xffff & Read16BitsHighLow (fp); 00099 second = 0xffff & Read16BitsHighLow (fp); 00100 00101 result = (first << 16) + second; 00102 #ifdef CRAY 00103 if (result & 0x80000000) 00104 result = result - 0x100000000; 00105 #endif 00106 return (result); 00107 } 00108 00109 void ReadBytes (fp, p, n) 00110 FILE *fp; 00111 char *p; 00112 int n; 00113 { 00114 while (!feof (fp) & (n-- > 0)) 00115 *p++ = getc (fp); 00116 }
1.5.5