summaryrefslogtreecommitdiff
path: root/src/fltk-show_argv.adb
blob: 52e22e24e6ac5a35ed95cc47200c32821595880e (plain)
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


--  Programmed by Jedidiah Barber
--  Released into the public domain


with

    Ada.Command_Line,
    Interfaces.C.Strings;


package body FLTK.Show_Argv is


    package ACom renames Ada.Command_Line;
    package IntC renames Interfaces.C;
    package ICS  renames Interfaces.C.Strings;


    function Create_Argv
        return ICS.chars_ptr_array
    is
        Result : ICS.chars_ptr_array (0 .. IntC.size_t (ACom.Argument_Count));
    begin
        Result (0) := ICS.New_String (ACom.Command_Name);
        for Index in Integer range 1 .. ACom.Argument_Count loop
            Result (IntC.size_t (Index)) := ICS.New_String (ACom.Argument (Index));
        end loop;
        return Result;
    end Create_Argv;


    procedure Dispatch
           (Func : in Show_With_Args_Func;
            CObj : in Storage.Integer_Address)
    is
        Argv : ICS.chars_ptr_array := Create_Argv;
    begin
        Func (CObj, IntC.int (ACom.Argument_Count + 1),
            Storage.To_Integer (Argv (Argv'First)'Address));
        for Ptr of Argv loop
            ICS.Free (Ptr);
        end loop;
    end Dispatch;


end FLTK.Show_Argv;