CS480-Projects/Sim01/configops.c
cdez e19542c060 Mostly Completed Step 5.
+- configops.c/h
+- metadataops.c/h
2024-01-30 23:15:13 -07:00

289 lines
No EOL
10 KiB
C

#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)
{
// initialize function and variables
// check that config data pointer is not null
// free data structure memory
// fct: free
// set config pointer to NULL
// set config data pointer to null
return NULL;
}
/*
Name: configCodeToString
Process: utility fct converts configuration code numbers to string they represent
Function Input/Parameters: configuration code (int)
Function Output/Parameters: resulting output string (char *)
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: copyString
*/
void configCodeToString(int code, char *outString)
{
// define array with eight items, and short (10) lengths
// copy string to return parameter
// fct: copyString
// void function, no return.
}
/*
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)
{
// initialize function and variables
// print lines of display for all member values
// fct: printf, codeToString
// 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: copyString, fopen, getStringToDelimiter, compareString, fclose,
malloc, free, stripTrailingSpaces, getDataLineCode, fscanf,
setStrToLowerCase, valueInRange, getCpuSchedCode, getLogToCode
*/
bool getConfigData(const char *fileName,
ConfigDataType **configData, char *endStateMsg)
{
// initialize function and variables
// set constant number of data lines
// set read only constant
// create pointer for data input
// declare other variables
// set endStateMsg to success
// fct: copyString
// initialize config data pointer in case of return error
// open file
// fct: fopen
// check for file open failure
// set end state message to config file access error
// fct: copyString
// return file access error
// get first line, check for failure
// fct: getStringToDelimiter, compareString
// close file access
// fct: fclose
// set end state message to corrupt leader line error
// fct: copyString
// return corrupt file data
// create temporary pointer to configuration data structure
// fct: malloc
// loop to end of config data items
// get line leader, check for failure
// fct: getStringToDelimiter
// free temp struct memory
// fct: free
// close file access
// fct: fclose
// set end state message to line capture failure
// fct: copyString
// return incomplete file error
// strip trailing spaces of config leader lines
// for use in other fcts
// fct: stripTrailingSpaces
// find correct data line code number from string
// fct: getDataLineCode
// check for data line found
// get data value
// check for version number (double value)
// get version number
// fct: fscanf
// otherwise, check for metaData, fileNames,
// CPU Scheduling names, or memory display setting (strings)
// get string input
// fct: fscanf
// set string to lower case for testing in valueInRange
// fct: setStrToLowerCase
// otherwise, assume integer data
// get integer input
// check for data value in range
// fct: valueInRange
// assign to data pointer depending on config item
// (all config line possibilities)
// fct: copyString, getCpuSchedCode,
// compareString, getLogToCode, as needed
// otherwise, assume data value not in range
// free temp struct memory
// fct: free
// close file access
// fct: fclose
// set end state message to configuration data out of range
// fct: copyString
// return data out of range
// otherwise, check for data line not found
// free temp struct memory
// fct: free
// close file access
// fct: fclose
// set end state message to configuration corrupt prompt error
// fct: copyString
// return corrupt config file code
// increment line counter
// end loop to end of config data items
// acquire end of sim config string
// fct: getStringToDelimiter, compareString
// free temp struct memory
// fct: free
// close file access
// fct: fclose
// set end state message to corrupt configuration end line
// fct: copyString
// return corrupt file data
// test for "file only" output so memory diagnostics do not display
// assign temp ptr to parameter return ptr
// close file access
// fct: fclose
// return no error code
// return false (temp)
return false;
}
/*
Name: getDataLineCode
Process: converts leader line string to configuration code value
(processes all config file leader lines)
Function Input/Parameters: config leader line string (const char *)
Function Output/Parameters: none
Function Output/Returned: configuration code value (ConfigCodeMessages)
Device Input/Device: none
Device Output/Device: none
Dependencies: compareString
*/
ConfigCodeMessages getDataLineCode(const char *dataBuffer)
{
// iniitalize function and variables
// return appropriate code depending on prompt string provided
// fct: compareString
// return corrupt leader line error code
// return zero (temp)
return 0;
}
/*
Name: getLogToCode
Process: ???
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
ConfigDataCodes getLogToCode(const char *lowerCaseLogToStr)
{
// initialize function and variables
// set default to log to monitor
// check for BOTH
// fct: compareString
// set return value to both code
// check for FILE
// fct: compareString
// set return value to file code
// return selected code
// return zero (temp)
return 0;
}
/*
Name: stripTrailingSpaces
Process: removes trailing spaces from input config leader lines
Function Input/Parameters: config leader line string (char *)
Function Output/Parameters: updates config leader line string (char *)
Function Output/Returned: none
Device Input/Device: none
Device Output/Device: none
Dependencies: getStringLength
*/
void stripTrailingSpaces(char *str)
{
// initialize index to length of string - 1 to get highest array index
// loop while space is found at the end of string
// set element to NULL_CHAR
// decrement index
// end loop from end of string
// void function, no return.
}
/*
Name: valueInRange
Process: checks for config data values in range, including str values
Function Input/Parameters: line code number for specific config value (int),
integer value, as needed (int),
double value, as needed (double),
string value, as needed (const char *)
Function Output/Parameters: none
Function Output/Returned: Boolean result of the range test (bool)
Device Input/Device: none
Device Output/Device: none
Dependencies: compareString
*/
bool valueInRange(int lineCode, int intVal, double doubleVal,
const char *lowerCaseStringVal)
{
// initialize function and variables
// set result to true, all tests are to find false
// use line code to identify prompt line
// for version code
// check if limits of version code are exceeded
// set bool to false
// break
// for cpu scheduling code
// check for not finding one of the scheduling strings
// fct: compareString
// set bool to false
// break
// for quantum cycles
// check for quantum cycles limits exceeded
// set bool to false
// for memory display
// check for not finding either on or off
// fct: compareString
// set bool to false
// break
// for memory available
// check for memory limits exceeded
// set bool to false
// break
// check for process cycles
// check for process cycles limits exceeded
// set bool to false
// break
// check for log to operation
// check for not finding one of the log to strings
// fct: compareString
// set bool to false
// break
// return result of limits analysis
return false;
}