-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shrmem_test.cpp
67 lines (60 loc) · 1.36 KB
/
Shrmem_test.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
#include<iostream>
#include "Shrmem.h"
using namespace std;
int main(int argc, char ** argv)
{
int block_num;
int block_size;
cout << "Number of blocks: ";
cin >> block_num;
cout << "Block sizes: ";
cin >> block_size;
Shrmem s(block_num, block_size);
int mailbox;
string input;
string temp = "";
do
{
cout << "> ";
input = "";
while(!cin.eof())
{
getline(cin, temp);
if(temp.length() == 1)
{
input = temp;
break;
}
else if(temp == "exit")
return 0;
else
input += temp + "\n";
}
cin.clear();
mailbox = input[0] -'0';
if(input.length() == 0)
continue;
if(!(mailbox >= 0 && mailbox < 10))
{
cout << "Mailbox must be between 0 and 10" << endl;
continue;
}
if(input.length() == 1)
{
cout << "Reading message stored in mailbox " << mailbox << endl;
cout << "Stored message: " << s[mailbox].read() << endl;
}
else if(input.length() > 1)
{
input = input.substr(1);
cout << "Writing message: " << input << " in mailbox " << mailbox << endl;
s[mailbox].write(input);
}
else
{
cout << "No args :(" << endl;
}
}
while(input != "exit");
return 0;
}