00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _buffer_h
00037 #define _buffer_h
00038
00039 #include <fstream.h>
00040 #include "types.h"
00041
00042 class Ptree;
00043
00044 class Program : public Object {
00045 public:
00046 Program(char *name) {
00047 replacement = nil;
00048 defaultname = name;
00049 }
00050
00051 virtual ~Program() {}
00052
00053 void Rewind() { index = 0; }
00054 void Rewind(uint i) { index = i; }
00055 uint GetSize() { return size; }
00056 void Unget() { --index; }
00057
00058 char Ref(uint position) { return buf[position]; }
00059 void Set(char c, uint position) { buf[position] = c; }
00060
00061
00062 uint GetCurPos() { return index - 1; }
00063
00064
00065 uint GetNextPos() { return index; }
00066
00067
00068 const char* Read(uint p) { return &buf[p]; }
00069
00070 virtual char Get();
00071
00072 void Subst(Ptree* newtext, Ptree* oldtext);
00073 void Insert(Ptree* pos, Ptree* before_text, Ptree* after_text);
00074 void Replace(char*, char*, Ptree*);
00075 void MinimumSubst(Ptree* newtext, Ptree* oldtext);
00076
00077 uint LineNumber(char*, char*&, int&);
00078
00079 void Write(ostream&, const char*);
00080 sint ReadLineDirective(uint, sint, uint&, int&);
00081
00082 private:
00083 bool MinimumSubst2(Ptree* newtext, Ptree* oldtext);
00084
00085 protected:
00086 char* buf;
00087 uint size, index;
00088 char *defaultname;
00089
00090 private:
00091 class Replacement : public LightObject {
00092 public:
00093 Replacement(Replacement*, uint, uint, Ptree*);
00094 Replacement* next;
00095 uint startpos;
00096 uint endpos;
00097 Ptree* text;
00098 };
00099
00100 Replacement* replacement;
00101 };
00102
00103 class ProgramFile : public Program {
00104 public:
00105 ProgramFile(ifstream&, char *filename = "unknown");
00106 ~ProgramFile();
00107 };
00108
00109 class ProgramFromStdin : public Program {
00110 public:
00111 ProgramFromStdin();
00112 ~ProgramFromStdin();
00113 char Get();
00114
00115 protected:
00116 uint buf_size;
00117 };
00118
00119
00120
00121 class ProgramString : public Program {
00122 public:
00123 ProgramString();
00124 ~ProgramString();
00125 void Clear() { buf[0] = '\0'; }
00126 uint Length() { return str_length; }
00127 ProgramString& operator << (const char*);
00128 ProgramString& operator << (const char);
00129
00130 private:
00131 uint str_length;
00132 };
00133
00134 #endif