| 
  
   Size: 1107 
  
  Comment:  
 | 
    ← Revision 18 as of 2019-11-27 17:56:59  ⇥ 
  Size: 5372 
  
  Comment:  
 | 
| Deletions are marked like this. | Additions are marked like this. | 
| Line 8: | Line 8: | 
|  * https://www.tutorialspoint.com/compile_ada_online.php * https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/the_gnat_library.html * https://www.adaic.org/resources/add_content/docs/craft/html/contents.htm  | 
|
| Line 25: | Line 28: | 
| use ada.text_io; | |
| Line 26: | Line 30: | 
| use gnat.calendar.time_io; | |
| Line 27: | Line 32: | 
| use ada.calendar; | |
| Line 29: | Line 35: | 
| datetime: string(1..26); -- has exactly 22 chars | datetime: string(1..26); -- has exactly 26 chars | 
| Line 32: | Line 38: | 
| datetime := gnat.calendar.time_io.image( ada.calendar.clock, "[%Y-%m-%dT%H:%M:%S.%i] " ); | datetime := image( clock, "[%Y-%m-%dT%H:%M:%S.%i] " ); | 
| Line 34: | Line 40: | 
| ada.text_io.put_line( datetime & "stuff " ); | put_line( datetime & "stuff " ); | 
| Line 36: | Line 42: | 
| Line 38: | Line 45: | 
== Person == '''person.ads''' {{{#!highlight ada -- The package encapsulates the type and code (functions,procedures) for the type. package Person is type Data is tagged private; -- constructor function Init(Name : in String; Address : in String) return Data; -- getter name function GetName(self : in Data; extra : in String) return String; -- getter address function GetAddress(self : in Data; extra : in String) return String; -- setter name procedure SetName(self : in out Data; name : in String); -- setter address procedure SetAddress(self : in out Data; address : in String); private type Data is tagged record Name : String (1 .. 10); Address : String (1 .. 10); end record; end Person; }}} '''person.adb''' {{{#!highlight ada package body Person is -- constructor function Init(Name : in String ; Address : in String) return Data is p : Person.Data;-- := (Name => Name , Address => Address); begin p.Name := Name; p.Address := Address; return p; end; -- getter name function GetName(self : in Data ; extra : in String) return String is begin return self.Name & extra; end; -- getter address function GetAddress(self : in Data ; extra : in String) return String is begin return self.Address & extra; end; -- setter name procedure SetName(self : in out Data ; name : String) is begin self.Name := name; end; -- setter address procedure SetAddress(self : in out Data ; address : String) is begin self.Address := address; end; end Person; }}} '''testperson.adb''' {{{#!highlight ada with ada.text_io; use ada.text_io; with Person; procedure TestPerson is p : Person.Data; q : Person.Data; begin p := Person.Init("0123456789", "9876543210"); q := Person.Init("aaaaaaaaaa", "bbbbbbbbbb"); q.SetName("zzzzzzzzzz"); put_line( p.GetName("ex1") & " " & p.GetAddress("ex3") ); put_line( q.GetName("ex2") & " " & q.GetAddress("ex4") ); end TestPerson; }}} * gnat make testperson.adb == Show file == '''show_file.adb''' {{{#!highlight ada with Ada.Text_IO; with Utils; with Ada.Command_Line; procedure Show_File is package acl renames Ada.Command_Line; package atio renames Ada.Text_IO; begin --Utils.Show_Content("/etc/hosts"); if acl.Argument_Count >= 1 then atio.Put_Line(acl.Argument(1)); Utils.Show_Content(acl.Argument(1)); else atio.Put_Line("Please insert the file name as an argument"); end if; end Show_File; }}} '''utils.ads''' {{{#!highlight ada package Utils is procedure Show_Content(File_Name: in String); end Utils; }}} '''utils.adb''' {{{#!highlight ada with Ada.Text_IO; package body Utils is procedure Show_Content(File_Name: in String) is package atio renames Ada.Text_IO; FileHandler : atio.File_Type; Text_Max_Size : Integer := 1024; Text : String(1 .. Text_Max_Size); Amount_Chars : Natural; begin atio.Open (FileHandler, Mode => atio.In_File, Name => File_Name); -- initialize the string for N in 1 .. Text_Max_Size loop Text(N) := '?'; end loop; while not atio.End_Of_File (FileHandler) loop atio.Get_Line(FileHandler, Text, Amount_Chars); for IDX in 1 .. Amount_Chars loop atio.Put( Text(IDX) ); end loop; --atio.Put_Line(Text); atio.New_Line; end loop; atio.Close(FileHandler); end; end Utils; }}} == Archive org - byte magazine == * https://archive.org/details/byte-magazine-1983-05/page/n419 * https://archive.org/details/byte-magazine-1983-05/page/n421 * https://archive.org/details/byte-magazine-1983-05/page/n423 * https://archive.org/details/byte-magazine-1983-12/page/n525 * https://archive.org/details/byte-magazine-1983-12/page/n527  | 
Ada
https://craftofcoding.files.wordpress.com/2013/07/ada_strings.pdf
https://www.adaic.org/resources/add_content/standards/05rm/html/RM-TOC.html
https://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT.Calendar.Time_IO
https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/the_gnat_library.html
https://www.adaic.org/resources/add_content/docs/craft/html/contents.htm
Hello world
hello.adb
- gnat make hello.adb
 
Hello date
hellodate.adb
   1 with ada.text_io;
   2 use ada.text_io;
   3 with gnat.calendar.time_io;
   4 use gnat.calendar.time_io;
   5 with ada.calendar;
   6 use ada.calendar;
   7 
   8 procedure HelloDate is
   9     datetime: string(1..26); -- has exactly 26 chars
  10 begin
  11     -- gets date to string with milliseconds
  12     datetime := image( clock, "[%Y-%m-%dT%H:%M:%S.%i] " );
  13     -- concatenetas string and shows date
  14     put_line( datetime & "stuff " );  
  15 end HelloDate;
- gnat make hellodate.adb
 
Person
person.ads
   1 -- The package encapsulates the type and code (functions,procedures) for the type.
   2 package Person is
   3    type Data is tagged private;
   4    -- constructor
   5    function Init(Name : in String; Address : in String) return Data;
   6    -- getter name
   7    function GetName(self : in Data; extra : in String) return String;
   8    -- getter address
   9    function GetAddress(self : in Data; extra : in String) return String;
  10    -- setter name
  11    procedure SetName(self : in out Data; name : in String);
  12    -- setter address
  13    procedure SetAddress(self : in out Data; address : in String);
  14    
  15    private 
  16      type Data is tagged 
  17        record
  18          Name : String (1 .. 10);
  19          Address : String (1 .. 10);
  20        end record;
  21    
  22 end Person;
person.adb
   1 package body Person is
   2 
   3    -- constructor
   4    function Init(Name : in String ; Address : in String) return Data is
   5       p : Person.Data;-- := (Name => Name , Address => Address);
   6    begin 
   7      p.Name := Name;
   8      p.Address := Address;
   9      return p;
  10    end;
  11 
  12    -- getter name
  13    function GetName(self : in Data ; extra : in String) return String is
  14    begin
  15      return self.Name & extra;
  16    end;
  17 
  18    -- getter address
  19    function GetAddress(self : in Data ; extra : in String) return String is
  20    begin
  21      return self.Address & extra;
  22    end;
  23 
  24    -- setter name
  25    procedure SetName(self : in out Data ; name : String) is
  26    begin
  27      self.Name := name;
  28    end;
  29 
  30    -- setter address
  31    procedure SetAddress(self : in out Data ; address : String) is
  32    begin
  33      self.Address := address;
  34    end;
  35    
  36 end Person;
testperson.adb
   1 with ada.text_io;
   2 use ada.text_io;
   3 with Person;
   4 
   5 procedure TestPerson is
   6   p : Person.Data;
   7   q : Person.Data;
   8 begin
   9   p := Person.Init("0123456789", "9876543210");
  10   q := Person.Init("aaaaaaaaaa", "bbbbbbbbbb");
  11   q.SetName("zzzzzzzzzz");
  12 
  13   put_line( p.GetName("ex1") & " " & p.GetAddress("ex3") );
  14   put_line( q.GetName("ex2") & " " & q.GetAddress("ex4") );
  15 end TestPerson;
- gnat make testperson.adb
 
Show file
show_file.adb
   1 with Ada.Text_IO;
   2 with Utils;
   3 with Ada.Command_Line;
   4 
   5 procedure Show_File is
   6   package acl renames Ada.Command_Line; 
   7   package atio renames Ada.Text_IO;
   8 begin
   9     --Utils.Show_Content("/etc/hosts");
  10     if acl.Argument_Count >= 1 then
  11       atio.Put_Line(acl.Argument(1));
  12       Utils.Show_Content(acl.Argument(1));
  13     else
  14       atio.Put_Line("Please insert the file name as an argument");  
  15     end if;
  16 end Show_File;
utils.ads
utils.adb
   1 with Ada.Text_IO;
   2 
   3 package body Utils is
   4 
   5   procedure Show_Content(File_Name: in String) is
   6     package atio renames Ada.Text_IO;
   7     FileHandler    : atio.File_Type;
   8     Text_Max_Size : Integer := 1024;
   9     Text : String(1 .. Text_Max_Size);
  10     Amount_Chars : Natural;
  11   begin
  12     atio.Open (FileHandler, Mode => atio.In_File, Name => File_Name);
  13     -- initialize the string
  14     for N in 1 .. Text_Max_Size loop
  15       Text(N) := '?'; 
  16     end loop;
  17 
  18     while not atio.End_Of_File (FileHandler) loop     
  19         atio.Get_Line(FileHandler, Text, Amount_Chars);
  20         for IDX in 1 .. Amount_Chars loop
  21             atio.Put( Text(IDX) );
  22         end loop;
  23         --atio.Put_Line(Text);
  24         atio.New_Line;
  25     end loop;
  26      
  27     atio.Close(FileHandler);
  28   end;
  29 end Utils;
