-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (60 loc) · 1.49 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
#include "circuit.h"
#include <math.h>
#include <fstream>
#include <utility>
using namespace std;
void usage(const char* exename);
int main(int argc, char **argv)
{
// parsing inputs
if (argc < 2)
{
usage(argv[0]);
}
for (int i = 1; i < argc; ++i)
{
if (argv[i] == string("-h") || argv[i] == string("-help"))
{
usage(argv[0]);
}
else if (argv[i] == string("-topoSort"))
{
if (i + 1 < argc)
{
string inFilename = string(argv[++i]);
Circuit c(inFilename);
c.printTopo();
}
else
{
cout << "option -topoSort requires an additional argument." << endl;
usage(argv[0]);
}
}
else if (argv[i] == string("-simulate"))
{
if (i + 2 < argc)
{
string inFilename = string(argv[++i]);
Circuit c(inFilename);
string inputFile(argv[++i]);
c.simOutputs(inputFile);
}
else
{
cout << "option -simulate requires two additional arguments." << endl;
usage(argv[0]);
}
}
}
return 0;
}
void usage(const char* exename)
{
cout << "Usage: " << exename << " <options> " << endl;
cout << "-h or -help prints out this help message. " << endl;
cout << "-topoSort <inFile> prints a topological ordering of the circuit in <inFile>. " << endl;
cout << "-simulate <inFile> <inputs> simulates the circuit in <inFile> with the inputs in <inputs>." << endl;
cout << endl;
exit(0);
}