The task is to read a configuration file in standard configuration file format,
and set variables accordingly.

For this task, we have a configuration file as follows:

# This is a configuration file in standard configuration file format
#
# Lines beginning with a hash or a semicolon are ignored by the application
# program. Blank lines are also ignored by the application program.

# This is the fullname parameter
FULLNAME Foo Barber

# This is a favourite fruit
FAVOURITEFRUIT banana

# This is a boolean that should be set
NEEDSPEELING

# This boolean is commented out
; SEEDSREMOVED

# Configuration option names are not case sensitive, but configuration parameter
# data is case sensitive and may be preserved by the application program.

# An optional equals sign can be used to separate configuration parameter data
# from the option name. This is dropped by the parser. 

# A configuration option may take multiple parameters separated by commas.
# Leading and trailing whitespace around parameter names and parameter data fields
# are ignored by the application program.

OTHERFAMILY Rhu Barber, Harry Barber



For the task we need to set four variables according to the configuration entries as follows:

fullname = Foo Barber
favouritefruit = banana
needspeeling = true
seedsremoved = false


We also have an option that contains multiple parameters. These may be stored in an array.

 otherfamily(1) = Rhu Barber
 otherfamily(2) = Harry Barber


Related tasks
 Update a configuration file


 
set: procedure options (main);
   declare text character (100) varying;
   declare (fullname, favouritefruit) character (100) varying initial ('');
   declare needspeeling bit (1) static initial ('0'b);
   declare seedsremoved bit (1) static initial ('0'b);
   declare otherfamily(10) character (100) varying;
   declare (i, j) fixed binary;
   declare in file;
 
   open file (in) title ( '/RD-CON.DAT,TYPE(TEXT),RECSIZE(200)' );
 
   on endfile (in) go to variables;
 
   otherfamily = ''; j = 0;
 
   do forever;
      get file (in) edit (text) (L);
      text = trim(text);
 
      if length(text) = 0 then iterate;
      if substr(text, 1, 1) = ';' then iterate;
      if substr(text, 1, 1) = '#' then iterate;
      if length(text) >= 9 then
         if substr(text, 1, 9) = 'FULLNAME ' then
            fullname = trim( substr(text, 9) );
      if length(text) >= 15 then
         if substr(text, 1, 15) = 'FAVOURITEFRUIT ' then
            favouritefruit = trim( substr(text, 15) );
      if length(text) >= 12 then
         if text = 'NEEDSPEELING' then needspeeling = '1'b;
      if length(text) >= 12 then
         if text = 'SEEDSREMOVED' then seedsremoved = '1'b;
      if length(text) >= 12 then
       if substr(text, 1, 12) = 'OTHERFAMILY ' then
         do;
                  text = trim(substr(text, 12) );
                  i = index(text, ',');
                  do while (i > 0);
                     j = j + 1;
                     otherfamily(j) = substr(text, 1, i-1);
                     text = trim(substr(text, i+1));
                     i = index(text, ',');
                  end;           
                  j = j + 1;
                  otherfamily(j) = trim(text);
         end;
   end;
 
variables:
      put skip data (fullname);
      put skip data (favouritefruit);
      put skip data (needspeeling);
      put skip data (seedsremoved);
      do i = 1 to j;
         put skip data (otherfamily(i));
      end;
 
end set;
 