SphinxBase  5prealpha
pio.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 /*
38  * pio.h -- Packaged I/O routines.
39  *
40  * **********************************************
41  * CMU ARPA Speech Project
42  *
43  * Copyright (c) 1999 Carnegie Mellon University.
44  * ALL RIGHTS RESERVED.
45  * **********************************************
46  *
47  * HISTORY
48  * $Log: pio.h,v $
49  * Revision 1.3 2005/06/22 08:00:09 arthchan2003
50  * Completed all doxygen documentation on file description for libs3decoder/libutil/libs3audio and programs.
51  *
52  * Revision 1.2 2005/06/22 03:09:52 arthchan2003
53  * 1, Fixed doxygen documentation, 2, Added keyword.
54  *
55  * Revision 1.2 2005/06/16 00:14:08 archan
56  * Added const keyword to file argument for file_open
57  *
58  * Revision 1.1 2005/06/15 06:11:03 archan
59  * sphinx3 to s3.generic: change io.[ch] to pio.[ch]
60  *
61  * Revision 1.5 2005/06/15 04:21:46 archan
62  * 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file.
63  *
64  * Revision 1.4 2005/04/20 03:49:32 archan
65  * Add const to string argument of myfopen.
66  *
67  * Revision 1.3 2005/03/30 01:22:48 archan
68  * Fixed mistakes in last updates. Add
69  *
70  *
71  * 08-Dec-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
72  * Added stat_mtime().
73  *
74  * 11-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
75  * Added _myfopen() and myfopen macro.
76  *
77  * 05-Sep-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
78  * Started.
79  */
80 
81 
82 #ifndef _LIBUTIL_IO_H_
83 #define _LIBUTIL_IO_H_
84 
85 #include <stdio.h>
86 #if !defined(_WIN32_WCE) && !(defined(__ADSPBLACKFIN__) && !defined(__linux__))
87 #include <sys/stat.h>
88 #endif
89 
90 /* Win32/WinCE DLL gunk */
91 #include <sphinxbase/sphinxbase_export.h>
92 #include <sphinxbase/prim_type.h>
93 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 #if 0
108 /* Fool Emacs. */
109 }
110 #endif
111 
116 SPHINXBASE_EXPORT
117 FILE *fopen_comp (const char *file,
118  const char *mode,
119  int32 *ispipe
121  );
122 
126 SPHINXBASE_EXPORT
127 void fclose_comp (FILE *fp,
128  int32 ispipe
130  );
131 
136 SPHINXBASE_EXPORT
137 FILE *fopen_compchk (const char *file,
138  int32 *ispipe
140  );
141 
145 SPHINXBASE_EXPORT
146 FILE *_myfopen(const char *file, const char *mode,
147  const char *pgm, int32 line); /* In: __FILE__, __LINE__ from where called */
148 #define myfopen(file,mode) _myfopen((file),(mode),__FILE__,__LINE__)
149 
150 
158 SPHINXBASE_EXPORT
159 int32 fread_retry(void *pointer, int32 size, int32 num_items, FILE *stream);
160 
171 SPHINXBASE_EXPORT
172 char *fread_line(FILE *stream, size_t *out_len);
173 
177 typedef struct lineiter_t {
178  char *buf;
179  FILE *fh;
180  int32 bsiz;
181  int32 len;
182  int32 clean;
183  int32 lineno;
184 } lineiter_t;
185 
189 SPHINXBASE_EXPORT
190 lineiter_t *lineiter_start(FILE *fh);
191 
195 SPHINXBASE_EXPORT
197 
201 SPHINXBASE_EXPORT
203 
207 SPHINXBASE_EXPORT
208 void lineiter_free(lineiter_t *li);
209 
213 SPHINXBASE_EXPORT
214 int lineiter_lineno(lineiter_t *li);
215 
216 
217 #ifdef _WIN32_WCE
218 /* Fake this for WinCE which has no stat() */
219 #include <windows.h>
220 struct stat {
221  DWORD st_mtime;
222  DWORD st_size;
223 };
224 #endif /* _WIN32_WCE */
225 
226 #if defined(__ADSPBLACKFIN__) && !defined(__linux__)
227 struct stat {
228  int32 st_mtime;
229  int32 st_size;
230 };
231 
232 #endif
233 
237 typedef struct bit_encode_s bit_encode_t;
238 
242 bit_encode_t *bit_encode_attach(FILE *outfh);
243 
248 
255 
259 int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits);
260 
264 int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits);
265 
270 
280 SPHINXBASE_EXPORT
281 int32 stat_retry (const char *file, struct stat *statbuf);
282 
287 SPHINXBASE_EXPORT
288 int32 stat_mtime (const char *file);
289 
295 SPHINXBASE_EXPORT
296 int build_directory(const char *path);
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 #endif
int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits)
Write bits to encoder.
Definition: pio.c:572
bit_encode_t * bit_encode_attach(FILE *outfh)
Attach bitstream encoder to a file.
Definition: pio.c:542
SPHINXBASE_EXPORT int lineiter_lineno(lineiter_t *li)
Returns current line number.
Definition: pio.c:362
struct lineiter_t lineiter_t
Line iterator for files.
SPHINXBASE_EXPORT FILE * fopen_compchk(const char *file, int32 *ispipe)
Open a file for reading, but if file not present try to open compressed version (if file is uncompres...
Definition: pio.c:201
SPHINXBASE_EXPORT int32 stat_retry(const char *file, struct stat *statbuf)
There is no bitstream decoder, because a stream abstraction is too slow.
Definition: pio.c:489
SPHINXBASE_EXPORT lineiter_t * lineiter_start_clean(FILE *fh)
Start reading lines from a file, skip comments and trim lines.
Definition: pio.c:288
Line iterator for files.
Definition: pio.h:177
Basic type definitions used in Sphinx.
bit_encode_t * bit_encode_retain(bit_encode_t *be)
Retain pointer to a bit encoder.
Definition: pio.c:553
SPHINXBASE_EXPORT int build_directory(const char *path)
Create a directory and all of its parent directories, as needed.
Definition: pio.c:621
SPHINXBASE_EXPORT char * fread_line(FILE *stream, size_t *out_len)
Read a line of arbitrary length from a file and return it as a newly allocated string.
Definition: pio.c:377
SPHINXBASE_EXPORT void lineiter_free(lineiter_t *li)
Stop reading lines from a file.
Definition: pio.c:368
SPHINXBASE_EXPORT lineiter_t * lineiter_next(lineiter_t *li)
Move to the next line in the file.
Definition: pio.c:347
SPHINXBASE_EXPORT lineiter_t * lineiter_start(FILE *fh)
Start reading lines from a file.
Definition: pio.c:264
int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits)
Write lowest-order bits of codeword to encoder.
Definition: pio.c:599
int bit_encode_free(bit_encode_t *be)
Release pointer to a bit encoder.
Definition: pio.c:560
SPHINXBASE_EXPORT FILE * fopen_comp(const char *file, const char *mode, int32 *ispipe)
Like fopen, but use popen and zcat if it is determined that &quot;file&quot; is compressed (i.e., has a .z, .Z, .gz, or .GZ extension).
Definition: pio.c:107
SPHINXBASE_EXPORT int32 fread_retry(void *pointer, int32 size, int32 num_items, FILE *stream)
NFS file reads seem to fail now and then.
Definition: pio.c:408
int bit_encode_flush(bit_encode_t *be)
Flush any unwritten bits, zero-padding if necessary.
Definition: pio.c:611
SPHINXBASE_EXPORT int32 stat_mtime(const char *file)
Return time of last modification for the given file, or -1 if stat fails.
Definition: pio.c:519
SPHINXBASE_EXPORT void fclose_comp(FILE *fp, int32 ispipe)
Close a file opened using fopen_comp.
Definition: pio.c:184
SPHINXBASE_EXPORT FILE * _myfopen(const char *file, const char *mode, const char *pgm, int32 line)
Wrapper around fopen to check for failure and E_FATAL if failed.