Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_cutils.c
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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 : Alan W Black and Paul Taylor */
34 /* Date : July 1996 */
35 /*-----------------------------------------------------------------------*/
36 /* Various Low level C utilities */
37 /* */
38 /*=======================================================================*/
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <sys/types.h>
42 #include "EST_unix.h"
43 #include <string.h>
44 #include "EST_cutils.h"
45 
46 #define _S_S_S(S) #S
47 #define STRINGIZE(S) _S_S_S(S)
48 
49 const char * const est_tools_version =
50  STRINGIZE(ESTVERSION) ":" STRINGIZE(ESTSTATE) " " STRINGIZE(ESTDATE) ;
51 
52 const char * const est_name = STRINGIZE(ESTNAME);
53 
54 #ifdef ESTLIBDIRC
55 # define ESTLIBDIR STRINGIZE(ESTLIBDIRC)
56 #endif
57 
58 #ifndef ESTLIBDIR
59 #define ESTLIBDIR "/usr/local/lib/speech_tools"
60 #endif
61 
62 const char * const est_libdir = ESTLIBDIR;
63 
64 const char * const est_ostype = STRINGIZE(ESTOSTYPE);
65 
66 char *cmake_tmp_filename()
67 {
68  char *tdir;
69  char fname[1024];
70  static int n=0;
71  char *t1;
72  int i,j;
73 
74  if (((tdir=getenv("TMPDIR")) == NULL) &&
75  ((tdir=getenv("TEMP")) == NULL) &&
76  ((tdir=getenv("TMP")) == NULL))
77  tdir = "/tmp";
78 
79  t1 = wstrdup(tdir);
80 
81  /* If it contains a double quote there might be a security hole */
82  for (j=i=0; t1[i] != '\0'; i++)
83  if (t1[i] != '"')
84  t1[j++]=t1[i];
85 
86  sprintf(fname,"%s/est_%05ld_%05d",t1,(long)getpid(),n++);
87  return wstrdup(fname);
88 }
89 
90 enum EST_bo_t str_to_bo(const char *boname)
91 {
92  /* EST_String to byte order */
93 
94  if ((streq(boname,"hilo")) || (streq(boname,"big")) ||
95  (streq(boname,"MSB")) || (streq(boname,"big_endian")))
96  return bo_big;
97  else if ((streq(boname,"lohi")) || (streq(boname,"little")) ||
98  (streq(boname,"LSB")) || (streq(boname,"little_endian")))
99  return bo_little;
100  else if ((streq(boname,"native")) || (streq(boname,"mine")))
101  return (EST_BIG_ENDIAN ? bo_big : bo_little);
102  else if ((streq(boname,"nonnative")) || (streq(boname,"other")) ||
103  (streq(boname,"wrong")) || (streq(boname,"swap")) ||
104  (streq(boname,"swapped")))
105  return (EST_BIG_ENDIAN ? bo_little : bo_big);
106  else
107  {
108  fprintf(stderr,"Unknown byte swap format: \"%s\" assuming native\n",
109  boname);
110  return (EST_BIG_ENDIAN ? bo_big : bo_little);
111  }
112 
113 }
114 
115 const char *bo_to_str(enum EST_bo_t bo)
116 {
117  /* byte order to str */
118 
119  switch (bo)
120  {
121  case bo_big: return "hilo";
122  case bo_little: return "lohi";
123  default:
124  fprintf(stderr,"Unrecognized byte order %d\n",bo);
125  return "unrecognized";
126  }
127 }
128