Re: [AD] Config files issues

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Mon, Feb 11, 2002 at 03:15:06PM +0100, Angelo Mottola wrote:
> Hum, if I get it correctly, this way a variable will always be stored
> with the type with which it was last read; this is not that good in
> certain situations, as a clueless user may change an int to bool,
> loosing informations.

Can you provide a real life example? All the while I still don't get why
it's useful to have config routines determine the type of a variable?
According to the API of Allegro 4.0 I would be doing the following in
my code:

  int value = get_config_int("player", "score", 200);

Now, if "a clueless user" edits the .cfg file and writes...

[player]
score = I have two thousand points

...I will be ignoring that anyway. Can you give me an example of types
being useful?

> What about surrounding valid strings with double quotes, allowing escape
> sequences inside the string like in C? This way we could have in a
> config file:
> 
> My_string = "This is a multiline string,
>              using the new \"filesystem-like\"
>              configure routines for Allegro 5!\n
>              Isn't this cool?"

Any way of notifying the user about parsing errors if he/she forgets
the initial " or the string ends prematurely? Apart from that, what
characters are allowed on the left of the '='? What happens with
'my=string="string"'.

> Another completely different approach to config files I was thinking
> sometime ago was to use XML. Imagine config loading/saving routines
> handling XML files as config files... This could be cool, but the
> disadvantage would be 1) to loose compatibility with the old config
> files structure and 2) the users could have problems manually editing
> the files.

Cool... so finally XML would be useful for something :-)... ahem...

OK, I forgot to ask for some features, one is even listed in the todo.txt
file, the third item from the wishlist. Basically the question is: how
is the config system going to support multiple .cfg files at the same
time? As you probably know you can have multiple files scattered around
your system, like /etc/allegro.cfg, ~/.allegro.cfg and ./allegro.cfg.

The ideal would load all of them in order, and whenever a variable is
retrieved, it would look backwards for it until it's found. Also, that
readonly variable thing could be done automatically for those .cfg files
the user doesn't have write access to.

In case you think unix is the only OS which can do this, you can have DOS
work the same way with that allegro environment variabble.  Under windows
you have the running directory and window's directory (an allegro.cfg
ala .ini). Under newer windows version where users are supported (NT?,
W2K?) maybe there's even a similar thing to a home directory.

xaviergonz@xxxxxxxxxx requested on the AL ML how to keep Allegro from
loading _any_ .cfg file. How can this be accomplished? Maybe a way to tell
Allegro what files it's allowed to load? Or the names of those files...

Finally, I would love if al_load_config_file or whatever it's called
returns a pointer to some AL_CFG structure: push/pop_config_state and
set_config_file are very horrible to use if you need to use several .cfg
files at the same time. This would require however an extra param for all
those al_get/set functions. Or let AL_CFG have pointers to the functions,
so you could write:

  AL_CFG *custom_config = al_load_config_file("database/users.cfg")
  int value = custom_config->get_int(section, variable, default);

You get rid of the al_ prefix and it looks like very OOP under plain C.

-- 
 Grzegorz Adam Hankiewicz   gradha@xxxxxxxxxx   http://gradha.infierno.org/



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/