An Example of using CCF with Ada

Consider an environment where two (or more) slightly different Ada compilers must be used. Obviously, the thing to do is to use CCF to hide the variations as much as possible.

In addition to the real Ada source files we'll use two "support" files, one to set up the keywords for the command line, the other to check that the user typed something reasonable.


This is the file (call it vars) that sets up the variables:

.ccf:init

#### set up variables representing compiler names

.enum apex alsys verdix gnat


#### Now take advantage of CCF's somewhat lenient variable naming policy

.set compiler_type'first apex
.set compiler_type'last gnat

... and here's check, which makes sure the user's being honest:

.ccf:init

#### check compiler variable is one of those allowed

.if not ccf:defined (compiler) then
.  error "Compiler" variable not defined
.elsif compiler < compiler_type'first or compiler > compiler_type'last then
.  error Unknown compiler
.end if


With this we can use a command like

      $  ccf -V vars -H check -D compiler=alsys comp_args.ads
    

to give the following:

--## CCF:init

with SYSTEM;
with UNCHECKED_CONVERSION;
package COMP_ARGS is

  type C_STR_T is new STRING (1 .. 30_000_000);

  type C_STR_PTR_T is access C_STR_T;

  type C_STR_PTR_ARRAY_T is array (0 .. 5_000_000) of C_STR_PTR_T;

  type C_STR_PTR_ARRAY_PTR_T is access C_STR_PTR_ARRAY_T;

  ARGC : NATURAL;
  ARGV_AS_INT : INTEGER;

  --## case COMPILER
  --## when alsys
  for Argv_As_Int use at System.Address'Import
                ("C", "__argv_value");
  for Argc use at System.Address'Import ("C", "__argc_value");
  --## when verdix
  --## when apex
  --##! pragma INTERFACE_NAME (ARGV_AS_INT, "__argv_value");
  --##! pragma INTERFACE_NAME (ARGC, "__argc_value");
  --## else 
  --##   error Unknown COMPILER
  --## end case

  function CNV is new UNCHECKED_CONVERSION (INTEGER, C_STR_PTR_ARRAY_PTR_T);

  ARGV : constant C_STR_PTR_ARRAY_PTR_T := CNV (ARGV_AS_INT);

  function IMAGE (VAL : C_STR_T) return STRING;

  -- For alsys, changes to ARGV are reflected in SYSTEM_ENVIRONMENT, for
  -- verdix they are not (package U_ENV takes a local copy).

end COMP_ARGS;