| 1 | /*************************************************************************/ |
| 2 | /* */ |
| 3 | /* Language Technologies Institute */ |
| 4 | /* Carnegie Mellon University */ |
| 5 | /* Copyright (c) 1999 */ |
| 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 | /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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: Alan W Black ([email protected]) */ |
| 34 | /* Date: August 2000 */ |
| 35 | /*************************************************************************/ |
| 36 | /* */ |
| 37 | /* Some File stuff */ |
| 38 | /* */ |
| 39 | /*************************************************************************/ |
| 40 | |
| 41 | /* ----------------------------------------------------------------- */ |
| 42 | /* The English TTS System "Flite+hts_engine" */ |
| 43 | /* developed by HTS Working Group */ |
| 44 | /* http://hts-engine.sourceforge.net/ */ |
| 45 | /* ----------------------------------------------------------------- */ |
| 46 | /* */ |
| 47 | /* Copyright (c) 2005-2013 Nagoya Institute of Technology */ |
| 48 | /* Department of Computer Science */ |
| 49 | /* */ |
| 50 | /* 2005-2008 Tokyo Institute of Technology */ |
| 51 | /* Interdisciplinary Graduate School of */ |
| 52 | /* Science and Engineering */ |
| 53 | /* */ |
| 54 | /* All rights reserved. */ |
| 55 | /* */ |
| 56 | /* Redistribution and use in source and binary forms, with or */ |
| 57 | /* without modification, are permitted provided that the following */ |
| 58 | /* conditions are met: */ |
| 59 | /* */ |
| 60 | /* - Redistributions of source code must retain the above copyright */ |
| 61 | /* notice, this list of conditions and the following disclaimer. */ |
| 62 | /* - Redistributions in binary form must reproduce the above */ |
| 63 | /* copyright notice, this list of conditions and the following */ |
| 64 | /* disclaimer in the documentation and/or other materials provided */ |
| 65 | /* with the distribution. */ |
| 66 | /* - Neither the name of the HTS working group nor the names of its */ |
| 67 | /* contributors may be used to endorse or promote products derived */ |
| 68 | /* from this software without specific prior written permission. */ |
| 69 | /* */ |
| 70 | /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */ |
| 71 | /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */ |
| 72 | /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ |
| 73 | /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ |
| 74 | /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */ |
| 75 | /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */ |
| 76 | /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */ |
| 77 | /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ |
| 78 | /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ |
| 79 | /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */ |
| 80 | /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */ |
| 81 | /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ |
| 82 | /* POSSIBILITY OF SUCH DAMAGE. */ |
| 83 | /* ----------------------------------------------------------------- */ |
| 84 | |
| 85 | #ifndef _CST_FILE_H__ |
| 86 | #define _CST_FILE_H__ |
| 87 | |
| 88 | #define CST_WRONG_FORMAT -2 |
| 89 | #define CST_ERROR_FORMAT -1 |
| 90 | #define CST_OK_FORMAT 0 |
| 91 | |
| 92 | #ifdef UNDER_CE |
| 93 | /* File access stuff (WinCE 2.11 is really damaged) */ |
| 94 | #include <windows.h> |
| 95 | #include <winbase.h> |
| 96 | typedef HANDLE cst_file; |
| 97 | #elif __palmos__ |
| 98 | #include <PalmOS.h> |
| 99 | #include <System/StdIOPalm.h> |
| 100 | typedef FILE * cst_file; |
| 101 | #else |
| 102 | #include <stdio.h> |
| 103 | typedef FILE * cst_file; |
| 104 | #endif |
| 105 | |
| 106 | /* File mapping stuff */ |
| 107 | #ifdef _WIN32 |
| 108 | #include <windows.h> |
| 109 | typedef struct cst_filemap_struct { |
| 110 | void *mem; |
| 111 | cst_file fh; |
| 112 | size_t mapsize; |
| 113 | HANDLE h; |
| 114 | } cst_filemap; |
| 115 | #elif __palmos__ |
| 116 | typedef struct cst_filemap_struct { |
| 117 | void *mem; |
| 118 | cst_file fh; |
| 119 | unsigned int mapsize; |
| 120 | int fd; |
| 121 | } cst_filemap; |
| 122 | #else |
| 123 | typedef struct cst_filemap_struct { |
| 124 | void *mem; |
| 125 | cst_file fh; |
| 126 | size_t mapsize; |
| 127 | int fd; |
| 128 | } cst_filemap; |
| 129 | #endif |
| 130 | |
| 131 | #define CST_OPEN_WRITE (1<<0) |
| 132 | #define CST_OPEN_READ (1<<1) |
| 133 | #define CST_OPEN_APPEND (1<<2) |
| 134 | #define CST_OPEN_BINARY (1<<3) |
| 135 | |
| 136 | #define CST_SEEK_ABSOLUTE 0 |
| 137 | #define CST_SEEK_RELATIVE 1 |
| 138 | #define CST_SEEK_ENDREL 2 |
| 139 | |
| 140 | cst_file cst_fopen(const char *path, int mode); |
| 141 | long cst_fwrite(cst_file fh, const void *buf, long size, long count); |
| 142 | long cst_fread(cst_file fh, void *buf, long size, long count); |
| 143 | int cst_fprintf(cst_file fh, char *fmt, ...); |
| 144 | #ifdef FLITE_PLUS_HTS_ENGINE |
| 145 | #define cst_sprintf sprintf |
| 146 | #else |
| 147 | int cst_sprintf(char *s, const char *fmt, ...); |
| 148 | #endif /* FLITE_PLUS_HTS_ENGINE */ |
| 149 | #if defined(__palmos__) |
| 150 | #include <stdarg.h> |
| 151 | int cst_vsprintf(char *s, const char *fmt, va_list args); |
| 152 | #endif |
| 153 | int cst_fclose(cst_file fh); |
| 154 | int cst_fgetc(cst_file fh); |
| 155 | |
| 156 | /* These aren't LFS-compliant. I don't think we'll need >2G files. */ |
| 157 | long cst_ftell(cst_file fh); |
| 158 | long cst_fseek(cst_file fh, long pos, int whence); |
| 159 | long cst_filesize(cst_file fh); |
| 160 | |
| 161 | cst_filemap *cst_mmap_file(const char *path); |
| 162 | int cst_munmap_file(cst_filemap *map); |
| 163 | |
| 164 | cst_filemap *cst_read_whole_file(const char *path); |
| 165 | int cst_free_whole_file(cst_filemap *map); |
| 166 | |
| 167 | cst_filemap *cst_read_part_file(const char *path); |
| 168 | int cst_free_part_file(cst_filemap *map); |
| 169 | |
| 170 | #endif |