1 /**
2  * @namespace   biew
3  * @file        bmfile.h
4  * @brief       This file contains prototypes of Buffering streams Manager.
5  * @version     -
6  * @remark      this source file is part of Binary vIEW project (BIEW).
7  *              The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
8  *              All rights reserved. This software is redistributable under the
9  *              licence given in the file "Licence.en" ("Licence.ru" in russian
10  *              translation) distributed in the BIEW archive.
11  * @note        Requires POSIX compatible development system
12  *
13  * @author      Nickols_K
14  * @since       1995
15  * @note        Development, fixes and improvements
16 **/
17 #ifndef __BMFILE_INC
18 #define __BMFILE_INC
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #ifndef __BBIO_H
25 #include "biewlib/bbio.h"
26 #endif
27 
28 #define HA_LEN ((BMFileFlags&BMFF_USE64)?18:10)
29 
30 #define BMFF_NONE	0x00000000
31 #define BMFF_USE64	0x00000001
32 extern unsigned BMFileFlags;
33 
34 #if __WORDSIZE == 16
35 #define BBIO_CACHE_SIZE        0x4000  /* 16k */
36 #define BBIO_SMALL_CACHE_SIZE  0x1000  /* 4k */
37 #else
38 #define BBIO_CACHE_SIZE        0xFFFF  /* 64k */
39 #define BBIO_SMALL_CACHE_SIZE  0x4000  /* 16k */
40 #endif
41 
42 BGLOBAL        __FASTCALL__ biewOpenRO(char *fname,unsigned cache_size);
43 BGLOBAL        __FASTCALL__ biewOpenRW(char *fname,unsigned cache_size);
44 
45 #define BM_SEEK_SET BIO_SEEK_SET
46 #define BM_SEEK_CUR BIO_SEEK_CUR
47 #define BM_SEEK_END BIO_SEEK_END
48 extern BGLOBAL bm_file_handle,sc_bm_file_handle;
49 
50 int            __FASTCALL__ BMOpen(char * fname);
51 void           __FASTCALL__ BMClose( void );
BMHandle(void)52 static inline bhandle_t		__FASTCALL__ BMHandle( void ) { return bioHandle(bm_file_handle); }
BMbioHandle(void)53 static inline BGLOBAL		__FASTCALL__ BMbioHandle( void ) { return bm_file_handle; }
BMName(void)54 static inline char *		__FASTCALL__ BMName( void ) { return bioFileName(bm_file_handle); }
BMGetCurrFilePos(void)55 static inline __filesize_t	__FASTCALL__ BMGetCurrFilePos( void ) { return bioTell(bm_file_handle); }
BMGetFLength(void)56 static inline __filesize_t	__FASTCALL__ BMGetFLength( void ) { return bioFLength(bm_file_handle); }
BMEOF(void)57 static inline tBool	__FASTCALL__ BMEOF( void ) { return bioEOF(bm_file_handle); }
BMSeek(__fileoff_t pos,int RELATION)58 static inline void	__FASTCALL__ BMSeek(__fileoff_t pos,int RELATION) { bioSeek(bm_file_handle,pos,RELATION); }
BMReRead(void)59 static inline void	__FASTCALL__ BMReRead( void )  { bioReRead(bm_file_handle); }
BMReadByte(void)60 static inline tUInt8	__FASTCALL__ BMReadByte( void ) { return bioReadByte(bm_file_handle); }
BMReadWord(void)61 static inline tUInt16	__FASTCALL__ BMReadWord( void ) { return bioReadWord(bm_file_handle); }
BMReadDWord(void)62 static inline tUInt32	__FASTCALL__ BMReadDWord( void ) { return bioReadDWord(bm_file_handle); }
BMReadQWord(void)63 static inline tUInt64	__FASTCALL__ BMReadQWord( void ) { return bioReadQWord(bm_file_handle); }
BMReadBuffer(void * buffer,unsigned len)64 static inline tBool	__FASTCALL__ BMReadBuffer(void  * buffer,unsigned len) { return bioReadBuffer(bm_file_handle,buffer,len); }
65 tUInt8        __FASTCALL__ BMReadByteEx(__fileoff_t pos,int RELATION);
66 tUInt16       __FASTCALL__ BMReadWordEx(__fileoff_t pos,int RELATION);
67 tUInt32       __FASTCALL__ BMReadDWordEx(__fileoff_t pos,int RELATION);
68 tUInt64       __FASTCALL__ BMReadQWordEx(__fileoff_t pos,int RELATION);
69 tBool         __FASTCALL__ BMReadBufferEx(void  * buffer,unsigned len,__fileoff_t pos,int RELATION);
BMWriteByte(tUInt8 byte)70 static inline tBool	__FASTCALL__ BMWriteByte(tUInt8 byte) { return bioWriteByte(bm_file_handle,byte); }
BMWriteWord(tUInt16 word)71 static inline tBool	__FASTCALL__ BMWriteWord(tUInt16 word) { return bioWriteWord(bm_file_handle,word); }
BMWriteDWord(tUInt32 dword)72 static inline tBool	__FASTCALL__ BMWriteDWord(tUInt32 dword) { return bioWriteDWord(bm_file_handle,dword); }
BMWriteQWord(tUInt64 qword)73 static inline tBool	__FASTCALL__ BMWriteQWord(tUInt64 qword) { return bioWriteQWord(bm_file_handle,qword); }
74 tBool		__FASTCALL__ BMWriteBuff(void* buff,unsigned len);
75 tBool		__FASTCALL__ BMWriteByteEx(__fileoff_t pos,int RELATION,tUInt8 byte);
76 tBool		__FASTCALL__ BMWriteWordEx(__fileoff_t pos,int RELATION,tUInt16 word);
77 tBool		__FASTCALL__ BMWriteDWordEx(__fileoff_t pos,int RELATION,tUInt32 dword);
78 tBool		__FASTCALL__ BMWriteBuffEx(__fileoff_t pos,int RELATION,void  * buff,unsigned len);
79 
80 /** Below analogs with using small cache size */
81 
bmEOF(void)82 static inline tBool	__FASTCALL__ bmEOF( void ) { return bioEOF(sc_bm_file_handle); }
bmSeek(__fileoff_t pos,int RELATION)83 static inline void	__FASTCALL__ bmSeek(__fileoff_t pos,int RELATION) { bioSeek(sc_bm_file_handle,pos,RELATION); }
bmReRead(void)84 static inline void	__FASTCALL__ bmReRead( void ) { bioReRead(sc_bm_file_handle); }
bmReadByte(void)85 static inline tUInt8	__FASTCALL__ bmReadByte( void ) { return bioReadByte(sc_bm_file_handle); }
bmReadWord(void)86 static inline tUInt16	__FASTCALL__ bmReadWord( void ) { return bioReadWord(sc_bm_file_handle); }
bmReadDWord(void)87 static inline tUInt32	__FASTCALL__ bmReadDWord( void ) { return bioReadDWord(sc_bm_file_handle); }
bmReadQWord(void)88 static inline tUInt64	__FASTCALL__ bmReadQWord( void ) { return bioReadQWord(sc_bm_file_handle); }
bmReadBuffer(void * buffer,unsigned len)89 static inline tBool	__FASTCALL__ bmReadBuffer(void  * buffer,unsigned len) { return bioReadBuffer(sc_bm_file_handle,buffer,len); }
90 tUInt8        __FASTCALL__ bmReadByteEx(__fileoff_t pos,int RELATION);
91 tUInt16       __FASTCALL__ bmReadWordEx(__fileoff_t pos,int RELATION);
92 tUInt32       __FASTCALL__ bmReadDWordEx(__fileoff_t pos,int RELATION);
93 tUInt64       __FASTCALL__ bmReadQWordEx(__fileoff_t pos,int RELATION);
94 tBool         __FASTCALL__ bmReadBufferEx(void  * buffer,unsigned len,__fileoff_t pos,int RELATION);
bmHandle(void)95 static inline bhandle_t	__FASTCALL__ bmHandle( void ) { return bioHandle(sc_bm_file_handle); }
bmbioHandle(void)96 static inline BGLOBAL	__FASTCALL__ bmbioHandle( void ) { return sc_bm_file_handle; }
bmName(void)97 static inline char *	__FASTCALL__ bmName( void ) { return bioFileName(sc_bm_file_handle); }
98 
bmGetCurrFilePos(void)99 static inline __filesize_t	__FASTCALL__ bmGetCurrFilePos( void ) { return bioTell(sc_bm_file_handle); }
bmGetFLength(void)100 static inline __filesize_t	__FASTCALL__ bmGetFLength( void ) {  return bioFLength(sc_bm_file_handle); }
101 
bmWriteByte(tUInt8 byte)102 static inline tBool	__FASTCALL__ bmWriteByte(tUInt8 byte) { return bioWriteByte(sc_bm_file_handle,byte); }
bmWriteWord(tUInt16 word)103 static inline tBool	__FASTCALL__ bmWriteWord(tUInt16 word) { return bioWriteWord(sc_bm_file_handle,word); }
bmWriteDWord(tUInt32 dword)104 static inline tBool	__FASTCALL__ bmWriteDWord(tUInt32 dword) { return bioWriteDWord(sc_bm_file_handle,dword); }
bmWriteQWord(tUInt64 qword)105 static inline tBool	__FASTCALL__ bmWriteQWord(tUInt64 qword) { return bioWriteQWord(sc_bm_file_handle,qword); }
106 tBool          __FASTCALL__ bmWriteBuff(void  * buff,unsigned len);
107 tBool          __FASTCALL__ bmWriteByteEx(__fileoff_t pos,int RELATION,tUInt8 byte);
108 tBool          __FASTCALL__ bmWriteWordEx(__fileoff_t pos,int RELATION,tUInt16 word);
109 tBool          __FASTCALL__ bmWriteDWordEx(__fileoff_t pos,int RELATION,tUInt32 dword);
110 tBool          __FASTCALL__ bmWriteQWordEx(__fileoff_t pos,int RELATION,tUInt64 dword);
111 tBool          __FASTCALL__ bmWriteBuffEx(__fileoff_t pos,int RELATION,void  * buff,unsigned len);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif
118