ENH: More cleanups

This commit is contained in:
Andy Cedilnik 2005-06-14 15:49:30 -04:00
parent 307b01002d
commit d797ba2c7e
2 changed files with 8 additions and 139 deletions

View File

@ -57,7 +57,8 @@ char* cmCommandArgumentParserHelper::AddString(const char* str)
} }
char* stVal = new char[strlen(str)+1]; char* stVal = new char[strlen(str)+1];
strcpy(stVal, str); strcpy(stVal, str);
return *(m_Variables.insert(stVal).first); m_Variables.push_back(stVal);
return stVal;
} }
char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, const char* var) char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, const char* var)
@ -106,57 +107,6 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
return this->AddString(value); return this->AddString(value);
} }
void cmCommandArgumentParserHelper::DeallocateParserType(char** pt)
{
if (!pt)
{
return;
}
if (!*pt)
{
//*pt = 0;
return;
}
// std::cout << (void*) *pt << " " << *pt << " this->DeallocateParserType" << std::endl;
//delete [] *pt;
*pt = 0;
this->UnionsAvailable --;
}
void cmCommandArgumentParserHelper::SafePrintMissing(const char* str, int line, int cnt)
{
if ( this->Verbose )
{
if ( str )
{
//std::cout << (void*) str << " JPSafePrintMissing" << std::endl;
std::cout << line << " String " << cnt << " exists: ";
unsigned int cc;
for ( cc = 0; cc < strlen(str); cc ++ )
{
unsigned char ch = str[cc];
if ( ch >= 32 && ch <= 126 )
{
std::cout << (char)ch;
}
else
{
std::cout << "<" << (int)ch << ">";
break;
}
}
std::cout << "- " << strlen(str) << std::endl;
}
}
}
void cmCommandArgumentParserHelper::Print(const char* place, const char* str)
{
if ( this->Verbose )
{
std::cout << "[" << place << "=" << str << "]" << std::endl;
}
}
char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2) char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2)
{ {
if ( !in1 ) if ( !in1 )
@ -171,25 +121,8 @@ char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2)
char* out = new char [ len ]; char* out = new char [ len ];
strcpy(out, in1); strcpy(out, in1);
strcat(out, in2); strcat(out, in2);
return *(m_Variables.insert(out).first); m_Variables.push_back(out);
} return out;
void cmCommandArgumentParserHelper::CheckEmpty(int line, int cnt, cmCommandArgumentParserHelper::ParserType* pt)
{
int cc;
int kk = -cnt + 1;
for ( cc = 1; cc <= cnt; cc ++)
{
cmCommandArgumentParserHelper::ParserType* cpt = pt + kk;
this->SafePrintMissing(cpt->str, line, cc);
kk ++;
}
}
void cmCommandArgumentParserHelper::PrepareElement(cmCommandArgumentParserHelper::ParserType* me)
{
// Inititalize self
me->str = 0;
} }
void cmCommandArgumentParserHelper::AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt, void cmCommandArgumentParserHelper::AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
@ -208,7 +141,7 @@ void cmCommandArgumentParserHelper::AllocateParserType(cmCommandArgumentParserHe
pt->str = new char[ len + 1 ]; pt->str = new char[ len + 1 ];
strncpy(pt->str, str, len); strncpy(pt->str, str, len);
pt->str[len] = 0; pt->str[len] = 0;
this->Allocates.push_back(pt->str); m_Variables.push_back(pt->str);
// std::cout << (void*) pt->str << " " << pt->str << " JPAllocateParserType" << std::endl; // std::cout << (void*) pt->str << " " << pt->str << " JPAllocateParserType" << std::endl;
} }
@ -250,22 +183,13 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
void cmCommandArgumentParserHelper::CleanupParser() void cmCommandArgumentParserHelper::CleanupParser()
{ {
std::vector<char*>::iterator it; std::vector<char*>::iterator sit;
for ( it = this->Allocates.begin();
it != this->Allocates.end();
++ it )
{
delete [] *it;
}
std::set<char*>::iterator sit;
for ( sit = m_Variables.begin(); for ( sit = m_Variables.begin();
sit != m_Variables.end(); sit != m_Variables.end();
++ sit ) ++ sit )
{ {
delete [] *sit; delete [] *sit;
} }
this->Allocates.erase(this->Allocates.begin(),
this->Allocates.end());
m_Variables.erase(m_Variables.begin(), m_Variables.end()); m_Variables.erase(m_Variables.begin(), m_Variables.end());
} }
@ -293,6 +217,7 @@ int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)
return( 0 ); return( 0 );
} }
} }
void cmCommandArgumentParserHelper::Error(const char* str) void cmCommandArgumentParserHelper::Error(const char* str)
{ {
unsigned long pos = static_cast<unsigned long>(this->InputBufferPos); unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
@ -312,42 +237,6 @@ void cmCommandArgumentParserHelper::Error(const char* str)
m_Error = ostr.str(); m_Error = ostr.str();
} }
void cmCommandArgumentParserHelper::UpdateCombine(const char* str1, const char* str2)
{
if ( this->CurrentCombine == "" && str1 != 0)
{
this->CurrentCombine = str1;
}
this->CurrentCombine += ".";
this->CurrentCombine += str2;
}
int cmCommandArgumentParserHelper::ParseFile(const char* file)
{
if ( !cmSystemTools::FileExists(file))
{
return 0;
}
std::ifstream ifs(file);
if ( !ifs )
{
return 0;
}
cmStdString fullfile = "";
cmStdString line;
while ( cmSystemTools::GetLineFromStream(ifs, line) )
{
fullfile += line + "\n";
}
return this->ParseString(fullfile.c_str(), 0);
}
void cmCommandArgumentParserHelper::Append(const char* str)
{
std::cout << "Append[" << str << "]" << std::endl;
}
void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf) void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf)
{ {
m_Makefile = mf; m_Makefile = mf;

View File

@ -43,7 +43,6 @@ public:
~cmCommandArgumentParserHelper(); ~cmCommandArgumentParserHelper();
int ParseString(const char* str, int verb); int ParseString(const char* str, int verb);
int ParseFile(const char* file);
// For the lexer: // For the lexer:
void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt, void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
@ -53,17 +52,6 @@ public:
void Error(const char* str); void Error(const char* str);
// For yacc // For yacc
void AddClassFound(const char* sclass);
void PrepareElement(ParserType* opt);
void DeallocateParserType(char** pt);
void CheckEmpty(int line, int cnt, ParserType* pt);
void StartClass(const char* cls);
void EndClass();
void AddPackagesImport(const char* sclass);
void SetCurrentCombine(const char* cmb) { this->CurrentCombine = cmb; }
const char* GetCurrentCombine() { return this->CurrentCombine.c_str(); }
void UpdateCombine(const char* str1, const char* str2);
void Append(const char* str);
char* CombineUnions(char* in1, char* in2); char* CombineUnions(char* in1, char* in2);
char* ExpandSpecialVariable(const char* key, const char* var); char* ExpandSpecialVariable(const char* key, const char* var);
@ -95,11 +83,6 @@ private:
int UnionsAvailable; int UnionsAvailable;
int Verbose; int Verbose;
std::vector<char*> Allocates;
std::string CurrentCombine;
void PrintClasses();
void Print(const char* place, const char* str); void Print(const char* place, const char* str);
void SafePrintMissing(const char* str, int line, int cnt); void SafePrintMissing(const char* str, int line, int cnt);
@ -107,16 +90,13 @@ private:
void CleanupParser(); void CleanupParser();
std::set<char*> m_Variables; std::vector<char*> m_Variables;
const cmMakefile* m_Makefile; const cmMakefile* m_Makefile;
std::string m_Result; std::string m_Result;
const char* m_FileName; const char* m_FileName;
long m_FileLine; long m_FileLine;
bool m_EscapeQuotes; bool m_EscapeQuotes;
std::string m_Error; std::string m_Error;
}; };
#endif #endif