Natools

Check-in [02abd531c8]
Login
Overview
Comment:generate_static_hash_map: add a target directory command-line option
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 02abd531c8eb96d277cebb1b2018dd05826b6497
User & Date: nat on 2014-06-20 20:04:09
Other Links: manifest | tags
Context
2014-06-21
19:52
s_expressions-encodings: replace assert-in-loop by asserting a slice comparison check-in: 6fad53c7fc user: nat tags: trunk
2014-06-20
20:04
generate_static_hash_map: add a target directory command-line option check-in: 02abd531c8 user: nat tags: trunk
2014-06-18
17:57
cron: add support for synchronized events check-in: 04a8a351dd user: nat tags: trunk
Changes

Modified tools/generate_static_hash_map.adb from [977ec5056f] to [64d024846d].

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
57
------------------------------------------------------------------------------
-- Generate_Static_Hash_Map is a command-line interface to the static hash  --
-- map package generator, using a description from S-expression files.      --
-- It also provides bootstrap for the S-expression description interpreter. --
------------------------------------------------------------------------------

with Ada.Command_Line;

with Ada.Text_IO;
with Natools.Static_Hash_Maps.S_Expressions;
with Natools.S_Expressions.File_Readers;
with Natools.S_Expressions.Lockable;

procedure Generate_Static_Hash_Map is



begin
   if Ada.Command_Line.Argument_Count = 0 then







      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "Usage: " & Ada.Command_Line.Command_Name

         & " input.sx [other-input.sx ...]");
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "   special argument ""--"" instead of input file bootstraps the");
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "   descriptor interpreter hash map.");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;

   for I in 1 .. Ada.Command_Line.Argument_Count loop
      if Ada.Command_Line.Argument (I) = "--" then
         declare
            use Natools.Static_Hash_Maps;
         begin





            Generate_Package
              ("Natools.Static_Hash_Maps.S_Expressions.Command_Maps",
               (Map
                 (Element_Type => "Package_Command",
                  Hash_Package_Name =>
                    "Natools.Static_Hash_Maps.S_Expressions.Command_Pkg",
                  Function_Name => "To_Package_Command",







>






>
>
>

|
>
>
>
>
>
>
>



>











|




>
>
>
>
>







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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
------------------------------------------------------------------------------
-- Generate_Static_Hash_Map is a command-line interface to the static hash  --
-- map package generator, using a description from S-expression files.      --
-- It also provides bootstrap for the S-expression description interpreter. --
------------------------------------------------------------------------------

with Ada.Command_Line;
with Ada.Directories;
with Ada.Text_IO;
with Natools.Static_Hash_Maps.S_Expressions;
with Natools.S_Expressions.File_Readers;
with Natools.S_Expressions.Lockable;

procedure Generate_Static_Hash_Map is
   Dir_Arg : Natural := 0;
   First_Arg : Positive := 1;
   Prev_Dir : constant String := Ada.Directories.Current_Directory;
begin
   if Ada.Command_Line.Argument_Count >= 2
     and then Ada.Command_Line.Argument (1) = "-C"
   then
      Dir_Arg := 2;
      First_Arg := 3;
   end if;

   if Ada.Command_Line.Argument_Count < First_Arg then
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "Usage: " & Ada.Command_Line.Command_Name
         & " [-C target_directory]"
         & " input.sx [other-input.sx ...]");
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "   special argument ""--"" instead of input file bootstraps the");
      Ada.Text_IO.Put_Line
        (Ada.Text_IO.Current_Error,
         "   descriptor interpreter hash map.");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;

   for I in First_Arg .. Ada.Command_Line.Argument_Count loop
      if Ada.Command_Line.Argument (I) = "--" then
         declare
            use Natools.Static_Hash_Maps;
         begin
            if Dir_Arg > 0 then
               Ada.Directories.Set_Directory
                 (Ada.Command_Line.Argument (Dir_Arg));
            end if;

            Generate_Package
              ("Natools.Static_Hash_Maps.S_Expressions.Command_Maps",
               (Map
                 (Element_Type => "Package_Command",
                  Hash_Package_Name =>
                    "Natools.Static_Hash_Maps.S_Expressions.Command_Pkg",
                  Function_Name => "To_Package_Command",
65
66
67
68
69
70
71




72
73
74

75
76
77
78





79
80
81




82
83
84
85
                  Function_Name => "To_Map_Command",
                  Nodes =>
                    (Node ("hash-package", "Hash_Package"),
                     Node ("nodes", "Nodes"),
                     Node ("function", "Function_Name"),
                     Node ("not-found", "Not_Found")))),
               Private_Child => True);




         end;
      else
         declare

            Input : Natools.S_Expressions.Lockable.Descriptor'Class
              := Natools.S_Expressions.File_Readers.Reader
                  (Ada.Command_Line.Argument (I));
         begin





            Natools.Static_Hash_Maps.S_Expressions.Generate_Packages
              (Input,
               "from " & Ada.Command_Line.Argument (I));




         end;
      end if;
   end loop;
end Generate_Static_Hash_Map;







>
>
>
>



>




>
>
>
>
>



>
>
>
>




82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                  Function_Name => "To_Map_Command",
                  Nodes =>
                    (Node ("hash-package", "Hash_Package"),
                     Node ("nodes", "Nodes"),
                     Node ("function", "Function_Name"),
                     Node ("not-found", "Not_Found")))),
               Private_Child => True);

            if Dir_Arg > 0 then
               Ada.Directories.Set_Directory (Prev_Dir);
            end if;
         end;
      else
         declare
            Prev_Dir : constant String := Ada.Directories.Current_Directory;
            Input : Natools.S_Expressions.Lockable.Descriptor'Class
              := Natools.S_Expressions.File_Readers.Reader
                  (Ada.Command_Line.Argument (I));
         begin
            if Dir_Arg > 0 then
               Ada.Directories.Set_Directory
                 (Ada.Command_Line.Argument (Dir_Arg));
            end if;

            Natools.Static_Hash_Maps.S_Expressions.Generate_Packages
              (Input,
               "from " & Ada.Command_Line.Argument (I));

            if Dir_Arg > 0 then
               Ada.Directories.Set_Directory (Prev_Dir);
            end if;
         end;
      end if;
   end loop;
end Generate_Static_Hash_Map;