Edinburgh Speech Tools  2.1-release
EST_cutils.c
Go to the documentation of this file.
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 
67 {
68  char *tdir;
69  char *fname;
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  /* Length of the tmp filename:
87  strlen(t1) + strlen("/est_00000_00000") + 1 (end of string character) */
88  size_t tmpfile_length = strlen(t1) + 17;
89  fname = walloc(char, tmpfile_length);
90  sprintf(fname,"%s/est_%05ld_%05d",t1,(long)getpid(),n++);
91  free(t1);
92  return fname;
93 }
94 
95 enum EST_bo_t str_to_bo(const char *boname)
96 {
97  /* EST_String to byte order */
98 
99  if ((streq(boname,"hilo")) || (streq(boname,"big")) ||
100  (streq(boname,"MSB")) || (streq(boname,"big_endian")))
101  return bo_big;
102  else if ((streq(boname,"lohi")) || (streq(boname,"little")) ||
103  (streq(boname,"LSB")) || (streq(boname,"little_endian")))
104  return bo_little;
105  else if ((streq(boname,"native")) || (streq(boname,"mine")))
106  return (EST_BIG_ENDIAN ? bo_big : bo_little);
107  else if ((streq(boname,"nonnative")) || (streq(boname,"other")) ||
108  (streq(boname,"wrong")) || (streq(boname,"swap")) ||
109  (streq(boname,"swapped")))
110  return (EST_BIG_ENDIAN ? bo_little : bo_big);
111  else
112  {
113  fprintf(stderr,"Unknown byte swap format: \"%s\" assuming native\n",
114  boname);
115  return (EST_BIG_ENDIAN ? bo_big : bo_little);
116  }
117 
118 }
119 
120 const char *bo_to_str(enum EST_bo_t bo)
121 {
122  /* byte order to str */
123 
124  switch (bo)
125  {
126  case bo_big: return "hilo";
127  case bo_little: return "lohi";
128  default:
129  fprintf(stderr,"Unrecognized byte order %d\n",bo);
130  return "unrecognized";
131  }
132 }
133 
char * wstrdup(const char *s)
Definition: walloc.c:117
const char *const est_tools_version
Definition: EST_cutils.c:49
#define walloc(TYPE, SIZE)
Definition: EST_walloc.h:52
const char *const est_name
Definition: EST_cutils.c:52
enum EST_bo_t str_to_bo(const char *boname)
Definition: EST_cutils.c:95
#define streq(X, Y)
Definition: EST_cutils.h:57
char * getenv()
const char *const est_libdir
Definition: EST_cutils.c:62
#define ESTLIBDIR
Definition: EST_cutils.c:59
char * cmake_tmp_filename()
Definition: EST_cutils.c:66
EST_bo_t
Definition: EST_cutils.h:65
const char * bo_to_str(enum EST_bo_t bo)
Definition: EST_cutils.c:120
NULL
Definition: EST_WFST.cc:55
#define STRINGIZE(S)
Definition: EST_cutils.c:47
const char *const est_ostype
Definition: EST_cutils.c:64
#define EST_BIG_ENDIAN
Definition: EST_cutils.h:69