Updated program to support the -fo option - forces continuation of parsing past mus_end

hg-commit-id: 595e13f32986
This commit is contained in:
KuroiIeWa5Da 2012-01-28 08:16:42 -06:00
parent 436c486d95
commit 1e6b99faa2
3 changed files with 44 additions and 2 deletions

View file

@ -10,6 +10,7 @@ Parser::Parser()
filePos = 0; filePos = 0;
stop = false; stop = false;
stopAddress = 0; stopAddress = 0;
force = false;
} }
Parser::Parser(std::string filename) Parser::Parser(std::string filename)
@ -19,6 +20,7 @@ Parser::Parser(std::string filename)
filePos = 0; filePos = 0;
stop = false; stop = false;
stopAddress = 0; stopAddress = 0;
force = false;
SetFilename(filename); SetFilename(filename);
} }
@ -58,6 +60,16 @@ void Parser::SetStopAddress(unsigned int value)
stopAddress = value; stopAddress = value;
} }
bool Parser::GetForce()
{
return force;
}
void Parser::SetForce(bool value)
{
force = value;
}
string Parser::GetParsedAsm() string Parser::GetParsedAsm()
{ {
string tmpStr; string tmpStr;
@ -139,14 +151,27 @@ void Parser::ParseNext() // Parses the block immidiately following
bool firstNonNote = false; // (unused so far)First byte wasn't a note or octacve switch, add ";Setup" comment bool firstNonNote = false; // (unused so far)First byte wasn't a note or octacve switch, add ";Setup" comment
bool firstNote = false; // (unused so far) First note or octave bool firstNote = false; // (unused so far) First note or octave
unsigned char lDataType = DATA_NA; unsigned char lDataType = DATA_NA;
bool newBranch = false; // Create a new branch
stringstream pos; stringstream pos;
pos << "; " << hex << uppercase << (unsigned int)filePos; pos << "; " << hex << uppercase << (unsigned int)filePos;
parsedString.push_back(pos.str()); parsedString.push_back(pos.str());
unsigned int count = 1; // Counter for processed instructions unsigned int count = 1; // Counter for processed instructions
newBranch = true;
for(unsigned int i = filePos; (i <= fileLength) && (stop == false); i++) for(unsigned int i = filePos; (i <= fileLength) && (stop == false); i++)
{ {
if(newBranch)
{
stringstream _tmpBr;
_tmpBr << "\n";
_tmpBr << "UnknSong_md_" << hex << i << ":";
parsedString.push_back(_tmpBr.str());
_tmpBr.str("");
newBranch = false;
}
// First peek to see what kind of data it is, then perform any pre and post setup // First peek to see what kind of data it is, then perform any pre and post setup
if(ParseData<Call>(i, true)) if(ParseData<Call>(i, true))
{ {
@ -236,7 +261,8 @@ void Parser::ParseNext() // Parses the block immidiately following
if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes if(lDataType == DATA_NOTE) parsedString.push_back("\n"); // Insert a newline after notes
ParseData<Stop>(i); ParseData<Stop>(i);
stop = true; // Raise the stop flag informing the parser to stop if(!force) stop = true; // Raise the stop flag informing the parser to stop
newBranch = true;
lDataType = DATA_STOP; lDataType = DATA_STOP;
} }
else else

View file

@ -41,6 +41,9 @@ public:
unsigned int GetStopAddress(); unsigned int GetStopAddress();
void SetStopAddress(unsigned int value); void SetStopAddress(unsigned int value);
bool GetForce();
void SetForce(bool value);
std::string GetParsedAsm(); std::string GetParsedAsm();
// File Operations // File Operations
@ -81,6 +84,7 @@ private:
unsigned int fileLength; unsigned int fileLength;
unsigned int filePos; unsigned int filePos;
bool stop; bool stop;
bool force;
// Optional Settings // Optional Settings
unsigned int stopAddress; unsigned int stopAddress;

View file

@ -33,6 +33,7 @@ void PrintUsage()
Console::PrintLn("--offset, -o - the parameterized offset in hexidecimal, It tells the parser where to start parsing"); Console::PrintLn("--offset, -o - the parameterized offset in hexidecimal, It tells the parser where to start parsing");
Console::PrintLn("--file, -f - the parameterized file path, It tells the parser which rom file to parse"); Console::PrintLn("--file, -f - the parameterized file path, It tells the parser which rom file to parse");
Console::PrintLn("--stop, -s - tells the parser to stop at that hexidecimal address or until it reaches mus_end."); Console::PrintLn("--stop, -s - tells the parser to stop at that hexidecimal address or until it reaches mus_end.");
Console::PrintLn("-fo - must be used with --stop, forces the program to proceed on despite discovering any mus_end");
Console::PrintLn("help, --help, -h - prints this info and exits, if the bare parameter is used it must be the first parameter"); Console::PrintLn("help, --help, -h - prints this info and exits, if the bare parameter is used it must be the first parameter");
} }
@ -51,6 +52,7 @@ int main(int argc, char** argv)
string filePath = ""; string filePath = "";
unsigned int offset = 0; unsigned int offset = 0;
unsigned int stop = 0; unsigned int stop = 0;
bool force = false;
// Get the file path, this can be set with -f filename, --file=filename, arg #2, or missing (missing means default) // Get the file path, this can be set with -f filename, --file=filename, arg #2, or missing (missing means default)
// the filepath can contain the actual filename or -- to use the built-in path, if the path is not missing then it must be set (can't be blank) // the filepath can contain the actual filename or -- to use the built-in path, if the path is not missing then it must be set (can't be blank)
@ -97,11 +99,21 @@ int main(int argc, char** argv)
else Console::Ask<unsigned int>("Offset: ", offset, ios_base::hex | ios_base::uppercase); else Console::Ask<unsigned int>("Offset: ", offset, ios_base::hex | ios_base::uppercase);
// Get the stop parameter, this can be set with -s <offset>, --stop=<offset> (it must be set via args) // Get the stop parameter, this can be set with -s <offset>, --stop=<offset> (it must be set via args)
if(a.SearchKeys("s") != -1) a.GetValueC<unsigned int>(a.SearchKeys("s"), offset, ios_base::hex | ios_base::uppercase, true); if(a.SearchKeys("s") != -1) a.GetValueC<unsigned int>(a.SearchKeys("s"), stop, ios_base::hex | ios_base::uppercase, true);
else if(a.SearchKeys("stop") != -1) filePath = a.GetValue(a.SearchKeys("stop")); else if(a.SearchKeys("stop") != -1) filePath = a.GetValue(a.SearchKeys("stop"));
// Get the force parameter, this can be set with -f (it must be set via args)
if(a.SearchKeys("fo") != -1) force = true;
if((stop == 0) && (force == true))
{
Console::ErrorLn("Error! You set the force command but did not set the stop command, this means it will parse every line until the end of the rom.");
return 1;
}
Parser p(filePath); Parser p(filePath);
if(stop != 0) p.SetStopAddress(stop); if(stop != 0) p.SetStopAddress(stop);
if(force) p.SetForce(true);
p.Parse(offset); p.Parse(offset);
Console::PrintLn(p.GetParsedAsm().c_str()); Console::PrintLn(p.GetParsedAsm().c_str());