| 1 | #pragma once
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include <vector>
 | 
|---|
| 4 | #include <string>
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #include <windows.h>
 | 
|---|
| 7 | #include <stdlib.h>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include <jenga/include/common/Exception.h>
 | 
|---|
| 10 | #include <jenga/include/smoothie/BasicFixed.h>
 | 
|---|
| 11 | 
 | 
|---|
| 12 | #include <BoostSerializationSupport.h>
 | 
|---|
| 13 | 
 | 
|---|
| 14 | using namespace std;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | struct INCLUDEFILEINFO{
 | 
|---|
| 17 |     char **ppFileNames;
 | 
|---|
| 18 |     int FilesNum;
 | 
|---|
| 19 |     int LineOfFile[MAX_LEN];
 | 
|---|
| 20 | };
 | 
|---|
| 21 | 
 | 
|---|
| 22 | class Text{
 | 
|---|
| 23 | protected:
 | 
|---|
| 24 |     char *buffer;
 | 
|---|
| 25 |     int length;
 | 
|---|
| 26 | 
 | 
|---|
| 27 | public:
 | 
|---|
| 28 | 
 | 
|---|
| 29 |     Text(){
 | 
|---|
| 30 |         buffer = (char *)calloc( 1, 1 );
 | 
|---|
| 31 |         length = 0;
 | 
|---|
| 32 |     }
 | 
|---|
| 33 |     ~Text(){
 | 
|---|
| 34 |         free( buffer );
 | 
|---|
| 35 |     }
 | 
|---|
| 36 |     void Clear()
 | 
|---|
| 37 |     {
 | 
|---|
| 38 |         length = 0;
 | 
|---|
| 39 |     }
 | 
|---|
| 40 |     void Add( const std::string &str )
 | 
|---|
| 41 |     {
 | 
|---|
| 42 |         buffer = (char *)realloc( buffer, length + str.size() + 1 );
 | 
|---|
| 43 |         lstrcpy( buffer + length, str.c_str() );
 | 
|---|
| 44 |         length += (int)str.size();
 | 
|---|
| 45 |     }
 | 
|---|
| 46 |     void Add( const std::vector<char> &str )
 | 
|---|
| 47 |     {
 | 
|---|
| 48 |         buffer = (char *)realloc( buffer, length + str.size() + 1 );
 | 
|---|
| 49 |         lstrcpy( buffer + length, &str[0] );
 | 
|---|
| 50 |         length += (int)str.size();
 | 
|---|
| 51 |     }
 | 
|---|
| 52 | 
 | 
|---|
| 53 |     bool ReadFile( const string &filePath );
 | 
|---|
| 54 | 
 | 
|---|
| 55 |     static void Text::SlideString(char *buffer, int slide){
 | 
|---|
| 56 |         char *temp;
 | 
|---|
| 57 |         temp=(char *)malloc(lstrlen(buffer)+1);
 | 
|---|
| 58 |         lstrcpy(temp,buffer);
 | 
|---|
| 59 |         lstrcpy(buffer+slide,temp);
 | 
|---|
| 60 |         free(temp);
 | 
|---|
| 61 |     }
 | 
|---|
| 62 | };
 | 
|---|
| 63 | 
 | 
|---|
| 64 | class BasicSource : public Text
 | 
|---|
| 65 | {
 | 
|---|
| 66 |     static const string generateDirectiveName;
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     void Realloc( int newLength ){
 | 
|---|
| 69 |         buffer = (char *)realloc( buffer, newLength + 255 );
 | 
|---|
| 70 | 
 | 
|---|
| 71 |         length = newLength;
 | 
|---|
| 72 | 
 | 
|---|
| 73 |         extern char *basbuf;
 | 
|---|
| 74 |         basbuf = buffer + 2;
 | 
|---|
| 75 |     }
 | 
|---|
| 76 | 
 | 
|---|
| 77 |     void IncludeFiles();
 | 
|---|
| 78 | 
 | 
|---|
| 79 |     void ChangeReturnLineChar();
 | 
|---|
| 80 | 
 | 
|---|
| 81 |     void RemoveComments();
 | 
|---|
| 82 | 
 | 
|---|
| 83 |     bool ReadFile_InIncludeDirective( const string &filePath );
 | 
|---|
| 84 |     void DirectiveIncludeOrRequire();
 | 
|---|
| 85 | 
 | 
|---|
| 86 |     void RemoveReturnLineUnderbar();
 | 
|---|
| 87 | 
 | 
|---|
| 88 | public:
 | 
|---|
| 89 |     BasicSource(){}
 | 
|---|
| 90 |     ~BasicSource(){}
 | 
|---|
| 91 | 
 | 
|---|
| 92 |     char *GetBuffer(){
 | 
|---|
| 93 |         return buffer+2;
 | 
|---|
| 94 |     }
 | 
|---|
| 95 |     const char *GetBuffer() const
 | 
|---|
| 96 |     {
 | 
|---|
| 97 |         return buffer+2;
 | 
|---|
| 98 |     }
 | 
|---|
| 99 |     int GetLength() const
 | 
|---|
| 100 |     {
 | 
|---|
| 101 |         return length-2;
 | 
|---|
| 102 |     }
 | 
|---|
| 103 | 
 | 
|---|
| 104 |     void SetBuffer( const char *buffer );
 | 
|---|
| 105 | 
 | 
|---|
| 106 |     bool ReadFile( const string &filePath );
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     bool Generate( const string &genName, const char *buffer );
 | 
|---|
| 109 | 
 | 
|---|
| 110 |     void Addition( const char *buffer );
 | 
|---|
| 111 | 
 | 
|---|
| 112 |     void operator = ( const BasicSource &source ){
 | 
|---|
| 113 |         Realloc( source.length );
 | 
|---|
| 114 |         lstrcpy( buffer, source.buffer );
 | 
|---|
| 115 |     }
 | 
|---|
| 116 | 
 | 
|---|
| 117 |     char operator[]( int index ) const
 | 
|---|
| 118 |     {
 | 
|---|
| 119 |         if( index>GetLength() )
 | 
|---|
| 120 |         {
 | 
|---|
| 121 |             Jenga::Throw( "BasicSource bad access" );
 | 
|---|
| 122 |         }
 | 
|---|
| 123 |         return buffer[2+index];
 | 
|---|
| 124 |     }
 | 
|---|
| 125 | };
 | 
|---|