Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ada: flexible Text_IO File_Type for redirecting output with SET_OUTPUT?

Tags:

ada

I've inherited a project that has two output modes, console and plain-text file. The project uses Ada.Text_IO.SET_OUTPUT to select one or the other.

I want to create a third SET_OUTPUT option, one that can easily re-direct output to a variety of formats other than stdout or a disk file. I'd like the output to be some sort of in-RAM object or "file" so that it can be quickly read by multiple clients. I also need to keep the code portable, so ideally the solution would stick to the standard libraries.

I've tried instantiations of Sequential_IO, but the code base is too large and inconsistent (wrt overloadings and renamings of Text_IO's procedures and whether Text_IO is called by full dot notation) to quickly and reliably replace calls.

I must be uncreative (and I'm certainly new to Ada), but the solution I keep coming to seems overly complex and convoluted--creating a container of Text_IO's File_Type in a memory pool managed at a low level; then SET_OUTPUT to that in-RAM file, from where it can be pushed or pulled to clients.

I hope I'm missing something, and that someone can help me find an simpler way. Thanks in advance.

like image 480
ds_j2 Avatar asked Mar 02 '23 10:03

ds_j2


1 Answers

Text_IO is specifically for files, so there's no portable way to use it to write to memory. The normal way to allow writing to files, memory, or anything else you can define, is to use streams, but that would require replacing most uses of Text_IO to use streams instead. If that's acceptable, then Ada.Text_IO.Text_Streams allows writing to Current_Output as a stream.

like image 82
Jeffrey R. Carter Avatar answered Apr 28 '23 13:04

Jeffrey R. Carter