openglada_0.9.0_4deb7eff/src/generator/generate.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--  part of OpenGLAda, (c) 2017 Felix Krause
--  released under the terms of the MIT license, see the file "COPYING"

with Ada.Command_Line;
with Ada.Containers.Indefinite_Vectors;
with Ada.Directories; use Ada.Directories;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO;

with Specs;

procedure Generate is
   Proc : Specs.Processor;

   package Spec_Vectors is new Ada.Containers.Indefinite_Vectors
     (Positive, String);

   Spec_Paths : Spec_Vectors.Vector;
   package Path_Sorting is new Spec_Vectors.Generic_Sorting;

   Source_Folder    : constant String := "src/specs";
   Target_Folder    : constant String := "src/generated";
   Interface_Folder : constant String := "src/interface";

   procedure Process_File (Directory_Entry : in Directory_Entry_Type) is
      Path : constant String := Full_Name (Directory_Entry);
   begin
      Ada.Text_IO.Put_Line ("Processing " & Path & " ...");
      Spec_Paths.Append (Path);
      Ada.Text_IO.Put_Line ("Done processing " & Path & " .");
   end Process_File;

begin
   Search (Source_Folder, "*.spec", (Ordinary_File => True, others => False),
           Process_File'Access);
   Path_Sorting.Sort (Spec_Paths);
   for Path of Spec_Paths loop
      Specs.Parse_File (Proc, Path);
   end loop;

   Create_Path (Target_Folder);
   declare
      use type Specs.Spec;
      Cur : Specs.Spec := Specs.First (Proc);
   begin
      while Cur /= Specs.No_Spec loop
         Specs.Write_API (Proc, Cur, Target_Folder);
         Cur := Specs.Next (Proc, Cur);
      end loop;
   end;
   Specs.Write_Init (Proc, Target_Folder);
   Specs.Write_Wrapper_Table (Proc, Target_Folder, Interface_Folder);
exception when Error : Specs.Parsing_Error =>
   Ada.Text_IO.Put_Line (Exception_Message (Error));
   Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
end Generate;