Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_svec_aux.cc
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 */
34 /* Date : May 1994 */
35 /*-----------------------------------------------------------------------*/
36 /* StrVector i/o utility functions */
37 /* */
38 /*=======================================================================*/
39 #include <cstdio>
40 #include <cctype>
41 #include <cstdlib>
42 #include <cstring>
43 #include <fstream>
44 #include <iostream>
45 #include "EST_types.h"
46 #include "EST_String.h"
47 #include "EST_Pathname.h"
48 #include "EST_string_aux.h"
49 #include "EST_cutils.h"
50 #include "EST_Token.h"
51 
52 EST_read_status load_TList_of_StrVector(EST_TList<EST_StrVector> &w,
53  const EST_String &filename,
54  const int vec_len)
55 {
56 
57  EST_TokenStream ts;
58  EST_String s;
59  EST_StrVector v;
60  int c;
61 
62  if(ts.open(filename) != 0){
63  cerr << "Can't open EST_TList<EST_StrVector> file " << filename << endl;
64  return misc_read_error;
65  }
66 
67  v.resize(vec_len);
68 // ts.set_SingleCharSymbols("");
69 // ts.set_PunctuationSymbols("");
70 
71  c=0;
72  while (!ts.eof())
73  {
74 
75  s = ts.get().string();
76  if(s != "")
77  {
78  if(c == vec_len)
79  {
80  cerr << "Too many points in line - expected " << vec_len << endl;
81  return wrong_format;
82  }
83  else
84  v[c++] = s;
85  }
86 
87  if(ts.eoln())
88  {
89  if(c != vec_len)
90  {
91  cerr << "Too few points in line - got "
92  << c << ", expected " << vec_len << endl;
93  return wrong_format;
94  }
95  else
96  {
97  w.append(v);
98  c=0;
99  }
100  }
101  }
102 
103  ts.close();
104  return format_ok;
105 
106 }
107