[gtkada] configuration files
Preben Randhol
randhol at pvv.org
Tue May 28 14:08:15 CEST 2002
Jacob Sparre Andersen <sparre at nbi.dk> wrote on 28/05/2002 (13:44) :
> It looks reasonable execept for a few details:
>
> * I would like to have the option of reading the settings
> from a prioritised list of configuration files, and not
> just a single named file.
Do you want the pacakge to search through the files over and over again
to find the value you want?
> * The above mentioned prioritised list of configuration
> files should be initialised according to the conventions
> of the operating system used.
What do you mean by this?
> * It would be practical to include a function for reading
> the configuration file(s) into a suitable data structure,
> so the files only need to be read once during the
> execution of a program.
Why do we need to do it some complicated? This sounds like XML.
First settings files change from version to version of the program. So
the first thing we need to do is to
1) Find out that this is a config file for this program
2) Which version of the program
Number 2 is perhaps not so imporant for settings files (except see to
that the settings files gets updated when the software is updated),
but if your program needs to read data files it must know which
version of the program that generated them. And therefore it would be
nice to have this functionality that one can use on other settings.
Say the program contains a procedure called Read_Settings then he can
simply do:
procedure Read_Settings
(Version : Float)
is
-- ...
begin
if Version <= 1.0 then
Read ("Directory.Help", Help_Directory);
Read ("Directory.Graphics", Graphics_Directory);
Read ("Entry.Max_Value", Max_Value);
elsif Version > 1.0 and Version <= 2.0 then
Read ("Directory.Help", Help_Directory);
Read ("Directory.Graphics", Graphics_Directory);
Read ("Directory.Data", Data_Directory);
Read ("Entry.Max_Value", Max_Value);
-- etc
end if;
end Read_Settings;
The program will be writing and reading the settings files so the
programmer knows the order in which the data comes. There is no need to
add extra dynamic. If there is a mistake in the settings file a
Program_Error should be raised I think.
--
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
«For me, Ada95 puts back the joy in programming.»
More information about the gtkada
mailing list