1 /////////////////////////////////////////////////////////////////////////// 2 // 3 // FILE: textbuf.h 4 // TextBuffer class 5 // 6 // Part of: Scid (Shane's Chess Information Database) 7 // Version: 2.7 8 // 9 // Notice: Copyright (c) 1999-2001 Shane Hudson. All rights reserved. 10 // 11 // Author: Shane Hudson (sgh@users.sourceforge.net) 12 // 13 /////////////////////////////////////////////////////////////////////////// 14 15 16 #ifndef SCID_TEXTBUF_H 17 #define SCID_TEXTBUF_H 18 19 #include "common.h" 20 #include <stdio.h> 21 22 class TextBuffer 23 { 24 private: 25 //---------------------------------- 26 // TextBuffer: Data Structures 27 28 uint Column; 29 uint IndentColumn; 30 uint WrapColumn; 31 uint LineIsEmpty; // true if current line is empty. 32 uint LineCount; 33 uint ByteCount; 34 uint BufferSize; 35 bool ConvertNewlines; // If true, convert newlines to spaces. 36 char * Buffer; 37 char * Current; 38 39 bool PausedTranslations; 40 bool HasTranslations; 41 const char * Translation [256]; 42 43 inline void AddChar (char ch); 44 TextBuffer(const TextBuffer&); 45 TextBuffer& operator=(const TextBuffer&); 46 47 //---------------------------------- 48 // TextBuffer: Public Functions 49 public: TextBuffer()50 TextBuffer() { 51 Init(); 52 SetBufferSize(1280000); 53 } ~TextBuffer()54 ~TextBuffer() { Free(); } 55 56 void Init (); 57 void Free (); 58 void Empty (); 59 60 void SetBufferSize (uint length); GetBufferSize()61 uint GetBufferSize() { return BufferSize; } GetByteCount()62 uint GetByteCount() { return ByteCount; } GetLineCount()63 uint GetLineCount() { return LineCount; } GetColumn()64 uint GetColumn() { return Column; } GetWrapColumn()65 uint GetWrapColumn () { return WrapColumn; } SetWrapColumn(uint column)66 void SetWrapColumn (uint column) { WrapColumn = column; } GetIndent()67 uint GetIndent () { return IndentColumn; } SetIndent(uint column)68 void SetIndent (uint column) { IndentColumn = column; } GetBuffer()69 char * GetBuffer () { return Buffer; } NewlinesToSpaces(bool b)70 void NewlinesToSpaces (bool b) { ConvertNewlines = b; } 71 72 void AddTranslation (char ch, const char * str); 73 // void ClearTranslation (char ch) { Translation[ch] = NULL; } 74 // Changed ch to int, to avoid compiler warnings. ClearTranslation(int ch)75 void ClearTranslation (int ch) { Translation[ch] = NULL; } ClearTranslations()76 void ClearTranslations () { HasTranslations = false; } PauseTranslations()77 void PauseTranslations () { PausedTranslations = true; } ResumeTranslations()78 void ResumeTranslations () { PausedTranslations = false; } 79 80 errorT NewLine(); 81 errorT Indent(); 82 errorT PrintLine (const char * str); 83 errorT PrintWord (const char * str); 84 errorT PrintString (const char * str); 85 errorT PrintSpace (); 86 errorT PrintChar (char b); 87 88 errorT PrintInt (uint i, const char * str); PrintInt(uint i)89 inline errorT PrintInt (uint i) { return PrintInt (i, ""); } 90 91 }; 92 93 inline void AddChar(char ch)94TextBuffer::AddChar (char ch) 95 { 96 if (HasTranslations && !PausedTranslations) { 97 byte b = (byte) ch; 98 const char * str = Translation[b]; 99 if (str != NULL) { 100 const char * s = str; 101 while (*s) { 102 *Current++ = *s++; 103 ByteCount++; 104 } 105 return; 106 } 107 } 108 *Current = ch; 109 Current++; 110 ByteCount++; 111 } 112 113 #endif // SCID_TEXTBUF_H 114 115 /////////////////////////////////////////////////////////////////////////// 116 // EOF: textbuf.h 117 /////////////////////////////////////////////////////////////////////////// 118 119