| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | with H2.Pool; | 
					
						
							| 
									
										
										
										
											2014-01-10 14:54:46 +00:00
										 |  |  | with Ada.Unchecked_Conversion; | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-14 14:22:06 +00:00
										 |  |  | with Ada.Text_IO; -- for debugging
 | 
					
						
							| 
									
										
										
										
											2014-05-30 03:15:40 +00:00
										 |  |  | with Ada.Exceptions; | 
					
						
							| 
									
										
										
										
											2014-01-14 14:22:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | package body Wide_Stream is | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | 	package Utf8 renames H2.Wide.Utf8; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	use type S.Object_Size; | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | 	------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	procedure Open (Stream: in out String_Input_Stream_Record) is | 
					
						
							|  |  |  | 	begin | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | Ada.Text_IO.Put_Line ("****** OPEN WIDE STRING STREAM ******"); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 		Stream.Pos := 0; | 
					
						
							|  |  |  | 	end Open; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Close (Stream: in out String_Input_Stream_Record) is | 
					
						
							|  |  |  | 	begin | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | Ada.Text_IO.Put_Line ("****** CLOSE WIDE STRING STREAM ******"); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 		Stream.Pos := Stream.Str'Last; | 
					
						
							|  |  |  | 	end Close; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Read (Stream: in out String_Input_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	                Data:   out    S.Object_Character_Array; | 
					
						
							|  |  |  | 	                Last:   out    S.Object_Size) is | 
					
						
							|  |  |  | 		Avail: S.Object_Size; | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	begin | 
					
						
							|  |  |  | 		Avail := Stream.Str'Last - Stream.Pos; | 
					
						
							|  |  |  | 		if Avail <= 0 then | 
					
						
							|  |  |  | 			-- EOF
 | 
					
						
							|  |  |  | 			Last := Data'First - 1; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			if Avail > Data'Length then | 
					
						
							|  |  |  | 				Avail := Data'Length; | 
					
						
							|  |  |  | 			end if; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			Data(Data'First .. Avail) := Stream.Str(Stream.Pos + 1..Stream.Pos + Avail); | 
					
						
							|  |  |  | 			Stream.Pos := Stream.Pos + Avail; | 
					
						
							|  |  |  | 			Last := Data'First + Avail - 1; | 
					
						
							|  |  |  | 		end if; | 
					
						
							|  |  |  | 	end Read; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Write (Stream: in out String_Input_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	                 Data:   out    S.Object_Character_Array; | 
					
						
							|  |  |  | 	                 Last:   out    S.Object_Size) is | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	begin | 
					
						
							|  |  |  | 		--raise S.Stream_Error;
 | 
					
						
							|  |  |  | 		Last := Data'First - 1; | 
					
						
							|  |  |  | 	end Write; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Open (Stream: in out File_Stream_Record) is | 
					
						
							|  |  |  | 	begin | 
					
						
							| 
									
										
										
										
											2014-05-30 03:15:40 +00:00
										 |  |  | Ada.Text_IO.Put_Line (">>>>> OPEN WIDE FILE STREAM <<<<< " & Standard.String(Utf8.From_Unicode_String(Utf8.Unicode_String(Stream.Name.all)))); | 
					
						
							| 
									
										
										
										
											2014-01-14 14:22:06 +00:00
										 |  |  | 		--Ada.Wide_Text_IO.Open (Stream.Handle, Ada.Wide_Text_IO.In_File, Ada.Characters.Conversions.To_String(Standard.Wide_String(Stream.Name.all)));
 | 
					
						
							| 
									
										
										
										
											2014-05-30 03:15:40 +00:00
										 |  |  | 		Ada.Wide_Text_IO.Open (Stream.Handle, Ada.Wide_Text_IO.In_File, Standard.String(Utf8.From_Unicode_String(Utf8.Unicode_String(Stream.Name.all)))); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	end Open; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Close (Stream: in out File_Stream_Record) is | 
					
						
							| 
									
										
										
										
											2014-01-10 14:54:46 +00:00
										 |  |  | 		subtype Wide_String is Standard.Wide_String(1 .. Standard.Natural(Stream.Name'Length)); | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 		function To_Wide_String is new Ada.Unchecked_Conversion (S.Object_Character_Array, Wide_String); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	begin | 
					
						
							| 
									
										
										
										
											2014-01-14 14:22:06 +00:00
										 |  |  | --Ada.Wide_Text_IO.Put_Line (">>>>> CLOSE File STREAM <<<<< " & Standard.Wide_String(Stream.Name.all));
 | 
					
						
							| 
									
										
										
										
											2014-05-30 03:15:40 +00:00
										 |  |  | Ada.Text_IO.Put_Line (">>>>> CLOSE WIDE FILE STREAM <<<<< " & Standard.String(Utf8.From_Unicode_String(Utf8.Unicode_String(Stream.Name.all)))); | 
					
						
							|  |  |  | begin | 
					
						
							|  |  |  | 	ada.wide_text_io.put_line (">> " & Standard.Wide_String(Utf8.To_Unicode_String(Utf8.From_Unicode_String(Utf8.Unicode_String(Stream.Name.all))))); | 
					
						
							|  |  |  | exception | 
					
						
							|  |  |  | 	when Ex: others => | 
					
						
							|  |  |  | 		ada.text_io.put_line ("fuck - " & Ada.Exceptions.Exception_Name(Ex) & Ada.Exceptions.Exception_Information(Ex)); | 
					
						
							|  |  |  | end; | 
					
						
							|  |  |  | ada.text_io.put_line (">>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 		Ada.Wide_Text_IO.Close (Stream.Handle); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	end Close; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Read (Stream: in out File_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	                Data:   out    S.Object_Character_Array; | 
					
						
							|  |  |  | 	                Last:   out    S.Object_Size) is | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	begin | 
					
						
							|  |  |  | 		for I in Data'First .. Data'Last loop | 
					
						
							|  |  |  | 			begin | 
					
						
							| 
									
										
										
										
											2014-01-14 14:22:06 +00:00
										 |  |  | 				if Ada.Wide_Text_IO.End_Of_File (Stream.Handle) then | 
					
						
							|  |  |  | 					Last := I - 1; | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				end if; | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 				Ada.Wide_Text_IO.Get_Immediate (Stream.Handle, Data(I)); | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 			exception | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 				when Ada.Wide_Text_IO.End_Error => | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 					Last := I - 1; | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				-- other exceptions must be just raised to indicate errors
 | 
					
						
							|  |  |  | 			end; | 
					
						
							|  |  |  | 		end loop; | 
					
						
							|  |  |  | 		Last := Data'Last; | 
					
						
							|  |  |  | 	end Read; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Write (Stream: in out File_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	                 Data:   out    S.Object_Character_Array; | 
					
						
							|  |  |  | 	                 Last:   out    S.Object_Size) is | 
					
						
							| 
									
										
										
										
											2013-12-28 16:52:31 +00:00
										 |  |  | 	begin | 
					
						
							|  |  |  | 		--raise S.Stream_Error;
 | 
					
						
							|  |  |  | 		Last := Data'First - 1; | 
					
						
							|  |  |  | 	end Write; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 	procedure Allocate_Stream (Interp: in out S.Interpreter_Record; | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 	                           Name:   access S.Object_Character_Array; | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 	                           Result: out    S.Stream_Pointer) is | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | 		subtype FSR is File_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 		type FSP is access all FSR; | 
					
						
							|  |  |  | 		package P is new H2.Pool (FSR, FSP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		X: FSP; | 
					
						
							|  |  |  | 		for X'Address use Result'Address; | 
					
						
							|  |  |  | 		pragma Import (Ada, X); | 
					
						
							|  |  |  | 	begin | 
					
						
							|  |  |  | 		X := P.Allocate (S.Get_Storage_Pool(Interp)); | 
					
						
							| 
									
										
										
										
											2014-01-16 16:52:18 +00:00
										 |  |  | 		X.Name := S.Constant_Object_Character_Array_Pointer(Name); | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 	end Allocate_Stream; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	procedure Deallocate_Stream (Interp: in out S.Interpreter_Record; | 
					
						
							|  |  |  | 	                             Source: in out S.Stream_Pointer) is | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | 		subtype FSR is File_Stream_Record; | 
					
						
							| 
									
										
										
										
											2014-01-01 14:07:03 +00:00
										 |  |  | 		type FSP is access all FSR; | 
					
						
							|  |  |  | 		package P is new H2.Pool (FSR, FSP); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		X: FSP; | 
					
						
							|  |  |  | 		for X'Address use Source'Address; | 
					
						
							|  |  |  | 		pragma Import (Ada, X); | 
					
						
							|  |  |  | 	begin | 
					
						
							|  |  |  | 		P.Deallocate (X, S.Get_Storage_Pool(Interp)); | 
					
						
							|  |  |  | 	end Deallocate_Stream; | 
					
						
							| 
									
										
										
										
											2014-03-26 14:28:41 +00:00
										 |  |  | end Wide_Stream; |