Skip to content

Commit d7e55e1

Browse files
committed
FEAT: new flush action for flushing console output stream buffers
1 parent 90b9756 commit d7e55e1

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/boot/actions.reb

+5
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,8 @@ rename: action [
473473
to [port! file! url! block!]
474474
]
475475

476+
flush: action [
477+
{Flush output stream buffer.}
478+
port [port!]
479+
]
480+

src/core/p-console.c

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@
156156
Ret_Query_Console(req, D_RET, D_ARG(ARG_QUERY_FIELD), spec);
157157
break;
158158

159+
case A_FLUSH:
160+
OS_DO_DEVICE(req, RDC_FLUSH);
161+
break;
162+
159163
default:
160164
Trap1(RE_NO_PORT_ACTION, Get_Action_Word(action));
161165
}

src/include/reb-device.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ enum {
6464
RDC_MODIFY, // set modes (also get modes)
6565

6666
RDC_CREATE, // create unit target
67+
RDC_FLUSH, // flush output buffers
6768
RDC_DELETE, // delete unit target
6869
RDC_RENAME,
6970
RDC_LOOKUP,

src/os/posix/dev-stdio.c

+16
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,21 @@ static void Close_StdIO_Local(void)
356356
return DR_DONE;
357357
}
358358

359+
/***********************************************************************
360+
**
361+
*/ DEVICE_CMD Flush_IO(REBREQ *req)
362+
/*
363+
** Flushes output buffers.
364+
**
365+
***********************************************************************/
366+
{
367+
fflush(Std_Out);
368+
if (Std_Echo) {
369+
fflush(Std_Echo);
370+
}
371+
return DR_DONE;
372+
}
373+
359374

360375
/***********************************************************************
361376
**
@@ -376,6 +391,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
376391
Query_IO,
377392
Modify_IO, // modify
378393
Open_Echo, // CREATE used for opening echo file
394+
Flush_IO
379395
};
380396

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

src/os/win32/dev-stdio.c

+16
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,21 @@ static void Close_StdIO_Local(void)
783783
return DR_DONE;
784784
}
785785

786+
/***********************************************************************
787+
**
788+
*/ DEVICE_CMD Flush_IO(REBREQ *req)
789+
/*
790+
** Flushes output buffers.
791+
**
792+
***********************************************************************/
793+
{
794+
fflush(NULL); // NULL means all output buffers
795+
if (Std_Echo) {
796+
FlushFileBuffers(Std_Echo);
797+
}
798+
return DR_DONE;
799+
}
800+
786801

787802
/***********************************************************************
788803
**
@@ -803,6 +818,7 @@ static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] =
803818
Query_IO,
804819
Modify_IO, // modify
805820
Open_Echo, // CREATE used for opening echo file
821+
Flush_IO
806822
};
807823

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

0 commit comments

Comments
 (0)