Sim1 Complete up until Step 5

+- .gitignore
++ Sim01 Files
++ SimTimer stuff
++ SimProgGen
This commit is contained in:
Charles Descamps 2024-01-30 03:07:38 -07:00
parent 08677204ca
commit dc4eca7285
25 changed files with 2059 additions and 0 deletions

246
Sim01/OS_SimDriver.c Normal file
View file

@ -0,0 +1,246 @@
// 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.
}

74
Sim01/OS_SimDriver.h Normal file
View file

@ -0,0 +1,74 @@
#ifndef OS_DRIVER
#define OS_DRIVER
// header files
#include <stdio.h>
#include "StringUtils.h"
#include "configops.h"
#include "metadataops.h"
#include "simulator.h"
// ??? #include "datatypes.h"
// program constants
typedef enum {SUBSTRING_NOT_FOUND = 0, MIN_NUM_ARGS = 3, LAST_FOUR_LETTERS = 4} PRG_CONSTANTS;
typedef struct CmdLineDataStruct
{
bool programRunFlag;
bool configDisplayFlag;
bool mdDisplayFlag;
bool runSimFlag;
char fileName[STD_STR_LEN];
} CmdLineData;
// function prototypes
/*
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);
/*
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);
/*
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();
#endif //OS_DRIVER

73
Sim01/StandardConstants.h Normal file
View file

@ -0,0 +1,73 @@
// Preprocessor directives
#ifndef STANDARD_CONSTANTS_H
#define STANDARD_CONSTANTS_H
// Include Boolean
#include <stdbool.h>
// global constants
// constant for end of c-string null character
#define CARRIAGE_RETURN_CHAR '\r'
//constant for a COLON
#define COLON ':'
//constant for a COMMA
#define COMMA ','
//Constant to print a dash
#define DASH '-'
// highest printable character
#define HIGHEST_PRINTABLE_CHAR '~'
// constant for huge string length
#define HUGE_STR_LEN 256
// lowest printable character
#define LOWEST_PRINTABLE_CHAR ' '
// constant for small string length
#define MIN_STR_LEN 32
// constant for maximum string length
#define MAX_STR_LEN 128
// constant for end of c-string null character
#define NEWLINE_CHAR '\n'
// first non-printable above ASCII
#define DELETE_KEY 127
// constant for end of c-string null character
#define NULL_CHAR '\0'
// columns found in grade sheet before grading columns
#define NUM_BASE_COLS 5
// constant for number of grading frequency bins
#define NUM_FREQUENCY_BINS 10
//Constant for printing a pipe
#define PIPE '|'
//Constant for a period
#define PERIOD '.'
//Constant for PRECISION, 2 digits
#define PRECISION_2 2
//Constant for PRECISION, 4 digits
#define PRECISION_4 4
// constant for space character
#define SPACE ' '
// constant for standard string length
#define STD_STR_LEN 64
// constant for smallest string length
#define TINY_STR_LEN 16
#endif // STANDARD_CONSTANTS

454
Sim01/StringUtils.c Normal file
View file

@ -0,0 +1,454 @@
// header files
#include "StringUtils.h"
// global constants
const int SUBSTRING_NOT_FOUND = 0;
// list of utils:
// string length
// getStringLength
// string copy
// copyString
// string concatenate
// catString
// string compare (<, >, =)
// compareString
// string substring get
// getSubString
// string substring find
// findSubString
// string set to lower
// toLowerCase
// string get to delimiter
// stringDelimiter
// string get to end of line
// stringEOL
// function implementations
/*
Name: catString
Process: concatenates two strings
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: malloc, free, getStringLength
*/
void catString(char *outString, const char *inString)
{
// initialize variables
// set dest index
int destIndex = getStringLength(outString);
// set source str length
int sourceStrLen = getStringLength(inString);
// create temp string pointer
char *tempString;
int sourceIndex = 0;
// copy source string in case of aliasing
tempString = (char *)malloc(sizeof(char) * sourceStrLen);
copyString(tempString, inString);
// loop to end of source string
while(tempString[sourceIndex] != NULL_CHAR)
{
// assign characters to end of destination string
outString[destIndex] = inString[sourceIndex];
// update indices
destIndex = destIndex + 1;
sourceIndex = sourceIndex + 1;
}
// end loop to end of source string
// set temporary end of destination string
outString[destIndex] = NULL_CHAR;
// release memory used for temp string
free(tempString);
// no return, void.
}
/*
Name: compareString
Process: compares two strings as follows:
- if left string is alphabetically greater than the right string,
returns value greater than zero
- if left string is alphabetically less than the right string,
returns value less than zero
- if strings are alphabetically equal but one is longer,
longer one is greater
- otherwise, returns zero
Function input/parameters: c-style strings (char *) [first and second/left&right]
Function output/parameters: NONE
Function output/returned: results as specfifed above (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int compareString(const char *firstString, const char *secondString)
{
// initialize variables
int diff, index = 0;
// loop to end of string (within bounds)
while(firstString[index] != NULL_CHAR && secondString[index] != NULL_CHAR)
{
// get diff of characters
diff = firstString[index] - secondString[index];
// check diff of characters
if(diff != 0)
{
// return diff
return diff;
}
// increment index
index = index + 1;
}
// end loop to end of string
// return difference in length of strings, if needed
return getStringLength(firstString) - getStringLength(secondString);
}
/*
Name: copyString
Process: copies string into new string variable, overwrites destination.
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void copyString(char *outString, const char *inString)
{
// initialize variables
int index = 0;
// check to see if outString is not the same as inString.
if(outString != inString)
{
// loop to end of inString
while(inString[index] != NULL_CHAR)
{
// assign characters to end of outString
outString[index] = inString[index];
// increment index
index = index + 1;
}
// end loop to end of inString
// set end of the outString
outString[index] = NULL_CHAR;
}
// no return, void.
}
/*
Name: findSubString
Process: linear search for given substring within another string
Function input/parameters: c-style test string (char *),
c-style source string (char *)
Function output/parameters: NONE
Function output/returned: index of found substring, or
SUBSTRING_NOT_FOUND constant
if string not found
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int findSubString(const char *testStr, const char *searchSubStr)
{
// initialize variables
// initialize test string length
int testStrLength = getStringLength(testStr);
// initialize master index (location of substring start point)
int masterIndex = 0;
int searchIndex, internalIndex;
// loop across testStr
while(masterIndex < testStrLength)
{
// set internal loop index to current test string index
internalIndex = masterIndex;
// set internal search index to zero
searchIndex = 0;
// loop to end of testStr
// while testStr/searchSubStr characters are the same
while(internalIndex <= testStrLength &&
testStr[internalIndex] == searchSubStr[searchIndex])
{
// increment testStr and substring indices
internalIndex = internalIndex + 1;
searchIndex = searchIndex + 1;
// check for end of substring (search complete)
if(searchSubStr[searchIndex] == NULL_CHAR)
{
// return beginning location of substring
return masterIndex;
}
}
// end while testStr/searchSubStr characters are the same
// increment current location starting index
masterIndex = masterIndex + 1;
}
// end loop across testStr
// return SUBSTRING_NOT_FOUND
return SUBSTRING_NOT_FOUND;
}
/*
Name: getStringConstrained
Process: captures a string from the file stream with various constraints
Function input/parameters: input stream (FILE *),
clears leading non printable (bool),
clears leading space (bool),
stops at non printable (bool),
stops at specified delimiter (char)
will consume the delimiter.
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: fgetc
*/
bool getStringConstrained(FILE *inStream, bool clearLeadingNonPrintable,
bool clearLeadingSpace, bool stopAtNonPrintable,
char delimiter, char *capString)
{
// initialize variables
int intChar = EOF, index = 0;
// initialize output string
capString[index] = NULL_CHAR;
// capture first value in stream using fgetc
intChar = fgetc(inStream);
// loop to clear non-printable or space if indicated
while((((intChar != EOF) &&
(clearLeadingNonPrintable && (intChar < (int)SPACE)))
|| (clearLeadingSpace && (intChar == (int)SPACE))))
{
// get next character in stream using fgetc
intChar = fgetc(inStream);
}
// end loop to clear non-printable or space if indicated
// check for end of file found
if(intChar == EOF)
{
// return false (failed)
return false;
}
// loop to get input from file stream
while(((intChar != EOF && index < MAX_STR_LEN - 1) &&
(stopAtNonPrintable && intChar >= (int)SPACE))
|| ((!stopAtNonPrintable) && (intChar != (char)delimiter)))
{
// [continues if not at end of file and max string len not reached ]
// [AND continues if not printable flag set and characters printable ]
// [OR continues if not printable flag not set ]
// [AND continues if specified delimited is not found ]
// place character in array element
capString[index] = (char)intChar;
// increment array index
index = index + 1;
// set next element to null character
capString[index] = NULL_CHAR;
// get next character as integer using fgetc
intChar = fgetc(inStream);
}
// end loop to get input from file stream
// return success
return true;
}
/*
Name: getStringLength
Process: gets length of string from start to NULL_CHAR ('\0')
Function input/parameters: c-style string (char *)
Function output/parameters: NONE
Function output/returned: length of string (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int getStringLength(const char *stringIn)
{
// define variables
int stringLength = 0, currentCharacter = 0;
// get user input (not needed)
// do calculations
while (currentCharacter < STD_STR_LEN && stringIn[currentCharacter] != NULL_CHAR)
{
// increment string length
stringLength = stringLength + 1;
// increment currentCharacter
currentCharacter = currentCharacter + 1;
}
// display results (not needed)
// return success
return stringLength;
}
/*
Name: getStringToDelimiter
Process: captures a string from the input stream to a specified delimiter.
will consume the delimiter.
Function input/parameters: input stream (FILE *),
stops at specified character
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToDelimiter(FILE *inStream, char delimiter, char *capString)
{
// use getStringConstrained with delimiter to get string
return getStringConstrained(inStream, true, true, true, delimiter, capString);
}
/*
Name: getStringToLineEnd
Process: captures a string from the input stream to the end of the line
Function input/parameters: input file stream (FILE *)
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToLineEnd(FILE *inStream, char *capString)
{
// use getStringConstrained with line end character to get string
return getStringConstrained(inStream, true, true, true, '\n', capString);
}
/*
Name: getSubString
Process: captures sub string within larger string
between two inclusive indices.
returns empty string if either index is out of range,
assumes enough memory in dest string
Function input/parameters: c-style string (char *)
start and end indices (int)
Function output/parameters: c-style destination string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength, malloc, copyString, free
*/
void getSubString(char *destStr, const char *sourceStr,
int startIndex, int endIndex)
{
// initialize variables
// set length of source string using getStringLength
int sourceStrLen = getStringLength(sourceStr);
// initialize the destination index to zero
int destIndex = 0;
// initialize source index to start index (parameter)
int sourceIndex = startIndex;
// create pointer for temp string
char *tempStr;
// check for indices within limits
if(startIndex >= 0 && startIndex <= endIndex && endIndex < sourceStrLen)
{
// create temp string using malloc and copyString
tempStr = (char *)malloc(sourceStrLen + 1);
copyString(tempStr, sourceStr);
// loop across requested substring indices
while(sourceIndex <= endIndex)
{
// assign source character to destination element
destStr[destIndex] = tempStr[sourceIndex];
// increment indices
destIndex = destIndex + 1;
sourceIndex = sourceIndex + 1;
// set temporary end of destination string
destStr[destIndex] = NULL_CHAR;
}
// end loop across requested substring indices
// free temp string
free(tempStr);
}
// no return, void.
}
/*
Name: strToLowerCase
Process: iterates through string, sets any uppercase letter to lowercase
equivalent, does not affect any letter with an upper/lower diff.
Function input/parameters: c-style source string (char *)
Function output/parameters: c-style dest string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: toLowerCase
*/
void strToLowerCase(char *outString, const char *inString)
{
// initialize variables
// get source string length
int sourceStrLen = getStringLength(inString);
// create temporary string pointer
char *tempStr;
int index = 0;
// copy source string in case of aliasing using malloc and copyString
tempStr = (char *)malloc((sizeof(char) * (sourceStrLen + 1)));
copyString(tempStr, inString);
// loop across source string
while(tempStr[index] != NULL_CHAR && index < MAX_STR_LEN)
{
// set individual character to lowercase as needed, assigning back
outString[index] = toLowerCase(tempStr[index]);
// update index
index = index + 1;
// set temporary end of destination string
outString[index] = NULL_CHAR;
}
// end loop across source string
// free temporary string
free(tempStr);
// no return, void.
}
/*
Name: toLowerCase
Process: sets character to lowercase letter if uppercase letter,
returns character
Function input/parameters: character input (char)
Function output/parameters: NONE
Function output/returned: character output (char)
Device input/---: NONE
Device output/---: NONE
Dependencies: none
*/
char toLowerCase(char testChar)
{
// check for uppercase letter
if(testChar >= 'A' && testChar <= 'Z')
{
// return lowercase letter
return testChar - 'A' + 'a';
}
// otherwise, assume not uppercase letter, return unchanged
return testChar;
}
/*
Name: ???
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/

176
Sim01/StringUtils.h Normal file
View file

@ -0,0 +1,176 @@
#ifndef STRINGUTILS
#define STRINGUTILS
// header files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include "StandardConstants.h"
// data structures
// program constants
// function prototypes
/*
Name: catString
Process: concatenates two strings
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: malloc, free, getStringLength
*/
void catString(char *outString, const char *inString);
/*
Name: compareString
Process: compares two strings as follows:
- if left string is alphabetically greater than the right string,
returns value greater than zero
- if left string is alphabetically less than the right string,
returns value less than zero
- if strings are alphabetically equal but one is longer,
longer one is greater
- otherwise, returns zero
Function input/parameters: c-style strings (char *) [first and second/left&right]
Function output/parameters: NONE
Function output/returned: results as specfifed above (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int compareString(const char *firstString, const char *secondString);
/*
Name: copyString
Process: copies string into new string variable, overwrites destination.
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void copyString(char *outString, const char *inString);
/*
Name: findSubString
Process: linear search for given substring within another string
Function input/parameters: c-style test string (char *),
c-style source string (char *)
Function output/parameters: NONE
Function output/returned: index of found substring, or
SUBSTRING_NOT_FOUND constant
if string not found
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int findSubString(const char *testStr, const char *searchSubStr);
/*
Name: getStringConstrained
Process: captures a string from the file stream with various constraints
Function input/parameters: input stream (FILE *),
clears leading non printable (bool),
clears leading space (bool),
stops at non printable (bool),
stops at specified delimiter (char)
will consume the delimiter.
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: fgetc
*/
bool getStringConstrained(FILE *inStream, bool clearLeadingNonPrintable,
bool clearLeadingSpace, bool stopAtNonPrintable,
char delimiter, char *capString);
/*
Name: getStringLength
Process: gets length of string from start to NULL_CHAR ('\0')
Function input/parameters: c-style string (char *)
Function output/parameters: NONE
Function output/returned: length of string (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int getStringLength(const char *stringIn);
/*
Name: getStringToDelimiter
Process: captures a string from the input stream to a specified delimiter.
will consume the delimiter.
Function input/parameters: input stream (FILE *),
stops at specified character
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToDelimiter(FILE *inStream, char delimiter, char *capString);
/*
Name: getStringToLineEnd
Process: captures a string from the input stream to the end of the line
Function input/parameters: input file stream (FILE *)
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToLineEnd(FILE *inStream, char *capString);
/*
Name: getSubString
Process: captures sub string within larger string
between two inclusive indices.
returns empty string if either index is out of range,
assumes enough memory in dest string
Function input/parameters: c-style string (char *)
start and end indices (int)
Function output/parameters: c-style destination string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength, malloc, copyString, free
*/
void getSubString(char *destStr, const char *sourceStr,
int startIndex, int endIndex);
/*
Name: strToLowerCase
Process: iterates through string, sets any uppercase letter to lowercase
equivalent, does not affect any letter with an upper/lower diff.
Function input/parameters: c-style source string (char *)
Function output/parameters: c-style dest string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: toLowerCase
*/
void strToLowerCase(char *outString, const char *inString);
/*
Name: toLowerCase
Process: sets character to lowercase letter if uppercase letter,
returns character
Function input/parameters: character input (char)
Function output/parameters: NONE
Function output/returned: character output (char)
Device input/---: NONE
Device output/---: NONE
Dependencies: none
*/
char toLowerCase(char testChar);
#endif // STRINGUTILS

