-
Notifications
You must be signed in to change notification settings - Fork 0
/
hq.h
223 lines (198 loc) · 6.3 KB
/
hq.h
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#ifndef HQ_H
#define HQ_H
#include "child.h"
#include <signal.h>
#include <stdbool.h>
#include <sys/types.h>
/*
* Sets handlers to ignore the interrupt and broken pipe signals and reap
* child process upon receiving the child signal.
*/
void set_handlers();
/*
* Parses the given command string. If the first argument of the command string
* is the name of a command, that command is called.
*/
void parse(char* command);
/*
* Usage: spawn <program> [<arg1>] [<arg2>] ...
*
* Runs the given program in a new process, with the arguments provided, if
* any. Arguments or program names containing spacesmay be quoted in double
* quotes. Standard input to and output from the new proceed can be accessed
* with the send and rcv commands, respectively. The new process's standard
* error is linked to this process's standard error, by default.
*/
void spawn(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the spawn
* command.
*
* The command string is valid if and only if:
* - <program> is present.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_spawn_args(int numArgs, char** args);
/*
* Usage: report [<jobid>]
*
* Reports on the status of the job with the given job ID or all jobs if the
* jobid parameter is not provided.
*/
void report(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the report
* command.
*
* The command string is valid if and only if:
* - <jobid> is either not present or is a complete and valid integer
* corresponding to the job ID of a process created using the spawn command.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_report_args(int numArgs, char** args);
/*
* Usage: signal <jobid> <signum>
*
* Send the signal with the given signum to the job with the given job ID.
*/
void send_signal(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the signal
* command.
*
* The command string is valid if and only if:
* - <jobid> is a complete and valid integer corresponding to a process
* created using the spawn command; and
* - <signum> is a complete and valid integer between 1 and 31, inclusive.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_signal_args(int numArgs, char** args);
/*
* Usage: sleep <seconds>
*
* Causes this process to sleep for the given number of seconds. The specified
* number of seconds can be integral or fractional.
*/
void sleep_hq(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the sleep
* command.
*
* The command string is valid if and only if:
* - <seconds> is a complete and valid non-negative number.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_sleep_args(int numArgs, char** args);
/*
* Usage: send <jobid> <text>
*
* Sends the given text to the job with the given job ID. Strings containing
* spaces must be quoted in double quotes.
*/
void send(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the send
* command.
*
* The command string is valid if and only if:
* - <jobid> is a complete and valid integer corresponding to the job ID of a
* process created using the spawn command; and
* - <text> is present.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_send_args(int numArgs, char** args);
/*
* Usage: rcv <jobid>
*
* Attempts to read one line of text from the job with the given job ID and
* displays it to this process's standard out.
*/
void rcv(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the rcv
* command.
*
* The command string is valid if and only if:
* - <jobid> is a complete and valid integer corresponding to the job ID of a
* process created using the spawn command.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_rcv_args(int numArgs, char** args);
/*
* Usage: eof <jobid>
*
* Closes the pipe connected to the standard input of the job with the given
* job ID, causing it to receive EOF on its next read attempt.
*/
void eof(int numArgs, char** args);
/*
* Determines whether the given command string is valid to execute the eof
* command.
*
* The command string is valid if and only if:
* - <jobid> is a complete and valid integer corresponding to the job ID of a
* process created using the spawn command.
*
* All extraneous arguments are ignored.
*
* Returns true if the command string is valid; false otherwise.
*/
bool validate_eof_args(int numArgs, char** args);
/*
* Usage: cleanup()
*
* Terminates and reaps all child processes spawned by this process by sending
* them the kill signal.
*/
void cleanup();
/*
* Determines whether the given number of arguments is valid, given the
* expected number of arguments.
*
* Returns true if and only if given >= minExpected; false otherwise.
*/
bool validate_num_args(int minExpected, int given);
/*
* Determines whether the given argument represents a complete and valid
* number. If allowFractional is set, the given argument may represent a
* fractional number; otherwise, the argument must represent an integer.
*
* Returns true if and only if arg is a valid and complete numerical argument;
* false otherwise.
*/
bool validate_numerical_arg(char* arg, int allowFractional);
/*
* Determines whether the given integer is a valid job ID. A valid job ID is
* one which corresponds to a child in the given ChildList, created using the
* spawn command.
*
* Returns true if and only if arg represents the job ID of a child of this
* process; false otherwise.
*/
bool validate_jobid(char* jobId);
/*
* Determines whether the given integer is a valid signal number. A signal
* number is valid if and only if it is between 1 and 31, inclusive.
*
* Returns true if and only if arg is a valid signal number; false otherwise.
*/
bool validate_signum(char* signum);
#endif