1 /*************************************************************************/
2 /*                                                                       */
3 /*                Centre for Speech Technology Research                  */
4 /*                     University of Edinburgh, UK                       */
5 /*                     Copyright (c) 1994,1995,1996                      */
6 /*                        All Rights Reserved.                           */
7 /*                                                                       */
8 /*  Permission is hereby granted, free of charge, to use and distribute  */
9 /*  this software and its documentation without restriction, including   */
10 /*  without limitation the rights to use, copy, modify, merge, publish,  */
11 /*  distribute, sublicense, and/or sell copies of this work, and to      */
12 /*  permit persons to whom this work is furnished to do so, subject to   */
13 /*  the following conditions:                                            */
14 /*   1. The code must retain the above copyright notice, this list of    */
15 /*      conditions and the following disclaimer.                         */
16 /*   2. Any modifications must be clearly marked as such.                */
17 /*   3. Original authors' names are not deleted.                         */
18 /*   4. The authors' names are not used to endorse or promote products   */
19 /*      derived from this software without specific prior written        */
20 /*      permission.                                                      */
21 /*                                                                       */
22 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
23 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
24 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
25 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
26 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
27 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
28 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
29 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
30 /*  THIS SOFTWARE.                                                       */
31 /*                                                                       */
32 /*************************************************************************/
33 /*                    Author :  Paul Taylor and Alan W Black             */
34 /*                    Date   :  July 1996                                */
35 /*-----------------------------------------------------------------------*/
36 /*              Various C utility functions                              */
37 /*                                                                       */
38 /*=======================================================================*/
39 #ifndef __EST_CUTILS_H__
40 #define __EST_CUTILS_H__
41 
42 #include "EST_common.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 extern const char * const est_tools_version;
49 extern const char * const est_name;
50 extern const char * const est_libdir;
51 extern const char * const est_ostype;
52 
53 #include "EST_walloc.h"
54 #include "EST_system.h"
55 
56 #ifndef streq
57 #define streq(X,Y) (strcmp(X,Y)==0)
58 #endif
59 
60 char *cmake_tmp_filename();
61 
62 /* NOTE perqs (from Three Rivers) have the third byte order, are not  */
63 /* supported, if you find a working one let me know and I'll add      */
64 /* support -- awb (hoping no one responds :-)                         */
65 enum EST_bo_t {bo_big, bo_little, bo_perq};
66 
67 extern int est_endian_loc;
68 /* Sun, HP, SGI Mips, M68000 */
69 #define EST_BIG_ENDIAN (((char *)&est_endian_loc)[0] == 0)
70 /* Intel, Alpha, DEC Mips, Vax */
71 #define EST_LITTLE_ENDIAN (((char *)&est_endian_loc)[0] != 0)
72 #define EST_NATIVE_BO (EST_BIG_ENDIAN ? bo_big : bo_little)
73 #define EST_SWAPPED_BO (EST_BIG_ENDIAN ? bo_little : bo_big)
74 
75 #define SWAPINT(x) ((((unsigned)x) & 0xff) << 24 | \
76                     (((unsigned)x) & 0xff00) << 8 | \
77 		    (((unsigned)x) & 0xff0000) >> 8 | \
78                     (((unsigned)x) & 0xff000000) >> 24)
79 #define SWAPSHORT(x) ((((unsigned)x) & 0xff) << 8 | \
80                       (((unsigned)x) & 0xff00) >> 8)
81 void swapdouble(double *d);
82 void swapfloat(float *f);
83 
84 void swap_bytes_ushort(unsigned short *data, int length);
85 void swap_bytes_short(short *data, int length);
86 void swap_bytes_uint(unsigned int *data, int length);
87 void swap_bytes_int(int *data, int length);
88 void swap_bytes_float(float *data, int length);
89 void swap_bytes_double(double *data, int length);
90 
91 enum EST_bo_t str_to_bo(const char *boname);
92 const char *bo_to_str(enum EST_bo_t bo);
93 
94 /* return the greater of the two values */
95 #define Gof(a, b) (((a) > (b)) ? (a) : (b))
96 /* return the lesser of the two values  */
97 #define Lof(a, b) (((a) < (b)) ? (a) : (b))
98 
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 
105 #endif /*__EST_CUTILS_H__ */
106