Skip to content

Commit

Permalink
FEAT: new flush action for flushing console output stream buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Jul 19, 2022
1 parent 90b9756 commit d7e55e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/boot/actions.reb
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,8 @@ rename: action [
to [port! file! url! block!]
]

flush: action [
{Flush output stream buffer.}
port [port!]
]

4 changes: 4 additions & 0 deletions src/core/p-console.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
Ret_Query_Console(req, D_RET, D_ARG(ARG_QUERY_FIELD), spec);
break;

case A_FLUSH:
OS_DO_DEVICE(req, RDC_FLUSH);
break;

default:
Trap1(RE_NO_PORT_ACTION, Get_Action_Word(action));
}
Expand Down
1 change: 1 addition & 0 deletions src/include/reb-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum {
RDC_MODIFY, // set modes (also get modes)

RDC_CREATE, // create unit target
RDC_FLUSH, // flush output buffers
RDC_DELETE, // delete unit target
RDC_RENAME,
RDC_LOOKUP,
Expand Down
16 changes: 16 additions & 0 deletions src/os/posix/dev-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ static void Close_StdIO_Local(void)
return DR_DONE;
}

/***********************************************************************
**
*/ DEVICE_CMD Flush_IO(REBREQ *req)
/*
** Flushes output buffers.
**
***********************************************************************/
{
fflush(Std_Out);
if (Std_Echo) {
fflush(Std_Echo);
}
return DR_DONE;
}


/***********************************************************************
**
Expand All @@ -376,6 +391,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
Query_IO,
Modify_IO, // modify
Open_Echo, // CREATE used for opening echo file
Flush_IO
};

DEFINE_DEV(Dev_StdIO, "Standard IO", 1, Dev_Cmds, RDC_MAX, 0);
16 changes: 16 additions & 0 deletions src/os/win32/dev-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,21 @@ static void Close_StdIO_Local(void)
return DR_DONE;
}

/***********************************************************************
**
*/ DEVICE_CMD Flush_IO(REBREQ *req)
/*
** Flushes output buffers.
**
***********************************************************************/
{
fflush(NULL); // NULL means all output buffers
if (Std_Echo) {
FlushFileBuffers(Std_Echo);
}
return DR_DONE;
}


/***********************************************************************
**
Expand All @@ -803,6 +818,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
Query_IO,
Modify_IO, // modify
Open_Echo, // CREATE used for opening echo file
Flush_IO
};

DEFINE_DEV(Dev_StdIO, "Standard IO", 1, Dev_Cmds, RDC_MAX, 0);
Expand Down

0 comments on commit d7e55e1

Please sign in to comment.