53
Sim01/configops.c Normal file
View file

@ -0,0 +1,53 @@
#include "configops.h"
#include "StandardConstants.h"
#include "StringUtils.h"
/*
Name: clearConfigData
Process: frees dynamically allocated config data structure
if it has not already been freed
Function Input/Parameters: pointer to config data structure (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: NULL (ConfigDataType *)
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
ConfigDataType *clearConfigData(ConfigDataType *configData)
{
// return NULL (temp)
return NULL;
}
/*
Name: displayConfigData
Process: screen dump/display of all config data
Function Input/Parameters: pointer to config data structure (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Monitor: displayed as spec'd
Dependencies: ???
*/
void displayConfigData(ConfigDataType *configData)
{
// void function, no return.
}
/*
Name: getConfigData
Process: driver function for capturing config data from config file
Function Input/Parameters: file name (const char *)
Function Output/Parameters: pointer to config data pointer (ConfigDataType **)
end/result state message pointer (char *)
Function Output/Returned: Boolean result of data access operation (bool)
Device Input/File: config data uploaded
Device Output/Device: none
Dependencies: ???
*/
bool getConfigData(const char *fileName,
ConfigDataType **configData, char *endStateMsg)
{
// return false (temp)
return false;
}

50
Sim01/configops.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef CONFIGOPS
#define CONFIGOPS
#include "StandardConstants.h"
typedef struct ConfigDataTypeStruct
{
char metaDataFileName[STD_STR_LEN];
} ConfigDataType;
/*
Name: clearConfigData
Process: frees dynamically allocated config data structure
if it has not already been freed
Function Input/Parameters: pointer to config data structure (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: NULL (ConfigDataType *)
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
ConfigDataType *clearConfigData(ConfigDataType *configData);
/*
Name: displayConfigData
Process: screen dump/display of all config data
Function Input/Parameters: pointer to config data structure (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Monitor: displayed as spec'd
Dependencies: ???
*/
void displayConfigData(ConfigDataType *configData);
/*
Name: getConfigData
Process: driver function for capturing config data from config file
Function Input/Parameters: file name (const char *)
Function Output/Parameters: pointer to config data pointer (ConfigDataType **)
end/result state message pointer (char *)
Function Output/Returned: Boolean result of data access operation (bool)
Device Input/File: config data uploaded
Device Output/Device: none
Dependencies: ???
*/
bool getConfigData(const char *fileName,
ConfigDataType **configData, char *endStateMsg);
#endif // CONFIGOPS

