Implement stdin input handler.
This uses a slight hack to figure out when a killable BSC has actually been killed (which I think should probably be a CCSP feature anyway).
This commit is contained in:
parent
f2d3280cee
commit
ac532be667
|
@ -50,12 +50,30 @@ static void tock_tlp_input (Workspace wptr) {
|
||||||
Channel *kill = ProcGetParam (wptr, 1, Channel *);
|
Channel *kill = ProcGetParam (wptr, 1, Channel *);
|
||||||
FILE *in = ProcGetParam (wptr, 2, FILE *);
|
FILE *in = ProcGetParam (wptr, 2, FILE *);
|
||||||
|
|
||||||
// FIXME: Implement using killable BSC
|
while (true) {
|
||||||
|
uint8_t ch;
|
||||||
|
KillableBlockingCallN (wptr, fread, kill, 4, &ch, sizeof ch, 1, in);
|
||||||
|
|
||||||
|
// Check if the call was killed.
|
||||||
|
// FIXME: This is a hack; it should be a proper CCSP function.
|
||||||
|
const word killval = *kill;
|
||||||
|
if (killval == 1 || killval == 2)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ChanOut (wptr, out, &ch, sizeof ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tock_tlp_input_kill (Workspace wptr, Channel *kill) occam_unused;
|
static void tock_tlp_input_kill (Workspace wptr, Channel *kill) occam_unused;
|
||||||
static void tock_tlp_input_kill (Workspace wptr, Channel *kill) {
|
static void tock_tlp_input_kill (Workspace wptr, Channel *kill) {
|
||||||
// FIXME: Implement
|
while (true) {
|
||||||
|
// If KillBlockingCall returns -1, the call hasn't started yet,
|
||||||
|
// so we reschedule and try again. (If tock_tlp_input is
|
||||||
|
// blocked on output we should deadlock anyway.)
|
||||||
|
if (KillBlockingCall (wptr, kill) != -1)
|
||||||
|
break;
|
||||||
|
Reschedule (wptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tock_tlp_output (Workspace wptr) occam_unused;
|
static void tock_tlp_output (Workspace wptr) occam_unused;
|
||||||
|
|
16
testcases/capitalise.occ
Normal file
16
testcases/capitalise.occ
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
PROC main (CHAN OF BYTE in, out)
|
||||||
|
BOOL running:
|
||||||
|
SEQ
|
||||||
|
running := TRUE
|
||||||
|
WHILE running
|
||||||
|
BYTE b:
|
||||||
|
SEQ
|
||||||
|
in ? b
|
||||||
|
IF
|
||||||
|
b = 27 -- ESC
|
||||||
|
running := FALSE
|
||||||
|
(b >= 'a') AND (b <= 'z')
|
||||||
|
out ! b - ('a' - 'A')
|
||||||
|
TRUE
|
||||||
|
out ! b
|
||||||
|
:
|
Loading…
Reference in New Issue
Block a user