config setters for number and word, thats it for now

This commit is contained in:
Christian Thaeter 2008-09-10 15:16:40 +02:00
parent 4b2973de27
commit 7c992c000d
3 changed files with 68 additions and 7 deletions

View file

@ -91,8 +91,16 @@ LumieraConfigitem
lumiera_config_number_set (const char* key, long long* value)
{
TRACE (config_typed);
UNIMPLEMENTED();
return 0;
LumieraConfigitem item = NULL;
LUMIERA_WRLOCK_SECTION (config_typed, &lumiera_global_config->lock)
{
const char* fmt = "= %lld"; TODO ("use the config system (config.format*...) to deduce the desired format for this key");
item = lumiera_config_set (key, lumiera_tmpbuf_snprintf (SIZE_MAX, fmt, *value));
}
return item;
}
@ -239,7 +247,7 @@ scan_word (const char* in)
char* end = ret;
/* chop trailing blanks */
while (*end != ' ' && *end != '\t')
while (*end && *end != ' ' && *end != '\t')
++end;
*end++ = '\0';
@ -274,8 +282,16 @@ LumieraConfigitem
lumiera_config_word_set (const char* key, const char** value)
{
TRACE (config_typed);
UNIMPLEMENTED();
return 0;
LumieraConfigitem item = NULL;
LUMIERA_WRLOCK_SECTION (config_typed, &lumiera_global_config->lock)
{
const char* fmt = "= %s"; TODO ("use the config system (config.format*...) to deduce the desired format for this key");
item = lumiera_config_set (key, lumiera_tmpbuf_snprintf (SIZE_MAX, fmt, scan_word (*value)));
}
return item;
}

View file

@ -61,7 +61,8 @@ out: LUMIERA_ERROR_CONFIG_NO_ENTRY:no configuration entry
END
PLANNED "number set" <<END
TEST "number set" number_set test.number '-123456789012345' <<END
out: '-123456789012345'
END
@ -117,7 +118,8 @@ END
unset LUMIERA_TEST_WORD
PLANNED "word set" <<END
TEST "word set" word_set test.word 'word foo bar' <<END
out: 'word'
END

View file

@ -145,6 +145,27 @@ TEST ("number_get_nodefault")
}
TEST ("number_set")
{
REQUIRE (argv[2]);
REQUIRE (argv[3]);
lumiera_config_init ("./");
signed long long number = atoll (argv[3]);
if (!lumiera_config_number_set (argv[2], &number))
printf ("failed setting number '%s=%lld': %s\n", argv[2], number, lumiera_error ());
if (lumiera_config_number_get (argv[2], &number))
printf ("'%lld'\n", number);
else
printf ("%s\n", lumiera_error ());
lumiera_config_destroy ();
}
TEST ("string_get")
{
REQUIRE (argv[2]);
@ -168,6 +189,7 @@ TEST ("string_get")
TEST ("string_set")
{
REQUIRE (argv[2]);
REQUIRE (argv[3]);
lumiera_config_init ("./");
@ -203,6 +225,27 @@ TEST ("word_get")
lumiera_config_destroy ();
}
TEST ("word_set")
{
REQUIRE (argv[2]);
REQUIRE (argv[3]);
lumiera_config_init ("./");
if (!lumiera_config_word_set (argv[2], &argv[3]))
printf ("failed setting word '%s=%s': %s\n", argv[2], argv[3], lumiera_error ());
const char* word;
if (lumiera_config_word_get (argv[2], &word))
printf ("'%s'\n", word);
else
printf ("%s\n", lumiera_error ());
lumiera_config_destroy ();
}
TEST ("configitem_simple_ctor_dtor")
{
REQUIRE (argv[2]);