readTextFile.h
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:10k
- /**************************************************************
- * readTextFile.h
- **************************************************************
- * Description:
- * ============
- * Functions for reading text file using caching.
- **************************************************************
- *
- * Hagayb 14.11.03
- **************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef USE_AUX_SUBTITLES
- #ifndef __READTEXTFILE_H_
- #define __READTEXTFILE_H_
- #define TF_SEEK_SET 0
- #define TF_SEEK_CUR 1
- #define TF_SEEK_END 2
- #define TF_BUFFER_SIZE 256
- #define TF_BUFFER_SIZE_HALF 128
- #include "IncludeSysDefs.h"
- typedef struct textFileTag {
- DWORD dwStartAddress;
- DWORD dwFileSize;
- DWORD dwCurrentDiscOffset; // offest in disc of the data currently stored in buffer
- char *caBuffer;
- char *pcCurrentBufferPosition; // points at the current position in the buffer,
- // or NULL after reading past the buffers end.
- WORD wCurrentBufferSize;
- } textFile, *textFilePtr;
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileOpen
- // Purpose : Open a text file for reading with buffering
- // Input Parameters : dwStartAddress - Address of the file on disc
- // dwFileSize - Size if the file
- // Return type : Handle to textFile on success, NULL on failure.
- // Description : The function allocates a textFile struct and sets up a buffer for reading
- /////////////////////////////////////////////////////////////////////////////////////////////
- textFilePtr textFileOpen(DWORD dwStartAddress, DWORD dwFileSize);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileClose
- // Purpose : Closes a text file
- // Input Parameters : tfpFile - Handle to the file
- // Return type : void.
- // Description : The function deallocates the buffer and textFile struct for the file
- /////////////////////////////////////////////////////////////////////////////////////////////
- void textFileClose(textFilePtr tfpFile);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileSeek
- // Purpose : Seeks to a position in the file
- // Input Parameters : tfpFile - Handle to the file
- // dwOffset - Offset in bytes, relative to the location specifed by bOrigin
- // bOrigin - Specifies the origin of the seek.
- // Can have the following values:
- // * TF_SEEK_SET - seek is relative to the file's beginning.
- // * TF_SEEK_CUR - seek is relative to the current position
- // * TF_SEEK_END - seek is relative to the file's end.
- // Return type : TRUE on success. FALSE on failure, or requested position isn't within the file
- // Description : The function checks is the requested position already exist in the buffer.
- // If not, it fills the buffer from that point. In both cases, it updates
- // the internal pointer pcCurrentBufferPosition to the requested position
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileSeek(textFilePtr tfpFile, long dwOffset, BYTE bOrigin);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileEOF
- // Purpose : Check if end of file was reached
- // Input Parameters : tfpFile - Handle to the file
- // Return type : TRUE if end of file was reached, FALSE otherwise
- // Description : Check if pcCurrentBufferPosition is NULL, and dwCurrentDiscOffset +
- // wCurrentBufferSize points outside of the file
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileEOF(textFilePtr tfpFile);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileReadChar
- // Purpose : Reads a character (single byte) from the file.
- // Input Parameters : tfpFile - Handle to the file
- // wReserveLast -
- // Output Parameters: c - The character that was read
- // Return type : TRUE if successful, FALSE if failed, or already on end of file
- // Description : Fills the buffer if necessary, and reads a character.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileReadChar(textFilePtr tfpFile,WORD wReserveLast, char *c );
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileGetPosition
- // Purpose : Get the current poision in the file.
- // Input Parameters : tfpFile - Handle to the file
- // Return type : DWORD specifying the position. This value can be used in textFileSeek
- // together with TF_SEEK_SET to reach this position again.
- // Description : calculates the offset on disc of the current character in the buffer.
- /////////////////////////////////////////////////////////////////////////////////////////////
- DWORD textFileGetPosition(textFilePtr tfpFile);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileFindString
- // Purpose : Searches for the specified string from het current position, in the
- // specified number of bytes.
- // Input Parameters : tfpFile - Handle to the file
- // szStr - String (null terminated, single byte) to look for.
- // dwRegionSize - a limit to the number of bytes in the file the search
- // will cover. Specify 0 for search until end of file.
- // Return type : TRUE is string was found, else otherwise.
- // The current position in the file will be the first character following the string
- // Description :
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileFindString(textFilePtr tfpFile, const char *szStr, DWORD dwRegionSize);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileFindNumber
- // Purpose : Finds the next digit in the file, if exists in the next specified number of bytes.
- // Input Parameters : tfpFile - Handle to the file
- // dwRegionSize - a limit to the number of bytes in the file the search
- // will cover. Specify 0 for search until end of file.
- // Return type : TRUE is a digit was found within the region, else otherwise.
- // The current position in the file will be the digit.
- // Description : The function looks of the next digit, starting from the current position
- // for dwRegionSize bytes. If there was already a digit in the current position,
- // it does nothing.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileFindNumber(textFilePtr tfpFile,DWORD dwRegionSize);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileReadNumber
- // Purpose : Reads a number from the current position in the file.
- // Input Parameters : tfpFile - Handle to the file
- // Output Parameters: uiNumber - The number that was read
- // Return type : TRUE if successful. FALSE if the was no number in the current position,
- // if already on EOF, or on error.
- // Description : The function checks if there's a digit in the current position. If there
- // is, it reads until (not including) the 1st non digit character and
- // converts the digit sequence to a number.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileReadNumber(textFilePtr tfpFile, DWORD *uiNumber);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileSkipLine
- // Purpose : Find the beginning of the next line
- // Input Parameters : tfpFile - Handle to the file
- // Return type : TRUE if successful. FALSE if EOF encountered before or right after 'n',
- // or on error.
- // Description : The function searches for the next 'n' and sets the current position
- // right after it.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileSkipLine(textFilePtr tfpFile);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileSkipLine
- // Purpose : Find the beginning of the next line
- // Input Parameters : tfpFile - Handle to the file
- // Return type : TRUE if successful. FALSE if EOF encountered before 'n',
- // or on error.
- // Description : The function searches for the next 'n' and sets the current position
- // right after it.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileSkipLine(textFilePtr tfpFile);
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Function name : textFileIsCurrentChar
- // Purpose : Asserts that the current character in the file is the specified char
- // Input Parameters : tfpFile - Handle to the file
- // c - character to be tested.
- // Return type : TRUE if character is correct. FALSE otherwise, and on error
- // Description : The function reads a character from the file and compares it to the
- // specified character. This function should be used to check correctness
- // of file format.
- /////////////////////////////////////////////////////////////////////////////////////////////
- BOOL textFileIsCurrentChar(textFilePtr tfpFile,char c);
-
- BOOL textFileIsCurrentChar2(textFilePtr tfpFile,char c);
-
- #endif // __READTEXTFILE_H_
- #endif // USE_OSD_DEBUG