| Line | |
|---|
| 1 | #ifndef TextFile_h |
|---|
| 2 | #define TextFile_h |
|---|
| 3 | |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | |
|---|
| 6 | struct TEXTFILEPOS |
|---|
| 7 | { |
|---|
| 8 | unsigned uOffset; |
|---|
| 9 | unsigned uLineNr; |
|---|
| 10 | unsigned uColNr; |
|---|
| 11 | }; |
|---|
| 12 | |
|---|
| 13 | const unsigned TextFileBufferSize = 256; |
|---|
| 14 | |
|---|
| 15 | class TextFile |
|---|
| 16 | { |
|---|
| 17 | private: |
|---|
| 18 | // no default c'tor, not implemented |
|---|
| 19 | TextFile(); |
|---|
| 20 | |
|---|
| 21 | public: |
|---|
| 22 | virtual ~TextFile(); |
|---|
| 23 | |
|---|
| 24 | TextFile(const char szFileName[], bool bWrite = false); |
|---|
| 25 | TextFile(FILE *ptrFile, const char *ptrFileName = "-"); |
|---|
| 26 | void Close() { fclose(m_ptrFile); m_ptrFile = 0; } |
|---|
| 27 | |
|---|
| 28 | bool GetLine(char szLine[], unsigned uBytes); |
|---|
| 29 | bool GetTrimLine(char szLine[], unsigned uBytes); |
|---|
| 30 | void GetLineX(char szLine[], unsigned uBytes); |
|---|
| 31 | |
|---|
| 32 | bool GetToken(char szToken[], unsigned uBytes, const char szCharTokens[] = "{}"); |
|---|
| 33 | void GetTokenX(char szToken[], unsigned uBytes, const char szCharTokens[] = "{}"); |
|---|
| 34 | |
|---|
| 35 | void Skip(); |
|---|
| 36 | void SkipLine(); |
|---|
| 37 | void SkipWhite(); |
|---|
| 38 | bool SkipWhiteX(); |
|---|
| 39 | void Rewind(); |
|---|
| 40 | TEXTFILEPOS GetPos(); |
|---|
| 41 | void SetPos(TEXTFILEPOS Pos); |
|---|
| 42 | bool GetChar(char &c); |
|---|
| 43 | void GetCharX(char &c); |
|---|
| 44 | void GetNonblankChar(char &c); |
|---|
| 45 | |
|---|
| 46 | unsigned GetLineNr() { return m_uLineNr; } |
|---|
| 47 | |
|---|
| 48 | void PutString(const char szLine[]); |
|---|
| 49 | void PutFormat(const char szFormat[], ...); |
|---|
| 50 | void PutChar(char c); |
|---|
| 51 | |
|---|
| 52 | const char *GetFileName() { return m_ptrName; } |
|---|
| 53 | |
|---|
| 54 | void PushBack(int c) { m_cPushedBack = c; } |
|---|
| 55 | |
|---|
| 56 | FILE *GetStdioFile() const { return m_ptrFile; } |
|---|
| 57 | |
|---|
| 58 | private: |
|---|
| 59 | void Init(FILE *ptrFile, const char *ptrFileName); |
|---|
| 60 | |
|---|
| 61 | private: |
|---|
| 62 | FILE *m_ptrFile; |
|---|
| 63 | unsigned m_uLineNr; |
|---|
| 64 | unsigned m_uColNr; |
|---|
| 65 | char *m_ptrName; |
|---|
| 66 | bool m_bLastCharWasEOL; |
|---|
| 67 | int m_cPushedBack; |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | #endif // TextFile_h |
|---|
Note: See
TracBrowser
for help on using the repository browser.