56
Sim01/metadataops.c Normal file
View file

@ -0,0 +1,56 @@
#include "metadataops.h"
#include "StandardConstants.h"
#include "StringUtils.h"
/*
Name: clearMetaDataList
Process: recursively traverses list, frees dynamically allocated nodes
Function Input/Parameters: node opcode (const OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: NULL (OpCodeType *)
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
OpCodeType *clearMetaDataList(OpCodeType *localPtr)
{
// return NULL (temp)
return NULL;
}
/*
Name: displayMetaData
Process: data dump/display of all opcode items
Function Input/Parameters: pointer to
head of opcode/metadata list (const OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void displayMetaData(const OpCodeType *localPtr)
{
// void function, no return.
}
/*
Name: getMetaData
Process: main driver function to upload, parse, and store list
of op code commands in a linked list
Function Input/Parameters: file name (const char *)
Function Output/Parameters: ptr to opcode linked list head ptr (OpCodeType **),
result msg of fct state after completion (char *)
Function Output/Returned: Boolean result of operation (bool)
Device Input/File: op code list uploaded
Device Output/Device: none
Dependencies: copyString fopen, getStringToDelimiter, compareString, fclose,
malloc, getOpCommand, updateStartCount, updateEndCount,
clearMetaDataList, free, addNode
*/
bool getMetaData(const char *fileName,
OpCodeType **opCodeDataHead, char *endStateMsg)
{
// return false (temp)
return false;
}

