-
+ D7B2ADC1631ECCE274D68D0BE36D1DF3A3F5BC1DDCAE3ECA0BCF7C67D266183F7B847FBA073EAE5F630474F44B0E58AD2B4781AF534EE02B9127592DABE55C4Fvtools/src/character_io.adb(0 . 0)(1 . 81)
13 package body Character_IO is
14 LM: constant Character := ASCII.LF;
15
16 procedure Get_Line(File : in Character_IO.File_Type;
17 Item : out String;
18 Last : out Natural;
19 New_Line : out Boolean) is
20 C: Character;
21 begin
22 New_Line := False;
23 Last := Item'First - 1;
24 if Last >= Item'Last then
25 return;
26 end if;
27 if Character_IO.End_Of_File(File) then
28 raise Character_IO.End_Error;
29 end if;
30 loop
31 Character_IO.Read(File, C);
32 if C = LM then
33 New_Line := True;
34 return;
35 end if;
36 Last := Last + 1;
37 Item(Last) := C;
38 if Last = Item'Last then
39 return;
40 end if;
41 exit when Character_IO.End_Of_File(File);
42 end loop;
43 end;
44
45 function Get_Line (File : Character_IO.File_Type;
46 New_Line : out Boolean) return String is
47 Buffer : String (1 .. 500);
48 Last : Natural;
49
50 function Get_Rest (S : String) return String is
51 Buffer : String (1 .. S'Length);
52 Last : Natural;
53 begin
54 Get_Line (File, Buffer, Last, New_Line);
55 declare
56 R : constant String := S & Buffer (1 .. Last);
57 begin
58 if Last < Buffer'Last then
59 return R;
60 else
61 return Get_Rest (R);
62 end if;
63 end;
64 end Get_Rest;
65
66 begin
67 Get_Line (File, Buffer, Last, New_Line);
68
69 if Last < Buffer'Last then
70 return Buffer (1 .. Last);
71 else
72 return Get_Rest (Buffer (1 .. Last));
73 end if;
74 end Get_Line;
75
76 function Get_Line(File : in Character_IO.File_Type) return String is
77 New_Line : Boolean;
78 begin
79 return Get_Line(File, New_Line);
80 end Get_Line;
81
82 procedure Put_Line(File : in Character_IO.File_Type;
83 Item : in String;
84 New_Line : Boolean := True) is
85 begin
86 for C of Item loop
87 Character_IO.Write(File, C);
88 end loop;
89 if New_Line then
90 Character_IO.Write(File, LM);
91 end if;
92 end;
93 end;