• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  pstream.h  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 
21 
22 #ifndef _PORTSTREAM_H_
23 #define _PORTSTREAM_H_
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30 #include <stdio.h>
31 #include "ptypes.h"
32 
33 #ifdef PFILE_VIRTUAL_SUPPORT
34 
35   struct FileBufferFrame;
36   typedef struct PORT_FILE_HANDLE
37   {
38     const char              *filename;
39     struct FileBufferFrame  *startFrame;
40     struct FileBufferFrame  *endFrame;
41     struct FileBufferFrame  *curFrame;  /* current buffer; useful for writable file */
42     const unsigned char     *curPos;
43     const unsigned char     *endPos;
44     unsigned int            size;       /* total buffer size; useful for writable file */
45     unsigned int            frame_size; /* buffer size in current frame; useful for writable file */
46     int                     eof;
47     int                     mode;      /* 0 readonly text; 1 readonly binary; 2 writable text; 3 writalbe binary */
48   }
49   PORT_FILE_HANDLE;
50 
51   typedef PORT_FILE_HANDLE* PORT_FILE;
52 
53   typedef struct _FileRecord
54   {
55     char name[80];
56     unsigned char *start;
57     int end;              /* offset of the end of the file */
58     int size;             /* total buffer size */
59     int mode;
60   }
61   FileRecord;
62 
63   typedef struct VirtualFileTable_t
64   {
65     const FileRecord* pFileTable;
66     const unsigned char* pFirstFile;
67   }
68   VirtualFileTable;
69 
70   /* Function prototypes */
71   PORTABLE_API void    PortFileInit(void);
72   PORTABLE_API PORT_FILE PortFopen(const char* filename, const char* mode);
73   PORTABLE_API int   PortFclose(PORT_FILE PortFile);
74   PORTABLE_API size_t  PortFread(void* buffer, size_t size, size_t count, PORT_FILE PortFile);
75   PORTABLE_API size_t  PortFwrite(const void* buffer, size_t size, size_t count, PORT_FILE PortFile);
76   PORTABLE_API int   PortFseek(PORT_FILE PortFile, long offset, int origin);
77   PORTABLE_API long    PortFtell(PORT_FILE PortFile);
78   PORTABLE_API int   PortFprintf(PORT_FILE PortFile, const char* format, ...);
79   PORTABLE_API char*  PortFgets(char* string, int n, PORT_FILE PortFile);
80   PORTABLE_API int   PortFflush(PORT_FILE PortFile);
81   PORTABLE_API int   PortFeof(PORT_FILE PortFile);
82   PORTABLE_API int   PortFgetc(PORT_FILE PortFile);
83   PORTABLE_API int   PortFscanf(PORT_FILE PortFile, const char *format, ...);
84   PORTABLE_API int   PortFerror(PORT_FILE PortFile);
85   PORTABLE_API void   PortClearerr(PORT_FILE PortFile);
86   PORTABLE_API void    PortRewind(PORT_FILE PortFile);
87   PORTABLE_API PORT_FILE PortFreopen(const char *path, const char *mode, PORT_FILE PortFile);
88   PORTABLE_API char*    PortGetcwd(char *buffer, int maxlen);
89   PORTABLE_API int      PortMkdir(const char *dirname);
90 
91   /* this function is to create a file with the limit size */
92   PORTABLE_API int      PortFcreate(const char *fname, void *pBuffer, int size);
93   PORTABLE_API void     PortFdelete(const char *fname);
94 
95   PORTABLE_API void     PortSetFileTable(const FileRecord* pFileTable, const unsigned char* pFirstFile);
96 
97   void     SetFileTable(VirtualFileTable *table);
98 
99 #endif /* #ifdef PFILE_VIRTUAL_SUPPORT */
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif /* _PORTSTREAM_H */
106