53
Sim01/metadataops.h Normal file
View file

@ -0,0 +1,53 @@
#ifndef METADATAOPS
#define METADATAOPS
#include "StandardConstants.h"
typedef struct OpCodeTypeStruct
{
int temp;
} OpCodeType;
/*
Name: clearMetaDataList
Process: recursively traverses list, frees dynamically allocated nodes
Function Input/Parameters: node opcode (const OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: NULL (OpCodeType *)
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
OpCodeType *clearMetaDataList(OpCodeType *localPtr);
/*
Name: displayMetaData
Process: data dump/display of all opcode items
Function Input/Parameters: pointer to
head of opcode/metadata list (const OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void displayMetaData(const OpCodeType *localPtr);
/*
Name: getMetaData
Process: main driver function to upload, parse, and store list
of op code commands in a linked list
Function Input/Parameters: file name (const char *)
Function Output/Parameters: ptr to opcode linked list head ptr (OpCodeType **),
result msg of fct state after completion (char *)
Function Output/Returned: Boolean result of operation (bool)
Device Input/File: op code list uploaded
Device Output/Device: none
Dependencies: copyString fopen, getStringToDelimiter, compareString, fclose,
malloc, getOpCommand, updateStartCount, updateEndCount,
clearMetaDataList, free, addNode
*/
bool getMetaData(const char *fileName,
OpCodeType **opCodeDataHead, char *endStateMsg);
#endif // METADATAOPS

