Resetting the Simulator 3 and 4 Projects here... Git repository got really bad...

This commit is contained in:
Charles Descamps 2024-04-21 14:42:28 -07:00
parent d98c664002
commit 46bd58931f
21 changed files with 0 additions and 4310 deletions

View file

@ -1,246 +0,0 @@
// header files
#include "OS_SimDriver.h"
int main(int argc, char **argv)
{
// initialize program (variables and title)
ConfigDataType *configDataPtr = NULL;
OpCodeType *metaDataPtr = NULL;
char errorMsg[MAX_STR_LEN];
CmdLineData cmdLineData;
bool configUploadSuccess = false;
// show title
// fct: printf
printf("\nSimulator Program\n");
printf("=================\n\n");
// process command line arguments
// check for at least one correct switch and config file name verified
// fct: processCmdLine
if(processCmdLine(argc, argv, &cmdLineData))
{
// upload config file, check for success
// fct: getConfigData
if(getConfigData(cmdLineData.fileName, &configDataPtr, errorMsg))
{
// check for config display flag
if(cmdLineData.configDisplayFlag)
{
// display config display flag
// fct: displayConfigData
displayConfigData(configDataPtr);
}
// set config upload success flag
configUploadSuccess = true;
}
// otherwise, assume config file upload failure
else
{
// show error message, end program
// fct: printf
printf("\nConfig Upload Error: %s, program aborted\n\n", errorMsg);
}
// check for config success and need for metadata
if(configUploadSuccess &&
(cmdLineData.mdDisplayFlag || cmdLineData.runSimFlag))
{
// upload metadata file, check for success
// fct: getMetaData
if(getMetaData(configDataPtr->metaDataFileName,
&metaDataPtr, errorMsg))
{
// check metadata display flag
if(cmdLineData.mdDisplayFlag)
{
// display metadata
// fct: displayMetaData
displayMetaData(metaDataPtr);
}
// check run simulator flag
if(cmdLineData.runSimFlag)
{
// run simulator
// fct: runSim
runSim(configDataPtr, metaDataPtr);
}
}
// otherwise, assume metadata upload failure
else
{
// show error message, end program
// fct: printf
printf("\nMetadata Upload Error: %s, program aborted\n",
errorMsg);
}
}
// end check for config success and need for metadata
// clean up config data as needed
// fct: clearConfigData
configDataPtr = clearConfigData(configDataPtr);
// clean up metadata as needed
// fct: clearMetaDataList
metaDataPtr = clearMetaDataList(metaDataPtr);
}
// end process command line arguments
// otherwise, assume command line failure
else
{
// show command line argument requirements
// fct: showCommandLineFormat
showCommandLineFormat();
}
// show program end
// fct: printf
printf("\nSimulator Program End.\n");
// return program success
return 0;
}
/*
Name: clearCmdLineStruct
Process: sets command line structure data to defaults
Booleans to false, fileName to empty string
Function Input/Parameters: pointer to command line structure (CmdLineData *)
Function Output/Parameters: pointer to command line structure (CmdLineData *)
with updated members
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: none
*/
void clearCmdLineStruct(CmdLineData *clDataPtr)
{
// set all struct members to default
clDataPtr->programRunFlag = false;
clDataPtr->configDisplayFlag = false;
clDataPtr->mdDisplayFlag = false;
clDataPtr->runSimFlag = false;
clDataPtr->fileName[0] = NULL_CHAR;
// void function, no return.
}
/*
Name: processCmdLine
Process: checks for at least two arguments,
then sets Booleans depending on command line switches
which can be in any order,
also captures config file name which must be last arugment
Function Input/Parameters: number of arguments (int),
vector of arguments (char **)
Function Output/Parameters: pointer to command line structure (CmdLineData *)
with updated members,
set to default values if failure
to capture arguments
Function Output/Returned: Boolean result of argument capture
true if at least one switch and config file name,
false otherwise
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
bool processCmdLine(int numArgs, char **strVector, CmdLineData *clDataPtr)
{
// initialize function and variables
// initialize structure to defaults
// fct: clearCmdLineStruct
clearCmdLineStruct(clDataPtr);
// initialize success flags to false
bool atLeastOneSwitchFlag = false;
bool correctConfigFileFlag = false;
// initialize first arg index to one
int argIndex = 1;
// iniitialize file variables
int fileStrLen, fileStrSubLoc;
// must have program name, one switch, config file name at minimum
if(numArgs >= MIN_NUM_ARGS)
{
// loop across args (starting at 1) and program run flag
while(argIndex < numArgs)
{
// check for -dc
if(compareString(strVector[argIndex], "-dc") == 0)
{
// set config display flag
clDataPtr->configDisplayFlag = true;
// set at least one switch flag
atLeastOneSwitchFlag = true;
}
// otherwise, check for -dm
else if(compareString(strVector[argIndex], "-dm") == 0)
{
// set metadata display flag
clDataPtr->mdDisplayFlag = true;
// set at least one switch flag
atLeastOneSwitchFlag = true;
}
// otherwise, check for -rs
else if(compareString(strVector[argIndex], "-rs") == 0)
{
// set run simulator flag
clDataPtr->runSimFlag = true;
// set at least one switch flag
atLeastOneSwitchFlag = true;
}
// otherwise, check for file name, ending in .cfg (must be last)
else
{
// find lengths to verify file name
// file name must be last argument, have '.cnf' extension
fileStrLen = getStringLength(strVector[numArgs - 1]);
fileStrSubLoc = findSubString(strVector[numArgs - 1], ".cnf");
// check for file existence and correct file format
if(fileStrSubLoc != SUBSTRING_NOT_FOUND &&
fileStrSubLoc == fileStrLen - LAST_FOUR_LETTERS)
{
// set file name to variable
copyString(clDataPtr->fileName, strVector[numArgs - 1]);
// set success flag to true
correctConfigFileFlag = true;
}
// otherwise, assume bad config file name
else
{
// reset struct, correct config file flag stays false
// fct: clearCmdLineStruct
clearCmdLineStruct(clDataPtr);
}
}
// update arg index
argIndex = argIndex + 1;
}
// end loop across args and program run flag
}
// return verification of at least one switch and file name
return atLeastOneSwitchFlag && correctConfigFileFlag;
}
/*
Name: showCommandLineFormat
Process: displays command line format as assistance to user
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Monitor: data displayed as spec'd
Dependencies: printf
*/
void showCommandLineFormat()
{
// display command line format
// fct: printf
printf("Command Line Format:\n");
printf(" sim_01 [-dc] [-dm] [-rs] <configfile.cnf>\n");
printf(" -dc [optional] displays configuration data\n");
printf(" -dm [optional] displays metadata\n");
printf(" -rs [optional] runs the simulator\n");
printf(" required configfile.cnf\n");
// void function, no return.
}