PFile.h

00001 /*---------------------------------------------------------------------------*
00002  *  PFile.h  *
00003  *                                                                           *
00004  *  Copyright 2007 Nuance Communciations, Inc.                               *
00005  *                                                                           *
00006  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
00007  *  you may not use this file except in compliance with the License.         *
00008  *                                                                           *
00009  *  You may obtain a copy of the License at                                  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0                           *
00011  *                                                                           *
00012  *  Unless required by applicable law or agreed to in writing, software      *
00013  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
00015  *  See the License for the specific language governing permissions and      *
00016  *  limitations under the License.                                           *
00017  *                                                                           *
00018  *---------------------------------------------------------------------------*/
00019 
00020 #ifndef __PFILE_H
00021 #define __PFILE_H
00022 
00023 
00024 
00025 #include <stdarg.h>
00026 #include <stddef.h>
00027 
00028 #include "ESR_ReturnCode.h"
00029 #include "PortPrefix.h"
00030 #include "ptypes.h"
00031 #include "pstdio.h"
00032 
00033 
00048 #define USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS        1
00049 
00050 
00051 #ifdef USE_NARROW_CHAR
00052 
00056 #define PEOF EOF
00057 
00058 #else
00059 
00063 #define PEOF WEOF
00064 
00065 #endif /* USE_NARROW_CHAR */
00066 
00071 #ifdef USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS
00072 
00073 typedef FILE PFile;
00074 
00075 #else
00076 typedef struct PFile_t
00077 {
00084   ESR_ReturnCode(*destroy)(struct PFile_t* self);
00085 
00086   
00087   ESR_ReturnCode(*open)(struct PFile_t* self, const LCHAR* mode);
00088 
00095   ESR_ReturnCode(*close)(struct PFile_t* self);
00096 
00109   ESR_ReturnCode(*read)(struct PFile_t* self, void* buffer, size_t size, size_t* count);
00110 
00122   ESR_ReturnCode(*write)(struct PFile_t* self, void* buffer, size_t size, size_t* count);
00123 
00130   ESR_ReturnCode(*flush)(struct PFile_t* self);
00131 
00140   ESR_ReturnCode(*seek)(struct PFile_t* self, long offset, int origin);
00141 
00149   ESR_ReturnCode(*getPosition)(struct PFile_t* self, size_t* position);
00150 
00158   ESR_ReturnCode(*isOpen)(struct PFile_t* self, ESR_BOOL* isOpen);
00159 
00167   ESR_ReturnCode(*isEOF)(struct PFile_t* self, ESR_BOOL* isEof);
00168 
00179   ESR_ReturnCode(*getFilename)(struct PFile_t* self, LCHAR* filename, size_t* len);
00180 
00189   ESR_ReturnCode(*isErrorSet)(struct PFile_t* self, ESR_BOOL* isError);
00190 
00198   ESR_ReturnCode(*clearError)(struct PFile_t* self);
00199 
00209   ESR_ReturnCode(*vfprintf)(struct PFile_t* self, int* result, const LCHAR* format, va_list args);
00218   ESR_ReturnCode(*fgetc)(struct PFile_t* self, LINT* result);
00229   ESR_ReturnCode(*fgets)(struct PFile_t* self, LCHAR* string, int n, LCHAR** result);
00238   ESR_ReturnCode(*hideMemoryAllocation)(struct PFile_t* self);
00239 }
00240 PFile;
00241 
00242 #endif
00243 
00244 
00245 
00246 /*
00247  * Expose functions only if use wrappers is not defined, otherwize only expose wrapper functions.
00248  */
00249 
00250 #ifndef USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS
00251 
00258 PORTABLE_API ESR_ReturnCode PFileDestroy(PFile* self);
00259 
00260 
00261 PORTABLE_API ESR_ReturnCode PFileOpen(PFile* self, const LCHAR* mode);
00262 
00269 PORTABLE_API ESR_ReturnCode PFileClose(PFile* self);
00270 
00283 PORTABLE_API ESR_ReturnCode PFileRead(PFile* self, void* buffer, size_t size, size_t* count);
00284 
00296 PORTABLE_API ESR_ReturnCode PFileWrite(PFile* self, void* buffer, size_t size, size_t* count);
00297 
00304 PORTABLE_API ESR_ReturnCode PFileFlush(PFile* self);
00305 
00314 PORTABLE_API ESR_ReturnCode PFileSeek(PFile* self, long offset, int origin);
00315 
00323 PORTABLE_API ESR_ReturnCode PFileGetPosition(PFile* self, size_t* position);
00324 
00332 PORTABLE_API ESR_ReturnCode PFileIsOpen(PFile* self, ESR_BOOL* isOpen);
00333 
00334 
00342 PORTABLE_API ESR_ReturnCode PFileIsEOF(PFile* self, ESR_BOOL* isEof);
00343 
00352 PORTABLE_API ESR_ReturnCode PFileIsErrorSet(PFile* self, ESR_BOOL* isError);
00353 
00361 PORTABLE_API ESR_ReturnCode PFileClearError(PFile* self);
00362 
00372 PORTABLE_API ESR_ReturnCode PFileFprintf(PFile* self, int* result, const LCHAR* format, va_list args);
00373 
00383 PORTABLE_API ESR_ReturnCode PFileVfprintf(PFile* self, int* result, const LCHAR* format, va_list args);
00391 PORTABLE_API ESR_ReturnCode PFileFgetc(PFile* self, LINT* result);
00401 PORTABLE_API ESR_ReturnCode PFileFgets(PFile* self, LCHAR* string, int n, LCHAR** result);
00402 
00411 PORTABLE_API ESR_ReturnCode PFileReadInt(PFile* self, int* value);
00412 
00422 PORTABLE_API ESR_ReturnCode PFileReadLCHAR(PFile* self, LCHAR* value, size_t len);
00423 
00434 PORTABLE_API ESR_ReturnCode PFileGetFilename(PFile* self, LCHAR* filename, size_t* len);
00435 
00436 #endif /* USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS */
00437 
00445 PORTABLE_API PFile* pfopen(const LCHAR* filename, const LCHAR* mode);
00446 
00456 PORTABLE_API size_t pfread(void* buffer, size_t size, size_t count, PFile* stream);
00457 
00467 PORTABLE_API size_t pfwrite(void* buffer, size_t size, size_t count, PFile* stream);
00468 
00475 PORTABLE_API int pfclose(PFile* stream);
00476 
00483 PORTABLE_API void prewind(PFile* stream);
00484 
00493 PORTABLE_API int pfseek(PFile* stream, long offset, int origin);
00494 
00501 PORTABLE_API long pftell(PFile* stream);
00502 
00511 PORTABLE_API LCHAR* pfgets(LCHAR* string, int n, PFile* stream);
00512 
00519 PORTABLE_API int pfeof(PFile* stream);
00520 
00527 PORTABLE_API int pferror(PFile* stream);
00528 
00534 PORTABLE_API void pclearerr(PFile* stream);
00535 
00542 PORTABLE_API LINT pfgetc(PFile* stream);
00543 
00550 PORTABLE_API int pfflush(PFile* stream);
00551 
00560 PORTABLE_API int pvfprintf(PFile* stream, const LCHAR* format, va_list args);
00561 
00569 PORTABLE_API int pfprintf(PFile* stream, const LCHAR* format, ...);
00570 
00578 #ifndef USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS
00579 PORTABLE_API int pprintf(const LCHAR* format, ...);
00580 #endif
00581 
00582 /*
00583  * The following are only defined when using pfile wrappers.
00584  */
00585 
00586 #ifdef USE_LIGHT_WEIGHT_PANSI_FILE_WRAPPERS
00587 PORTABLE_API ESR_ReturnCode pf_convert_backslashes_to_forwardslashes ( LCHAR *string_to_convert );
00588 PORTABLE_API ESR_ReturnCode pf_is_path_absolute ( const LCHAR* input_path, ESR_BOOL* isAbsolute );
00589 PORTABLE_API ESR_ReturnCode pf_make_dir ( const LCHAR* path );
00590 PORTABLE_API ESR_ReturnCode pf_get_cwd ( LCHAR* path, size_t *len );
00591 PORTABLE_API ESR_ReturnCode pf_change_dir ( const LCHAR* path );
00592 #endif
00593 
00597 #endif /* __PFILE_H */

Generated on Thu May 1 15:37:25 2008 for SREC by  doxygen 1.5.3