29
Sim01/sim01_mf Normal file
View file

@ -0,0 +1,29 @@
CC = gcc -Wall -std=c99 -pedantic -g
SOURCES = StringUtils.c simulator.c metadataops.c configops.c OS_SimDriver.c
OBJECTS = OS_SimDriver.o simulator.o metadataops.o configops.o StringUtils.o
all: Simulator
Simulator: $(OBJECTS)
$(CC) $(OBJECTS) -o sim01
StringUtils.o: StringUtils.c
$(CC) -c StringUtils.c -o StringUtils.o
simulator.o: simulator.c
$(CC) -c simulator.c -o simulator.o
metadataops.o: metadataops.c
$(CC) -c metadataops.c -o metadataops.o
configops.o: configops.c
$(CC) -c configops.c -o configops.o
OS_SimDriver.o: OS_SimDriver.c
$(CC) -c OS_SimDriver.c -o OS_SimDriver.o
clean:
rm -f $(OBJECTS) sim01 sim01.out
clean_objects:
rm -f $(OBJECTS)

19
Sim01/simulator.c Normal file
View file

@ -0,0 +1,19 @@
#include "configops.h"
#include "metadataops.h"
#include "StandardConstants.h"
/*
Name: runSim
Process: primary simulation driver
Function Input/Parameters: configuration data (ConfigDataType *),
metadata (OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
{
// void function, no return.
}

19
Sim01/simulator.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef SIMULATORX
#define SIMULATORX
#include "StandardConstants.h"
/*
Name: runSim
Process: primary simulation driver
Function Input/Parameters: configuration data (ConfigDataType *),
metadata (OpCodeType *)
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr);
#endif // SIMULATORX