[AD] Allegro, config file routines addition |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
Greetings to you... was writing some config
file loading routines, and I wanted a feature not too dissimilar to
classic Windows boolean INI file
entries.
Below is the solution I used, get_config_boolean().
Allegro has been a great help to me, and I hope someone
finds some use out of this.
Returns:
0 if config entry is (case-insensitive strings) FALSE, OFF, or
NO;
1 if TRUE, ON, or YES; and
if neither, it tries to convert it to a
number using atoi() (which would return 0 if it was not a number at all) and
return that as the value.
#include <allegro.h>
#include <string.h> #include <stdlib.h>
int get_config_boolean(char *section, char *name, char *def)
{ char *tmp; int value; tmp = get_config_string(section, name,
def);
if (!stricmp(tmp, "false")) value =
0;
else if (!stricmp(tmp, "true")) value = 1; else if (!stricmp(tmp, "off")) value = 0; else if (!stricmp(tmp, "on")) value = 1; else if (!stricmp(tmp, "no")) value = 0; else if (!stricmp(tmp, "yes")) value = 1; else value = atoi(tmp); return value;
} -Charles Bilyue'
|
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |