pio.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* pio.h -- Packaged I/O routines.
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1999 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*
* HISTORY
* $Log: pio.h,v $
* Revision 1.3 2005/06/22 08:00:09 arthchan2003
* Completed all doxygen documentation on file description for libs3decoder/libutil/libs3audio and programs.
*
* Revision 1.2 2005/06/22 03:09:52 arthchan2003
* 1, Fixed doxygen documentation, 2, Added keyword.
*
* Revision 1.2 2005/06/16 00:14:08 archan
* Added const keyword to file argument for file_open
*
* Revision 1.1 2005/06/15 06:11:03 archan
* sphinx3 to s3.generic: change io.[ch] to pio.[ch]
*
* Revision 1.5 2005/06/15 04:21:46 archan
* 1, Fixed doxygen-documentation, 2, Add keyword such that changes will be logged into a file.
*
* Revision 1.4 2005/04/20 03:49:32 archan
* Add const to string argument of myfopen.
*
* Revision 1.3 2005/03/30 01:22:48 archan
* Fixed mistakes in last updates. Add
*
*
* 08-Dec-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added stat_mtime().
*
* 11-Mar-1999 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added _myfopen() and myfopen macro.
*
* 05-Sep-97 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Started.
*/
#ifndef _LIBUTIL_IO_H_
#define _LIBUTIL_IO_H_
#include <stdio.h>
#if !defined(_WIN32_WCE) && !(defined(__ADSPBLACKFIN__) && !defined(__linux__))
#include <sys/stat.h>
#endif
/* Win32/WinCE DLL gunk */
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
SPHINXBASE_EXPORT
FILE *fopen_comp (const char *file,
const char *mode,
int32 *ispipe
);
SPHINXBASE_EXPORT
void fclose_comp (FILE *fp,
int32 ispipe
);
SPHINXBASE_EXPORT
FILE *fopen_compchk (const char *file,
int32 *ispipe
);
SPHINXBASE_EXPORT
FILE *_myfopen(const char *file, const char *mode,
const char *pgm, int32 line); /* In: __FILE__, __LINE__ from where called */
#define myfopen(file,mode) _myfopen((file),(mode),__FILE__,__LINE__)
SPHINXBASE_EXPORT
int32 fread_retry(void *pointer, int32 size, int32 num_items, FILE *stream);
SPHINXBASE_EXPORT
char *fread_line(FILE *stream, size_t *out_len);
typedef struct lineiter_t {
char *buf;
size_t bsiz;
size_t len;
FILE *fh;
int32 clean;
int32 lineno;
} lineiter_t;
SPHINXBASE_EXPORT
lineiter_t *lineiter_start(FILE *fh);
SPHINXBASE_EXPORT
lineiter_t *lineiter_start_clean(FILE *fh);
SPHINXBASE_EXPORT
lineiter_t *lineiter_next(lineiter_t *li);
SPHINXBASE_EXPORT
void lineiter_free(lineiter_t *li);
SPHINXBASE_EXPORT
int lineiter_lineno(lineiter_t *li);
#ifdef _WIN32_WCE
/* Fake this for WinCE which has no stat() */
#include <windows.h>
struct stat {
DWORD st_mtime;
DWORD st_size;
};
#endif /* _WIN32_WCE */
#if defined(__ADSPBLACKFIN__) && !defined(__linux__)
struct stat {
int32 st_mtime;
int32 st_size;
};
#endif
typedef struct bit_encode_s bit_encode_t;
bit_encode_t *bit_encode_attach(FILE *outfh);
bit_encode_t *bit_encode_retain(bit_encode_t *be);
int bit_encode_free(bit_encode_t *be);
int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits);
int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits);
int bit_encode_flush(bit_encode_t *be);
SPHINXBASE_EXPORT
int32 stat_retry (const char *file, struct stat *statbuf);
SPHINXBASE_EXPORT
int32 stat_mtime (const char *file);
SPHINXBASE_EXPORT
int build_directory(const char *path);
#ifdef __cplusplus
}
#endif
#endif
bit_encode_write
int bit_encode_write(bit_encode_t *be, unsigned char const *bits, int nbits)
Write bits to encoder.
Definition: pio.c:568
bit_encode_attach
bit_encode_t * bit_encode_attach(FILE *outfh)
Attach bitstream encoder to a file.
Definition: pio.c:538
lineiter_lineno
SPHINXBASE_EXPORT int lineiter_lineno(lineiter_t *li)
Returns current line number.
Definition: pio.c:352
lineiter_t
struct lineiter_t lineiter_t
Line iterator for files.
fopen_compchk
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:192
stat_retry
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:480
lineiter_start_clean
SPHINXBASE_EXPORT lineiter_t * lineiter_start_clean(FILE *fh)
Start reading lines from a file, skip comments and trim lines.
Definition: pio.c:279
lineiter_t
Line iterator for files.
Definition: pio.h:177
prim_type.h
Basic type definitions used in Sphinx.
bit_encode_retain
bit_encode_t * bit_encode_retain(bit_encode_t *be)
Retain pointer to a bit encoder.
Definition: pio.c:549
build_directory
SPHINXBASE_EXPORT int build_directory(const char *path)
Create a directory and all of its parent directories, as needed.
Definition: pio.c:653
fread_line
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:367
lineiter_free
SPHINXBASE_EXPORT void lineiter_free(lineiter_t *li)
Stop reading lines from a file.
Definition: pio.c:358
bit_encode_s
Definition: pio.c:531
lineiter_next
SPHINXBASE_EXPORT lineiter_t * lineiter_next(lineiter_t *li)
Move to the next line in the file.
Definition: pio.c:338
lineiter_start
SPHINXBASE_EXPORT lineiter_t * lineiter_start(FILE *fh)
Start reading lines from a file.
Definition: pio.c:255
bit_encode_write_cw
int bit_encode_write_cw(bit_encode_t *be, uint32 codeword, int nbits)
Write lowest-order bits of codeword to encoder.
Definition: pio.c:595
bit_encode_free
int bit_encode_free(bit_encode_t *be)
Release pointer to a bit encoder.
Definition: pio.c:556
fopen_comp
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 "file" is compressed (i.e., has a .z, .Z, .gz, or .GZ extension).
Definition: pio.c:98
fread_retry
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:398
bit_encode_flush
int bit_encode_flush(bit_encode_t *be)
Flush any unwritten bits, zero-padding if necessary.
Definition: pio.c:607
stat_mtime
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:515
fclose_comp
SPHINXBASE_EXPORT void fclose_comp(FILE *fp, int32 ispipe)
Close a file opened using fopen_comp.
Definition: pio.c:175
_myfopen
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.