// Content generator // usage: content file.cpp [files.cpp] // Oleg Mazonka 2009 /** Content (autogenerated by http://mazonka.com/subleq/content.cpp) 1 Standard headers ..................................... (30-38:8) 2 Section class definition ............................. (39-60:21) 3 Forward declarations ................................. (61-65:4) 4 Function definitions ................................. (66-365) 4.1 Main ............................................. (67-124:57) 4.2 Utility .......................................... (125-133:8) 4.3 Section implementation ........................... (134-234) 4.3.1 depth ........................................ (135-141:6) 4.3.2 add .......................................... (142-148:6) 4.3.3 recursive line initialization ................ (149-163:14) 4.3.4 recursive counter ............................ (164-175:11) 4.3.5 recursive printing content ................... (176-205:29) 4.3.6 recursive printing body ...................... (206-225:19) 4.3.7 getting grand parent ......................... (226-234:8) 4.4 Functions implementation ......................... (235-365) 4.4.1 Consume header ............................... (237-249:12) 4.4.2 Consume conetnt .............................. (250-263:13) 4.4.3 Consume section .............................. (264-365) 4.4.3.1 Read in section .......................... (265-285:20) 4.4.3.2 Calculate sector depth ................... (286-295:9) 4.4.3.3 Extract section header ................... (296-313:17) 4.4.3.4 Consume section main function ............ (314-365:51) **/ /** 1 Standard headers **/ #include #include #include #include #include using namespace std; /** 2 Section class definition **/ struct section { section * parent; vector kids; string body, sector, header; int start, size, end; section(section *p): parent(p), start(0), size(0) {} section(string b, string s, string h, int sz): parent(0), body(b), sector(s), header(h), start(0), size(sz) {} int getDepth(); void add(section * p); string print(string newsector); string printfull(string newsector); section * getGrand(int depth); int lines(int offset); int getsize() const { return end-start; } int counter() const; }; /** 3 Forward declarations **/ string getHeader(vector & v, int *index); string getContent(vector & v, int *index); bool getSection(vector & v, int *index, section * parent); /** 4 Function definitions **/ /** 4.1 Main **/ int main(int ac, char *av[]) { try{ if( ac < 2 ) { cout<<"Usage: content file.cpp [other filenames]\n"; return 0; } vector file; for( int i=1; igetDepth(); } /** 4.3.2 add **/ void section::add(section * p) { kids.push_back(p); p->parent = this; } /** 4.3.3 recursive line initialization **/ int section::lines(int offset) { start = offset; offset += size; for( int i=0; ilines(offset); } end = offset; return end-start; } /** 4.3.4 recursive counter **/ int section::counter() const { int sum = 1; for( int i=0; icounter(); } return sum; } /** 4.3.5 recursive printing content **/ string section::print(string newsector) { string r; int depth = getDepth(); for( int i=0; iprint(s); } return r; } /** 4.3.6 recursive printing body **/ string section::printfull(string newsector) { string r; if( header!="" ) r += "/** "+newsector + ' '+ header+ " **/\n"; r += body; for( int i=0; iprintfull(s); } return r; } /** 4.3.7 getting grand parent **/ section * section::getGrand(int depth) { int mydepth = getDepth(); if( depth==mydepth ) return this; if( parent ) return parent->getGrand(depth); return 0; } /** 4.4 Functions implementation **/ /** 4.4.1 Consume header **/ string getHeader(vector & v, int *index) { int & i = * index; string r; for( ;i & v, int *index) { int & i = * index; string r; for( ;i & v, int *index) { int & i = * index; string r; for( ;i & v, int *index, section * parent) { int size = *index; string body = readSection(v,index); size = *index - size; if( body == "" ) return false; istringstream is(body); string sector; is>>sector>>sector; string header = extractSectionHeader(body,sector); int sector_depth = getDepth(sector); int section_depth = parent->getDepth(); cout<kids.empty() ) throw "Cannot add (no kids): "+header; parent->kids.back()->add(psection); return getSection(v,index,parent->kids.back()); } if( sector_depth > section_depth ) { cout<<"Section depth ("<getGrand(sector_depth); if( !grandpa ) throw "Error in: "+header; grandpa->add(psection); return getSection(v,index,grandpa); } cout<