2014-01-10 14:54:46 +00:00
|
|
|
|
2014-03-26 14:28:41 +00:00
|
|
|
with H2.Wide;
|
|
|
|
with H2.Slim;
|
2013-12-28 16:52:31 +00:00
|
|
|
with H2.Pool;
|
2013-12-10 16:14:06 +00:00
|
|
|
with Storage;
|
2014-03-26 14:28:41 +00:00
|
|
|
with Slim_Stream;
|
|
|
|
with Wide_Stream;
|
2013-12-10 16:14:06 +00:00
|
|
|
with Ada.Text_IO;
|
2014-06-06 16:44:45 +00:00
|
|
|
with Ada.Wide_Text_IO;
|
2013-12-28 16:52:31 +00:00
|
|
|
with Ada.Unchecked_Deallocation;
|
2014-06-17 15:23:35 +00:00
|
|
|
with Ada.Exceptions;
|
2014-06-04 17:15:52 +00:00
|
|
|
|
2014-06-05 15:26:37 +00:00
|
|
|
with H2.OS;
|
2014-06-04 17:15:52 +00:00
|
|
|
with H2.IO;
|
2014-06-05 15:26:37 +00:00
|
|
|
use type H2.System_Length;
|
2013-12-10 16:14:06 +00:00
|
|
|
|
2014-05-30 03:15:40 +00:00
|
|
|
with Interfaces.C;
|
2013-12-10 16:14:06 +00:00
|
|
|
|
2014-05-30 03:15:40 +00:00
|
|
|
procedure scheme is
|
|
|
|
package Stream renames Wide_Stream;
|
|
|
|
package Scheme renames H2.Wide.Scheme;
|
|
|
|
--package Stream renames Slim_Stream;
|
|
|
|
--package Scheme renames H2.Slim.Scheme;
|
2014-06-02 15:25:42 +00:00
|
|
|
|
2013-12-10 16:14:06 +00:00
|
|
|
Pool: aliased Storage.Global_Pool;
|
2014-03-26 14:28:41 +00:00
|
|
|
SI: Scheme.Interpreter_Record;
|
2013-12-10 16:14:06 +00:00
|
|
|
|
2014-03-26 14:28:41 +00:00
|
|
|
I: Scheme.Object_Pointer;
|
|
|
|
O: Scheme.Object_Pointer;
|
2013-12-28 16:52:31 +00:00
|
|
|
|
|
|
|
--String: aliased S.Object_String := "(car '(1 2 3))";
|
2014-03-26 14:28:41 +00:00
|
|
|
String: aliased constant Scheme.Object_Character_Array := "((lambda (x y) (+ x y)) 9 7)";
|
2013-12-28 16:52:31 +00:00
|
|
|
String_Stream: Stream.String_Input_Stream_Record (String'Unchecked_Access);
|
|
|
|
--String_Stream: Stream.String_Input_Stream_Record := (Len => String'Length, Str => String, Pos => 0);
|
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
File_Name: aliased Scheme.Object_Character_Array := "test.adb";
|
|
|
|
--File_Name: aliased constant Scheme.Object_Character_Array := "시험.scm";
|
2013-12-28 16:52:31 +00:00
|
|
|
--File_Stream: Stream.File_Stream_Record (File_Name'Unchecked_Access);
|
|
|
|
--File_Stream: Stream.File_Stream_Record := (Name => File_Name'Unchecked_Access);
|
|
|
|
File_Stream: Stream.File_Stream_Record;
|
|
|
|
|
2014-03-09 18:01:38 +00:00
|
|
|
--procedure h2init;
|
|
|
|
--pragma Import (C, h2init, "h2init");
|
|
|
|
|
2013-12-10 16:14:06 +00:00
|
|
|
begin
|
2014-03-09 18:01:38 +00:00
|
|
|
--h2init;
|
2013-12-10 16:14:06 +00:00
|
|
|
|
2014-05-30 03:15:40 +00:00
|
|
|
declare
|
2014-06-05 15:26:37 +00:00
|
|
|
package OS is new H2.OS (
|
2014-05-30 03:15:40 +00:00
|
|
|
H2.Slim.Character,
|
|
|
|
H2.Wide.Character,
|
|
|
|
H2.Slim.String,
|
|
|
|
H2.Wide.String,
|
|
|
|
H2.Wide.Utf8.To_Unicode_String,
|
|
|
|
H2.Wide.Utf8.From_Unicode_String);
|
2014-06-05 15:26:37 +00:00
|
|
|
package File renames OS.File;
|
2014-05-30 03:15:40 +00:00
|
|
|
|
2014-06-04 17:15:52 +00:00
|
|
|
F: File.File_Pointer;
|
|
|
|
FL: File.Flag_Record;
|
2014-06-05 15:26:37 +00:00
|
|
|
Length: H2.System_Length;
|
2014-06-04 17:15:52 +00:00
|
|
|
Buffer: H2.System_Byte_Array (50 .. 100);
|
2014-05-30 03:15:40 +00:00
|
|
|
begin
|
2014-06-05 15:26:37 +00:00
|
|
|
--OS.File.Set_Flag_Bits (FL, OS.File.FLAG_WRITE);
|
2014-06-04 17:15:52 +00:00
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_READ);
|
|
|
|
File.Open (F, H2.Wide.String'("/etc/passwd"), FL);
|
2014-06-05 15:26:37 +00:00
|
|
|
File.Read (F, Buffer, Length);
|
2014-06-04 17:15:52 +00:00
|
|
|
File.Close (F);
|
|
|
|
|
2014-06-05 15:26:37 +00:00
|
|
|
File.Write (OS.File.Get_Stdout, Buffer(Buffer'First .. Buffer'First + Length - 1), Length);
|
2014-05-30 03:15:40 +00:00
|
|
|
end;
|
|
|
|
|
2014-06-04 17:15:52 +00:00
|
|
|
declare
|
|
|
|
package IO is new H2.IO (
|
|
|
|
H2.Slim.Character,
|
|
|
|
H2.Wide.Character,
|
|
|
|
H2.Slim.String,
|
|
|
|
H2.Wide.String,
|
|
|
|
H2.Wide.Utf8.To_Unicode_String,
|
2014-06-05 15:26:37 +00:00
|
|
|
H2.Wide.Utf8.From_Unicode_String,
|
|
|
|
H2.Wide.Utf8.Sequence_Length);
|
2014-06-04 17:15:52 +00:00
|
|
|
|
|
|
|
package File renames IO.File;
|
|
|
|
|
2014-06-06 16:44:45 +00:00
|
|
|
F, F2: File.File_Record;
|
2014-06-04 17:15:52 +00:00
|
|
|
FL: File.Flag_Record;
|
2014-06-06 16:44:45 +00:00
|
|
|
Buffer: H2.Slim.String (1 .. 200);
|
2014-06-17 15:23:35 +00:00
|
|
|
BufferW: H2.Wide.String (1 .. 27);
|
2014-06-06 16:44:45 +00:00
|
|
|
IL, OL: H2.System_Length;
|
2014-06-19 14:13:19 +00:00
|
|
|
Option: File.Option_Record;
|
2014-06-04 17:15:52 +00:00
|
|
|
begin
|
2014-06-05 15:26:37 +00:00
|
|
|
--File.Open (F, H2.Slim.String'("/etc/passwd"), FL);
|
|
|
|
--File.Read (F, Buffer, Length);
|
|
|
|
--Ada.Text_IO.PUt_Line (Standard.String(Buffer(Buffer'First .. Buffer'First + Length - 1)));
|
|
|
|
|
|
|
|
--File.Read (F, Buffer, Length);
|
2014-06-06 16:44:45 +00:00
|
|
|
--Ada.Text_IO.PUt (Standard.String(Buffer(Buffer'First .. Buffer'First + Length - 1)));
|
2014-06-05 15:26:37 +00:00
|
|
|
--File.Close (F);
|
|
|
|
|
|
|
|
ada.text_io.put_line ("------------------");
|
2014-06-17 15:23:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
--Stdout.Get_Line (..
|
|
|
|
--Stdout.Print ("-----------------");
|
|
|
|
--Stdout.Print_Line ("-------------------");
|
|
|
|
|
2014-06-06 16:44:45 +00:00
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_READ);
|
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_NONBLOCK);
|
|
|
|
File.Open (F, H2.Slim.String'("/tmp/xxx"), FL);
|
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
--Option := File.Get_Option(F2);
|
2014-06-06 16:44:45 +00:00
|
|
|
File.Clear_Flag_Bits (FL, FL.Bits);
|
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_WRITE);
|
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_CREATE);
|
|
|
|
File.Set_Flag_Bits (FL, File.FLAG_TRUNCATE);
|
|
|
|
File.Open (F2, H2.Wide.String'("/tmp/yyy"), FL);
|
2014-06-21 16:31:49 +00:00
|
|
|
|
|
|
|
File.Set_Option_Bits (Option, File.Option_CRLF_IN);
|
|
|
|
--File.Set_Option_Bits (Option, File.Option_CRLF_OUT);
|
|
|
|
--Option.LF := IO.Ascii.Code.Colon;
|
2014-06-19 14:13:19 +00:00
|
|
|
File.Set_Option (F2, Option);
|
2014-06-21 16:31:49 +00:00
|
|
|
File.Set_Option (F, Option);
|
2014-06-17 15:23:35 +00:00
|
|
|
|
2014-06-05 15:26:37 +00:00
|
|
|
loop
|
2014-06-17 15:23:35 +00:00
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
--File.Get_Line (F, Buffer, IL);
|
|
|
|
File.Get_Line (F, BufferW, IL);
|
2014-06-17 15:23:35 +00:00
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
--ada.text_io.put_line (standard.string(buffer(1..il)));
|
2014-06-19 14:13:19 +00:00
|
|
|
--ada.wide_text_io.put_line (standard.wide_string(bufferw(1..il)));
|
2014-06-06 16:44:45 +00:00
|
|
|
--File.Read (F, BufferW, IL);
|
|
|
|
exit when IL <= 0;
|
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
--File.Put_Line (F2, Buffer(Buffer'First .. Buffer'First + IL - 1), OL);
|
|
|
|
File.Put_Line (F2, BufferW(Buffer'First .. Buffer'First + IL - 1), OL);
|
2014-06-06 16:44:45 +00:00
|
|
|
pragma Assert (IL = OL);
|
|
|
|
|
|
|
|
--Ada.Text_IO.PUt (Standard.String(Buffer(Buffer'First .. Buffer'First + IL - 1)));
|
|
|
|
--Ada.Wide_Text_IO.Put_Line (Standard.Wide_String(BufferW(BufferW'First .. BufferW'First + IL - 1)));
|
2014-06-05 15:26:37 +00:00
|
|
|
end loop;
|
|
|
|
|
2014-06-21 16:31:49 +00:00
|
|
|
--File.Write (F2, H2.Wide.String'("나는 피리부는 사나이 정말로 멋있는 사나이"), OL);
|
|
|
|
--File.Write_Line (F2, H2.Wide.String'("이세상에 문디없어면 무슨재미로 너도 나도 만세."), OL);
|
|
|
|
--File.Write_Line (F2, H2.Wide.String'("이세상에 for the first time 우하."), OL);
|
|
|
|
--File.Write_Line (F2, H2.Wide.String'(""), OL);
|
2014-06-06 16:44:45 +00:00
|
|
|
File.Close (F2);
|
2014-06-04 17:15:52 +00:00
|
|
|
File.Close (F);
|
2014-06-17 15:23:35 +00:00
|
|
|
|
|
|
|
exception
|
|
|
|
when Error: others =>
|
|
|
|
Ada.Text_IO.Put_Line ("~~~~~~~~~~ EXCEPTION ~~~~~~~~~~" & Ada.Exceptions.Exception_Information(Error));
|
|
|
|
|
|
|
|
if File.Is_Open(F2) then
|
|
|
|
File.Close (F2);
|
|
|
|
end if;
|
|
|
|
if File.Is_Open(F) then
|
|
|
|
File.Close (F);
|
|
|
|
end if;
|
2014-06-04 17:15:52 +00:00
|
|
|
end;
|
2014-05-30 03:15:40 +00:00
|
|
|
|
|
|
|
declare
|
|
|
|
|
|
|
|
LC_ALL : constant Interfaces.C.int := 0;
|
|
|
|
procedure setlocale (
|
|
|
|
category : Interfaces.C.int;
|
|
|
|
locale : Interfaces.C.char_array);
|
|
|
|
pragma Import (C, setlocale);
|
|
|
|
Empty : aliased Interfaces.C.char_array := (0 => Interfaces.C.nul);
|
|
|
|
|
|
|
|
begin
|
|
|
|
setlocale (LC_ALL, Empty);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-03-26 14:28:41 +00:00
|
|
|
Scheme.Open (SI, 2_000_000, Pool'Unchecked_Access);
|
|
|
|
--Scheme.Open (SI, null);
|
2013-12-28 16:52:31 +00:00
|
|
|
|
2014-01-01 14:07:03 +00:00
|
|
|
-- Specify the named stream handler
|
2014-06-02 15:25:42 +00:00
|
|
|
Scheme.Set_Option (SI, (Scheme.Stream_Option,
|
|
|
|
Stream.Allocate_Stream'Access,
|
2014-01-01 14:07:03 +00:00
|
|
|
Stream.Deallocate_Stream'Access)
|
|
|
|
);
|
|
|
|
|
2014-03-26 14:28:41 +00:00
|
|
|
Scheme.Set_Option (SI, (Scheme.Trait_Option, Scheme.No_Optimization));
|
2014-01-28 15:42:28 +00:00
|
|
|
|
2014-01-01 14:07:03 +00:00
|
|
|
File_Stream.Name := File_Name'Unchecked_Access;
|
2014-01-14 14:22:06 +00:00
|
|
|
begin
|
2014-03-26 14:28:41 +00:00
|
|
|
Scheme.Set_Input_Stream (SI, File_Stream); -- specify main input stream
|
|
|
|
--Schee.Set_Input_Stream (SI, String_Stream);
|
2014-01-14 14:22:06 +00:00
|
|
|
exception
|
|
|
|
when others =>
|
|
|
|
Ada.Text_IO.Put_Line ("Cannot open Input Stream");
|
|
|
|
end;
|
2014-03-26 14:28:41 +00:00
|
|
|
--Scheme.Set_Output_Stream (SI, Stream); -- specify main output stream.
|
2014-01-01 14:07:03 +00:00
|
|
|
|
2014-01-07 17:02:12 +00:00
|
|
|
Ada.Text_IO.Put_Line ("-------------------------------------------");
|
2014-03-26 14:28:41 +00:00
|
|
|
Scheme.Run_Loop (SI, I);
|
|
|
|
Scheme.Print (SI, I);
|
|
|
|
Scheme.Close (SI);
|
2013-12-10 16:14:06 +00:00
|
|
|
|
|
|
|
Ada.Text_IO.Put_Line ("BYE...");
|
|
|
|
|
|
|
|
end scheme;
|