-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.c
104 lines (87 loc) · 2.48 KB
/
display.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "matrix.h"
#include <stdio.h>
/* display.c: This source file implements the methods used to display
the data that describes the simulated system's state.
Author: Jason Franklin. */
/* declare global data structures */
extern int NUMBER_OF_PROCESSES;
extern int NUMBER_OF_RESOURCES;
extern Vector AVAILABLE;
extern Matrix MAX;
extern Matrix ALLOCATION;
extern Matrix NEED;
/* display_allocation: display the system's allocation matrix */
void display_allocation(void)
{
/* print title */
printf("ALLOCATION:\n");
printf("===========\n");
int i, j;
/* print top row of our table */
printf(" ");
for (i = 0; i < NUMBER_OF_RESOURCES; i++)
printf("| R%-2d ", i);
putchar('\n');
/* print separator */
printf("------");
for (i = 0; i < NUMBER_OF_RESOURCES; i++)
printf("------");
putchar('\n');
/* print rows */
for (i = 0; i < NUMBER_OF_PROCESSES; i++) {
printf("Pr%-2d ", i);
for (j = 0; j < NUMBER_OF_RESOURCES; j++) {
printf("| %-3d ", ALLOCATION[i][j]);
}
putchar('\n');
}
}
/* display_need: display the system's need request matrix */
void display_need(void)
{
/* print title */
printf("NEED:\n");
printf("=====\n");
int i, j;
/* print top row of our table */
printf(" ");
for (i = 0; i < NUMBER_OF_RESOURCES; i++)
printf("| R%-2d ", i);
putchar('\n');
/* print separator */
printf("------");
for (i = 0; i < NUMBER_OF_RESOURCES; i++)
printf("------");
putchar('\n');
/* print rows */
for (i = 0; i < NUMBER_OF_PROCESSES; i++) {
printf("Pr%-2d ", i);
for (j = 0; j < NUMBER_OF_RESOURCES; j++) {
printf("| %-3d ", NEED[i][j]);
}
putchar('\n');
}
}
/* display_available: display the system's available vector */
void display_available(void)
{
/* print title */
printf("AVAILABLE:\n");
printf("==========\n");
/* loop control */
int j;
/* print top row of our table */
for (j = 0; j < NUMBER_OF_RESOURCES - 1; j++)
printf(" R%-2d |", j);
printf(" R%-2d ", j);
putchar('\n');
/* print separator */
for (j = 0; j < NUMBER_OF_RESOURCES; j++)
printf("------");
putchar('\n');
/* print table elements */
for (j = 0; j < NUMBER_OF_RESOURCES - 1; j++)
printf(" %-2d |", AVAILABLE[j]);
printf(" %-2d ", AVAILABLE[j]);
putchar('\n');
}