Edinburgh Speech Tools 2.4-release
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
49const char * const est_tools_version =
50 STRINGIZE(ESTVERSION) ":" STRINGIZE(ESTSTATE) " " STRINGIZE(ESTDATE) ;
51
52const char * const est_name = STRINGIZE(ESTNAME);
53
54#ifdef ESTLIBDIRC
55# define ESTLIBDIR STRINGIZE(ESTLIBDIRC)
56#endif
57#ifndef ESTLIBDIR
58#define ESTLIBDIR "/usr/local/lib/speech_tools"
59#endif
60
61#ifdef ESTDATADIRC
62# define ESTDATADIR STRINGIZE(ESTDATADIRC)
63#endif
64#ifndef ESTDATADIR
65#define ESTDATADIR "/usr/local/share/speech_tools"
66#endif
67
68const char * const est_libdir = ESTLIBDIR;
69const char * const est_datadir = ESTDATADIR;
70
71const char * const est_ostype = STRINGIZE(ESTOSTYPE);
72
73char *cmake_tmp_filename()
74{
75 char *tdir;
76 char fname[1024];
77 static int n=0;
78 char *t1;
79 int i,j;
80
81 if (((tdir=getenv("TMPDIR")) == NULL) &&
82 ((tdir=getenv("TEMP")) == NULL) &&
83 ((tdir=getenv("TMP")) == NULL))
84 tdir = "/tmp";
85
86 t1 = wstrdup(tdir);
87
88 /* If it contains a double quote there might be a security hole */
89 for (j=i=0; t1[i] != '\0'; i++)
90 if (t1[i] != '"')
91 t1[j++]=t1[i];
92
93 sprintf(fname,"%s/est_%05ld_%05d",t1,(long)getpid(),n++);
94 return wstrdup(fname);
95}
96
97enum EST_bo_t str_to_bo(const char *boname)
98{
99 /* EST_String to byte order */
100
101 if ((streq(boname,"hilo")) || (streq(boname,"big")) ||
102 (streq(boname,"MSB")) || (streq(boname,"big_endian")))
103 return bo_big;
104 else if ((streq(boname,"lohi")) || (streq(boname,"little")) ||
105 (streq(boname,"LSB")) || (streq(boname,"little_endian")))
106 return bo_little;
107 else if ((streq(boname,"native")) || (streq(boname,"mine")))
108 return (EST_BIG_ENDIAN ? bo_big : bo_little);
109 else if ((streq(boname,"nonnative")) || (streq(boname,"other")) ||
110 (streq(boname,"wrong")) || (streq(boname,"swap")) ||
111 (streq(boname,"swapped")))
112 return (EST_BIG_ENDIAN ? bo_little : bo_big);
113 else
114 {
115 fprintf(stderr,"Unknown byte swap format: \"%s\" assuming native\n",
116 boname);
117 return (EST_BIG_ENDIAN ? bo_big : bo_little);
118 }
119
120}
121
122const char *bo_to_str(enum EST_bo_t bo)
123{
124 /* byte order to str */
125
126 switch (bo)
127 {
128 case bo_big: return "hilo";
129 case bo_little: return "lohi";
130 default:
131 fprintf(stderr,"Unrecognized byte order %d\n",bo);
132 return "unrecognized";
133 }
134}
135