[gtkada] configuration files

Preben Randhol randhol at pvv.org
Wed May 29 14:59:45 CEST 2002


Stephen Leake <stephen_leake at acm.org> wrote on 29/05/2002 (14:16) :
> Preben Randhol <randhol at pvv.org> writes:
>
>
> Yes, but if I have two distinct databases, both accessed by 'myadadb',
> then I need two distinct config files. I can use /etc/myadadb/.myadadb
> and ~/.myadadb as defaults, but I also need a way to specify any
> arbitrary name (perhaps as a command line parameter).

Ah nonono then you do it like this:

you make a directory called .myadadb for the user not a file
and in this directory you can have a files called:

   program_settings.ini
   phone_db.ini
   cd_db.ini
   book_db.ini

   etc...

Then I would have put into the program_settings.ini:

[Databases]
Phone=phone_book_db.ini
CD=cd_db.ini
Book=book_db.ini

now your program reads the program_settings.ini file and read the ini
file of the database you need when you start using it.

You can alternatively do:

program_settings.ini
database_settings.ini
phone_db.ini
cd_db.ini
book_db.ini

and put the section I mentioned above in the database_settings.ini
so that you can keep the program_settings.ini as similar to the
/etc/myadadb/program_settings.ini as possible


> Well, there are other possible formats that are platform independent.
> For example, X windows stores stuff like this in a similar format; I
> have not looked at it in detail.

Section "ServerLayout"
        Identifier     "Default Layout"
        Screen         "Default Screen" 0 0
        InputDevice    "Generic Keyboard"
        InputDevice    "Configured Mouse"
        InputDevice    "Generic Mouse"
EndSection

Yes this is OK too. I meant that I want a text file that I can simply
copy to Windows from Linux or visa versa and only have to change
directory path in it to work on the other platform.

> Because they are useful. I have written applications that stored such
> data in files, so these routines are here. I like keeping things
> strongly typed, so I want more than just String, Float, Integer in
> config files.

I see, but can't we just make a

   generic
      type Data_Type is private;
   function Read
      (File    : in File_Type;
       Section : in String;
       Keyword : in String;
       Default : in Data_Type)
       return Data_Type;

But I really think it makes more sense to have all the Read functions
simply done as Strings and then we make generic functions for converting
the string to the type afterwards.

Say

   Value : Modular_Type := 1;

   Value := Get_Value
               (Section => "Somewhere",
                Keyword => "Something",
                Default => Value)

Another question should we expect the config file to be

keyword=value

in one line or can the value span several lines?

Should we have

[Directory]

or

Section "Directory"
EndSection

--
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 «For me, Ada95 puts back the joy in programming.»




More information about the gtkada mailing list