考虑为您想要的每个非交互式“控制台”创建一个文件:
with Ada.Text_IO;
generic
type Names is (<>);
package Generic_Consoles is
procedure Open_Or_Create;
function File (Name : in Names) return Ada.Text_IO.File_Access;
end Generic_Consoles;
package body Generic_Consoles is
Files : array (Names) of aliased Ada.Text_IO.File_Type;
procedure Open_Or_Create is
use Ada.Text_IO;
begin
for Name in Files'Range loop
begin
Open (File => Files (Name),
Mode => Append_File,
Name => Names'Image (Name));
exception
when others =>
Create (File => Files (Name),
Mode => Append_File,
Name => Names'Image (Name));
end;
end loop;
end Open_Or_Create;
function File (Name : in Names) return Ada.Text_IO.File_Access is
begin
return Files (Name)'Access;
end File;
end Generic_Consoles;
实例化包并调用Open_Or_Create
后,您可以将不同的“控制台”与所有常见的 Ada.Text_IO 输出过程一起使用:
Put_Line (File => Consoles (Parser_Errors),
Item => "Error 42: Could not parse statement.");