Finite Field Arithmetic

cmdline.adb


   1 ------------------------------------------------------------------------------
   2 ------------------------------------------------------------------------------
   3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'.               --
   4 --                                                                          --
   5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org )                      --
   6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html     --
   7 --                                                                          --
   8 -- You do not have, nor can you ever acquire the right to use, copy or      --
   9 -- distribute this software ; Should you use this software for any purpose, --
  10 -- or copy and distribute it to anyone or in any manner, you are breaking   --
  11 -- the laws of whatever soi-disant jurisdiction, and you promise to         --
  12 -- continue doing so for the indefinite future. In any case, please         --
  13 -- always : read and understand any software ; verify any PGP signatures    --
  14 -- that you use - for any purpose.                                          --
  15 --                                                                          --
  16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm .     --
  17 ------------------------------------------------------------------------------
  18 ------------------------------------------------------------------------------
  19 
  20 with System; use System;
  21 
  22 package body CmdLine is
  23    
  24    -- Test if GNAT's cmdline mechanism is available
  25    function Initialized return Boolean is
  26       gnat_argv : System.Address;
  27       pragma Import (C, gnat_argv, "gnat_argv");
  28 
  29    begin
  30       return gnat_argv /= System.Null_Address;
  31    end Initialized;
  32    
  33    
  34    -- Fill the provided string with the text of Number-th cmdline arg
  35    procedure Get_Argument(Number : in  Natural;
  36                           Result : out CmdLineArg) is
  37    begin
  38       if Number >= Arg_Count or (not Initialized) then
  39          raise Constraint_Error;
  40       end if;
  41       
  42       declare
  43          L   : constant Integer := Len_Arg(Number);
  44          Arg : aliased String(1 .. L);
  45       begin
  46          -- Will it fit into the available space?
  47          if L > Result'Length then
  48             raise Constraint_Error;
  49          end if;
  50          
  51          -- Get this arg string from where GNAT stowed it
  52          Fill_Arg(Arg'Address, Number);
  53          
  54          -- Copy it to Result:
  55          Result := (others => ' ');
  56          Result(Arg'Range) := Arg;
  57       end;
  58    end Get_Argument;
  59    
  60 end CmdLine;