Edinburgh Speech Tools  2.1-release
pathname_example.cc
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: Richard Caley (rjc@cstr.ed.ac.uk) */
34  /* Date: Tue Apr 29 1997 */
35  /************************************************************************/
36  /* */
37  /* Test of EST_Pathname class. */
38  /* */
39  /************************************************************************/
40 
41 #include <cstdlib>
42 #include "EST_Pathname.h"
43 
44 using namespace std;
45 
46 #if defined(DATAC)
47 # define __STRINGIZE(X) #X
48 # define DATA __STRINGIZE(DATAC)
49 #endif
50 
51 int main(void)
52 {
53 
54  // a relative pathname
55 
57 
58  f= "baz/ptooie";
59 
60  // can be used as a file or a directory
61 
62  cout << "file f = " << f.as_file() << "\n";
63  cout << "dir f = " << f.as_directory() << "\n";
64 
65  // and absolute one
66 
67  EST_Pathname d;
68 
69  d = "/foo/bar/";
70 
71  // we can combine paths as expected
72 
73  cout << "combine = " << d+f << "\n";
74  cout << "combine = " << f+f << "\n";
75 
76  // and can build up paths from components
77 
78  EST_Pathname built(EST_Pathname::construct(d,f,"test"));
79 
80  cout << " build = " << built << "\n";
81  cout << " filename = " << built.filename() << "\n";
82  cout << "extension = " << built.extension() << "\n";
83  cout << " basename = " << built.basename() << "\n";
84  cout << "basename1 = " << built.basename(1) << "\n";
85 
86  EST_Pathname data(DATA);
87 
88  // getting the contents of a directory...
89  EST_TList<EST_String> contents(data.entries());
90 
91  sort(contents);
92 
93  cout << "listing " << data.filename() << ":\n";
94 
95  EST_Litem *item;
96  for(item=contents.head(); item; item=item->next())
97  if (EST_Pathname(contents(item)).is_filename())
98  cout << " " << contents(item) << "\n";
99 
100  cout << "done.\n";
101 
102  return (0);
103 }
104 
int main(void)
static EST_Pathname construct(EST_Pathname dir, EST_String basename, EST_String extension)
EST_TList< EST_String > entries(int check_for_directories=1) const
int is_filename(void) const
Definition: EST_Pathname.h:70
EST_UItem * next()
Definition: EST_UList.h:55
EST_Pathname as_file(void) const
f
Definition: EST_item_aux.cc:48
EST_Pathname filename(void) const
void sort(EST_TList< T > &a)
EST_String extension(void) const
EST_Pathname as_directory(void) const