File: EST_cutils.c

package info (click to toggle)
speech-tools 1.1.0-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 5,280 kB
  • ctags: 6,800
  • sloc: cpp: 53,460; ansic: 2,936; java: 1,405; makefile: 830; perl: 728; sh: 538; awk: 49; pascal: 14
file content (129 lines) | stat: -rw-r--r-- 4,859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*************************************************************************/
/*                                                                       */
/*                Centre for Speech Technology Research                  */
/*                     University of Edinburgh, UK                       */
/*                       Copyright (c) 1996,1997                         */
/*                        All Rights Reserved.                           */
/*                                                                       */
/*  Permission to use, copy, modify, distribute this software and its    */
/*  documentation for research, educational and individual use only, is  */
/*  hereby granted without fee, subject to the following conditions:     */
/*   1. The code must retain the above copyright notice, this list of    */
/*      conditions and the following disclaimer.                         */
/*   2. Any modifications must be clearly marked as such.                */
/*   3. Original authors' names are not deleted.                         */
/*  This software may not be used for commercial purposes without        */
/*  specific prior written permission from the authors.                  */
/*                                                                       */
/*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
/*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
/*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
/*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
/*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
/*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
/*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
/*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
/*  THIS SOFTWARE.                                                       */
/*                                                                       */
/*************************************************************************/
/*                 Author :  Alan W Black and Paul Taylor                */
/*                 Date   :  July 1996                                   */
/*-----------------------------------------------------------------------*/
/*               Various Low level C utilities                           */
/*                                                                       */
/*=======================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "EST_unix.h"
#include <string.h>
#include "EST_cutils.h"

char *est_tools_version = 
     "Edinburgh Speech Tools Library 1.1.0 August 1998";

char *cmake_tmp_filename()
{
    char *tdir;
    char fname[1024];
    static int n=0;
    char *t1;
    int i,j;

   if ((tdir=getenv("TMPDIR")) == NULL)
	tdir = "/tmp";
    
    t1 = wstrdup(tdir);

    /* If it contains a double quote there might be a security hole */
    for (j=i=0; t1[i] != '\0'; i++)
	if (t1[i] != '"')
	    t1[j++]=t1[i];

    sprintf(fname,"%s/est_%05ld_%05d",t1,(long)getpid(),n++);
    return wstrdup(fname);
}

long_long watoll(const char *str)
{
    /* EST_String to long_long, ignore leading whitespace, and stopping */
    /* at first non-digit.  This works in base ten                  */
    /* We would use strtoll but it doesn't exist on some systems    */
    long_long a = 0;
    int i=0;

    for (i=0; 
	 (strchr(" \n\r\t",str[i]) != NULL) && (str[i] != '\0');
	 i++);

    for ( ;
	 (str[i] != '\0') && (str[i] >= '0') && (str[i] <= '9');
	 i++)
    {
	a = a*10l;
	a += str[i]-'0';
    }

    return a;

}

enum EST_bo_t str_to_bo(const char *boname)
{
    /* EST_String to byte order */

    if ((streq(boname,"hilo")) || (streq(boname,"big")) || 
	(streq(boname,"MSB")) ||  (streq(boname,"big_endian")))
	return bo_big;
    else if ((streq(boname,"lohi")) || (streq(boname,"little")) || 
	     (streq(boname,"LSB")) ||  (streq(boname,"little_endian")))
	return bo_little;
    else if ((streq(boname,"native")) || (streq(boname,"mine")))
	return (EST_BIG_ENDIAN ? bo_big : bo_little);
    else if ((streq(boname,"nonnative")) || (streq(boname,"other")) ||
	     (streq(boname,"wrong")) || (streq(boname,"swap")) ||
	     (streq(boname,"swapped")))
	return (EST_BIG_ENDIAN ? bo_little : bo_big);
    else
    {
	fprintf(stderr,"Unknown byte swap format: \"%s\" assuming native\n",
		boname);
	return (EST_BIG_ENDIAN ? bo_big : bo_little);
    }

}    

const char *bo_to_str(enum EST_bo_t bo)
{
    /* byte order to str */

    switch (bo)
    {
      case bo_big:    return "hilo";
      case bo_little: return "lohi";
      default:
	fprintf(stderr,"Unrecognized byte order %d\n",bo);
	return "unrecognized";
    }
}