-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBLPSecure.cpp
60 lines (52 loc) · 1.43 KB
/
BLPSecure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Author: Justin Muskopf
Instructor: Hoffman
Course: CSCE 4550, Fall 2018
Assignment: Project 1
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include "instruction.h"
#include "referencemonitor.h"
int main(int argc, char *argv[])
{
// Improper usage, no file provided
if (argc != 2)
{
std::cout << "USAGE: ./" << argv[0] << "FILENAME\n";
exit(0);
}
// Create reference monitor
ReferenceMonitor refMon;
// Get filename and attempt to open file
char *filename = argv[1];
std::ifstream inputFile(filename);
if (!inputFile.good())
{
std::cout << "Could not open file: " << filename << ". Terminating.\n";
exit(1);
}
// Loop through input file and run instructions
int instructionCount = 0;
for (std::string line; std::getline(inputFile, line); )
{
if (instructionCount && instructionCount % 10 == 0)
{
refMon.printState();
}
// Create an instruction and check for validity / execute
Instruction instruction(line);
if (instruction.isInvalid() || !refMon.executeInstruction(instruction))
{
std::cout << std::left << std::setw(16) << "Bad Instruction";
std::cout << ": " << line << std::endl;
}
instructionCount++;
}
// Final state print
refMon.printState();
return 0;
}