#include <iostream>
#include <ostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <algorithm>
// Enumerators
enum META_DATA_CODE { S, A, P, I, O, M };
enum META_DATA_DESCRIPTERS { end, hard, keyboard, printer, monitor, run, start, allocate, mouse, speaker };
/*
Note: "hard" in the descripter type will be for the hard drive. We shall not have any name conflictions
or spacings between words
*/
// External Headers
// #include "MemoryHandling"
// #include "ErrorHandling"
// Public Functions
bool is_conf( const std::string &path );
bool isEmpty( std::ifstream &file );
int main( int argc, char* argv[] )
{
// Initialize Variables and Constants
// File Stream Management
std::ifstream inFile;
std::ofstream outFile;
std::string STRING;
// Error check command line
if( argc != 2 )
{
// This will automatically check for a missing file name
std::cout << "Not enough arguments, please enter a file name" << std::endl;
std::cout << "Program Terminated." << std::endl;
}
// Error checking for file types, mispellings, or not found files
// Attempt to open file
inFile.open( argv[1] );
// File has incorrect extension (e.g. .conf)
// if( extension is NOT .conf and NOT .cnf )
if( !is_conf( argv[1] ) )
{
// Display general error message and terminate program
std::cout << "You have entered a file that does not have the .conf extension." << std::endl;
std::cout << "Program Terminated" << std::endl;
}
// Incorrect file name spelling
// File is not found in the system
else if(inFile.fail() )
{
std::cout << "ERROR: File could not be found. Please check spelling" << std::endl;
std::cout << "Program Terminated." << std::endl;
}
// File is empty
else if( isEmpty( inFile ) )
{
std::cout << "ERROR: File is empty or corrupted!" << std::endl;
std::cout << "Program Terminated." << std::endl;
}
// File was correctly entered within specifications
else
{
std::cout << argv[1] << std::endl;
std::cout << "File Successfully opened. Please wait." << std::endl;
while(!inFile.eof())
{
getline( inFile, STRING );
std::cout << STRING << std::endl;
}
}
return 0;
}
// Function Implementations
// This function is to check within the file name that it has the matching
// Extension of .conf before even reading the file.
bool is_conf( const std::string &path )
{
std::string isConfExt = path.substr(path.length() - 5);
return isConfExt == ".conf";
}
// This function checks if the file opened is empty
// Terminate program if the file is empty or corrupted
bool isEmpty( std::ifstream &file )
{
bool isempty = false;
file.seekg(0, std::ios::end);
size_t size = file.tellg();
if( size == 0 )
{
isempty = true;
}
return isempty;
}
/*
Start Simulator Configuration File
Version/Phase: 1.0
File Path: test_1a.mdf
Processor cycle time (msec): 10
Monitor display time (msec): 25
Hard drive cycle time (msec): 50
Printer cycle time (msec): 500
Keyboard cycle time (msec): 1000
Memory cycle time (msec): 35
Mouse cycle time (msec): 20
Speaker cycle time (msec): 10
Log: Log to Both
Log File Path: output/output_1.out
End Simulator Configuration File
*/