Code :
with Ada.Text_Io; use Ada; with System.Os_Lib; use System; with Ada.Characters.Handling; use Ada.Characters; with Ada.Command_Line; use Ada.Command_Line; with Ada.Directories; use Ada.Directories; procedure Main is function System(Cmd : in String) return Integer; pragma Import(C, System, "system" ); Errno : Integer := 0; Verax : Boolean := False; Args : Os_Lib.Argument_List_Access := new Os_Lib.Argument_List(1..0); Pid : Os_Lib.Process_Id; Prolog : Text_Io.File_Type; Ada : Text_Io.File_Type; begin Text_Io.Put("Name : " ); declare Name : String := Text_Io.Get_Line; begin Name := Handling.To_Lower(Name); Errno := System("echo is_name\(" & Name & "\). | /usr/bin/swipl -q -f " & Base_Name(Command_Name) & ".pl" & Character'Val(0)); if Os_Lib.Is_Regular_File("./error.txt" ) then Os_Lib.Delete_file("./error.txt", Verax); Text_Io.Create(Prolog, Text_Io.Out_File, Name & ".pl" ); Text_Io.Put_Line(Prolog, "name(" & Name & " )." ); Text_Io.Put_Line(Prolog, "is_name(V) :-" ); Text_Io.Put_Line(Prolog, " name(V), !," ); Text_Io.Put_Line(Prolog, " write('Eureka')" ); Text_Io.Put_Line(Prolog, "; write('false')," ); Text_Io.Put_Line(Prolog, "open('./error.txt', write, Stream)," ); Text_Io.Put_Line(Prolog, "close(Stream)." ); Text_Io.Close(Prolog); Errno := System("ln -s main bin/" & Name & Character'Val(0)); if Errno = 0 then Text_Io.Create(Ada, Text_Io.Out_File, Name & ".adb" ); Text_Io.Put_line(Ada, "with Ada.Text_Io;" ); Text_Io.Put_line(Ada, "use Ada;" ); Text_Io.Put_line(Ada, "with System.Os_Lib;" ); Text_Io.Put_line(Ada, "use System;" ); Text_Io.Put_line(Ada, "with Ada.Characters.Handling;" ); Text_Io.Put_line(Ada, "use Ada.Characters;" ); Text_Io.Put_line(Ada, "with Ada.Command_Line;" ); Text_Io.Put_line(Ada, "use Ada.Command_Line;" ); Text_Io.Put_line(Ada, "with Ada.Directories;" ); Text_Io.Put_line(Ada, "use Ada.Directories;" ); Text_Io.Put_line(Ada, "procedure " & Name & " is" ); Text_Io.New_Line(Ada); Text_Io.Put_Line(Ada, " function System(Cmd : in String) return Integer;" ); Text_Io.Put_Line(Ada, " pragma Import(C, System, ""system"" );" ); Text_Io.Put_Line(Ada, " Errno : Integer := 0;" ); Text_Io.Put_Line(Ada, " Verax : Boolean := False;" ); Text_Io.Put_Line(Ada, " Args : Os_Lib.Argument_List_Access;" ); Text_Io.Put_Line(Ada, " Pid : Os_Lib.Process_Id;" ); Text_Io.Put_Line(Ada, " Prolog : Text_Io.File_Type;" ); Text_Io.Put_Line(Ada, " Ada : Text_Io.File_Type;" ); Text_Io.Put_Line(Ada, "begin" ); Text_Io.New_Line(Ada); Text_Io.Put_Line(Ada, " Text_Io.Put(""Name : "" );" ); Text_Io.Put_Line(Ada, " declare" ); Text_Io.Put_Line(Ada, " Name : String := Text_Io.Get_Line;" ); Text_Io.Put_Line(Ada, " begin" ); Text_Io.New_Line(Ada); Text_Io.Put_Line(Ada, " Name := Handling.To_Lower(Name);" ); Text_Io.Put_Line(Ada, " Errno := System(""echo is_name\("" & Name & ""\). | /usr/bin/swipl -q -f "" & Base_Name(Command_Name) & "".pl"" & Character'Val(0));" ); Text_Io.Put_Line(Ada, " if Errno /= 0 then" ); Text_Io.Put_Line(Ada, " Text_Io.Create(Prolog, Text_Io.Out_File, Name & "".pl"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, ""name("" & Name & "" )."" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, ""is_name(V) :-"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, "" name(V), !,"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, "" write('Eureka')"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, ""; write('false'),"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, ""open('./error.txt', write, Stream),"" );" ); Text_Io.Put_Line(Ada, " Text_Io.Put_Line(Prolog, ""close(Stream)."" );" ); Text_Io.Put_Line(Ada, " Text_Io.Close(Prolog);" ); Text_Io.Put_Line(Ada, " Errno := System(""ln -s main bin/"" & Name & Character'Val(0));" ); Text_Io.Put_Line(Ada, " pid := Os_Lib.Non_Blocking_Spawn(""./bin/"" & Name, Args.all);" ); Text_Io.Put_Line(Ada, " end if;" );Errno := System("ln -s main bin/" & Name & Character'Val(0)); Text_Io.Put_Line(Ada, " end;" ); Text_Io.Put_Line(Ada, "end " & Name & ";" ); Text_Io.Close(Ada); Os_Lib.Spawn("./bin/" & Name, Args.all, verax); else Text_Io.Put("Faillure" ); end if; end if; end; exception when Text_Io.End_Error => Text_Io.Put_Line("bye!" ); end Main;
|